review write method recipe (single if < 30)

This commit is contained in:
Samuele Locatelli
2020-07-06 16:47:22 +02:00
parent c5ff5ab8ac
commit f0bb12d549
+22 -6
View File
@@ -2080,6 +2080,8 @@ namespace CMS_CORE_Library.S7Net
int memIndex = 0;
int packSize = 20;
bool writeSingle = newParameters.Count < 30;
// leggo da PLC a array di byte di appoggio...
libraryError = MEM_RWByteList(R, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref currMem);
if (libraryError.IsError())
@@ -2104,18 +2106,32 @@ namespace CMS_CORE_Library.S7Net
if (currParam.Id != (short)item.Key)
currParam.Id = (short)item.Key;
currParam.SetpointHMI = (int)item.Value;
// scrivo 1:1 se pochi dati SOLO i singoli valori HMI
if (writeSingle)
{
newMem = S7.Net.Types.DInt.ToByteArray(currParam.SetpointHMI).ToList();// currParam.convertToByte().ToList();
libraryError = MEM_RWByteList(W, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress + packSize * (currParam.Id - 1) + 2, 0, 4, ref newMem);
if (libraryError.IsError())
return libraryError;
}
else
{
// accodo su memoria generale
Buffer.BlockCopy(currParam.convertToByte(), 0, memArray, memIndex, packSize);
}
}
// riconverto in byte e sostituisco...
Buffer.BlockCopy(currParam.convertToByte(), 0, memArray, memIndex, packSize);
}
// converto nuova memoria
newMem = memArray.ToList();
memIndex = 0;
// SCRIVO in blocco!
libraryError = MEM_RWByteList(W, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref newMem);
if (libraryError.IsError())
return libraryError;
if (!writeSingle)
{
// SCRIVO in blocco!
libraryError = MEM_RWByteList(W, 0, PARAMETER_DATA.MemType, PARAMETER_DATA.Address, PARAMETER_DATA.SubAddress, 0, PARAMETER_DATA.Size, ref newMem);
if (libraryError.IsError())
return libraryError;
}
}
return NO_ERROR;