diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index f7d3c91..9d2ea36 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -649,11 +649,11 @@ namespace CMS_CORE_Library /// public abstract CmsError PLC_RRecipeParamList(bool onlyRT, ref Dictionary currParamList); /// - /// Write recipe updated parameter + /// Write recipe updated MULTIPLE parameter /// /// /// - public abstract CmsError PLC_WRecipeParam(ThermoModels.RecipeParam updtParam); + 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..93241fd 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2016,30 +2016,55 @@ namespace CMS_CORE_Library.S7Net return currError; } /// - /// Write recipe updated parameter + /// Write recipe updated MULTIPLE parameter /// /// /// - public override CmsError PLC_WRecipeParam(ThermoModels.RecipeParam updtParam) + public override CmsError PLC_WRecipeParameters(Dictionary newParameters) { // init variabili accessorie + CmsError cmsError = NO_ERROR; List currMem = new List(); + int memIndex = 0; 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); + + // 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; - // 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; + 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; }