From e2f248f57ca4cad9cb1506c19f6ebead279b78be Mon Sep 17 00:00:00 2001 From: "S.E.Locatelli" Date: Mon, 27 Jun 2022 10:52:20 +0200 Subject: [PATCH] Correzione decodifica bitmap NWSE - prende dati correttamente - costruisce stringa corretta --- IOB-WIN-NEXT/DATA/CONF/GIACO_NWSE.json | 16 ++++++++-------- IOB-WIN-NEXT/IobGeneric.cs | 13 +++++++------ IOB-WIN-NEXT/IobSiemens.cs | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/IOB-WIN-NEXT/DATA/CONF/GIACO_NWSE.json b/IOB-WIN-NEXT/DATA/CONF/GIACO_NWSE.json index 6de99151..66e7a0b0 100644 --- a/IOB-WIN-NEXT/DATA/CONF/GIACO_NWSE.json +++ b/IOB-WIN-NEXT/DATA/CONF/GIACO_NWSE.json @@ -14,7 +14,7 @@ "name": "StatoOsmosi", "description": "Stato Osmosi Inversa", "memAddr": "DB100.DBB20", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 20, "size": 2, "func": "MAX", @@ -28,7 +28,7 @@ "name": "StatoDepurazione", "description": "Stato Depurazione", "memAddr": "DB100.DBB22", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 22, "size": 2, "func": "MAX", @@ -43,7 +43,7 @@ "name": "StatoFiltro01", "description": "Stato Filtro 1", "memAddr": "DB100.DBB24", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 24, "size": 2, "func": "MAX", @@ -62,7 +62,7 @@ "name": "StatoFiltro02", "description": "Stato Filtro 2", "memAddr": "DB100.DBB26", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 26, "size": 2, "func": "MAX", @@ -81,7 +81,7 @@ "name": "StatoFiltro03", "description": "Stato Filtro 3", "memAddr": "DB100.DBB28", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 28, "size": 2, "func": "MAX", @@ -100,7 +100,7 @@ "name": "StatoFiltro04", "description": "Stato Filtro 4", "memAddr": "DB100.DBB30", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 30, "size": 2, "func": "MAX", @@ -119,7 +119,7 @@ "name": "StatoFiltro05", "description": "Stato Filtro 5", "memAddr": "DB100.DBB32", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 32, "size": 2, "func": "MAX", @@ -138,7 +138,7 @@ "name": "StatoFiltro06", "description": "Stato Filtro 6", "memAddr": "DB100.DBB34", - "tipoMem": "Int", + "tipoMem": "BitMap", "index": 34, "size": 2, "func": "MAX", diff --git a/IOB-WIN-NEXT/IobGeneric.cs b/IOB-WIN-NEXT/IobGeneric.cs index a51439a5..b51587db 100644 --- a/IOB-WIN-NEXT/IobGeneric.cs +++ b/IOB-WIN-NEXT/IobGeneric.cs @@ -1885,27 +1885,28 @@ namespace IOB_WIN_NEXT /// Effettua conversione da valore bitmap ai valori configurati /// /// - /// + /// /// - public string getBitmapState(dataConfTSVC memConf, int bitMapVal) + public string getBitmapState(dataConfTSVC memConf, byte[] bState) { string valTransl = ""; List descAttivi = new List(); - BitArray bitAttivi = new BitArray(bitMapVal); + BitArray bitAttivi = new BitArray(bState); bool[] bitStati = new bool[bitAttivi.Count]; bitAttivi.CopyTo(bitStati, 0); // cerco bit attivi int idx = 0; foreach (var item in bitStati) { - if (item) + if (item && memConf.decodeMap.Count > idx) { - string currState = memConf.decodeMap.Count >= idx ? memConf.decodeMap[idx] : $"State_{idx}"; + string currState = memConf.decodeMap[idx]; descAttivi.Add(currState); } + idx++; } // combino string - string.Join(",", descAttivi); + valTransl= string.Join(",", descAttivi); return valTransl; } diff --git a/IOB-WIN-NEXT/IobSiemens.cs b/IOB-WIN-NEXT/IobSiemens.cs index 9abdcc21..d24a886e 100644 --- a/IOB-WIN-NEXT/IobSiemens.cs +++ b/IOB-WIN-NEXT/IobSiemens.cs @@ -848,9 +848,9 @@ namespace IOB_WIN_NEXT break; case plcDataType.BitMap: - valore = ((double)S7.Net.Types.Int.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor; + byte[] byteState = RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray(); // calcolo valore string come unione delle bitmap attive... - valString = getBitmapState(item.Value, (int)valore); + valString = getBitmapState(item.Value, byteState); saveValueString(ref outVal, valString, item.Key); break;