diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index 0badc0d..d24126d 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -539,8 +539,8 @@ namespace CMS_CORE_Library.Models public class RecipeParam { public short Id { get; set; } = 0; - public int SetpointHMI { get; set; } = 0; - public int SetpointPLC { get; set; } = 0; + public double SetpointHMI { get; set; } = 0; + public double SetpointPLC { get; set; } = 0; public double ValMax { get; set; } = 0; public double ValMin { get; set; } = 0; public ushort UnitMeasure { get; set; } = 0; diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index c5449fe..0ccc3b9 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -632,6 +632,9 @@ namespace CMS_CORE_Library #region THERMO high level data public abstract CmsError PLC_RRecipeParamList(bool onlyRT, ref Dictionary currParamList); + public abstract CmsError PLC_RRecipeLastParamList(ref Dictionary currParamList); + + public abstract CmsError PLC_WRecipeParam(RecipeParam updtParam); #endregion THERMO high level data @@ -1774,7 +1777,7 @@ namespace CMS_CORE_Library internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_TYPE.Null, 3281, 0, 1); internal MEMORY_CELL PARAM_LING_FANUC_W = new MEMORY_CELL(MEMORY_TYPE.Fanuc_G, 581, 0, 1); - + #endregion Fixed memory area /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 8deab4a..7463bba 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2132,15 +2132,6 @@ namespace CMS_CORE_Library.S7Net public override CmsError PLC_RGaugeData(ref GaugeModel gaugeData) { List Values = new List(); - //// TODO FIXME quando disponibile memoria... - //gaugeData = new GaugeModel() - //{ - // TimeAdv = 1, - // Power = 2, - // Vacuum = 3, - // Air = 4, - //}; -#if true CmsError cmsError = MEM_RWIntegerList(R, 1, MACHINE_GAUGE_DATA.MemType, MACHINE_GAUGE_DATA.Address, MACHINE_GAUGE_DATA.SubAddress, MACHINE_GAUGE_DATA.Size / 4, ref Values); if (cmsError.IsError()) @@ -2153,7 +2144,6 @@ namespace CMS_CORE_Library.S7Net Vacuum = Values[2], Air = Values[3], }; -#endif return NO_ERROR; } @@ -2173,15 +2163,56 @@ namespace CMS_CORE_Library.S7Net return NO_ERROR; } + + public override CmsError PLC_RRecipeLastParamList(ref Dictionary currParamList) + { + // copio lista act in output... + refreshMemRecipeParameter(); + refreshMemRecipeParameterRT(); + currParamList = thermoParamList; + return NO_ERROR; + } + + public override CmsError PLC_WRecipeParam(RecipeParam updtParam) + { + // init variabili accessorie + List currMem = new List(); + int packSize = 20; + int memIndex = PARAMETER_DATA.SubAddress + (updtParam.Id - 1) * packSize; + // leggo in primis il parametro che mi richiedono + CmsError cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, memIndex, 0, packSize, ref currMem); + if (cmsError.IsError()) + return cmsError; + + // converto in parametro... + PlcParam currParam = new PlcParam(currMem.ToArray()); + // aggiorno SetpointHMI... + currParam.SetpointHMI = (int)updtParam.SetpointHMI; + // converto a NUOVA lista byte + List newMem = currParam.convertToByte().ToList(); + cmsError = MEM_RWByteList(W, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, memIndex, 0, packSize, ref newMem); + if (cmsError.IsError()) + return cmsError; + +#if false + + // rileggo x verifica... DELETE ME! + cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, memIndex, 0, packSize, ref currMem); + if (cmsError.IsError()) + return cmsError; +#endif + + return NO_ERROR; + } + protected void refreshMemRecipeParameterRT() { List currMem = new List(); + int packSize = 8; // leggo da PLC a array di byte di appoggio... CmsError cmsError = MEM_RWByteList(R, 0, PARAMETER_RT_DATA.MemType, PARAMETER_RT_DATA.Address, PARAMETER_RT_DATA.SubAddress, 0, PARAMETER_RT_DATA.Size, ref currMem); - int packSize = 8; - // controllo SE ho dati... if (currMem.Count > 0) { @@ -2212,11 +2243,11 @@ namespace CMS_CORE_Library.S7Net protected void refreshMemRecipeParameter() { List currMem = new List(); + int packSize = 20; // leggo da PLC a array di byte di appoggio... CmsError cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref currMem); - int packSize = 20; // controllo SE ho dati... if (currMem.Count > 0) @@ -2272,6 +2303,23 @@ namespace CMS_CORE_Library.S7Net Enabled = (Stato & 2) == 2; HasError = (Stato & 4) == 4; } + /// + /// Converte un singolo item in un array di byte per scrittura su PLC S7 + /// + /// + public byte[] convertToByte() + { + // convero stato dai bit... + Stato = 0; + Stato += (ushort)(Visible ? 1 : 0); + Stato += (ushort)(Enabled ? 2 : 0); + Stato += (ushort)(HasError ? 4 : 0); + byte[] answ = new byte[8]; + Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(Id), 0, answ, 0, 2); + Buffer.BlockCopy(S7.Net.Types.Word.ToByteArray(Stato), 0, answ, 2, 2); + Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ValueAct), 0, answ, 4, 4); + return answ; + } } /// /// Oggetto Parametro da PLC @@ -2298,6 +2346,21 @@ namespace CMS_CORE_Library.S7Net ValMin = S7.Net.Types.DInt.FromByteArray(rawData.Skip(14).Take(4).ToArray()); UnitMeasure = S7.Net.Types.Word.FromByteArray(rawData.Skip(18).Take(2).ToArray()); } + /// + /// Converte un singolo item in un array di byte per scrittura su PLC S7 + /// + /// + public byte[] convertToByte() + { + byte[] answ = new byte[20]; + Buffer.BlockCopy(S7.Net.Types.Int.ToByteArray(Id), 0, answ, 0, 2); + Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(SetpointHMI), 0, answ, 2, 4); + Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(SetpointPLC), 0, answ, 6, 4); + Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ValMax), 0, answ, 10, 4); + Buffer.BlockCopy(S7.Net.Types.DInt.ToByteArray(ValMin), 0, answ, 14, 4); + Buffer.BlockCopy(S7.Net.Types.Word.ToByteArray(UnitMeasure), 0, answ, 18, 2); + return answ; + } } #endregion @@ -2786,8 +2849,16 @@ namespace CMS_CORE_Library.S7Net //Prevent some exceptions if (Values.Count == 0) return NO_ERROR; - - currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, Values.ToArray()); + // try/catch + try + { + currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, Values.ToArray()); + } + catch + { + // FIXME TODO rivedere codice errore!!! + return PLC_MEM_CONF_ERROR; + } } else {