From 92fab66462d55045cc37b8b8d98a9d88928cc7a3 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 23 Sep 2020 19:03:52 +0200 Subject: [PATCH 1/3] Start abstract config for axis read data --- CMS_CORE_Library/Models/ThermoModels.cs | 18 ++-- CMS_CORE_Library/NcThermo.cs | 12 +++ CMS_CORE_Library/S7Net/Nc_S7Net.cs | 114 ++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/CMS_CORE_Library/Models/ThermoModels.cs b/CMS_CORE_Library/Models/ThermoModels.cs index 84ccf7e..d742a4b 100644 --- a/CMS_CORE_Library/Models/ThermoModels.cs +++ b/CMS_CORE_Library/Models/ThermoModels.cs @@ -136,9 +136,11 @@ namespace CMS_CORE_Library.Models public class AxisInfo { public short Id { get; set; } = 0; - public int errorCode { get; set; } = 0; - public int movPhase { get; set; } = 0; - public int statusCode { get; set; } = 0; + public int ErrorCode { get; set; } = 0; + public int MovPhase { get; set; } = 0; + public int StatusWord { get; set; } = 0; + public int ControlWord { get; set; } = 0; + public double TargetPos { get; set; } = 0; public override bool Equals(object obj) { @@ -148,11 +150,15 @@ namespace CMS_CORE_Library.Models if (Id != item.Id) return false; - if (errorCode != item.errorCode) + if (ErrorCode != item.ErrorCode) return false; - if (movPhase != item.movPhase) + if (MovPhase != item.MovPhase) return false; - if (statusCode != item.statusCode) + if (StatusWord != item.StatusWord) + return false; + if (ControlWord != item.ControlWord) + return false; + if (TargetPos != item.TargetPos) return false; return true; } diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index 88d3e5c..3480140 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -626,6 +626,18 @@ namespace CMS_CORE_Library /// public abstract CmsError PLC_WAckPzProdEnd(); + /// + /// Get current Axis RT data + /// + /// + /// + public abstract CmsError PLC_RAxisRTList(ref Dictionary currAxisRT); + /// + /// Get current Axis Info data + /// + /// + /// + public abstract CmsError PLC_RAxisInfoList(ref Dictionary currAxisInfo); /// /// Get current recipe parameter list /// diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 31b18e4..3c39db1 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2073,6 +2073,120 @@ namespace CMS_CORE_Library.S7Net return libraryError; } + /// + /// Get current Axis RT data + /// + /// + /// + public override CmsError PLC_RAxisRTList(ref Dictionary currAxisRT) + { + CmsError libraryError = NO_ERROR; +#if false + CmsError libraryError = NO_ERROR; + List currMem = new List(); + int packSize = 8; + + // leggo da PLC a array di byte di appoggio... + libraryError = MEM_RWByteList(R, 0, PARAMETER_RT_DATA.MemType, PARAMETER_RT_DATA.Address, PARAMETER_RT_DATA.SubAddress, 0, PARAMETER_RT_DATA.Size, ref currMem); + if (libraryError.IsError()) + return libraryError; + + // controllo SE ho dati... + if (currMem.Count > 0) + { + // converto a blocchi di 8 byte... + byte[] memArray = currMem.ToArray(); + for (int i = 0; i < PARAMETER_RT_DATA.Size / packSize; i++) + { + PlcParamRT currParam = new PlcParamRT(memArray.Skip(i * packSize).Take(packSize).ToArray()); + // solo se ID > 0... + if (currParam.Id > 0) + { + // update oggetto thermoParamList... + if (ThermoParamList.ContainsKey(currParam.Id)) + { + try + { + ThermoParamList[currParam.Id].Enabled = currParam.Enabled; + ThermoParamList[currParam.Id].HasError = currParam.HasError; + ThermoParamList[currParam.Id].Visible = currParam.Visible; + ThermoParamList[currParam.Id].ValueAct = currParam.ValueAct; + } + catch + { } + } + else + { + try + { + ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, Enabled = currParam.Enabled, HasError = currParam.HasError, Visible = currParam.Visible, ValueAct = currParam.ValueAct }); + } + catch + { } + } + } + } + } +#endif + return libraryError; + } + /// + /// Get current Axis Info data + /// + /// + /// + public override CmsError PLC_RAxisInfoList(ref Dictionary currAxisInfo) + { + CmsError libraryError = NO_ERROR; +#if false + CmsError libraryError = NO_ERROR; + List currMem = new List(); + int packSize = 8; + + // leggo da PLC a array di byte di appoggio... + libraryError = MEM_RWByteList(R, 0, PARAMETER_RT_DATA.MemType, PARAMETER_RT_DATA.Address, PARAMETER_RT_DATA.SubAddress, 0, PARAMETER_RT_DATA.Size, ref currMem); + if (libraryError.IsError()) + return libraryError; + + // controllo SE ho dati... + if (currMem.Count > 0) + { + // converto a blocchi di 8 byte... + byte[] memArray = currMem.ToArray(); + for (int i = 0; i < PARAMETER_RT_DATA.Size / packSize; i++) + { + PlcParamRT currParam = new PlcParamRT(memArray.Skip(i * packSize).Take(packSize).ToArray()); + // solo se ID > 0... + if (currParam.Id > 0) + { + // update oggetto thermoParamList... + if (ThermoParamList.ContainsKey(currParam.Id)) + { + try + { + ThermoParamList[currParam.Id].Enabled = currParam.Enabled; + ThermoParamList[currParam.Id].HasError = currParam.HasError; + ThermoParamList[currParam.Id].Visible = currParam.Visible; + ThermoParamList[currParam.Id].ValueAct = currParam.ValueAct; + } + catch + { } + } + else + { + try + { + ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, Enabled = currParam.Enabled, HasError = currParam.HasError, Visible = currParam.Visible, ValueAct = currParam.ValueAct }); + } + catch + { } + } + } + } + } +#endif + return libraryError; + } /// /// read current recipe parameter list /// From 40a937b17bd8926cf2a01607d50c33f03ba754b6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 23 Sep 2020 19:23:21 +0200 Subject: [PATCH 2/3] Continue axis data read --- CMS_CORE_Library/Models/ThermoModels.cs | 44 +++++++++++++++++++++++-- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 30 ++++++++--------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/CMS_CORE_Library/Models/ThermoModels.cs b/CMS_CORE_Library/Models/ThermoModels.cs index d742a4b..5d2af95 100644 --- a/CMS_CORE_Library/Models/ThermoModels.cs +++ b/CMS_CORE_Library/Models/ThermoModels.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace CMS_CORE_Library.Models { @@ -103,7 +104,7 @@ namespace CMS_CORE_Library.Models /// public class AxisRT { - public short Id { get; set; } = 0; + public int Id { get; set; } = 0; public double Position { get; set; } = 0; public double Speed { get; set; } = 0; public double Load { get; set; } = 0; @@ -129,13 +130,52 @@ namespace CMS_CORE_Library.Models { return base.GetHashCode(); } + +#if false + /// + /// Deserializzazione da byte ad oggetto AxisRT + /// + /// + public AxisRT(int currId, double currPosition, double currSpeed, double currLoad) + { + Id = currId; + Position = currPosition; + Speed = currSpeed; + Load = currLoad; + } +#endif + /// + /// Deserializzazione da byte ad oggetto AxisRT + /// + /// + public AxisRT(int currId, byte[] rawData) + { + // converto i dati da byte grezzi ai 3 componenti... + Id = currId; + //Id = S7.Net.Types.Int.FromByteArray(rawData.Skip(0).Take(2).ToArray()); + Position = S7.Net.Types.Double.FromByteArray(rawData.Skip(0).Take(4).ToArray()); + Speed = S7.Net.Types.Double.FromByteArray(rawData.Skip(4).Take(4).ToArray()); + Load = S7.Net.Types.Double.FromByteArray(rawData.Skip(8).Take(4).ToArray()); + } + /// + /// Converte un singolo item in un array di byte per scrittura su PLC S7 + /// + /// + public byte[] convertToByte() + { + byte[] answ = new byte[12]; + Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Position), 0, answ, 0, 4); + Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Speed), 0, answ, 4, 4); + Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Load), 0, answ, 8, 4); + return answ; + } } /// /// Single AXIS Info Data /// public class AxisInfo { - public short Id { get; set; } = 0; + public int Id { get; set; } = 0; public int ErrorCode { get; set; } = 0; public int MovPhase { get; set; } = 0; public int StatusWord { get; set; } = 0; diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 3c39db1..76c950f 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -1072,7 +1072,7 @@ namespace CMS_CORE_Library.S7Net // Read machine variable libraryError = MEM_RWDouble(R, 0, M156_RESPONSE_MEMORY.MemType, M156_RESPONSE_MEMORY.Address, M156_RESPONSE_MEMORY.SubAddress + (int)processId - 1, ref responseVal); if (libraryError.IsError()) - return libraryError; + return libraryError; // Parse line & get parameters value.Add(new M156InputIsNeededModel() { @@ -2081,36 +2081,33 @@ namespace CMS_CORE_Library.S7Net public override CmsError PLC_RAxisRTList(ref Dictionary currAxisRT) { CmsError libraryError = NO_ERROR; -#if false - CmsError libraryError = NO_ERROR; List currMem = new List(); - int packSize = 8; + int packSize = 12; // leggo da PLC a array di byte di appoggio... - libraryError = MEM_RWByteList(R, 0, PARAMETER_RT_DATA.MemType, PARAMETER_RT_DATA.Address, PARAMETER_RT_DATA.SubAddress, 0, PARAMETER_RT_DATA.Size, ref currMem); + libraryError = MEM_RWByteList(R, 0, AXES_RTDATA.MemType, AXES_RTDATA.Address, AXES_RTDATA.SubAddress, 0, AXES_RTDATA.Size, ref currMem); if (libraryError.IsError()) return libraryError; // controllo SE ho dati... if (currMem.Count > 0) { - // converto a blocchi di 8 byte... + // converto a blocchi di byte... byte[] memArray = currMem.ToArray(); - for (int i = 0; i < PARAMETER_RT_DATA.Size / packSize; i++) + for (int i = 0; i < AXES_RTDATA.Size / packSize; i++) { - PlcParamRT currParam = new PlcParamRT(memArray.Skip(i * packSize).Take(packSize).ToArray()); + ThermoModels.AxisRT currData = new ThermoModels.AxisRT(i + 1, memArray.Skip(i * packSize).Take(packSize).ToArray()); // solo se ID > 0... - if (currParam.Id > 0) + if (currData.Id > 0) { // update oggetto thermoParamList... - if (ThermoParamList.ContainsKey(currParam.Id)) + if (currAxisRT.ContainsKey(currData.Id)) { try { - ThermoParamList[currParam.Id].Enabled = currParam.Enabled; - ThermoParamList[currParam.Id].HasError = currParam.HasError; - ThermoParamList[currParam.Id].Visible = currParam.Visible; - ThermoParamList[currParam.Id].ValueAct = currParam.ValueAct; + currAxisRT[currData.Id].Position = currData.Position; + currAxisRT[currData.Id].Speed = currData.Speed; + currAxisRT[currData.Id].Load = currData.Load; } catch { } @@ -2119,7 +2116,7 @@ namespace CMS_CORE_Library.S7Net { try { - ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, Enabled = currParam.Enabled, HasError = currParam.HasError, Visible = currParam.Visible, ValueAct = currParam.ValueAct }); + currAxisRT.Add(currData.Id, currData); } catch { } @@ -2127,7 +2124,6 @@ namespace CMS_CORE_Library.S7Net } } } -#endif return libraryError; } /// @@ -4861,7 +4857,7 @@ namespace CMS_CORE_Library.S7Net // assi internal static MEMORY_CELL AXES_RTDATA = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, 615, 0, 768); - internal static MEMORY_CELL AXES_INFO = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, 616, 0, 640); + internal static MEMORY_CELL AXES_INFO = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, 616, 0, 896); // aree Parametri internal static MEMORY_CELL PARAMETER_DATA = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, 600, 20, 8000); From 784a35cb8d3e9de50462e3ab90c7eb08aa773442 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 23 Sep 2020 20:02:42 +0200 Subject: [PATCH 3/3] Completed axis thermo read (to check...) --- CMS_CORE_Library/Models/ThermoModels.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/CMS_CORE_Library/Models/ThermoModels.cs b/CMS_CORE_Library/Models/ThermoModels.cs index 5d2af95..c235bc4 100644 --- a/CMS_CORE_Library/Models/ThermoModels.cs +++ b/CMS_CORE_Library/Models/ThermoModels.cs @@ -131,19 +131,6 @@ namespace CMS_CORE_Library.Models return base.GetHashCode(); } -#if false - /// - /// Deserializzazione da byte ad oggetto AxisRT - /// - /// - public AxisRT(int currId, double currPosition, double currSpeed, double currLoad) - { - Id = currId; - Position = currPosition; - Speed = currSpeed; - Load = currLoad; - } -#endif /// /// Deserializzazione da byte ad oggetto AxisRT /// @@ -152,7 +139,6 @@ namespace CMS_CORE_Library.Models { // converto i dati da byte grezzi ai 3 componenti... Id = currId; - //Id = S7.Net.Types.Int.FromByteArray(rawData.Skip(0).Take(2).ToArray()); Position = S7.Net.Types.Double.FromByteArray(rawData.Skip(0).Take(4).ToArray()); Speed = S7.Net.Types.Double.FromByteArray(rawData.Skip(4).Take(4).ToArray()); Load = S7.Net.Types.Double.FromByteArray(rawData.Skip(8).Take(4).ToArray());