From c63e59b18783fd7746dc0f14a3ffb5b89b8cc5a5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 30 Sep 2021 14:45:42 +0200 Subject: [PATCH 1/6] GEstione bypass emergenza x robotservice --- IOB-WIN-NEXT/DATA/CONF/1033.ini | 2 ++ IOB-WIN-NEXT/IobSiemensRobotService.cs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/IOB-WIN-NEXT/DATA/CONF/1033.ini b/IOB-WIN-NEXT/DATA/CONF/1033.ini index dc69397a..4a3dadb6 100644 --- a/IOB-WIN-NEXT/DATA/CONF/1033.ini +++ b/IOB-WIN-NEXT/DATA/CONF/1033.ini @@ -59,6 +59,8 @@ ENABLE_DYN_DATA=TRUE FORCE_DYN_DATA=TRUE ; gestione scrittura string/char[]: true = string / false = char[] WRITE_PRE=TRUE +; gestione emergenza forzata (ignora valore letto, mette sempre ARMED) +EMERGENCY_BYPASS=true ; conf parametri memoria READ/WRITE PARAM_CONF=1033.json diff --git a/IOB-WIN-NEXT/IobSiemensRobotService.cs b/IOB-WIN-NEXT/IobSiemensRobotService.cs index 069979c5..f3124f9f 100644 --- a/IOB-WIN-NEXT/IobSiemensRobotService.cs +++ b/IOB-WIN-NEXT/IobSiemensRobotService.cs @@ -29,6 +29,7 @@ namespace IOB_WIN_NEXT * B0.4 Bit Manuale * B0.5 Bit MagOutPieno * B0.6 Bit MagInVuoto + * B0.7 Bit EmergenzaArmata (0=triggered,premuta) * Contapezzi DInt 2 * PezziRiman DInt 6 * @@ -45,6 +46,12 @@ namespace IOB_WIN_NEXT * * -------------------------------------------------------------------------------- */ + #region Protected Fields + + protected bool EmergencyBypass = false; + + #endregion Protected Fields + #region Public Constructors /// @@ -55,6 +62,12 @@ namespace IOB_WIN_NEXT public IobSiemensRobotService(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf) { lgInfo("NEW IOB SIEMENS versione RobotService"); + + if (IOBConf.optPar.ContainsKey("EMERGENCY_BYPASS")) + { + bool.TryParse(IOBConf.optPar["EMERGENCY_BYPASS"], out EmergencyBypass); + lgInfo($"Override EmergencyBypass da conf: {IOBConf.optPar["EMERGENCY_BYPASS"]} --> {EmergencyBypass}"); + } } #endregion Public Constructors @@ -95,6 +108,12 @@ namespace IOB_WIN_NEXT byteSignals &= ~(1 << 0); } + // se bypass emergenza attivo --> forzo a ARMED... + if (EmergencyBypass) + { + byteSignals |= (1 << 7); + } + // salvo! B_input = byteSignals; From 2cebc14c34099f8d2c1b76f686c4644de9abc5fd Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 1 Oct 2021 15:14:07 +0200 Subject: [PATCH 2/6] FIX SIM x avere dati tipo GWMS --- IOB-UT-NEXT/baseUtils.cs | 25 +++- IOB-WIN-NEXT/App.config | 3 +- IOB-WIN-NEXT/DATA/CONF/MAIN.ini | 3 +- IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json | 70 ++++++++++ IOB-WIN-NEXT/DATA/CONF/SIM_PIZ03.ini | 74 +++++++++++ IOB-WIN-NEXT/DATA/CONF/SIM_PIZ04.ini | 74 +++++++++++ IOB-WIN-NEXT/DATA/CONF/SIM_PIZ05.ini | 74 +++++++++++ IOB-WIN-NEXT/DATA/CONF/SIM_PIZ08.ini | 74 +++++++++++ IOB-WIN-NEXT/IOB-WIN-NEXT.csproj | 15 +++ IOB-WIN-NEXT/IobGeneric.cs | 6 +- IOB-WIN-NEXT/IobSimula.cs | 177 +++++++++++++++----------- 11 files changed, 514 insertions(+), 81 deletions(-) create mode 100644 IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json create mode 100644 IOB-WIN-NEXT/DATA/CONF/SIM_PIZ03.ini create mode 100644 IOB-WIN-NEXT/DATA/CONF/SIM_PIZ04.ini create mode 100644 IOB-WIN-NEXT/DATA/CONF/SIM_PIZ05.ini create mode 100644 IOB-WIN-NEXT/DATA/CONF/SIM_PIZ08.ini diff --git a/IOB-UT-NEXT/baseUtils.cs b/IOB-UT-NEXT/baseUtils.cs index 84363305..4315e155 100644 --- a/IOB-UT-NEXT/baseUtils.cs +++ b/IOB-UT-NEXT/baseUtils.cs @@ -151,7 +151,7 @@ namespace IOB_UT_NEXT // controllo se ho un VETO all'invio... if (dtVetoSend < DateTime.Now) { - callUrlNow(URL, payload); + answ = callUrlNow(URL, payload); } // restituisco valore! return answ; @@ -197,6 +197,13 @@ namespace IOB_UT_NEXT client.Headers.Add("user-agent", $"{CRS("appName")}"); try { + // problema certificati locali... + // https://living-sun.com/it/c/226351-webexception-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-c-aspnet-web-services-ssl-webexception.html + // hack x certificati locali in 10.74.82.* + if (URL.Contains("10.74.82.")) + { + System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; }; + } answ = client.DownloadString(URL); } catch (Exception exc) @@ -235,7 +242,23 @@ namespace IOB_UT_NEXT clientPayload.Headers.Add("Content-Type", "application/json"); try { + // problema certificati locali... + // https://living-sun.com/it/c/226351-webexception-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-c-aspnet-web-services-ssl-webexception.html + // hack x certificati locali in 10.74.82.* + if (URL.Contains("10.74.82.")) + { + System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; }; + } answ = clientPayload.UploadString(URL, payload); + if (answ != "OK") + { + logReduxFactor--; + if (logReduxFactor <= 0) + { + lg.Error($"Invio dati fallito:{Environment.NewLine}- URL{Environment.NewLine}{URL}{Environment.NewLine}- payload{Environment.NewLine}{payload}"); + logReduxFactor = 5; + } + } } catch (Exception exc) { diff --git a/IOB-WIN-NEXT/App.config b/IOB-WIN-NEXT/App.config index 1c941d10..6b3846da 100644 --- a/IOB-WIN-NEXT/App.config +++ b/IOB-WIN-NEXT/App.config @@ -39,7 +39,8 @@ - + + diff --git a/IOB-WIN-NEXT/DATA/CONF/MAIN.ini b/IOB-WIN-NEXT/DATA/CONF/MAIN.ini index 86d8995d..72923f8f 100644 --- a/IOB-WIN-NEXT/DATA/CONF/MAIN.ini +++ b/IOB-WIN-NEXT/DATA/CONF/MAIN.ini @@ -68,7 +68,8 @@ CLI_INST=SteamWareSim ;STARTLIST=PIZ08 ;STARTLIST=PIZ04 ;STARTLIST=PIZ05 -STARTLIST=FOV062 +;STARTLIST=FOV062 +STARTLIST=SIM_PIZ03 ;STARTLIST=OPC_UA MAXCNC=10 \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json new file mode 100644 index 00000000..9534a73f --- /dev/null +++ b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json @@ -0,0 +1,70 @@ +{ + //"mMapWrite": { + // "setArt": { + // "name": "setArt", + // "description": "Articolo", + // "memAddr": "DB150.DBB12", + // "tipoMem": "String", + // "index": 12, + // "size": 20 + // }, + // "setComm": { + // "name": "setComm", + // "description": "Commessa", + // "memAddr": "DB150.DBB32", + // "tipoMem": "String", + // "index": 32, + // "size": 20 + // }, + // "setPzComm": { + // "name": "setPzComm", + // "description": "Qty", + // "memAddr": "DB150.DBB8", + // "tipoMem": "Int", + // "index": 8, + // "size": 4 + // }, + // "forceSetPzCount": { + // "name": "forceSetPzCount", + // "description": "Qty", + // "memAddr": "DB150.DBB8", + // "tipoMem": "Int", + // "index": 8, + // "size": 4 + // } + //}, + "mMapRead": { + "Level": { + "name": "SIM_LEVEL", + "description": "Livello Serbatoio", + "tipoMem": "Real", + "minVal": 5000, + "maxVal": 250000, + "factor": 1 + }, + "PressBH": { + "name": "SIM_PressBH", + "description": "Pressione ALTA Bolbole", + "tipoMem": "Real", + "minVal": 2000, + "maxVal": 2300, + "factor": 10 + }, + "PressBL": { + "name": "SIM_PressBL", + "description": "Pressione Media Bolbole", + "tipoMem": "Real", + "minVal": 2100, + "maxVal": 2500, + "factor": 10 + }, + "MainPress": { + "name": "SIM_MainPress", + "description": "Pressione principale", + "tipoMem": "Real", + "minVal": 30, + "maxVal": 150, + "factor": 10 + } + } +} \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ03.ini b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ03.ini new file mode 100644 index 00000000..9f996f7e --- /dev/null +++ b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ03.ini @@ -0,0 +1,74 @@ +;Configurazione IOB-WIN +[IOB] +CNCTYPE=SIMULA +PING_MS_TIMEOUT=500 + +[MACHINE] +VENDOR=STEAMWARE +MODEL=DEMO_SIMULATOR_GWMS + +[CNC] +IP=127.0.0.1 +PORT=0000 + +[SERVER] +MPIP=https://10.74.82.240 +MPURL=/api +CMDBASE=/IOB/input/ +CMDFLOG=/IOB/flog/ +CMDALIVE=/IOB +CMDENABLED=/IOB/enabled/ +CMDADV1=?valore= +CMDREBO=/IOB/sendReboot?idxMacchina= + +CMD_ODL_STARTED=/IOB/getCurrOdlStart/ +CMD_FORCLE_SPLIT_ODL=/IOB/forceSplitOdlFull/ +CMD_IDLE_TIME=/IOB/getIdlePeriod/ + +[MEMORY] + +[BLINK] +MAX_COUNTER_BLINK = 15 +BLINK_FILT=0 + +[OPTPAR] +AUTO_CHANGE_ODL=false +DISABLE_SIM_STATUS=true +;PZCOUNT_MODE=STD.[PAR/MEM].info|BIT.indice +PZCOUNT_MODE=BIT +ENABLE_PZ_RESET=TRUE +; per il simulatore: 50|1 = WAIT 50, DURATION 1 con riferimento al PERIODO base (PER_BASE, default 1 secondo) +PER_BASE=9800 +SIM_PZCNT=13|1 +SIM_ALARM=200|10 +SIM_MANU=130|3 +; indica gestione e simulazione bit 5 --> slow +SIM_SLOW=2500|20 +; indica gestione e simulazione bit 6 --> warmup/cooldown +SIM_WUCD=8000|20 +; indica gestione e simulazione bit 7 --> emergenza +SIM_EMRG=4000|10 +; indica simulazione delle funzionalita power ON/ OFF +SIM_POW_ON_OFF=false +T_ON=6 +T_OFF=22 +; gestione DynData simulati +ENABLE_DYN_DATA=TRUE +FORCE_DYN_DATA=TRUE +NEW_DYN_DATA=TRUE +;gestione invio pezzi in blocco +ENABLE_SEND_PZC_BLOCK=TRUE +MIN_SEND_PZC_BLOCK=0 +MAX_SEND_PZC_BLOCK=100 +MIN_DURATA_ODL=240 +; indica parametri gestione TcMan +TC_MAX_TC_FACTOR=3.9 +TC_LAMBDA=0.4 +TC_MAX_INCR=5 +MAX_PZ_INCR_PERC=1000 + +; conf parametri memoria READ/WRITE +PARAM_CONF=SIM_PIZ00.json + +[BRANCH] +NAME=master \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ04.ini b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ04.ini new file mode 100644 index 00000000..9f996f7e --- /dev/null +++ b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ04.ini @@ -0,0 +1,74 @@ +;Configurazione IOB-WIN +[IOB] +CNCTYPE=SIMULA +PING_MS_TIMEOUT=500 + +[MACHINE] +VENDOR=STEAMWARE +MODEL=DEMO_SIMULATOR_GWMS + +[CNC] +IP=127.0.0.1 +PORT=0000 + +[SERVER] +MPIP=https://10.74.82.240 +MPURL=/api +CMDBASE=/IOB/input/ +CMDFLOG=/IOB/flog/ +CMDALIVE=/IOB +CMDENABLED=/IOB/enabled/ +CMDADV1=?valore= +CMDREBO=/IOB/sendReboot?idxMacchina= + +CMD_ODL_STARTED=/IOB/getCurrOdlStart/ +CMD_FORCLE_SPLIT_ODL=/IOB/forceSplitOdlFull/ +CMD_IDLE_TIME=/IOB/getIdlePeriod/ + +[MEMORY] + +[BLINK] +MAX_COUNTER_BLINK = 15 +BLINK_FILT=0 + +[OPTPAR] +AUTO_CHANGE_ODL=false +DISABLE_SIM_STATUS=true +;PZCOUNT_MODE=STD.[PAR/MEM].info|BIT.indice +PZCOUNT_MODE=BIT +ENABLE_PZ_RESET=TRUE +; per il simulatore: 50|1 = WAIT 50, DURATION 1 con riferimento al PERIODO base (PER_BASE, default 1 secondo) +PER_BASE=9800 +SIM_PZCNT=13|1 +SIM_ALARM=200|10 +SIM_MANU=130|3 +; indica gestione e simulazione bit 5 --> slow +SIM_SLOW=2500|20 +; indica gestione e simulazione bit 6 --> warmup/cooldown +SIM_WUCD=8000|20 +; indica gestione e simulazione bit 7 --> emergenza +SIM_EMRG=4000|10 +; indica simulazione delle funzionalita power ON/ OFF +SIM_POW_ON_OFF=false +T_ON=6 +T_OFF=22 +; gestione DynData simulati +ENABLE_DYN_DATA=TRUE +FORCE_DYN_DATA=TRUE +NEW_DYN_DATA=TRUE +;gestione invio pezzi in blocco +ENABLE_SEND_PZC_BLOCK=TRUE +MIN_SEND_PZC_BLOCK=0 +MAX_SEND_PZC_BLOCK=100 +MIN_DURATA_ODL=240 +; indica parametri gestione TcMan +TC_MAX_TC_FACTOR=3.9 +TC_LAMBDA=0.4 +TC_MAX_INCR=5 +MAX_PZ_INCR_PERC=1000 + +; conf parametri memoria READ/WRITE +PARAM_CONF=SIM_PIZ00.json + +[BRANCH] +NAME=master \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ05.ini b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ05.ini new file mode 100644 index 00000000..9f996f7e --- /dev/null +++ b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ05.ini @@ -0,0 +1,74 @@ +;Configurazione IOB-WIN +[IOB] +CNCTYPE=SIMULA +PING_MS_TIMEOUT=500 + +[MACHINE] +VENDOR=STEAMWARE +MODEL=DEMO_SIMULATOR_GWMS + +[CNC] +IP=127.0.0.1 +PORT=0000 + +[SERVER] +MPIP=https://10.74.82.240 +MPURL=/api +CMDBASE=/IOB/input/ +CMDFLOG=/IOB/flog/ +CMDALIVE=/IOB +CMDENABLED=/IOB/enabled/ +CMDADV1=?valore= +CMDREBO=/IOB/sendReboot?idxMacchina= + +CMD_ODL_STARTED=/IOB/getCurrOdlStart/ +CMD_FORCLE_SPLIT_ODL=/IOB/forceSplitOdlFull/ +CMD_IDLE_TIME=/IOB/getIdlePeriod/ + +[MEMORY] + +[BLINK] +MAX_COUNTER_BLINK = 15 +BLINK_FILT=0 + +[OPTPAR] +AUTO_CHANGE_ODL=false +DISABLE_SIM_STATUS=true +;PZCOUNT_MODE=STD.[PAR/MEM].info|BIT.indice +PZCOUNT_MODE=BIT +ENABLE_PZ_RESET=TRUE +; per il simulatore: 50|1 = WAIT 50, DURATION 1 con riferimento al PERIODO base (PER_BASE, default 1 secondo) +PER_BASE=9800 +SIM_PZCNT=13|1 +SIM_ALARM=200|10 +SIM_MANU=130|3 +; indica gestione e simulazione bit 5 --> slow +SIM_SLOW=2500|20 +; indica gestione e simulazione bit 6 --> warmup/cooldown +SIM_WUCD=8000|20 +; indica gestione e simulazione bit 7 --> emergenza +SIM_EMRG=4000|10 +; indica simulazione delle funzionalita power ON/ OFF +SIM_POW_ON_OFF=false +T_ON=6 +T_OFF=22 +; gestione DynData simulati +ENABLE_DYN_DATA=TRUE +FORCE_DYN_DATA=TRUE +NEW_DYN_DATA=TRUE +;gestione invio pezzi in blocco +ENABLE_SEND_PZC_BLOCK=TRUE +MIN_SEND_PZC_BLOCK=0 +MAX_SEND_PZC_BLOCK=100 +MIN_DURATA_ODL=240 +; indica parametri gestione TcMan +TC_MAX_TC_FACTOR=3.9 +TC_LAMBDA=0.4 +TC_MAX_INCR=5 +MAX_PZ_INCR_PERC=1000 + +; conf parametri memoria READ/WRITE +PARAM_CONF=SIM_PIZ00.json + +[BRANCH] +NAME=master \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ08.ini b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ08.ini new file mode 100644 index 00000000..9f996f7e --- /dev/null +++ b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ08.ini @@ -0,0 +1,74 @@ +;Configurazione IOB-WIN +[IOB] +CNCTYPE=SIMULA +PING_MS_TIMEOUT=500 + +[MACHINE] +VENDOR=STEAMWARE +MODEL=DEMO_SIMULATOR_GWMS + +[CNC] +IP=127.0.0.1 +PORT=0000 + +[SERVER] +MPIP=https://10.74.82.240 +MPURL=/api +CMDBASE=/IOB/input/ +CMDFLOG=/IOB/flog/ +CMDALIVE=/IOB +CMDENABLED=/IOB/enabled/ +CMDADV1=?valore= +CMDREBO=/IOB/sendReboot?idxMacchina= + +CMD_ODL_STARTED=/IOB/getCurrOdlStart/ +CMD_FORCLE_SPLIT_ODL=/IOB/forceSplitOdlFull/ +CMD_IDLE_TIME=/IOB/getIdlePeriod/ + +[MEMORY] + +[BLINK] +MAX_COUNTER_BLINK = 15 +BLINK_FILT=0 + +[OPTPAR] +AUTO_CHANGE_ODL=false +DISABLE_SIM_STATUS=true +;PZCOUNT_MODE=STD.[PAR/MEM].info|BIT.indice +PZCOUNT_MODE=BIT +ENABLE_PZ_RESET=TRUE +; per il simulatore: 50|1 = WAIT 50, DURATION 1 con riferimento al PERIODO base (PER_BASE, default 1 secondo) +PER_BASE=9800 +SIM_PZCNT=13|1 +SIM_ALARM=200|10 +SIM_MANU=130|3 +; indica gestione e simulazione bit 5 --> slow +SIM_SLOW=2500|20 +; indica gestione e simulazione bit 6 --> warmup/cooldown +SIM_WUCD=8000|20 +; indica gestione e simulazione bit 7 --> emergenza +SIM_EMRG=4000|10 +; indica simulazione delle funzionalita power ON/ OFF +SIM_POW_ON_OFF=false +T_ON=6 +T_OFF=22 +; gestione DynData simulati +ENABLE_DYN_DATA=TRUE +FORCE_DYN_DATA=TRUE +NEW_DYN_DATA=TRUE +;gestione invio pezzi in blocco +ENABLE_SEND_PZC_BLOCK=TRUE +MIN_SEND_PZC_BLOCK=0 +MAX_SEND_PZC_BLOCK=100 +MIN_DURATA_ODL=240 +; indica parametri gestione TcMan +TC_MAX_TC_FACTOR=3.9 +TC_LAMBDA=0.4 +TC_MAX_INCR=5 +MAX_PZ_INCR_PERC=1000 + +; conf parametri memoria READ/WRITE +PARAM_CONF=SIM_PIZ00.json + +[BRANCH] +NAME=master \ No newline at end of file diff --git a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj index 9c04d0e4..6a0cb6b6 100644 --- a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj +++ b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj @@ -396,6 +396,21 @@ Always + + Always + + + Always + + + Always + + + Always + + + Always + Always diff --git a/IOB-WIN-NEXT/IobGeneric.cs b/IOB-WIN-NEXT/IobGeneric.cs index 2a71d2ec..bac431f8 100644 --- a/IOB-WIN-NEXT/IobGeneric.cs +++ b/IOB-WIN-NEXT/IobGeneric.cs @@ -870,7 +870,7 @@ namespace IOB_WIN_NEXT { if (DemoOut) { - answ = false; + answ = true; } else { @@ -881,7 +881,7 @@ namespace IOB_WIN_NEXT string callResp = ""; try { - // chiamo URL, se restituisce "OK" è alive! + // chiamo URL, se restituisce "OK" è alive! provo con chiamata http callResp = callUrl(urlAlive, false); answ = (callResp == "OK"); } @@ -3304,7 +3304,7 @@ namespace IOB_WIN_NEXT else { lgError($"Attenzione! memMap è nullo, non posso eseguire task2exe!"); - } + } } return taskDone; diff --git a/IOB-WIN-NEXT/IobSimula.cs b/IOB-WIN-NEXT/IobSimula.cs index 685c346b..8d771f5f 100644 --- a/IOB-WIN-NEXT/IobSimula.cs +++ b/IOB-WIN-NEXT/IobSimula.cs @@ -44,6 +44,8 @@ namespace IOB_WIN_NEXT /// protected int cP = 1; + protected bool disableSimStatus = false; + /// /// ultimo controllo decremento eventi /// @@ -138,6 +140,11 @@ namespace IOB_WIN_NEXT bit6 = setupSimPar("SIM_WUCD"); bit7 = setupSimPar("SIM_EMRG"); int.TryParse(getOptPar("MIN_DURATA_ODL"), out minDurataODL); + var strDisableSim = getOptPar("DISABLE_SIM_STATUS"); + if (!string.IsNullOrEmpty(strDisableSim)) + { + bool.TryParse(strDisableSim, out disableSimStatus); + } } setParamPlc(); // ricarico da server i dati dei pezzi fatti... @@ -149,6 +156,9 @@ namespace IOB_WIN_NEXT // imposto pezzi CNC ai pezzi contati da server... contapezziPLC = contapezziIOB; lgInfo($"Impostazione iniziale contatori: contapezzi macchina contapezziPLC: {contapezziPLC} | contapezziIOB: {contapezziIOB}"); + + // parto processando dynData + processDynData(); } #endregion Public Constructors @@ -540,88 +550,91 @@ namespace IOB_WIN_NEXT { // Verificare il protocollo: dovrebeb togliere SOLO i task eseguiti... Dictionary taskDone = new Dictionary(); - string taskVal = ""; - // verifico non sia null - if (task2exe != null) + // controlo SE sia disabilitata simulazione principale + if (!disableSimStatus) { - // cerco task specifici - foreach (var item in task2exe) + string taskVal = ""; + // verifico non sia null + if (task2exe != null) { - taskVal = ""; - // converto richiesta in enum... - taskType tName = taskType.nihil; - Enum.TryParse(item.Key, out tName); - // controllo sulla KEY - switch (tName) + // cerco task specifici + foreach (var item in task2exe) { - case taskType.setArt: - case taskType.setComm: - case taskType.setProg: - case taskType.setPzComm: - memMap.mMapWrite[item.Key].value = item.Value; - taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | UPDATED memMap.mMapWrite"; - break; + taskVal = ""; + // converto richiesta in enum... + taskType tName = taskType.nihil; + Enum.TryParse(item.Key, out tName); + // controllo sulla KEY + switch (tName) + { + case taskType.setArt: + case taskType.setComm: + case taskType.setProg: + case taskType.setPzComm: + memMap.mMapWrite[item.Key].value = item.Value; + taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | UPDATED memMap.mMapWrite"; + break; - case taskType.setParameter: - // richiedo da URL i parametri WRITE da popolare - lgInfo("Chiamata processMemWriteRequests"); - taskVal = processMemWriteRequests(); - // se restituiscce "" faccio altra prova... - if (string.IsNullOrEmpty(taskVal)) - { - // i parametri me li aspetto come stringa composta paramName|paramvalue - if (item.Value.Contains("|")) + case taskType.setParameter: + // richiedo da URL i parametri WRITE da popolare + lgInfo("Chiamata processMemWriteRequests"); + taskVal = processMemWriteRequests(); + // se restituiscce "" faccio altra prova... + if (string.IsNullOrEmpty(taskVal)) { - string[] paramsJob = item.Value.Split('|'); - taskVal = $"REQUEST SET PARAMETERS: {paramsJob[0]} --> {paramsJob[1]}"; + // i parametri me li aspetto come stringa composta paramName|paramvalue + if (item.Value.Contains("|")) + { + string[] paramsJob = item.Value.Split('|'); + taskVal = $"REQUEST SET PARAMETERS: {paramsJob[0]} --> {paramsJob[1]}"; + } + else + { + taskVal = $"WRONG REQUEST FOR SET PARAMETERS: {item.Value} doesnt contain pipe for splitting key/value"; + } } - else - { - taskVal = $"WRONG REQUEST FOR SET PARAMETERS: {item.Value} doesnt contain pipe for splitting key/value"; - } - } - break; + break; - case taskType.nihil: - case taskType.fixStopSetup: - case taskType.forceResetPzCount: - case taskType.sendWatchDogMes2Plc: - case taskType.startSetup: - case taskType.stopSetup: - taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; - break; + case taskType.nihil: + case taskType.fixStopSetup: + case taskType.forceResetPzCount: + case taskType.sendWatchDogMes2Plc: + case taskType.startSetup: + case taskType.stopSetup: + taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; + break; - case taskType.forceSetPzCount: - // forzo sul SIM il valore pzCount dell'IOB... - int newPzCount = contapezziPLC; - bool fatto = int.TryParse(item.Value, out newPzCount); - if (fatto) - { - // verifico SE sia ammesso il cambio ... - int deltaPzCount = newPzCount - contapezziPLC; - double maxDelta = DateTime.Now.Subtract(plcLastPzRead).TotalMinutes / (plcAvgTc / 60); - // se incremento superiore del doppio atteso --> segnalo errore e NON accetto - if (deltaPzCount > (maxDelta * maxPzDeltaPerc) / 100) + case taskType.forceSetPzCount: + // forzo sul SIM il valore pzCount dell'IOB... + int newPzCount = contapezziPLC; + bool fatto = int.TryParse(item.Value, out newPzCount); + if (fatto) { - lgError($"[DELTA CHECK]: intremento contapezziPLC troppo elevato: lettura {newPzCount} | contapezzi attuale: {contapezziPLC} | ultima lettura PLC: {plcLastPzRead} | TCiclo medio: {plcAvgTc}s | incremento accettato "); + // verifico SE sia ammesso il cambio ... + int deltaPzCount = newPzCount - contapezziPLC; + double maxDelta = DateTime.Now.Subtract(plcLastPzRead).TotalMinutes / (plcAvgTc / 60); + // se incremento superiore del doppio atteso --> segnalo errore e NON accetto + if (deltaPzCount > (maxDelta * maxPzDeltaPerc) / 100) + { + lgError($"[DELTA CHECK]: intremento contapezziPLC troppo elevato: lettura {newPzCount} | contapezzi attuale: {contapezziPLC} | ultima lettura PLC: {plcLastPzRead} | TCiclo medio: {plcAvgTc}s | incremento accettato "); + } + else + { + contapezziPLC = newPzCount; + taskVal = $"Set new contapezziPLC: {contapezziPLC}"; + } } - else - { - contapezziPLC = newPzCount; - taskVal = $"Set new contapezziPLC: {contapezziPLC}"; - } - } - break; + break; - default: - taskVal = "SKIPPED | NO EXEC"; - break; + default: + taskVal = "SKIPPED | NO EXEC"; + break; + } + // aggiungo task! + taskDone.Add(item.Key, taskVal); } - // aggiungo task! - taskDone.Add(item.Key, taskVal); } } - return taskDone; } @@ -659,9 +672,18 @@ namespace IOB_WIN_NEXT { foreach (var item in memMap.mMapRead) { - // uso factor come valore MAX ammesso - int randVal = rnd.Next(item.Value.minVal, item.Value.maxVal); - outVal.Add(item.Key, randVal.ToString()); + if (item.Value.factor == 1) + { + // uso factor come valore MAX ammesso + int randVal = rnd.Next(item.Value.minVal, item.Value.maxVal); + outVal.Add(item.Key, randVal.ToString()); + } + else + { + // uso factor come fattore di divisione x simulare decimali + float randVal = ((float)rnd.Next(item.Value.minVal, item.Value.maxVal)) / item.Value.factor; + outVal.Add(item.Key, randVal.ToString()); + } } } } @@ -724,10 +746,15 @@ namespace IOB_WIN_NEXT public override void readSemafori(ref newDisplayData currDispData) { base.readSemafori(ref currDispData); - // decodifica e gestione - decodeToBaseBitmap(); - decodeOtherData(); - reportRawInput(ref currDispData); + + // controlo SE sia disabilitata simulazione principale + if (!disableSimStatus) + { + // decodifica e gestione + decodeToBaseBitmap(); + decodeOtherData(); + reportRawInput(ref currDispData); + } } /// From 22c2c3d88475a78c7368b5a5cbacb8a8e069f75a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 1 Oct 2021 16:18:41 +0200 Subject: [PATCH 3/6] Affinamento SIM x livello (descending + lento) + prog name --- IOB-WIN-NEXT/App.config | 2 +- IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json | 4 +-- IOB-WIN-NEXT/IobSimula.cs | 43 +++++++++++++++++++++------ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/IOB-WIN-NEXT/App.config b/IOB-WIN-NEXT/App.config index 6b3846da..e98ffce7 100644 --- a/IOB-WIN-NEXT/App.config +++ b/IOB-WIN-NEXT/App.config @@ -39,7 +39,7 @@ - + diff --git a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json index 9534a73f..c929fe76 100644 --- a/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json +++ b/IOB-WIN-NEXT/DATA/CONF/SIM_PIZ00.json @@ -39,8 +39,8 @@ "description": "Livello Serbatoio", "tipoMem": "Real", "minVal": 5000, - "maxVal": 250000, - "factor": 1 + "maxVal": 25000, + "factor": 5 }, "PressBH": { "name": "SIM_PressBH", diff --git a/IOB-WIN-NEXT/IobSimula.cs b/IOB-WIN-NEXT/IobSimula.cs index 8d771f5f..41968dad 100644 --- a/IOB-WIN-NEXT/IobSimula.cs +++ b/IOB-WIN-NEXT/IobSimula.cs @@ -672,17 +672,42 @@ namespace IOB_WIN_NEXT { foreach (var item in memMap.mMapRead) { - if (item.Value.factor == 1) + // se il TIPO di valore è livello --> simulo variazione da MAX --> min, con un delta in CALO pari a factor * (80-120)% + if (item.Value.name == "SIM_LEVEL") { - // uso factor come valore MAX ammesso - int randVal = rnd.Next(item.Value.minVal, item.Value.maxVal); - outVal.Add(item.Key, randVal.ToString()); + // verifico last value + float lastVal = 0; + float.TryParse(item.Value.value, out lastVal); + if (lastVal == 0) + { + lastVal = item.Value.maxVal - item.Value.factor; + } + // decremento casuale... + float newVal = lastVal - ((float)item.Value.factor * rnd.Next(80, 120) / 100); + // se inferiore a minimo --> massimo! + if (newVal < item.Value.minVal) + { + newVal = item.Value.maxVal; + } + // salvo il suo VALUE... + item.Value.value = $"{newVal}"; + outVal.Add(item.Key, $"{newVal}"); } + // altrimenti siulazione random walk... else { - // uso factor come fattore di divisione x simulare decimali - float randVal = ((float)rnd.Next(item.Value.minVal, item.Value.maxVal)) / item.Value.factor; - outVal.Add(item.Key, randVal.ToString()); + if (item.Value.factor == 1) + { + // uso factor come valore MAX ammesso + int randVal = rnd.Next(item.Value.minVal, item.Value.maxVal); + outVal.Add(item.Key, randVal.ToString()); + } + else + { + // uso factor come fattore di divisione x simulare decimali + float randVal = ((float)rnd.Next(item.Value.minVal, item.Value.maxVal)) / item.Value.factor; + outVal.Add(item.Key, randVal.ToString()); + } } } } @@ -700,8 +725,8 @@ namespace IOB_WIN_NEXT /// public override string getPrgName() { - // valore non presente in vers default... se gestito fare override - string prgName = string.Format("DEMO_{0:00}", DateTime.Now.Minute); + // NOME DEL SIM! + string prgName = $"PROG_{cIobConf.codIOB}"; return prgName; } From 397198e37f782f45d8e4c2e8ef99954f6771f50c Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 2 Oct 2021 10:53:47 +0200 Subject: [PATCH 4/6] binary formatter ANCHE da UINT --- IOB-UT-NEXT/baseUtils.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/IOB-UT-NEXT/baseUtils.cs b/IOB-UT-NEXT/baseUtils.cs index 84363305..3fc4c35f 100644 --- a/IOB-UT-NEXT/baseUtils.cs +++ b/IOB-UT-NEXT/baseUtils.cs @@ -122,6 +122,22 @@ namespace IOB_UT_NEXT { } return answ; } + /// + /// formatta un numero in forma binaria 0/1 + /// + /// + /// + public static string binaryForm(uint valore) + { + string answ = ""; + try + { + answ = string.Format(new BinaryFormatter(), "{0:B}", valore); + } + catch + { } + return answ; + } /// /// Effettua chiamata URL e restituisce risultato, SE NON E' in veto send (x mmitigare chiamate...) From f1badda3b05be665e2e69bcaa874ff9fe355f18c Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 2 Oct 2021 10:58:15 +0200 Subject: [PATCH 5/6] Modifica siemens torri x intercettare banchi allarmi (hard coded!!!) --- IOB-WIN-NEXT/IobSiemensTorri.cs | 54 ++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/IOB-WIN-NEXT/IobSiemensTorri.cs b/IOB-WIN-NEXT/IobSiemensTorri.cs index 0abcf29c..7e9192bc 100644 --- a/IOB-WIN-NEXT/IobSiemensTorri.cs +++ b/IOB-WIN-NEXT/IobSiemensTorri.cs @@ -75,6 +75,12 @@ namespace IOB_WIN_NEXT // salvo infine variabile bit x invio B_input = byteSem; + // se ho il bit di allarme + if ((RawInput[0] & (1 << 3)) != 0) + { + checkAlarms(); + } + // procedo SOLO SE è enabled IOB if (IobOnline) { @@ -202,6 +208,48 @@ namespace IOB_WIN_NEXT } } + private void checkAlarms() + { + // leggo i banchi allarmi : cablato D700.DBDW2 --> D700 DBDW14, sono 4 banchi a 32 bit da verificare + + int trovati = 0; + // ciclo nei 4 banchi... + trovati += checkAlarmBank("DB700.DBDW2"); + trovati += checkAlarmBank("DB700.DBDW6"); + trovati += checkAlarmBank("DB700.DBDW10"); + trovati += checkAlarmBank("DB700.DBDW14"); + } + + private int checkAlarmBank(string memAddrAlarms) + { + int trovato = 0; + uint valDW = 0; + var MemBlockPZ = new byte[4]; + bool fatto = S7ReadBB(ref MemBlockPZ, memAddrAlarms, 4); + if (fatto) + { + valDW = S7.Net.Types.DWord.FromByteArray(MemBlockPZ.ToArray()); + // se <> 0 --> log e accodo a dynData + if (valDW != 0) + { + string key = $"MTH_ALARM_{memAddrAlarms}_{valDW}"; + var biteVal = baseUtils.binaryForm(valDW); + lgInfo($"Stato allarmi rilevati: {key} | {valDW} | {biteVal}"); + // accodo a dictionary + string almMsg = $"{DateTime.Now} | val {valDW} | {biteVal}"; + // se non ci fosse aggiungo + if (!lastReadAlarms.ContainsKey(key)) + { + lastReadAlarms.Add(key, almMsg); + } + trovato++; + } + } + return trovato; + } + + protected Dictionary lastReadAlarms = new Dictionary(); + #endregion Protected Methods #region Public Methods @@ -277,7 +325,9 @@ namespace IOB_WIN_NEXT /// public override Dictionary getCncAlarms() { - Dictionary outVal = new Dictionary(); + // parto da ultimo vettore allarmi rilevato + Dictionary outVal = lastReadAlarms; + // se ho altro --> accodo try { string almMsg = string.Format("{0} | {1}", currPLC.LastErrorCode.ToString(), currPLC.LastErrorString); @@ -287,6 +337,8 @@ namespace IOB_WIN_NEXT { lgError(exc, "Errore in getCncAlarms"); } + // resetto vettore allarmi + lastReadAlarms = new Dictionary(); return outVal; } From 40411f56ddea4c59e552a7d993655b550cf53641 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 2 Oct 2021 11:33:12 +0200 Subject: [PATCH 6/6] Completata review x trasmissione allarmi Torri --- IOB-WIN-NEXT/DATA/CONF/MAIN.ini | 5 +++-- IOB-WIN-NEXT/IobGeneric.cs | 8 +++++++- IOB-WIN-NEXT/IobSiemensTorri.cs | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/IOB-WIN-NEXT/DATA/CONF/MAIN.ini b/IOB-WIN-NEXT/DATA/CONF/MAIN.ini index 72923f8f..5370415f 100644 --- a/IOB-WIN-NEXT/DATA/CONF/MAIN.ini +++ b/IOB-WIN-NEXT/DATA/CONF/MAIN.ini @@ -68,8 +68,9 @@ CLI_INST=SteamWareSim ;STARTLIST=PIZ08 ;STARTLIST=PIZ04 ;STARTLIST=PIZ05 -;STARTLIST=FOV062 -STARTLIST=SIM_PIZ03 ;STARTLIST=OPC_UA +;STARTLIST=SIM_PIZ03 +;STARTLIST=FOV062 +STARTLIST=3013 MAXCNC=10 \ No newline at end of file diff --git a/IOB-WIN-NEXT/IobGeneric.cs b/IOB-WIN-NEXT/IobGeneric.cs index bac431f8..782b7f78 100644 --- a/IOB-WIN-NEXT/IobGeneric.cs +++ b/IOB-WIN-NEXT/IobGeneric.cs @@ -4071,12 +4071,12 @@ namespace IOB_WIN_NEXT { try { + string sVal = ""; if (lastAlarm != currAlarms["CNC_ALARM"]) { // salvo! lastAlarm = currAlarms["CNC_ALARM"]; // per ogni valore del dizionario mostro ed accodo! - string sVal = ""; foreach (var item in currAlarms) { sVal = string.Format("[CNC_ALARM]{0}|{1}", item.Key, item.Value); @@ -4084,6 +4084,12 @@ namespace IOB_WIN_NEXT accodaFLog(sVal, qEncodeFLog(item.Key, item.Value)); } } + // accodo ALTRI allarmi NON CNC... + foreach (var item in currAlarms.Where(X => X.Key != "CNC_ALARM")) + { + sVal = $"{item.Key} | {item.Value}"; + accodaFLog(sVal, qEncodeFLog(item.Key, item.Value)); + } } catch (Exception exc) { diff --git a/IOB-WIN-NEXT/IobSiemensTorri.cs b/IOB-WIN-NEXT/IobSiemensTorri.cs index 7e9192bc..c0b8cc75 100644 --- a/IOB-WIN-NEXT/IobSiemensTorri.cs +++ b/IOB-WIN-NEXT/IobSiemensTorri.cs @@ -226,8 +226,8 @@ namespace IOB_WIN_NEXT uint valDW = 0; var MemBlockPZ = new byte[4]; bool fatto = S7ReadBB(ref MemBlockPZ, memAddrAlarms, 4); - if (fatto) - { + //if (fatto) + //{ valDW = S7.Net.Types.DWord.FromByteArray(MemBlockPZ.ToArray()); // se <> 0 --> log e accodo a dynData if (valDW != 0) @@ -244,7 +244,7 @@ namespace IOB_WIN_NEXT } trovato++; } - } + //} return trovato; }