diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 1f1855c..d167384 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -3831,68 +3831,52 @@ namespace CMS_CORE_Library.S7Net protected CmsError refreshChIOVisib() { CmsError libraryError = NO_ERROR; -#if false - List currMem = new List(); - int packSize = 20; + Byte[] byteArray = null; + List readValuesDI = new List(); + List readValuesDO = new List(); + List readValuesAI = new List(); + List readValuesAO = new List(); - // 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); + // leggo da PLC a array di byte di appoggio x visibilità DI... + libraryError = MEM_RWWordList(R, 0, IO_DI_VISIB.MemType, IO_DI_VISIB.Address, IO_DI_VISIB.SubAddress, IO_DI_VISIB.Size, ref readValuesDI); + if (libraryError.IsError()) + return libraryError; + // leggo da PLC a array di byte di appoggio x visibilità DO... + libraryError = MEM_RWWordList(R, 0, IO_DO_VISIB.MemType, IO_DO_VISIB.Address, IO_DO_VISIB.SubAddress, IO_DO_VISIB.Size, ref readValuesDO); + if (libraryError.IsError()) + return libraryError; + // leggo da PLC a array di byte di appoggio x visibilità AI... + libraryError = MEM_RWWordList(R, 0, IO_AI_VISIB.MemType, IO_AI_VISIB.Address, IO_AI_VISIB.SubAddress, IO_AI_VISIB.Size, ref readValuesAI); + if (libraryError.IsError()) + return libraryError; + // leggo da PLC a array di byte di appoggio x visibilità AO... + libraryError = MEM_RWWordList(R, 0, IO_AO_VISIB.MemType, IO_AO_VISIB.Address, IO_AO_VISIB.SubAddress, IO_AO_VISIB.Size, ref readValuesAO); if (libraryError.IsError()) return libraryError; - - - // controllo SE ho dati... - if (currMem.Count > 0) - { - // converto a blocchi di 8 byte... - byte[] memArray = currMem.ToArray(); - - for (int i = 0; i < PARAMETER_DATA.Size / packSize; i++) - { - PlcParam currParam = new PlcParam(memArray.Skip(i * packSize).Take(packSize).ToArray()); - // solo se ID > 0... - if (currParam.Id > 0) - { - // update oggetto thermoParamList... - if (ThermoParamList.ContainsKey(currParam.Id)) - { - try - { - ThermoParamList[currParam.Id].SetpointHMI = currParam.SetpointHMI; - ThermoParamList[currParam.Id].SetpointPLC = currParam.SetpointPLC; - ThermoParamList[currParam.Id].ValMax = currParam.ValMax; - ThermoParamList[currParam.Id].ValMin = currParam.ValMin; - ThermoParamList[currParam.Id].UnitMeasure = currParam.UnitMeasure; - } - catch - { } - } - else - { - try - { - ThermoParamList.Add(currParam.Id, new ThermoModels.RecipeParam() { Id = currParam.Id, SetpointHMI = currParam.SetpointHMI, SetpointPLC = currParam.SetpointPLC, ValMax = currParam.ValMax, ValMin = currParam.ValMin, UnitMeasure = currParam.UnitMeasure }); - } - catch - { } - } - } - else - { - libraryError = S7_PLC_WRONG_DATA; - } - } - } - else - { - libraryError = S7_PLC_EMPTY_READ; - } -#endif - + ThermoIOVis.DI = convShortToDict(readValuesDI); + ThermoIOVis.DO = convShortToDict(readValuesDO); + ThermoIOVis.AI = convShortToDict(readValuesAI); + ThermoIOVis.AO = convShortToDict(readValuesAO); return libraryError; } + + internal static Dictionary convShortToDict(List origVal) + { + Byte[] byteArray = null; + // Convert List into Byte Array + byteArray = origVal.SelectMany(j => BitConverter.GetBytes(j)).ToArray(); + // converto a bit + BitArray bitArr = new BitArray(byteArray); + Dictionary answ = new Dictionary(); + for (int i = 0; i < bitArr.Count; i++) + { + answ.Add(i, bitArr[i]); + } + return answ; + } + /// /// Refresh recipe parameters /// diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index 3515087..c12d8ff 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -203,7 +203,7 @@ namespace CMS_CORE_Library.Utils .Cast() .ToArray(); } - + // Convert a byte into an array of bools public static bool[] ByteToBits(byte val) {