diff --git a/CMS_CORE_Library/Models/ThermoModels.cs b/CMS_CORE_Library/Models/ThermoModels.cs index 84ccf7e..c235bc4 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,16 +130,43 @@ namespace CMS_CORE_Library.Models { return base.GetHashCode(); } + + /// + /// Deserializzazione da byte ad oggetto AxisRT + /// + /// + public AxisRT(int currId, byte[] rawData) + { + // converto i dati da byte grezzi ai 3 componenti... + Id = currId; + 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 errorCode { get; set; } = 0; - public int movPhase { get; set; } = 0; - public int statusCode { 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; + public int ControlWord { get; set; } = 0; + public double TargetPos { get; set; } = 0; public override bool Equals(object obj) { @@ -148,11 +176,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..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() { @@ -2073,6 +2073,116 @@ namespace CMS_CORE_Library.S7Net return libraryError; } + /// + /// Get current Axis RT data + /// + /// + /// + public override CmsError PLC_RAxisRTList(ref Dictionary currAxisRT) + { + CmsError libraryError = NO_ERROR; + List currMem = new List(); + int packSize = 12; + + // leggo da PLC a array di byte di appoggio... + 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 byte... + byte[] memArray = currMem.ToArray(); + for (int i = 0; i < AXES_RTDATA.Size / packSize; i++) + { + ThermoModels.AxisRT currData = new ThermoModels.AxisRT(i + 1, memArray.Skip(i * packSize).Take(packSize).ToArray()); + // solo se ID > 0... + if (currData.Id > 0) + { + // update oggetto thermoParamList... + if (currAxisRT.ContainsKey(currData.Id)) + { + try + { + currAxisRT[currData.Id].Position = currData.Position; + currAxisRT[currData.Id].Speed = currData.Speed; + currAxisRT[currData.Id].Load = currData.Load; + } + catch + { } + } + else + { + try + { + currAxisRT.Add(currData.Id, currData); + } + catch + { } + } + } + } + } + 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 /// @@ -4747,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);