From d4324ad50f0602292959c7eaa54f8742cf88a2ee Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 15 Jun 2020 19:13:01 +0200 Subject: [PATCH 1/2] Remove old method (single param) --- CMS_CORE_Library/NcThermo.cs | 10 +++++- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 57 +++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index f7d3c91..391f728 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -648,12 +648,20 @@ namespace CMS_CORE_Library /// /// public abstract CmsError PLC_RRecipeParamList(bool onlyRT, ref Dictionary currParamList); +#if false /// /// Write recipe updated parameter /// /// /// - public abstract CmsError PLC_WRecipeParam(ThermoModels.RecipeParam updtParam); + public abstract CmsError PLC_WRecipeParam(ThermoModels.RecipeParam updtParam); +#endif + /// + /// Write recipe updated MULTIPLE parameter + /// + /// + /// + public abstract CmsError PLC_WRecipeParameters(Dictionary newParameters); /// /// Confirm/Cancel recipe modifications /// diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index d91990c..329dfc0 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2015,8 +2015,9 @@ namespace CMS_CORE_Library.S7Net currParamList = ThermoParamList; return currError; } +#if false /// - /// Write recipe updated parameter + /// Write recipe updated SINGLE parameter /// /// /// @@ -2041,6 +2042,60 @@ namespace CMS_CORE_Library.S7Net if (cmsError.IsError()) return cmsError; + return NO_ERROR; + } +#endif + /// + /// Write recipe updated MULTIPLE parameter + /// + /// + /// + public override CmsError PLC_WRecipeParameters(Dictionary newParameters) + { + // init variabili accessorie + CmsError cmsError = NO_ERROR; + List currMem = new List(); + int memIndex = 0; + int packSize = 20; + + // leggo da PLC a array di byte di appoggio... + cmsError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref currMem); + if (cmsError.IsError()) + return cmsError; + + PlcParam currParam; + List newMem = new List(); + // controllo SE ho dati... + if (currMem.Count > 0) + { + // converto in array di byte... + byte[] memArray = currMem.ToArray(); + // ciclo x ogni parametro x aggiornare il valore... + foreach (var item in newParameters) + { + memIndex = (item.Key - 1) * packSize; + // recupero oggetto parametri + currParam = new PlcParam(memArray.Skip(memIndex).Take(packSize).ToArray()); + if (currParam.Id > 0) + { + // se servisse resetto... + if (currParam.Id != (short)item.Key) + currParam.Id = (short)item.Key; + currParam.SetpointHMI = (int)item.Value; + } + // riconverto in byte e sostituisco... + Buffer.BlockCopy(currParam.convertToByte(), 0, memArray, memIndex, packSize); + } + + // converto nuova memoria + newMem = memArray.ToList(); + memIndex = 0; + // SCRIVO in blocco! + cmsError = MEM_RWByteList(W, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref newMem); + if (cmsError.IsError()) + return cmsError; + } + return NO_ERROR; } /// From 31624c5ee719c72c08a1bae10cd75558b7536373 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 15 Jun 2020 19:29:02 +0200 Subject: [PATCH 2/2] Removed old method + fix startup --- CMS_CORE_Library/NcThermo.cs | 8 -------- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 30 ------------------------------ 2 files changed, 38 deletions(-) diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index 391f728..9d2ea36 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -648,14 +648,6 @@ namespace CMS_CORE_Library /// /// public abstract CmsError PLC_RRecipeParamList(bool onlyRT, ref Dictionary currParamList); -#if false - /// - /// Write recipe updated parameter - /// - /// - /// - public abstract CmsError PLC_WRecipeParam(ThermoModels.RecipeParam updtParam); -#endif /// /// Write recipe updated MULTIPLE parameter /// diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 329dfc0..93241fd 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2015,36 +2015,6 @@ namespace CMS_CORE_Library.S7Net currParamList = ThermoParamList; return currError; } -#if false - /// - /// Write recipe updated SINGLE parameter - /// - /// - /// - public override CmsError PLC_WRecipeParam(ThermoModels.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; - - return NO_ERROR; - } -#endif /// /// Write recipe updated MULTIPLE parameter ///