Added Demo & Siemens tools management

This commit is contained in:
Lucio Maranta
2018-04-19 15:52:31 +00:00
parent d7eec792b3
commit 2a03078e34
20 changed files with 1558 additions and 1583 deletions
+32 -28
View File
@@ -77,6 +77,8 @@ namespace CMS_CORE_Application
List<FunctionalityModel> functionality = new List<FunctionalityModel>();
AxisResetDataModel axesReset = new AxisResetDataModel();
ProcessDataModel processData = new ProcessDataModel();
ToolTableConfiguration toolsConfig = new ToolTableConfiguration();
List<SiemensToolModel> dataTable = new List<SiemensToolModel>();
byte axisId = 0;
@@ -116,7 +118,7 @@ namespace CMS_CORE_Application
error = true;
SetError(Lines, cmsError);
}
cmsError = N.PLC_RActiveMessages(ref Msg);
if (cmsError.IsError())
{
@@ -137,7 +139,7 @@ namespace CMS_CORE_Application
error = true;
SetError(Lines, cmsError);
}
// cmsError = N.PLC_WRefreshMessage(1);
if (cmsError.IsError())
{
error = true;
@@ -150,34 +152,35 @@ namespace CMS_CORE_Application
error = true;
SetError(Lines, cmsError);
}
// N.PLC_WPowerOnData(6, true);
N.PLC_RFunctionAccess(ref functionality);
N.PLC_RAxesResetData(ref axesReset);
cmsError = N.PLC_RUserSoftKeys(ref keys);
cmsError = N.PLC_RNcSoftKeys(ref keys);
N.PROC_RSelectedProcess(ref procnum);
// cmsError = N.PLC_WNcSoftKey(1);
// cmsError = N.PLC_WUserSoftKey(1);
//N.PLC_WRefreshAllMessages();
N.PROC_RStatusAndData(1, ref processData);
sw.Restart();
cmsError = N.AXES_RAxesNames(1, ref axesNames);
//cmsError = N.AXES_WSelectAxis(2);
//N.PROC_WSelectProcess(4);
cmsError = N.AXES_RSelectedAxis(ref axisId);
//cmsError = N.PLC_WRefreshAllMessages();
cmsError = N.TOOLS_RConfiguration(ref toolsConfig);
// cmsError = N.PLC_WRefreshAllMessages();
cmsError = N.PLC_RHeadsData(headsTest, 1);
cmsError = N.PLC_WHeadOverride(1, HEAD_OVERRIDE_SIGN.MINUS);
Dictionary<int, string> messages = new Dictionary<int, string>();
cmsError = N.NC_GetTranslatedPlcMessages("it", ref messages);
MessageBox.Show(messages.Count.ToString() + " " + messages.FirstOrDefault());
//cmsError = N.PROC_RSelectedProcess(ref procnum);
cmsError = N.TOOLS_RToolTable(ref dataTable);
// N.PLC_WPowerOnData(6, true);
//N.PLC_RFunctionAccess(ref functionality);
//N.PLC_RAxesResetData(ref axesReset);
//cmsError = N.PLC_RUserSoftKeys(ref keys);
//cmsError = N.PLC_RNcSoftKeys(ref keys);
//N.PROC_RSelectedProcess(ref procnum);
//cmsError = N.PLC_WNcSoftKey(1);
//// cmsError = N.PLC_WUserSoftKey(1);
//N.PROC_RStatusAndData(1, ref processData);
//sw.Restart();
//cmsError = N.AXES_RAxesNames(1, ref axesNames);
////cmsError = N.AXES_WSelectAxis(2);
////N.PROC_WSelectProcess(4);
//cmsError = N.AXES_RSelectedAxis(ref axisId);
////cmsError = N.PLC_WRefreshAllMessages();
//cmsError = N.PLC_WHeadOverride(1, HEAD_OVERRIDE_SIGN.MINUS);
//Dictionary<int, string> messages = new Dictionary<int, string>();
//cmsError = N.NC_GetTranslatedPlcMessages("it", ref messages);
//MessageBox.Show(messages.Count.ToString() + " " + messages.FirstOrDefault());
////cmsError = N.PROC_RSelectedProcess(ref procnum);
sw.Stop();
if (!this.IsDisposed && this.InvokeRequired)
@@ -396,6 +399,7 @@ namespace CMS_CORE_Application
private void Disconnect_Click(object sender, EventArgs e)
{
N.NC_Disconnect();
if (t != null)
t.Abort();
//if (toolThread != null)
+2
View File
@@ -137,6 +137,7 @@
<Compile Include="Demo\Models\NcAxisModel.cs" />
<Compile Include="Demo\Models\NcDataModel.cs" />
<Compile Include="Demo\Models\NcProcessModel.cs" />
<Compile Include="Demo\Models\ToolsDataModel.cs" />
<Compile Include="Demo\Nc_Demo.cs" />
<Compile Include="Exceptions\Nc_Exception.cs" />
<Compile Include="Fanuc\fwlib32_64.cs" />
@@ -146,6 +147,7 @@
<Compile Include="Osai\OSAIErrMgr.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Siemens\Nc_Siemens.cs" />
<Compile Include="Siemens\ToolsConfiguration.cs" />
<Compile Include="Utils\Nc_Utils.cs" />
</ItemGroup>
<ItemGroup>
+106
View File
@@ -339,6 +339,8 @@ namespace CMS_CORE_Library
#endregion Cms Errors Codes
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Constants
public const int USER_SOFTKEYS_NUMBER = 128;
@@ -401,5 +403,109 @@ namespace CMS_CORE_Library
};
#endregion Constants
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region ToolsConfig
public enum ROTATION
{
NONE = 0,
CLOCKWHISE = 1,
COUNTERCLOCKWHISE = 2
}
public enum MAGAZINE_TYPE
{
MAGAZINE = 0,
SPINDLE = 1,
MAGAZINE_GROUND = 2
}
public class ToolConfiguration
{
public string Name;
public string Type;
public Dictionary<int, string> SelectValues;
}
public static List<ToolConfiguration> SiemensToolsConfig = new List<ToolConfiguration>()
{
new ToolConfiguration{Name = "id", Type = "int", SelectValues = null},
new ToolConfiguration{Name = "name", Type = "string", SelectValues = null},
new ToolConfiguration{Name = "childId", Type = "int", SelectValues = null},
new ToolConfiguration{Name = "isActive", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "isInhibited", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "fixedPlace", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "isMeasured", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "changeTool", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "isInUse", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "preAlarm", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "cooling1", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "cooling2", Type = "boolean", SelectValues = null},
new ToolConfiguration{Name = "rotation", Type = "select",
SelectValues = new Dictionary<int, string>()
{
{0, "none"},
{1, "clockWhise"},
{2, "counterClockWhise"}
}},
new ToolConfiguration{Name = "toolLife", Type="select", SelectValues = new Dictionary<int, string>()
{
{0, "toolLifeType"},
{1, "countLife"},
{2, "wearLife"}
}},
new ToolConfiguration{Name = "edgeId", Type = "int", SelectValues = null},
new ToolConfiguration{Name = "edgeResidualLife", Type = "double", SelectValues = null},
new ToolConfiguration{Name = "edgeNominalLife", Type = "double", SelectValues = null},
new ToolConfiguration{Name = "edgeNominalLife", Type = "double", SelectValues = null},
new ToolConfiguration{Name = "edgePreAlarmVal", Type = "double", SelectValues = null},
new ToolConfiguration{Name= "toolType", Type = "select",
SelectValues = new Dictionary<int, string>()
{
{100, "milling"},
{110, "ballNoseAndMill"},
{111, "canonicalBallEnd"},
{120, "endMill" }
}}
};
public class MagazineModel
{
public int Id;
public MAGAZINE_TYPE Type;
}
public class ToolTableConfiguration
{
public List<MagazineModel> Magazines;
public List<ToolConfiguration> FieldsConfiguration;
}
public class SiemensToolModel
{
public int Id;
public string FamilyName;
public int ChildId;
public int MagazinePositionType;
public int ToolType;
public int LeftSize;
public int RightSize;
public ROTATION Rotation;
public bool Cooling1;
public bool Cooling2;
public bool IsActive;
public bool FixedPlace;
public bool IsInhibited;
public bool IsMeasured;
public bool ChangeTool;
public bool IsInUse;
public bool PreAlarm;
public List<Dictionary<string, double>> EdgesData;
}
#endregion ToolsConfig
}
}
+7
View File
@@ -156,5 +156,12 @@ namespace Nc_Demo_Application.Server.Service
[WebGet(UriTemplate = "translation/{language}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void GetTranslations(string language, out Dictionary<int, string> fileContent);
#endregion
#region Tools
[WebGet(UriTemplate = "tool_table", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void GetTools(out List<ToolsDataModel> toolsData);
#endregion
}
}
+66
View File
@@ -1702,6 +1702,72 @@ namespace CMS_CORE.Demo
}
#endregion File Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Tools Management
public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config)
{
config.FieldsConfiguration = SiemensToolsConfig;
config.Magazines = new List<MagazineModel>()
{
new MagazineModel{Id = 1, Type = MAGAZINE_TYPE.MAGAZINE},
new MagazineModel{Id = 2, Type = MAGAZINE_TYPE.MAGAZINE},
new MagazineModel{Id = 3, Type = MAGAZINE_TYPE.SPINDLE},
};
return NO_ERROR;
}
public override CmsError TOOLS_RToolTable(ref List<SiemensToolModel> toolTable)
{
// Check if the NC Demo is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
try
{
toolTable = new List<SiemensToolModel>();
// Get tool table data
serverService.GetTools(out List<ToolsDataModel> toolsData);
foreach(ToolsDataModel tool in toolsData)
{
toolTable.Add(new SiemensToolModel()
{
Id = tool.Id,
FamilyName = tool.FamilyName,
ChildId = tool.ChildId,
MagazinePositionType = tool.MagazinePositionType,
ToolType = tool.ToolType,
LeftSize = tool.LeftSize,
RightSize = tool.RightSize,
Rotation = (ROTATION)tool.Rotation,
Cooling1 = tool.Cooling1,
Cooling2 = tool.Cooling2,
IsActive = tool.IsActive,
FixedPlace = tool.FixedPlace,
IsInhibited = tool.IsInhibited,
IsMeasured = tool.IsMeasured,
ChangeTool = tool.ChangeTool,
IsInUse = tool.IsInUse,
PreAlarm = tool.PreAlarm,
EdgesData = tool.EdgesData
});
}
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
#endregion Tools Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+15
View File
@@ -1664,6 +1664,21 @@ namespace CMS_CORE.Fanuc
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Tools Management
public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config)
{
return NO_ERROR;
}
public override CmsError TOOLS_RToolTable(ref List<SiemensToolModel> toolTable)
{
return NO_ERROR;
}
#endregion Tools Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Subordinate Private Functions
private CmsError ErrorHandler(short exNum)
+34 -3
View File
@@ -17,9 +17,10 @@ namespace CMS_CORE
internal ushort Port;
internal Boolean UseProxy;
internal String LibName = "CMS_CORE_Library.dll";
//Osai Variable
internal string OSAI_PlcMessagesPath = @"C:\CMS\OSAI\";
internal string OSAI_WinNbiPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\OSAI\WinNBI\";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -464,7 +465,7 @@ namespace CMS_CORE
* </summary>
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
* <param name="id">Alarm id to restore</param>
*
*
* */
public abstract CmsError PLC_WRestoreMessage(uint id);
@@ -809,7 +810,7 @@ namespace CMS_CORE
public abstract CmsError AXES_RAxesNames(ushort process, ref List<AxisModel> axesData);
public abstract CmsError AXES_RSelectedAxis(ref byte axisId);
public abstract CmsError AXES_WSelectAxis(byte axisId);
#endregion AXES data (to override)
@@ -1275,6 +1276,36 @@ namespace CMS_CORE
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region File Management (To override)
/**
* <summary>Read tool table configuration
* <para>
* Compatibility: Fanuc | Osai | Demo | Siemens
* </para>
* </summary>
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
* <param name="config">Reference to the tool table configuration data</param>
**/
public abstract CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config);
/**
* <summary>Read tool table data
* <para>
* Compatibility: Siemens
* </para>
* </summary>
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
* <param name="config">Reference to the tool table data object</param>
**/
public abstract CmsError TOOLS_RToolTable(ref List<SiemensToolModel> toolTable);
#endregion File Management (To override)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region CONSTANTS (Struct and Enum are Static for definition)
// Read Write type
+17
View File
@@ -15,6 +15,7 @@ using System.Threading;
using static CMS_CORE_Library.DataStructures;
using static CMS_CORE.Nc;
using static CMS_CORE.Osai.MEMORY_ADDRESS;
using CMS_CORE_Library;
namespace CMS_CORE.Osai
{
@@ -2032,6 +2033,22 @@ namespace CMS_CORE.Osai
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Tools Management
public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config)
{
return NO_ERROR;
}
public override CmsError TOOLS_RToolTable(ref List<SiemensToolModel> toolTable)
{
return NO_ERROR;
}
#endregion Tools Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Subordinate Private Functions
private void SetupAckStrobeAddresses(int ackAddress, int strobeAddress, uint id, out int ackWord, out int strobeWord, out int bit)
+160 -1
View File
@@ -1,4 +1,6 @@
using CMS_CORE.Utils;
using CMS_CORE_Library;
using CMS_CORE_Library.Siemens;
using Siemens.Sinumerik.Operate.Services;
using System;
using System.Collections;
@@ -13,6 +15,7 @@ using System.Xml.Linq;
using static CMS_CORE.Nc;
using static CMS_CORE.Siemens.MEMORY_ADDRESS;
using static CMS_CORE_Library.DataStructures;
using static Siemens.Sinumerik.Operate.Services.ToolMngmntSvc;
namespace CMS_CORE.Siemens
{
@@ -62,11 +65,15 @@ namespace CMS_CORE.Siemens
// STatic variables
private AlarmSvc SiemensAlmSvc;
private ToolMngmntSvc SiemensToolSvc = null;
private Guid ToolMngmtListGuid = Guid.Empty;
private Alarm[] SiemensAlarms;
private static string PlcMessagesFilePath = "C:\\Program Files (x86)\\Siemens\\MotionControl\\oem\\sinumerik\\hmi\\lng\\";
private const string AXES_FILE_PATH = "C:\\CMS\\axes.xml";
private static List<SiemensToolModel> ToolTableData = new List<SiemensToolModel>();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Contructor & global methods
@@ -112,6 +119,10 @@ namespace CMS_CORE.Siemens
SiemensAlarms = new Alarm[] { };
SiemensAlmSvc = new AlarmSvc(ConvertToSTEPLanguage(SiemensLanguage).ThreeLetterISOLanguageName);
SiemensAlmSvc.Subscribe(AlarmsChanged);
SiemensToolSvc = new ToolMngmntSvc(1);
ToolMngmtListGuid = SiemensToolSvc.Subscribe(TOOLS_UpdateToolsData);
}
catch (Exception ex)
{
@@ -126,7 +137,7 @@ namespace CMS_CORE.Siemens
{
//Set Connected to FALSE and close the session
Connected = false;
// SiemensToolSvc.UnSubscribe(TOOLS_UpdateToolsData);
return NO_ERROR;
}
@@ -1721,6 +1732,144 @@ namespace CMS_CORE.Siemens
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Tool Management
public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config)
{
config.FieldsConfiguration = SiemensToolsConfig;
return NO_ERROR;
}
public override CmsError TOOLS_RToolTable(ref List<SiemensToolModel> toolTable)
{
toolTable = ToolTableData;
return NO_ERROR;
}
private void TOOLS_UpdateToolsData(Guid guid, ToolInfo[] toolInfos)
{
try
{
for (int i = 0; i < toolInfos.Count(); i++)
{
TOOLS_ChooseActions(toolInfos[i]);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private CmsError TOOLS_ChooseActions(ToolInfo toolInfo)
{
try
{
switch (toolInfo.action)
{
case ToolAction.TOOL_DELETED:
{
var tool = ToolTableData.SingleOrDefault(t => t.Id == toolInfo.tNo);
if (tool != null)
ToolTableData.Remove(tool);
}
break;
case ToolAction.TOOL_CREATED:
{
// Create a configuration file
FileStream f = new FileStream("C:\\TO_INI.INI", FileMode.Create);
// Read siemens configuration file
FILES_RProgramToFile("//NC/ACT.DIR/TO.DIR/TO_INI.INI", f);
f.Close();
string[] toolStrings = File.ReadAllLines("C:\\TO_INI.INI");
var newTool = TOOLS_CreateToolFromType((int)toolInfo.tNo, toolStrings);
ToolTableData.Add(newTool);
}
break;
case ToolAction.TOOL_DATA_CHANGED: { } break;
case ToolAction.TOOL_MOVED: { } break;
}
} catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return NO_ERROR;
}
private SiemensToolModel TOOLS_CreateToolFromType(int toolId, string[] toolStrings)
{
// Find its status
var toolStatus = Convert.ToByte(toolStrings.FirstOrDefault(X => X.Contains("$TC_TP8[" + toolId)).Split('=').LastOrDefault());
// Find basic info (rotation, cooling ...)
var toolInfo = Convert.ToInt32(toolStrings.FirstOrDefault(X => X.Contains("$TC_DP25[" + toolId)).Split('=').LastOrDefault());
// Get rotation data
ROTATION rotation = ROTATION.NONE;
if (GetBitValue(toolInfo, 9))
rotation = ROTATION.CLOCKWHISE;
else if (GetBitValue(toolInfo, 10))
rotation = ROTATION.COUNTERCLOCKWHISE;
// Create tool model
SiemensToolModel toolValues = new SiemensToolModel()
{
Id = toolId,
FamilyName = toolStrings.FirstOrDefault(x => x.Contains("$TC_TP2[" + toolId)).Split('=').LastOrDefault(),
ChildId = Convert.ToInt32(toolStrings.FirstOrDefault(x => x.Contains("$TC_TP1[" + toolId)).Split('=').LastOrDefault()),
// ToolType = toolType,
LeftSize = Convert.ToByte(toolStrings.FirstOrDefault(X => X.Contains("$TC_TP3[" + toolId)).Split('=').LastOrDefault()),
RightSize = Convert.ToByte(toolStrings.FirstOrDefault(X => X.Contains("$TC_TP4[" + toolId)).Split('=').LastOrDefault()),
Rotation = rotation,
Cooling1 = GetBitValue(toolInfo, 11),
Cooling2 = GetBitValue(toolInfo, 12),
IsActive = GetBitValue(toolStatus, 1),
FixedPlace = GetBitValue(toolStatus, 2),
IsInhibited = GetBitValue(toolStatus, 3),
IsMeasured = GetBitValue(toolStatus, 4),
ChangeTool = GetBitValue(toolStatus, 5),
IsInUse = GetBitValue(toolStatus, 7),
PreAlarm = GetBitValue(toolStatus, 8),
EdgesData = new List<Dictionary<string, double>>()
};
// LEGGERE MAX = $MN_MM_MAX_CUTTING_EDGE_PERTOOL
// For each possible edges
for(int i = 0; i < 5; i++)
{
// Find the type of the edges
var toolType = toolStrings.FirstOrDefault(X => X.Contains("$TC_DP1[" + toolId + "," + i));
// If type doesn't exist than edges doesn't exist
if( toolType != null)
{
int toolTypeVal = Convert.ToByte(toolType.Split('=').LastOrDefault());
// Get tool type additional parameters
SiemensAdditionalParams toolsConfig = new SiemensAdditionalParams();
var toolTypeConfig = toolsConfig.ToolsSettings[toolTypeVal];
Dictionary<string, double> tmpDictionary = new Dictionary<string, double>();
// For each parameter
foreach (var item in toolTypeConfig)
{
tmpDictionary.Add(
item.Name,
Convert.ToDouble(toolStrings.FirstOrDefault(X => X.Contains(item.Path + toolId + "," + i)).Split('=').LastOrDefault())
);
}
toolValues.EdgesData.Add(tmpDictionary);
}
}
return toolValues;
}
#endregion Tool Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Subordinate Private Functions
//Manage the Alarms - Called automatically on changes
@@ -1729,6 +1878,16 @@ namespace CMS_CORE.Siemens
SiemensAlarms = alarms;
}
private bool GetBitValue(int b, int bitNumber)
{
return (b & (1 << bitNumber - 1)) != 0;
}
private bool GetBitValue(byte b, int bitNumber)
{
return (b & (1 << bitNumber - 1)) != 0;
}
//Manage the Mode
private PROC_MODE ConvertToSTEPMode(uint mode, uint JogMode, uint AdvMode)
{
@@ -141,9 +141,6 @@
<Compile Include="Views\ToolStripEx.cs">
<SubType>Component</SubType>
</Compile>
<EmbeddedResource Include="Views\DemoApplicationForm.resx">
<DependentUpon>DemoApplicationForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -154,6 +151,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Views\DemoApplicationForm.resx">
<DependentUpon>DemoApplicationForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\StartupPanel.resx">
<DependentUpon>StartupPanel.cs</DependentUpon>
</EmbeddedResource>
@@ -14,8 +14,8 @@ namespace Nc_Demo_Application
public const string READ_NC_ALARMS_QUERY = "SELECT * FROM alarm";
public const string READ_NC_AXES_QUERY = "SELECT * FROM axis";
public const string READ_BINARY_MEMORY_QUERY = "SELECT * FROM binary_memory";
public const string READ_TOOLS_QUERY = "SELECT * FROM tools";
// Server configuration
public static string SERVER_PORT = ":8080";
public const string SERVER_IP_ADDRESS = "http://localhost";
@@ -27,6 +27,37 @@ namespace Nc_Demo_Application
// CMS Process mode
public enum PROC_MODE : ushort { AUTO = 1, EDIT = 2, MDI = 3, REMOTE = 4, TEACH = 5, REF = 6, JOG = 7, JOGINC = 8, RETPROF = 9, HANDLE = 10, RESTART = 11, ERROR = 12 };
public enum ROTATION
{
NONE = 0,
CLOCKWHISE = 1,
COUNTERCLOCKWHISE = 2
}
public enum TOOLS_TYPE
{
MILLING = 100,
BALL_NOSE = 110,
BALL_END = 111,
END_MILL = 120,
END_MILL_CORNER = 121,
ANGLE_HEAD_CUTTER = 130,
CORN_ROUND_ANDLE_HD_CUT = 131,
FACING_TOOL = 140,
THREAD_CUTTER = 145,
SAW = 151,
BEVELLED_CUTTER = 155,
BEVELLED_CUTTER_CORNER = 156,
TAP_DIESINK_CUTTER = 157,
DRILL_THREAD_CUTTER = 160
}
public enum MAGAZINES
{
MAGAZINE1 = 0,
MAGAZINE2 = 1,
SPINDLE = 2
}
// File
public const string FILE_FOLDER = "./part_program/";
public const string LANGUAGE_FOLDER = "./Languages/";
@@ -1,40 +1,40 @@
using System;
using Nc_Demo_Application.Database.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Nc_Demo_Application.Database.Models;
using static Nc_Demo_Application.Constants;
namespace Nc_Demo_Application.Database
{
class DatabaseController
internal class DatabaseController
{
private static DatabaseController databaseInstance;
private static SQLiteConnection sqlConnection;
private static SQLiteCommand sqlCommand;
private DataTable ncDatatable;
private DataTable ncProcessDataTable;
private DataTable ncAlarmDataTable;
private DataTable ncAxesDataTable;
private DataTable NcDatatable;
private DataTable NcProcessDataTable;
private DataTable NcAlarmDataTable;
private DataTable NcAxesDataTable;
private DataTable BinaryMemory;
private DataTable ToolsDataTable;
private DatabaseController()
{
SetConnection();
ncDatatable = new DataTable();
ncAlarmDataTable = new DataTable();
ncAxesDataTable = new DataTable();
NcDatatable = new DataTable();
NcAlarmDataTable = new DataTable();
NcAxesDataTable = new DataTable();
ncProcessDataTable = new DataTable();
NcProcessDataTable = new DataTable();
// Create ncProcess columns
ncProcessDataTable.Columns.Add("status", typeof(PROC_STATUS));
ncProcessDataTable.Columns.Add("mode", typeof(PROC_MODE));
NcProcessDataTable.Columns.Add("status", typeof(PROC_STATUS));
NcProcessDataTable.Columns.Add("mode", typeof(PROC_MODE));
BinaryMemory = new DataTable();
@@ -45,6 +45,8 @@ namespace Nc_Demo_Application.Database
BinaryMemory.Columns.Add("binary", typeof(string)).SetOrdinal(2);
BinaryMemory.Columns.Add("word", typeof(short)).SetOrdinal(3);
BinaryMemory.Columns.Add("integer", typeof(int)).SetOrdinal(4);
ToolsDataTable = new DataTable();
}
public static DatabaseController getInstance()
@@ -64,9 +66,10 @@ namespace Nc_Demo_Application.Database
public void ResetDatabase()
{
BinaryMemory.Dispose();
ncProcessDataTable.Dispose();
ncAlarmDataTable.Dispose();
ncAxesDataTable.Dispose();
NcProcessDataTable.Dispose();
NcAlarmDataTable.Dispose();
NcAxesDataTable.Dispose();
ToolsDataTable.Dispose();
sqlConnection.Close();
}
@@ -88,11 +91,12 @@ namespace Nc_Demo_Application.Database
}
#region Nc Data Methods
public NcDataModel ReadNcData()
{
try
{
ReadDataFromDatabase(READ_NC_DATA_QUERY, ref ncDatatable);
ReadDataFromDatabase(READ_NC_DATA_QUERY, ref NcDatatable);
return GetNcData();
}
@@ -101,7 +105,6 @@ namespace Nc_Demo_Application.Database
Console.WriteLine("ReadNcData exception: " + ex.Message);
return null;
}
}
public NcDataModel GetNcData()
@@ -109,7 +112,7 @@ namespace Nc_Demo_Application.Database
NcDataModel ncDataModel = new NcDataModel();
// Populate NcDataModel with db data
foreach (DataRow row in ncDatatable.Rows)
foreach (DataRow row in NcDatatable.Rows)
{
ncDataModel.id = Convert.ToInt32(row["id"]);
ncDataModel.name = row["name"].ToString();
@@ -139,7 +142,7 @@ namespace Nc_Demo_Application.Database
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(adapter);
// Update local ncDatatable data
foreach (DataRow row in ncDatatable.Rows)
foreach (DataRow row in NcDatatable.Rows)
{
row["name"] = ncData.name;
row["serial_number"] = ncData.serialNumber;
@@ -151,7 +154,7 @@ namespace Nc_Demo_Application.Database
row["process_count"] = Convert.ToInt32(ncData.processCount);
}
// Update database
adapter.Update(ncDatatable);
adapter.Update(NcDatatable);
// Close the connection with database
sqlConnection.Close();
@@ -161,21 +164,23 @@ namespace Nc_Demo_Application.Database
Console.WriteLine("ReadNcData exception: " + ex.Message);
}
}
#endregion
#endregion Nc Data Methods
#region Nc Processes Data
public DataTable ReadNcProcesses()
{
try
{
ReadDataFromDatabase(READ_NC_PROCESS_QUERY, ref ncProcessDataTable);
foreach (DataRow row in ncProcessDataTable.Rows)
ReadDataFromDatabase(READ_NC_PROCESS_QUERY, ref NcProcessDataTable);
foreach (DataRow row in NcProcessDataTable.Rows)
{
row["status"] = (int)Convert.ToInt32(row["status"]);
row["mode"] = (int)Convert.ToInt32(row["mode"]);
row["status"] = Convert.ToInt32(row["status"]);
row["mode"] = Convert.ToInt32(row["mode"]);
}
return ncProcessDataTable;
return NcProcessDataTable;
}
catch (Exception ex)
{
@@ -189,7 +194,7 @@ namespace Nc_Demo_Application.Database
List<NcProcessModel> processes = new List<NcProcessModel>();
int lastId = 0;
foreach (DataRow row in ncProcessDataTable.Rows)
foreach (DataRow row in NcProcessDataTable.Rows)
{
if (Convert.IsDBNull(row["id"]))
lastId = lastId + 1;
@@ -237,16 +242,17 @@ namespace Nc_Demo_Application.Database
}
}
#endregion
#endregion Nc Processes Data
#region Nc Alarms Data
public DataTable ReadNcAlarms()
{
try
{
ReadDataFromDatabase(READ_NC_ALARMS_QUERY, ref ncAlarmDataTable);
ReadDataFromDatabase(READ_NC_ALARMS_QUERY, ref NcAlarmDataTable);
return ncAlarmDataTable;
return NcAlarmDataTable;
}
catch (Exception ex)
{
@@ -259,7 +265,7 @@ namespace Nc_Demo_Application.Database
{
int lastId = 0;
List<NcAlarmModel> alarms = new List<NcAlarmModel>();
foreach (DataRow row in ncAlarmDataTable.Rows)
foreach (DataRow row in NcAlarmDataTable.Rows)
{
if (Convert.IsDBNull(row["id"]))
lastId = lastId + 1;
@@ -306,16 +312,17 @@ namespace Nc_Demo_Application.Database
}
}
#endregion
#endregion Nc Alarms Data
#region Nc Axes Data
public DataTable ReadNcAxes()
{
try
{
ReadDataFromDatabase(READ_NC_AXES_QUERY, ref ncAxesDataTable);
ReadDataFromDatabase(READ_NC_AXES_QUERY, ref NcAxesDataTable);
return ncAxesDataTable;
return NcAxesDataTable;
}
catch (Exception ex)
{
@@ -328,9 +335,8 @@ namespace Nc_Demo_Application.Database
{
int lastId = 0;
List<NcAxisModel> axes = new List<NcAxisModel>();
foreach (DataRow row in ncAxesDataTable.Rows)
foreach (DataRow row in NcAxesDataTable.Rows)
{
if (Convert.IsDBNull(row["id"]))
lastId = lastId + 1;
else
@@ -377,7 +383,8 @@ namespace Nc_Demo_Application.Database
Console.WriteLine("ReadNcData exception: " + ex.Message);
}
}
#endregion
#endregion Nc Axes Data
#region Binary Memory
@@ -586,6 +593,189 @@ namespace Nc_Demo_Application.Database
throw new WebFaultException(HttpStatusCode.BadRequest);
}
}
#endregion
#endregion Binary Memory
#region Tools
public List<ToolsDataModel> ReadTools()
{
try
{
ReadDataFromDatabase(READ_TOOLS_QUERY, ref ToolsDataTable);
return GetToolsData();
}
catch (Exception ex)
{
Console.WriteLine("ReadsTools exception: " + ex.Message);
return null;
}
}
public List<ToolsDataModel> GetToolsData()
{
List<ToolsDataModel> toolsDataModel = new List<ToolsDataModel>();
// Populate NcDataModel with db data
foreach (DataRow row in ToolsDataTable.Rows)
{
ToolsDataModel tool = new ToolsDataModel
{
Id = Convert.ToInt32(row["id"]),
MagazineId = Convert.ToInt32(row["magazine"]),
FamilyName = row["family"].ToString(),
ChildId = Convert.ToInt32(row["childId"]),
MagazinePositionType = Convert.ToInt32(row["magazinePositionType"]),
ToolType = Convert.ToInt32(row["toolType"]),
LeftSize = Convert.ToInt32(row["sizeLeft"]),
RightSize = Convert.ToInt32(row["sizeRight"]),
Rotation = Convert.ToInt32(row["rotation"]),
Cooling1 = Convert.ToInt32(row["cooling1"]) == 1,
Cooling2 = Convert.ToInt32(row["cooling2"]) == 1,
IsActive = Convert.ToInt32(row["isActive"]) == 1,
FixedPlace = Convert.ToInt32(row["fixedPlace"]) == 1,
IsInhibited = Convert.ToInt32(row["isInhibited"]) == 1,
IsMeasured = Convert.ToInt32(row["IsMeasured"]) == 1,
ChangeTool = Convert.ToInt32(row["changeTool"]) == 1,
IsInUse = Convert.ToInt32(row["isInUse"]) == 1,
PreAlarm = Convert.ToInt32(row["preAlarm"]) == 1
};
toolsDataModel.Add(tool);
}
return toolsDataModel;
}
public void AddToolToDatabase(ref ToolsDataModel toolData)
{
try
{
SetConnection();
// Open the connection with database
sqlConnection.Open();
// Create a SQLite command with query, adapter and commandbuilder in order to update.
sqlCommand = new SQLiteCommand(READ_TOOLS_QUERY, sqlConnection);
SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqlCommand);
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(adapter);
// Create new row that must be inserted
// DataRow row = ToolsDataTable.AsEnumerable().SingleOrDefault(x => Convert.ToInt32(x["id"]) == toolData.Id);
DataRow row = ToolsDataTable.NewRow();
toolData.Id = Convert.ToInt32(ToolsDataTable.Rows[ToolsDataTable.Rows.Count - 1]["id"]) + 1;
// Setup autoincrement Id
row["id"] = toolData.Id;
row["family"] = toolData.FamilyName;
row["magazine"] = toolData.MagazineId;
row["childId"] = toolData.ChildId;
row["magazinePositionType"] = toolData.MagazinePositionType;
row["toolType"] = toolData.ToolType;
row["sizeLeft"] = toolData.LeftSize;
row["sizeRight"] = toolData.RightSize;
row["rotation"] = toolData.Rotation;
row["cooling1"] = toolData.Cooling1;
row["cooling2"] = toolData.Cooling2;
row["isActive"] = toolData.IsActive;
row["fixedPlace"] = toolData.FixedPlace;
row["isInhibited"] = toolData.IsInhibited;
row["IsMeasured"] = toolData.IsMeasured;
row["changeTool"] = toolData.ChangeTool;
row["isInUse"] = toolData.IsInUse;
row["preAlarm"] = toolData.PreAlarm;
// Add the new row
ToolsDataTable.Rows.Add(row);
// Update database
adapter.Update(ToolsDataTable);
// Close the connection with database
sqlConnection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Add tool exception: " + ex.Message);
}
}
public void UpdateToolData(ToolsDataModel toolData)
{
try
{
SetConnection();
// Open the connection with database
sqlConnection.Open();
// Create a SQLite command with query, adapter and commandbuilder in order to update.
sqlCommand = new SQLiteCommand(READ_TOOLS_QUERY, sqlConnection);
SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqlCommand);
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(adapter);
// Create new row that must be inserted
DataRow row = ToolsDataTable.AsEnumerable().SingleOrDefault(x => Convert.ToInt32(x["id"]) == toolData.Id);
row["family"] = toolData.FamilyName;
row["magazine"] = toolData.MagazineId;
row["magazinePositionType"] = toolData.MagazinePositionType;
row["childId"] = toolData.ChildId;
row["toolType"] = toolData.ToolType;
row["sizeLeft"] = toolData.LeftSize;
row["sizeRight"] = toolData.RightSize;
row["rotation"] = toolData.Rotation;
row["cooling1"] = toolData.Cooling1;
row["cooling2"] = toolData.Cooling2;
row["isActive"] = toolData.IsActive;
row["fixedPlace"] = toolData.FixedPlace;
row["isInhibited"] = toolData.IsInhibited;
row["IsMeasured"] = toolData.IsMeasured;
row["changeTool"] = toolData.ChangeTool;
row["isInUse"] = toolData.IsInUse;
row["preAlarm"] = toolData.PreAlarm;
// Update database
adapter.Update(ToolsDataTable);
// Close the connection with database
sqlConnection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Update tool exception: " + ex.Message);
}
}
public void DeleteToolFromDatabase(int id)
{
try
{
SetConnection();
// Open the connection with database
sqlConnection.Open();
// Create a SQLite command with query, adapter and commandbuilder in order to update.
sqlCommand = new SQLiteCommand(READ_TOOLS_QUERY, sqlConnection);
SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqlCommand);
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(adapter);
// Delete row with matching id
DataRow row = ToolsDataTable.AsEnumerable().SingleOrDefault(x => Convert.ToInt32(x["id"]) == id);
row.Delete();
// Update database
adapter.Update(ToolsDataTable);
// Close the connection with database
sqlConnection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Delete tool exception: " + ex.Message);
}
}
#endregion Tools
}
}
}
@@ -59,5 +59,35 @@ namespace Nc_Demo_Application.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Cerca una risorsa localizzata di tipo System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap addButton {
get {
object obj = ResourceManager.GetObject("addButton", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Cerca una risorsa localizzata di tipo System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap removeButton {
get {
object obj = ResourceManager.GetObject("removeButton", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Cerca una risorsa localizzata di tipo System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap saveButton {
get {
object obj = ResourceManager.GetObject("saveButton", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
@@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@@ -109,9 +112,32 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="addButton" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAABISURBVDhPY8AGvn379h8bhkoTBiDFFl0mKHg4GwCSwIax
GYANY7WNWDycDMCGsSnGhqFxgQpAEtgMgEoTBsPEAGwYKo0EGBgAMACkrMWZPQwAAAAASUVORK5CYII=
</value>
</data>
<data name="removeButton" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAAmSURBVDhPYxgFVADfvn37TwkGG+Dk5EQWHk4GUIKhcTEK
yAcMDABULP5BZjjimQAAAABJRU5ErkJggg==
</value>
</data>
<data name="saveButton" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAABRSURBVDhPY6AK+Pbt239S8NevX+dDtUIASJAheA4cf3j/
EY6RxUB0zIR9mIaQYgAIwwyBaifdABAm2gBkjKyGtgYQg0cNGJQGkIOh2ikBDAwAR/4LjdUkCHIAAAAA
SUVORK5CYII=
</value>
</data>
</root>
@@ -160,5 +160,12 @@ namespace Nc_Demo_Application.Server.Service
void GetTranslations(string language, out Dictionary<int, string> fileContent);
#endregion
#region Tools
[WebGet(UriTemplate = "tool_table", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void GetTools(out List<ToolsDataModel> toolsData);
#endregion
}
}
@@ -453,5 +453,14 @@ namespace Nc_Demo_Application.Server.Service
}
#endregion File Management
#region Tools
public void GetTools(out List<ToolsDataModel> toolsData)
{
toolsData = DatabaseController.getInstance().ReadTools();
}
#endregion
}
}
File diff suppressed because it is too large Load Diff
@@ -1,22 +1,22 @@
using Nc_Demo_Application.Database;
using Nc_Demo_Application.Database.Models;
using Nc_Demo_Application.Server;
using Nc_Demo_Application.Views;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Nc_Demo_Application.Constants;
using System.Data;
using System.Linq;
using System.IO;
using Nc_Demo_Application.Views;
using System.Threading.Tasks;
namespace Nc_Demo_Application
{
public partial class DemoApplicationForm : Form
{
StartupPanel startupPanel;
bool axisResetRunning = false;
private StartupPanel startupPanel;
private bool axisResetRunning = false;
public DemoApplicationForm()
{
@@ -54,7 +54,10 @@ namespace Nc_Demo_Application
// Populate process model and status ComboBox
ncProcessModeColumn.DataSource = Enum.GetValues(typeof(PROC_MODE));
ncProcessStatusColumn.DataSource = Enum.GetValues(typeof(PROC_STATUS));
rotationSelect.DataSource = Enum.GetValues(typeof(ROTATION));
toolTypeSelect.DataSource = Enum.GetValues(typeof(TOOLS_TYPE));
magazineComboBox.DataSource = Enum.GetValues(typeof(MAGAZINES));
ShowServer(true);
// Read data from database
@@ -63,7 +66,8 @@ namespace Nc_Demo_Application
FillNcAlarmsInput();
FillNAxisInput();
FillBinaryMemoryInput();
ListDirectory("./part_program");
ReadPartProgramDirectory("./part_program");
FillToolsInput();
serverStatusLabel.Text = "Server running on: http://localhost:" + SERVER_PORT + API_URL;
}
@@ -71,7 +75,6 @@ namespace Nc_Demo_Application
{
MessageBox.Show("Server couldn't start: " + ex.Message);
}
}
private void StopServer_Click(object sender, EventArgs e)
@@ -131,23 +134,32 @@ namespace Nc_Demo_Application
private void FillBinaryMemoryInput()
{
// Insert binaryMemory into Grid View
DataTable binaryMemoryData = DatabaseController.getInstance().ReadBinaryMemory();
binaryMemoryGridView.DataSource = binaryMemoryData;
}
private void FillToolsInput()
{
List<ToolsDataModel> toolsData = DatabaseController.getInstance().ReadTools();
SetupToolData(toolsData);
}
private void SaveCnDataButton_Click(object sender, EventArgs e)
{
NcDataModel ncData = new NcDataModel();
NcDataModel ncData = new NcDataModel
{
// Read data from user NcData input
ncData.name = ncNameTxb.Text;
ncData.model = modelTxb.Text;
ncData.serialNumber = serialNumberTxb.Text;
ncData.machineNumber = machineNumberTxb.Text;
ncData.dateTime = dateTimeTxb.Text;
ncData.processCount = Convert.ToInt32(processNumberTxb.Text);
ncData.softwareVersion = softwareVersionTxb.Text;
ncData.language = languageTxb.Text;
// Read data from user NcData input
name = ncNameTxb.Text,
model = modelTxb.Text,
serialNumber = serialNumberTxb.Text,
machineNumber = machineNumberTxb.Text,
dateTime = dateTimeTxb.Text,
processCount = Convert.ToInt32(processNumberTxb.Text),
softwareVersion = softwareVersionTxb.Text,
language = languageTxb.Text
};
// Update user data
DatabaseController.getInstance().UpdateNcData(ncData);
@@ -157,7 +169,6 @@ namespace Nc_Demo_Application
{
DatabaseController.getInstance().UpdateNcProcess((DataTable)ncProcessGridView.DataSource);
FillNcProcessInput();
}
private void SaveNcAlarmsButton_Click(object sender, EventArgs e)
@@ -178,7 +189,6 @@ namespace Nc_Demo_Application
private void ncProcessGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
// TODO
}
private void BinaryMemoryGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
@@ -189,7 +199,7 @@ namespace Nc_Demo_Application
// Get cells ref
var binaryCell = binaryMemoryGridView.Rows[e.RowIndex].Cells["BinaryMemoryBinaryColumn"];
var decimalCell = binaryMemoryGridView.Rows[e.RowIndex].Cells["BinaryMemoryDecimalColumn"];
// If decimal value is changed, by user or programmatically, update all the row cells
if (e.ColumnIndex == 1)
{
@@ -254,6 +264,7 @@ namespace Nc_Demo_Application
binaryCell.Value = binaryCell.Value.ToString().PadLeft(8, '0');
}
break;
case 3:
{
var wordCell = binaryMemoryGridView.Rows[e.RowIndex].Cells["BinaryMemoryWordColumn"];
@@ -267,6 +278,7 @@ namespace Nc_Demo_Application
binaryMemoryGridView.Rows[e.RowIndex - 1].Cells["BinaryMemoryDecimalColumn"].Value = Convert.ToByte(binary.Substring(8, 8), 2);
}
break;
case 4:
{
var integerCell = binaryMemoryGridView.Rows[e.RowIndex].Cells["BinaryMemoryIntegerColumn"];
@@ -330,7 +342,7 @@ namespace Nc_Demo_Application
}
}
private void ListDirectory(string path)
private void ReadPartProgramDirectory(string path)
{
// Clear Tree view
fileTreeView.Nodes.Clear();
@@ -343,14 +355,13 @@ namespace Nc_Demo_Application
rootDirectory.Create();
}
// Push
// Push
var node = new TreeNode(rootDirectory.Name) { Tag = rootDirectory };
stack.Push(node);
while (stack.Count > 0)
{
// Get new node
// Get new node from tree
var currentNode = stack.Pop();
// Add tag to new node
var directoryInfo = (DirectoryInfo)currentNode.Tag;
@@ -366,6 +377,7 @@ namespace Nc_Demo_Application
{
if (!String.IsNullOrEmpty(newFileNameTextBox.Text))
{
// Create file and add to new node to tree
File.Create(FILE_FOLDER + newFileNameTextBox.Text).Dispose();
fileTreeView.Nodes[0].Nodes.Add(new TreeNode(newFileNameTextBox.Text));
}
@@ -394,11 +406,10 @@ namespace Nc_Demo_Application
else
MessageBox.Show("Select a file");
}
catch(Exception ex)
catch (Exception ex)
{
Console.WriteLine("File exception: " + ex.Message);
}
}
private void FileTreeView_AfterSelect(object sender, TreeViewEventArgs e)
@@ -407,12 +418,14 @@ namespace Nc_Demo_Application
// On treeview change, update textview if file exists
if (File.Exists(FILE_FOLDER + selectedFile))
{
// Read all the text of the selected file
fileContentTextBox.Text = File.ReadAllText(FILE_FOLDER + selectedFile);
fileContentTextBox.Enabled = true;
saveFileButton.Enabled = true;
}
else
{
// If not exists block input
fileContentTextBox.Text = "";
fileContentTextBox.Enabled = false;
saveFileButton.Enabled = false;
@@ -431,10 +444,10 @@ namespace Nc_Demo_Application
{
DataTable dt = binaryMemoryGridView.DataSource as DataTable;
row.Cells["BinaryMemoryDecimalColumn"].Value = 128;
// Set new percentage of the axis reset
for (int i = 0; i < 100; i++)
{
this.Invoke((MethodInvoker)delegate ()
Invoke((MethodInvoker)delegate ()
{
row.Cells["BinaryMemoryDecimalColumn"].Value = (int)row.Cells["BinaryMemoryDecimalColumn"].Value + 1;
});
@@ -444,11 +457,184 @@ namespace Nc_Demo_Application
row.Cells["BinaryMemoryDecimalColumn"].Value = 1;
}
private void openDoc_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
private void OpenDoc_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://docs.google.com/spreadsheets/d/17AHl_qwPTGupYdWCmFYV3ubXmJykQpy1ciSTk8AgNek/edit?usp=sharing");
}
private void SetupToolData(List<ToolsDataModel> toolsList)
{
try
{
// Create root and push it
var stack = new Stack<TreeNode>();
// Push
var node = new TreeNode("ToolTable") { Tag = "ToolTable" };
stack.Push(node);
while (stack.Count > 0)
{
// Get new node from tree
var currentNode = stack.Pop();
// Add node to Treeview
foreach (ToolsDataModel tool in toolsList)
{
var tmpNode = new TreeNode
{
Tag = tool.Id,
Text = tool.FamilyName
};
currentNode.Nodes.Add(tmpNode);
}
}
toolsTreeView.Nodes.Add(node);
}
catch(Exception ex)
{
}
}
private void AddTool_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(toolNameTxt.Text))
{
// Create new tool
ToolsDataModel newTool = new ToolsDataModel()
{
FamilyName = toolNameTxt.Text,
MagazineId = 0,
ChildId = 1,
MagazinePositionType = 1,
ToolType = 100,
LeftSize = 1,
RightSize = 1,
Cooling1 = false,
Cooling2 = false,
Rotation= 0,
IsActive = false,
FixedPlace = false,
IsMeasured = false,
ChangeTool = false,
PreAlarm = false,
IsInUse = false,
IsInhibited = false,
};
// Add to database
DatabaseController.getInstance().AddToolToDatabase(ref newTool);
// Add to treeView
toolsTreeView.Nodes[0].Nodes.Add(new TreeNode
{
Tag = newTool.Id,
Text = newTool.FamilyName
});
}
else
{
MessageBox.Show("Insert tool name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RemoveTool_Click(object sender, EventArgs e)
{
if (toolsTreeView.SelectedNode == null)
return;
// If the selected node is root exit
if (toolsTreeView.SelectedNode.Level == 0)
return;
try
{
// Delete database row
DatabaseController.getInstance().DeleteToolFromDatabase(Convert.ToInt32(toolsTreeView.SelectedNode.Tag));
// Remove from treeView
toolsTreeView.SelectedNode.Remove();
}
catch (Exception ex)
{
Console.WriteLine("File exception: " + ex.Message);
}
}
private void ToolsTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
// Get selected Node
var selectedTool = toolsTreeView.SelectedNode;
if (selectedTool.Level == 0)
return;
// Find selected tools data from database
List<ToolsDataModel> toolsInfo = DatabaseController.getInstance().ReadTools();
ToolsDataModel toolInfo = toolsInfo.Where(x => x.Id == Convert.ToInt32(selectedTool.Tag)).SingleOrDefault();
if(toolInfo != null)
{
// Update form inputs
toolsIdLlb.Text = toolInfo.Id.ToString();
FamilyTxt.Text = toolInfo.FamilyName;
childIdTxt.Text = toolInfo.ChildId.ToString();
magazinePositionTypeTxt.Text = toolInfo.MagazinePositionType.ToString();
rightSizeTxt.Text = toolInfo.RightSize.ToString();
leftSizeTxt.Text = toolInfo.LeftSize.ToString();
cooling1CheckBox.Checked = toolInfo.Cooling1;
cooling2CheckBox.Checked = toolInfo.Cooling2;
isActiveCheckBox.Checked = toolInfo.IsActive;
fixedPlaceCheckBox.Checked = toolInfo.FixedPlace;
inhibitedCheckBox.Checked = toolInfo.IsInhibited;
measuredCheckBox.Checked = toolInfo.IsMeasured;
preAlarmCheckBox.Checked = toolInfo.PreAlarm;
changeToolCheckBox.Checked = toolInfo.ChangeTool;
useCheckBox.Checked = toolInfo.IsInUse;
toolTypeSelect.SelectedItem = (TOOLS_TYPE)toolInfo.ToolType;
rotationSelect.SelectedItem = (ROTATION)toolInfo.Rotation;
magazineComboBox.SelectedItem = (MAGAZINES)toolInfo.MagazineId;
}
}
private void SaveToolButton_Click(object sender, EventArgs e)
{
// Get selected Node
var selectedTool = toolsTreeView.SelectedNode;
if (selectedTool.Level == 0)
return;
// Find selected tools data from database
List<ToolsDataModel> toolsInfo = DatabaseController.getInstance().ReadTools();
ToolsDataModel toolInfo = new ToolsDataModel();
// Update form inputs
toolInfo.Id = Convert.ToInt32(selectedTool.Tag);
toolInfo.MagazineId = (int)magazineComboBox.SelectedItem;
toolInfo.FamilyName = FamilyTxt.Text;
toolInfo.ChildId = Convert.ToInt32(childIdTxt.Text);
toolInfo.MagazinePositionType = Convert.ToInt32(magazinePositionTypeTxt.Text);
toolInfo.RightSize = Convert.ToInt32(rightSizeTxt.Text);
toolInfo.LeftSize = Convert.ToInt32(leftSizeTxt.Text);
toolInfo.Cooling1 = cooling1CheckBox.Checked;
toolInfo.Cooling2 = cooling2CheckBox.Checked;
toolInfo.IsActive = isActiveCheckBox.Checked;
toolInfo.FixedPlace = fixedPlaceCheckBox.Checked;
toolInfo.IsInhibited = inhibitedCheckBox.Checked;
toolInfo.IsMeasured = measuredCheckBox.Checked;
toolInfo.PreAlarm = preAlarmCheckBox.Checked;
toolInfo.ChangeTool = changeToolCheckBox.Checked;
toolInfo.IsInUse = useCheckBox.Checked;
toolInfo.ToolType = (int)toolTypeSelect.SelectedItem;
toolInfo.Rotation = (int)rotationSelect.SelectedItem;
DatabaseController.getInstance().UpdateToolData(toolInfo);
}
}
}
File diff suppressed because it is too large Load Diff