From 8608bad05517c2cb3734ab272469fe100b77514d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 29 May 2020 15:58:05 +0200 Subject: [PATCH] Updated methods for S7 write --- CMS_CORE_Library/Models/DataStructures.cs | 4 +- CMS_CORE_Library/NcThermo.cs | 5 +- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 69 ++++++++++++++++++----- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index ad38b3e..4fdd1fa 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -531,8 +531,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 c7b6069..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) @@ -2818,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 {