From 455b4ebfc63b20ba3e01d1246b04ad0238432996 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Thu, 22 Feb 2018 15:12:19 +0000 Subject: [PATCH] --- CMS_CORE_Application/Form1.Designer.cs | 88 ++++++- CMS_CORE_Application/Form1.cs | 87 ++++++- CMS_CORE_Library/DataStructures.cs | 223 ++++++++++++++++-- CMS_CORE_Library/Demo/Nc_Demo.cs | 30 +++ CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 15 +- CMS_CORE_Library/Nc.cs | 43 ++-- CMS_CORE_Library/Osai/Nc_Osai.cs | 5 + CMS_CORE_Library/Siemens/Nc_Siemens.cs | 6 + .../Database/DatabaseController.cs | 9 +- .../Server/Service/LibraryService.cs | 5 + .../Views/DemoApplicationForm.Designer.cs | 80 ++++--- .../Views/DemoApplicationForm.cs | 24 ++ .../Views/DemoApplicationForm.resx | 52 ++-- 13 files changed, 536 insertions(+), 131 deletions(-) diff --git a/CMS_CORE_Application/Form1.Designer.cs b/CMS_CORE_Application/Form1.Designer.cs index bf8d4f8..6fd7698 100644 --- a/CMS_CORE_Application/Form1.Designer.cs +++ b/CMS_CORE_Application/Form1.Designer.cs @@ -69,10 +69,16 @@ this.TXTPPName = new System.Windows.Forms.TextBox(); this.TXTPPLines = new System.Windows.Forms.TextBox(); this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.lastTimeDbTXT = new System.Windows.Forms.TextBox(); + this.mediaTestDbTXT = new System.Windows.Forms.TextBox(); this.TXTNow = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.Error = new System.Windows.Forms.TextBox(); + this.totalTimesTXT = new System.Windows.Forms.TextBox(); + this.label12 = new System.Windows.Forms.Label(); + this.lastTime = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); @@ -351,7 +357,7 @@ this.tableLayoutPanel1.ColumnCount = 3; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.76253F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 49.23747F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 286F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 289F)); this.tableLayoutPanel1.Controls.Add(this.groupBox2, 1, 0); this.tableLayoutPanel1.Controls.Add(this.groupBox1, 0, 0); this.tableLayoutPanel1.Controls.Add(this.groupBox4, 2, 0); @@ -370,9 +376,9 @@ | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.TXTMsg); this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.groupBox2.Location = new System.Drawing.Point(163, 3); + this.groupBox2.Location = new System.Drawing.Point(162, 3); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(150, 265); + this.groupBox2.Size = new System.Drawing.Size(148, 265); this.groupBox2.TabIndex = 28; this.groupBox2.TabStop = false; this.groupBox2.Text = "Plc"; @@ -386,7 +392,7 @@ this.TXTMsg.Multiline = true; this.TXTMsg.Name = "TXTMsg"; this.TXTMsg.ReadOnly = true; - this.TXTMsg.Size = new System.Drawing.Size(139, 238); + this.TXTMsg.Size = new System.Drawing.Size(137, 238); this.TXTMsg.TabIndex = 18; // // groupBox1 @@ -397,7 +403,7 @@ this.groupBox1.Controls.Add(this.TXTAlmNc); this.groupBox1.Location = new System.Drawing.Point(3, 3); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(154, 265); + this.groupBox1.Size = new System.Drawing.Size(153, 265); this.groupBox1.TabIndex = 27; this.groupBox1.TabStop = false; this.groupBox1.Text = "Nc"; @@ -411,7 +417,7 @@ this.TXTAlmNc.Multiline = true; this.TXTAlmNc.Name = "TXTAlmNc"; this.TXTAlmNc.ReadOnly = true; - this.TXTAlmNc.Size = new System.Drawing.Size(142, 240); + this.TXTAlmNc.Size = new System.Drawing.Size(141, 240); this.TXTAlmNc.TabIndex = 20; // // groupBox4 @@ -421,9 +427,9 @@ | System.Windows.Forms.AnchorStyles.Right))); this.groupBox4.Controls.Add(this.tabControl1); this.groupBox4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.groupBox4.Location = new System.Drawing.Point(319, 3); + this.groupBox4.Location = new System.Drawing.Point(316, 3); this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(281, 265); + this.groupBox4.Size = new System.Drawing.Size(284, 265); this.groupBox4.TabIndex = 29; this.groupBox4.TabStop = false; this.groupBox4.Text = "Path"; @@ -437,7 +443,7 @@ this.tabControl1.Location = new System.Drawing.Point(6, 21); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(268, 238); + this.tabControl1.Size = new System.Drawing.Size(271, 238); this.tabControl1.TabIndex = 0; // // tabPage1 @@ -446,7 +452,7 @@ this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(260, 212); + this.tabPage1.Size = new System.Drawing.Size(263, 212); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "Path 1"; this.tabPage1.UseVisualStyleBackColor = true; @@ -460,7 +466,7 @@ this.TXTAlm.Multiline = true; this.TXTAlm.Name = "TXTAlm"; this.TXTAlm.ReadOnly = true; - this.TXTAlm.Size = new System.Drawing.Size(248, 203); + this.TXTAlm.Size = new System.Drawing.Size(251, 203); this.TXTAlm.TabIndex = 18; // // groupBox3 @@ -562,6 +568,12 @@ this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox5.Controls.Add(this.label13); + this.groupBox5.Controls.Add(this.lastTime); + this.groupBox5.Controls.Add(this.label12); + this.groupBox5.Controls.Add(this.totalTimesTXT); + this.groupBox5.Controls.Add(this.lastTimeDbTXT); + this.groupBox5.Controls.Add(this.mediaTestDbTXT); this.groupBox5.Controls.Add(this.TXTNow); this.groupBox5.Controls.Add(this.label7); this.groupBox5.Controls.Add(this.TXTSft); @@ -583,6 +595,20 @@ this.groupBox5.TabStop = false; this.groupBox5.Text = "Nc Info"; // + // lastTimeDbTXT + // + this.lastTimeDbTXT.Location = new System.Drawing.Point(114, 87); + this.lastTimeDbTXT.Name = "lastTimeDbTXT"; + this.lastTimeDbTXT.Size = new System.Drawing.Size(100, 20); + this.lastTimeDbTXT.TabIndex = 28; + // + // mediaTestDbTXT + // + this.mediaTestDbTXT.Location = new System.Drawing.Point(114, 60); + this.mediaTestDbTXT.Name = "mediaTestDbTXT"; + this.mediaTestDbTXT.Size = new System.Drawing.Size(100, 20); + this.mediaTestDbTXT.TabIndex = 27; + // // TXTNow // this.TXTNow.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -620,6 +646,40 @@ this.Error.Size = new System.Drawing.Size(462, 20); this.Error.TabIndex = 27; // + // totalTimesTXT + // + this.totalTimesTXT.Location = new System.Drawing.Point(114, 113); + this.totalTimesTXT.Name = "totalTimesTXT"; + this.totalTimesTXT.Size = new System.Drawing.Size(100, 20); + this.totalTimesTXT.TabIndex = 29; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(56, 63); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(47, 13); + this.label12.TabIndex = 30; + this.label12.Text = "Avarage"; + // + // lastTime + // + this.lastTime.AutoSize = true; + this.lastTime.Location = new System.Drawing.Point(59, 90); + this.lastTime.Name = "lastTime"; + this.lastTime.Size = new System.Drawing.Size(46, 13); + this.lastTime.TabIndex = 31; + this.lastTime.Text = "lastTime"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(62, 120); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(41, 13); + this.label13.TabIndex = 32; + this.label13.Text = "label13"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -707,6 +767,12 @@ private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox Error; + private System.Windows.Forms.TextBox mediaTestDbTXT; + private System.Windows.Forms.TextBox lastTimeDbTXT; + private System.Windows.Forms.Label lastTime; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.TextBox totalTimesTXT; + private System.Windows.Forms.Label label13; } } diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 565691a..964c137 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -22,6 +22,7 @@ namespace CMS_CORE_Application static String NCIp; static ushort NCPort; Thread t; + Thread toolThread; public Form1() { @@ -36,7 +37,7 @@ namespace CMS_CORE_Application private void connectDemo_Click(object sender, EventArgs e) { t = new Thread(new ThreadStart(ReadBasicData)); - Thread toolThread = new Thread(new ThreadStart(ChangeTool)); + toolThread = new Thread(new ThreadStart(ChangeTool)); if (NcCombo.SelectedItem == null) return; @@ -72,9 +73,10 @@ namespace CMS_CORE_Application List Lines = new List(); PostPowerOnModel postPowerOn = new PostPowerOnModel(); AxisResetDataModel axisResetDataModel = new AxisResetDataModel(); + List counters = new List(); N = SetNcByType(); - + CmsError cmsError = N.NC_Connect(); cmsError = N.NC_RModelName(ref ModelName); N.NC_RProcessesNum(ref procnum); @@ -140,6 +142,8 @@ namespace CMS_CORE_Application SetError(Lines, cmsError); } + cmsError = N.PLC_RMachineCounters(ref counters); + if (!this.IsDisposed && this.InvokeRequired) { this.Invoke((ThreadStart)delegate () @@ -179,6 +183,65 @@ namespace CMS_CORE_Application { if (NCType != "Fanuc") return; + Nc ncFanuc = SetNcByType(); + + ToolModel toola = RicercaPerManina(1); + + CmsError cmsError = ncFanuc.NC_Connect(); + byte id = 0; + Stopwatch stopwatch = new Stopwatch(); + int times = 0; + long time = 0; + while (true) + { + //id = 12; + //ncFanuc.MEM_RWByte(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 9000, 1, ref id); + //id = 0; + + stopwatch.Restart(); + // Read next tool area + ncFanuc.MEM_RWByte(Nc.R, 0, Nc.MEMORY_TYPE.Fanuc_R, 9200, 1, ref id); + // if not empty + if (id != 0) + { + // Query + ToolModel tool = RicercaPerManina(id); + List list = new List() { + id, + tool.FamilyId, + tool.ShankId, + 2, + 3, + 4 + }; + // Write ids into nc memory + ncFanuc.MEM_RWIntegerList(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 9201, 0, ref list); + + id = 0; + // Reset id to 0 + ncFanuc.MEM_RWByte(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 9200, 1, ref id); + stopwatch.Stop(); + + times++; + time += stopwatch.ElapsedMilliseconds + 100; + // Write counters + this.Invoke((ThreadStart)delegate () + { + mediaTestDbTXT.Text = (time/ times).ToString(); + lastTimeDbTXT.Text = stopwatch.ElapsedMilliseconds.ToString(); + totalTimesTXT.Text = times.ToString(); + }); + } + + // Wait + Thread.Sleep(100); + } + } + + public void ChangeToolOsai() + { + if (NCType != "Osai") + return; N = SetNcByType(); ToolModel toola = RicercaPerManina(1); @@ -194,18 +257,22 @@ namespace CMS_CORE_Application if (id != 0) { ToolModel tool = RicercaPerManina(id); - List list = new List() { id, tool.FamilyId, tool.ShankId}; - N.MEM_RWIntegerList(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 8001, 0, ref list); + List list = new List() { id, tool.FamilyId, tool.ShankId }; + N.MEM_RWIntegerList(Nc.W, 0, Nc.MEMORY_TYPE.Osai_GW, 8001, 0, ref list); id = 0; - N.MEM_RWByte(Nc.W, 0, Nc.MEMORY_TYPE.Fanuc_R, 8000, 1, ref id); + N.MEM_RWByte(Nc.W, 0, Nc.MEMORY_TYPE.Osai_GW, 8000, 1, ref id); stopwatch.Stop(); - Debug.WriteLine(stopwatch.ElapsedMilliseconds.ToString()); + + this.Invoke((ThreadStart)delegate () + { + mediaTestDbTXT.Text = stopwatch.ElapsedMilliseconds.ToString(); + }); } - Thread.Sleep(200); } } + private ToolModel RicercaPerManina(int maninaId) { ToolDatabaseContext dbCtx = new ToolDatabaseContext(); @@ -225,7 +292,7 @@ namespace CMS_CORE_Application { this.Invoke((ThreadStart)delegate () { - + Error.Text = cmsError.message; TXTPPLines.Text = String.Join(Environment.NewLine, Lines); @@ -258,7 +325,7 @@ namespace CMS_CORE_Application { TXTip.Enabled = true; TXTport.Enabled = true; - TXTip.Text = "10.69.36.33"; + TXTip.Text = "192.168.139.1"; TXTport.Text = "8193"; } @@ -295,6 +362,8 @@ namespace CMS_CORE_Application { if (t != null) t.Abort(); + if (toolThread != null) + toolThread.Abort(); TXTPath1.Text = ""; TXTStat1.Text = ""; diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs index c7e0e93..91f5385 100644 --- a/CMS_CORE_Library/DataStructures.cs +++ b/CMS_CORE_Library/DataStructures.cs @@ -1,4 +1,6 @@ -namespace CMS_CORE_Library +using static CMS_CORE.Nc; + +namespace CMS_CORE_Library { public static class DataStructures { @@ -6,33 +8,163 @@ #region Data structor models - public struct PreAndPostPowerOnModel - { - public PrePowerOnModel PrePowerOn; - public PostPowerOnModel PostPowerOn; - } + #region Pre and Post Power on Models - public struct PowerOnDataModel + public class PreAndPostPowerOnModel { - public uint Id; - public bool Active; - public bool Clickable; + public PrePowerOnModel PrePowerOn { get; set; } + public PostPowerOnModel PostPowerOn { get; set; } + + public PreAndPostPowerOnModel() + { + PrePowerOn = new PrePowerOnModel(); + PostPowerOn = new PostPowerOnModel(); + } + + public override bool Equals(object obj) + { + var item = obj as PreAndPostPowerOnModel; + + if (item == null) + return false; + + if (!PrePowerOn.Equals(item.PrePowerOn) || !PostPowerOn.Equals(item.PostPowerOn)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class PrePowerOnModel { - public PowerOnDataModel PowerOn; - public PowerOnDataModel AirPressure; - public PowerOnDataModel ProtectionStatus; - public PowerOnDataModel EmergencyButtons; - public PowerOnDataModel SettingMode; - public PowerOnDataModel StartingKey; + public PowerOnDataModel PowerOn { get; set; } + public PowerOnDataModel AirPressure { get; set; } + public PowerOnDataModel ProtectionStatus { get; set; } + public PowerOnDataModel EmergencyButtons { get; set; } + public PowerOnDataModel SettingMode { get; set; } + public PowerOnDataModel StartingKey { get; set; } + + public PrePowerOnModel() + { + PowerOn = new PowerOnDataModel(); + AirPressure = new PowerOnDataModel(); + ProtectionStatus = new PowerOnDataModel(); + EmergencyButtons = new PowerOnDataModel(); + SettingMode = new PowerOnDataModel(); + StartingKey = new PowerOnDataModel(); + } + + public override bool Equals(object obj) + { + var item = obj as PrePowerOnModel; + + if (item == null) + return false; + + if (!PowerOn.Equals(item.PowerOn) || + !AirPressure.Equals(item.AirPressure) || + !ProtectionStatus.Equals(item.ProtectionStatus) || + !EmergencyButtons.Equals(item.EmergencyButtons) || + !SettingMode.Equals(item.SettingMode) || + !StartingKey.Equals(item.StartingKey)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class PostPowerOnModel { - public PowerOnDataModel AxisReset; - public PowerOnDataModel WaterjetPump; + public PowerOnDataModel AxisReset { get; set; } + public PowerOnDataModel WaterjetPump { get; set; } + + public override bool Equals(object obj) + { + var item = obj as PostPowerOnModel; + + if (item == null) + return false; + + if (!AxisReset.Equals(item.AxisReset) || + !WaterjetPump.Equals(item.WaterjetPump)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public class PowerOnDataModel + { + public uint Id { get; set; } + public bool Active { get; set; } + public bool Clickable { get; set; } + + public PowerOnDataModel() + { + Id = 0; + Active = false; + Clickable = false; + } + + public override bool Equals(object obj) + { + var item = obj as PowerOnDataModel; + + if (item == null) + return false; + + if (Id != item.Id || Active != item.Active || Clickable != item.Clickable) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + #endregion Pre and Post Power on Models + + // R-W MEMORY Cell + internal struct MEMORY_CELL + { + public readonly MEMORY_TYPE MemType; + public readonly int Address; + public readonly int SubAddress; //Only for Siemens + public readonly int Size; + + public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int SubAddr, int Sz) + { + MemType = MType; + Address = Addr; + SubAddress = SubAddr; + Size = Sz; + } + + public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int Sz) + { + MemType = MType; + Address = Addr; + SubAddress = 0; + Size = Sz; + } } public class AlarmModel @@ -52,6 +184,32 @@ public string Status; public bool Visible; public byte Reps; + + public override bool Equals(object obj) + { + var item = obj as ProcessDataModel; + + if (item == null) + return false; + + if (Id != item.Id) + return false; + + if (Type != item.Type || + IsInAlarm != item.IsInAlarm || + PartProgramName != item.PartProgramName || + Status != item.Status || + Visible != item.Visible || + Reps != item.Reps) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public struct FunctionalityModel @@ -66,10 +224,37 @@ public bool IsActive; } - public struct AxisResetDataModel + public class AxisResetDataModel { public bool IsActive; public int Percentage; + + public AxisResetDataModel() + { + IsActive = false; + Percentage = 0; + } + + public override bool Equals(object obj) + { + var item = obj as AxisResetDataModel; + + if (IsActive == item.IsActive && Percentage == item.Percentage) + return true; + else + return false; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public struct CounterModel + { + public uint Id; + public uint Value; } #endregion Data structor models diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 07ddccb..5fb746a 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -424,6 +424,34 @@ namespace CMS_CORE.Demo return NO_ERROR; } + public override CmsError PLC_RMachineCounters(ref List counters) + { + try + { + counters = new List(); + List readedValues = new List(); + // Read on data from memory + CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.COUNTERS.MemType, MEMORY_ADDRESS.COUNTERS.Address, MEMORY_ADDRESS.COUNTERS.Size / 4 , ref readedValues); + if (cmsError.IsError()) + return cmsError; + + for ( int i = 0; i < readedValues.Count; i++) + { + counters.Add(new CounterModel() + { + Id = (uint)i, + Value = (uint)readedValues[i] + }); + } + + return NO_ERROR; + } + catch (Exception ex) + { + return ManageException(ex); + } + } + //public override CmsError PLC_RStrobe(ref List functions) //{ // List readValue = new List(); @@ -1319,6 +1347,8 @@ namespace CMS_CORE.Demo internal static MEMORY_CELL AXIS_RESET_PROCEDURE = new MEMORY_CELL(MEMORY_TYPE.Demo, 51, 7, 2); internal static MEMORY_CELL PROCESS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Demo, 55, 0, 16); + + internal static MEMORY_CELL COUNTERS = new MEMORY_CELL(MEMORY_TYPE.Demo, 71, 0, 40); } #endregion Memory addresses diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 11839e4..6fbbb86 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -360,27 +360,32 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - + // Get pre and post power on data public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel) { return NO_ERROR; } - + // Write power on data public override CmsError PLC_WPowerOnData(uint id, bool value) { return NO_ERROR; } - + // Get functionality data public override CmsError PLC_RFunctionAccess(ref List functions) { functions = new List(); return NO_ERROR; } - + // Get axis reset procedure data public override CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData) { return NO_ERROR; } + // Get all the machine counters + public override CmsError PLC_RMachineCounters(ref List counters) + { + return NO_ERROR; + } #endregion PLC High-level data @@ -1956,5 +1961,7 @@ namespace CMS_CORE.Fanuc } #endregion Subordinate Private Functions + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } } \ No newline at end of file diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index fb211fc..d7a5edf 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -411,7 +411,7 @@ namespace CMS_CORE /** * - * Read the status of the functions of the UI + * Read the status of the UI functions from PLC * * Compatibility: Fanuc | Osai | Demo | Siemens * @@ -422,16 +422,28 @@ namespace CMS_CORE /** * - * Read axes reset procedure data + * Read axes reset procedure data from PLC * * Compatibility: Fanuc | Osai | Demo | Siemens * * Returns an error when an internal or a library error occours - * Reference of the data of axes reset procedure + * Reference to the data of axes reset procedure * **/ public abstract CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData); + /** + * + * Read machine counters value from PLC + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * Returns an error when an internal or a library error occours + * Reference to the data of counters + * + **/ + public abstract CmsError PLC_RMachineCounters(ref List counters); + #endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1224,31 +1236,6 @@ namespace CMS_CORE /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Fixed memory area - // R-W MEMORY Cell - internal struct MEMORY_CELL - { - public readonly MEMORY_TYPE MemType; - public readonly int Address; - public readonly int SubAddress; //Only for Siemens - public readonly int Size; - - public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int SubAddr, int Sz) - { - MemType = MType; - Address = Addr; - SubAddress = SubAddr; - Size = Sz; - } - - public MEMORY_CELL(MEMORY_TYPE MType, int Addr, int Sz) - { - MemType = MType; - Address = Addr; - SubAddress = 0; - Size = Sz; - } - } - //Lingua CN internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_TYPE.Null, 3281, 0, 1); diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 6ca22e2..f464cbd 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -408,6 +408,11 @@ namespace CMS_CORE.Osai return NO_ERROR; } + public override CmsError PLC_RMachineCounters(ref List counters) + { + return NO_ERROR; + } + #endregion PLC High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 382d8f2..113c31e 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -1,4 +1,5 @@ using CMS_CORE.Utils; +using CMS_CORE_Library; using Siemens.Sinumerik.Operate.Services; using System; using System.Collections.Generic; @@ -309,6 +310,11 @@ namespace CMS_CORE.Siemens return NO_ERROR; } + public override CmsError PLC_RMachineCounters(ref List counters) + { + return NO_ERROR; + } + #endregion PLC High-level data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs index dea2361..6c9c47f 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs @@ -186,12 +186,19 @@ namespace Nc_Demo_Application.Database public List GetNcProcesses() { List processes = new List(); + int lastId = 0; + foreach (DataRow row in ncProcessDataTable.Rows) { + if (Convert.IsDBNull(row["id"])) + lastId = lastId + 1; + else + lastId = Convert.ToInt32(row["id"]); + // Convert DataTable.row into process model NcProcessModel tmpProcess = new NcProcessModel { - id = Convert.ToInt32(row["id"]), + id = lastId, name = row["name"].ToString(), status = Convert.ToInt32(row["status"]), mode = Convert.ToInt32(row["mode"]), diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs index 8340c52..7cc922b 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs @@ -94,12 +94,14 @@ namespace Nc_Demo_Application.Server.Service public void NcAlarms(out List alarms) { List ncAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + // Get only CN ( == 0) alarms alarms = ncAlarmsData.FindAll(i => i.processId == 0); } public void PlcAlarms(out List alarms) { List ncAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + // Get only alarms = ncAlarmsData.FindAll(i => i.processId == -1); } @@ -108,12 +110,14 @@ namespace Nc_Demo_Application.Server.Service CheckProcess(Convert.ToInt32(id)); List procAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + // Get all the alarms of a process alarms = procAlarmsData.FindAll(i => i.processId == Convert.ToInt32(id) && i.processId != 0 && i.processId != -1); } public void ProcessesAlarms(out List alarms) { List procAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + // Get only process Alarms, not != 0 (cn) != -1 (plc) alarms = procAlarmsData.FindAll(i => i.processId != 0 && i.processId != -1); } @@ -127,6 +131,7 @@ namespace Nc_Demo_Application.Server.Service public void GetAxesActualPosition(string id, out List axes) { List ncAxesModel = DatabaseController.getInstance().GetNcAxes(); + // Get axis data filtered by process axes = ncAxesModel.FindAll(i => i.processId == Convert.ToInt32(id)); } diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.Designer.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.Designer.cs index fdd2567..39ccd62 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.Designer.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.Designer.cs @@ -55,6 +55,11 @@ this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.saveNcProcessData = new System.Windows.Forms.ToolStripButton(); this.ncProcessGridView = new System.Windows.Forms.DataGridView(); + this.ncProcessIdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ProcessPartProgram = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ncProcessNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ncProcessStatusColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); + this.ncProcessModeColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.alarms = new System.Windows.Forms.TabPage(); this.toolStrip3 = new System.Windows.Forms.ToolStrip(); this.saveNcAlarmsButton = new System.Windows.Forms.ToolStripButton(); @@ -95,11 +100,6 @@ this.newFileNameTextBox = new System.Windows.Forms.ToolStripTextBox(); this.fileTreeView = new System.Windows.Forms.TreeView(); this.stopServer = new System.Windows.Forms.Button(); - this.ncProcessIdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ProcessPartProgram = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ncProcessNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ncProcessStatusColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); - this.ncProcessModeColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.ncDataPage.SuspendLayout(); this.toolStrip5.SuspendLayout(); this.ncTabControl.SuspendLayout(); @@ -365,6 +365,7 @@ this.saveNcProcessData.Name = "saveNcProcessData"; this.saveNcProcessData.Size = new System.Drawing.Size(23, 22); this.saveNcProcessData.Text = "Save"; + this.saveNcProcessData.Click += new System.EventHandler(this.SaveNcProcessData_Click); // // ncProcessGridView // @@ -385,6 +386,39 @@ this.ncProcessGridView.TabIndex = 4; this.ncProcessGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.ncProcessGridView_DataError); // + // ncProcessIdColumn + // + this.ncProcessIdColumn.DataPropertyName = "id"; + this.ncProcessIdColumn.HeaderText = "Process Id"; + this.ncProcessIdColumn.Name = "ncProcessIdColumn"; + this.ncProcessIdColumn.ReadOnly = true; + // + // ProcessPartProgram + // + this.ProcessPartProgram.DataPropertyName = "part_program_name"; + this.ProcessPartProgram.HeaderText = "Part Program Name"; + this.ProcessPartProgram.Name = "ProcessPartProgram"; + // + // ncProcessNameColumn + // + this.ncProcessNameColumn.DataPropertyName = "name"; + this.ncProcessNameColumn.HeaderText = "Name"; + this.ncProcessNameColumn.Name = "ncProcessNameColumn"; + // + // ncProcessStatusColumn + // + this.ncProcessStatusColumn.DataPropertyName = "status"; + this.ncProcessStatusColumn.HeaderText = "Status"; + this.ncProcessStatusColumn.Name = "ncProcessStatusColumn"; + this.ncProcessStatusColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.ncProcessStatusColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + // + // ncProcessModeColumn + // + this.ncProcessModeColumn.DataPropertyName = "mode"; + this.ncProcessModeColumn.HeaderText = "Mode"; + this.ncProcessModeColumn.Name = "ncProcessModeColumn"; + // // alarms // this.alarms.Controls.Add(this.toolStrip3); @@ -418,8 +452,9 @@ this.saveNcAlarmsButton.Image = ((System.Drawing.Image)(resources.GetObject("saveNcAlarmsButton.Image"))); this.saveNcAlarmsButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.saveNcAlarmsButton.Name = "saveNcAlarmsButton"; - this.saveNcAlarmsButton.Size = new System.Drawing.Size(23, 22); + this.saveNcAlarmsButton.Size = new System.Drawing.Size(23, 20); this.saveNcAlarmsButton.Text = "Save"; + this.saveNcAlarmsButton.Click += new System.EventHandler(this.SaveNcAlarmsButton_Click); // // ncAlarmsGridView // @@ -772,39 +807,6 @@ this.stopServer.UseVisualStyleBackColor = true; this.stopServer.Click += new System.EventHandler(this.StopServer_Click); // - // ncProcessIdColumn - // - this.ncProcessIdColumn.DataPropertyName = "id"; - this.ncProcessIdColumn.HeaderText = "Process Id"; - this.ncProcessIdColumn.Name = "ncProcessIdColumn"; - this.ncProcessIdColumn.ReadOnly = true; - // - // ProcessPartProgram - // - this.ProcessPartProgram.DataPropertyName = "part_program_name"; - this.ProcessPartProgram.HeaderText = "Part Program Name"; - this.ProcessPartProgram.Name = "ProcessPartProgram"; - // - // ncProcessNameColumn - // - this.ncProcessNameColumn.DataPropertyName = "name"; - this.ncProcessNameColumn.HeaderText = "Name"; - this.ncProcessNameColumn.Name = "ncProcessNameColumn"; - // - // ncProcessStatusColumn - // - this.ncProcessStatusColumn.DataPropertyName = "status"; - this.ncProcessStatusColumn.HeaderText = "Status"; - this.ncProcessStatusColumn.Name = "ncProcessStatusColumn"; - this.ncProcessStatusColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.ncProcessStatusColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - // - // ncProcessModeColumn - // - this.ncProcessModeColumn.DataPropertyName = "mode"; - this.ncProcessModeColumn.HeaderText = "Mode"; - this.ncProcessModeColumn.Name = "ncProcessModeColumn"; - // // DemoApplicationForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs index 38a9ce7..c7e973d 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.cs @@ -9,12 +9,14 @@ 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; public DemoApplicationForm() { @@ -226,6 +228,11 @@ namespace Nc_Demo_Application // Update cell integerCell.Value = Convert.ToInt32(binaryIntegerCellValue, 2).ToString(); } + if(e.RowIndex == 51 && (int)decimalCell.Value == 0 && !axisResetRunning) + { + axisResetRunning = true; + Task.Run(() => AxisResetProcedureAsync(binaryMemoryGridView.Rows[e.RowIndex])); + } } } @@ -415,5 +422,22 @@ namespace Nc_Demo_Application if (File.Exists(FILE_FOLDER + selectedFile)) File.WriteAllText(FILE_FOLDER + selectedFile, fileContentTextBox.Text); } + + private async Task AxisResetProcedureAsync(DataGridViewRow row) + { + DataTable dt = binaryMemoryGridView.DataSource as DataTable; + row.Cells["BinaryMemoryDecimalColumn"].Value = 128; + + for (int i = 0; i < 100; i++) + { + this.Invoke((MethodInvoker)delegate () + { + row.Cells["BinaryMemoryDecimalColumn"].Value = (int)row.Cells["BinaryMemoryDecimalColumn"].Value + 1; + }); + await Task.Delay(200); + } + axisResetRunning = false; + row.Cells["BinaryMemoryDecimalColumn"].Value = 1; + } } } \ No newline at end of file diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.resx b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.resx index c470576..085e514 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.resx +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Views/DemoApplicationForm.resx @@ -135,6 +135,14 @@ 542, 56 + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABRSURBVDhPY6AK+Pbt239S8NevX+dDtUIASJAheA4cf3j/ + EY6RxUB0zIR9mIaQYgAIwwyBaifdABAm2gBkjKyGtgYQg0cNGJQGkIOh2ikBDAwAR/4LjdUkCHIAAAAA + SUVORK5CYII= + + True @@ -153,26 +161,6 @@ 647, 56 - - 752, 56 - - - 17, 95 - - - 122, 95 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABRSURBVDhPY6AK+Pbt239S8NevX+dDtUIASJAheA4cf3j/ - EY6RxUB0zIR9mIaQYgAIwwyBaifdABAm2gBkjKyGtgYQg0cNGJQGkIOh2ikBDAwAR/4LjdUkCHIAAAAA - SUVORK5CYII= - - - - 647, 56 - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 @@ -193,6 +181,30 @@ True + + 752, 56 + + + 17, 95 + + + 122, 95 + + + True + + + True + + + True + + + True + + + True + True