From b2128bc23b4847ec0775ab5bf94b34579349f7bd Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 16 Sep 2022 16:23:13 +0200 Subject: [PATCH] Update modbus x HELPI e contapezzi --- IOB-WIN-NEXT/DATA/CONF/FINASSI_HELPI_01.ini | 4 +- IOB-WIN-NEXT/IobModbusTCP.cs | 168 ++++---------------- 2 files changed, 31 insertions(+), 141 deletions(-) diff --git a/IOB-WIN-NEXT/DATA/CONF/FINASSI_HELPI_01.ini b/IOB-WIN-NEXT/DATA/CONF/FINASSI_HELPI_01.ini index 04609c9a..36bbcdb0 100644 --- a/IOB-WIN-NEXT/DATA/CONF/FINASSI_HELPI_01.ini +++ b/IOB-WIN-NEXT/DATA/CONF/FINASSI_HELPI_01.ini @@ -48,8 +48,8 @@ BLINK_FILT=0 ;BLINK_FILT=28 [OPTPAR] -;PZCOUNT_MODE=STD.[PAR/MEM].info|BIT.indice -PZCOUNT_MODE=STD.41100.UDINT32 +;PZCOUNT_MODE=STD.Nome valore DynData +PZCOUNT_MODE=STD.NumPacchi DISABLE_PZCOUNT=TRUE ENABLE_SEND_PZC_BLOCK=TRUE MIN_SEND_PZC_BLOCK=0 diff --git a/IOB-WIN-NEXT/IobModbusTCP.cs b/IOB-WIN-NEXT/IobModbusTCP.cs index 2f9bb72e..fa46428d 100644 --- a/IOB-WIN-NEXT/IobModbusTCP.cs +++ b/IOB-WIN-NEXT/IobModbusTCP.cs @@ -243,26 +243,6 @@ namespace IOB_WIN_NEXT outVal = new Dictionary(); tryConnect(); } - // refuso, gestito da getAlarmData di IobGeneric -#if false - // ora aggiungo (se ci fossero) gli allarmi... - if (alarmMaps != null && alarmMaps.Count > 0) - { - if (hasAlarms) - { - string bankVal = ""; - foreach (var item in alarmMaps) - { - bankVal = ""; - var currState = currAlarmsState(item); - // calcolo vettore stringa degli allarmi... - bankVal = getAlarmState(item, currState); - bankVal = string.IsNullOrEmpty(bankVal) ? "OK" : bankVal; - saveAlarmString(ref outVal, bankVal, item.description); - } - } - } -#endif } } else @@ -663,125 +643,6 @@ namespace IOB_WIN_NEXT return answ; } -#if false - // refuso: usato metodo base IobGeneric - protected override bool hasAlarms() - { - bool answ = false; - int numErrors = 0; - int currStatus = 0; - int[] listInt = new int[2]; - if (alarmMaps != null) - { - // leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme... - foreach (var item in alarmMaps) - { - // banchi in array Int16 --> scompongo - for (int i = 0; i < item.size / 2; i++) - { - // verifico se usare LUT - bool useLUT = memSetR != null && memSetR.Count > 0; - if (useLUT) - { - int lutAddress = 40000 + item.index; - if (HoldingRegisterLUT.ContainsKey(lutAddress)) - { - try - { - listInt = HoldingRegisterLUT[lutAddress]; - } - catch (Exception exc) - { - lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}"); - } - } - } - else - { - listInt = readInputReg(item.index, item.size); - } - currStatus = ModbusClient.ConvertRegistersToInt(listInt); - - // aggiornamento blink counters dato nuovo valore - item.checkBlinkCounter(i, (uint)currStatus); - - // calcolo indice errori - if ((uint)(item.alarmsMask[i] & currStatus) > 0) - { - numErrors++; - } - // verifico SE sia variato... confronto allarmi filtrato stile blink per bit status: - // - allarmi che iniziano per # IGNORATI - // - altri allarmi con un countdown da MAX_COUNTER_BLINK a 0 per il fronte - // di discesa - if (item.isChanged(i, (uint)currStatus)) - { - // registro gli allarmi attivi e trasmetto... - if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], (uint)(item.alarmsMask[i] & currStatus), item.messages)) - { - // se inviato --> salvo stato da current... - item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus)); - } - } - } - } - } - answ = numErrors > 0; - return answ; - } -#endif -#if false - /// - /// Restituisce stato allarmi in formato byte[] - /// - /// - /// - protected byte[] currAlarmsState(BaseAlarmConf item) - { - byte[] answ = new byte[item.size]; - int currStatus = 0; - int[] listInt = new int[2]; - // banchi in array Int16 --> scompongo - for (int i = 0; i < item.size / 2; i++) - { - // verifico se usare LUT - bool useLUT = memSetR != null && memSetR.Count > 0; - if (useLUT) - { - int lutAddress = 40000 + item.index; - if (HoldingRegisterLUT.ContainsKey(lutAddress)) - { - try - { - listInt = HoldingRegisterLUT[lutAddress]; - } - catch (Exception exc) - { - lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}"); - } - } - } - else - { - listInt = readInputReg(item.index, item.size); - } - currStatus = ModbusClient.ConvertRegistersToInt(listInt); - - // aggiornamento blink counters dato nuovo valore - item.checkBlinkCounter(i, (uint)currStatus); - - // calcolo indice errori - if ((uint)(item.alarmsMask[i] & currStatus) > 0) - { - var currByte = BitConverter.GetBytes(currStatus); - // salvo nell'array di byte - Buffer.BlockCopy(currByte, 0, answ, i * 2, 2); - } - } - return answ; - } -#endif - /// /// Override metodo x scrittura parametri su PLC /// @@ -932,6 +793,35 @@ namespace IOB_WIN_NEXT } } + public override void processContapezzi() + { + if ((enablePzCountByApp || enablePzCountByIob) && !(disablePzCounteByIob)) + { + if (cIobConf.optPar.Count > 0 && !string.IsNullOrWhiteSpace(getOptPar("PZCOUNT_MODE"))) + { + // cerco in lastDynData... + string pzCountKey = getOptPar("PZCOUNT_MODE").Replace("STD.",""); + if (lastDynData.ContainsKey(pzCountKey)) + { + string rawVal = lastDynData[pzCountKey]; + int pzCounter = -1; + if (!string.IsNullOrEmpty(rawVal)) + { + int.TryParse(rawVal, out pzCounter); + if (pzCounter >= 0) + { + contapezziPLC = pzCounter; + } + } + } + } + } + else + { + lgTrace($"processContapezzi escluso: enablePzCountByApp = {enablePzCountByApp} | enablePzCountByIob: {enablePzCountByIob} | disablePzCounteByIob: {disablePzCounteByIob}"); + } + } + /// /// Imposto parametri PLC ///