From 553b5d33c7eb180d384ecf97b7e903f299a6cf74 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 10 Sep 2021 16:29:30 +0200 Subject: [PATCH] Update comportamento reconnect x ping + log fix --- IOB-WIN-NEXT/IobGeneric.cs | 10 +++++----- IOB-WIN-NEXT/IobSiemens.cs | 23 +++++++++++------------ IOB-WIN-NEXT/IobSiemensCosmap.cs | 5 ++++- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/IOB-WIN-NEXT/IobGeneric.cs b/IOB-WIN-NEXT/IobGeneric.cs index 4b765cff..3d7e1ff2 100644 --- a/IOB-WIN-NEXT/IobGeneric.cs +++ b/IOB-WIN-NEXT/IobGeneric.cs @@ -743,16 +743,16 @@ namespace IOB_WIN_NEXT // se != null --> uso address... if (address != null) { - reply = pingSender.Send(address, 100); + reply = pingSender.Send(address, pingMsTimeout); } else { - reply = pingSender.Send(cIobConf.cncIpAddr, 100); + reply = pingSender.Send(cIobConf.cncIpAddr, pingMsTimeout); } } catch { - reply = pingSender.Send(IPAddress.Loopback, 100); + reply = pingSender.Send(IPAddress.Loopback, pingMsTimeout); } answ = reply.Status; } @@ -2706,7 +2706,6 @@ namespace IOB_WIN_NEXT } } // richiamo scrittura parametri su PLC - lgInfo("Chiamate processMemWriteRequests --> plcWriteParams"); plcWriteParams(updatedPar); // invio su cloud parametri! string rawData = JsonConvert.SerializeObject(updatedPar); @@ -4239,9 +4238,10 @@ namespace IOB_WIN_NEXT Dictionary taskDone = new Dictionary(); if (task2exe != null) { - lgInfo($"Task2Exe: trovati {task2exe.Count} task da eseguire, procedo"); + lgInfo($"Task2Exe S01: trovati {task2exe.Count} task da eseguire, procedo"); // chiamo procedura esecutiva (diversa x ogni IOB) taskDone = executeTasks(task2exe); + lgInfo($"Task2Exe S02: eseguiti {taskDone.Count} task"); // loggo tutti i task done... foreach (var item in taskDone) { diff --git a/IOB-WIN-NEXT/IobSiemens.cs b/IOB-WIN-NEXT/IobSiemens.cs index 8793bac0..7eb01309 100644 --- a/IOB-WIN-NEXT/IobSiemens.cs +++ b/IOB-WIN-NEXT/IobSiemens.cs @@ -437,10 +437,9 @@ namespace IOB_WIN_NEXT // faccio preliminarmente upsertKey... upsertKey(currMem.name, currMem.value); serObj = JsonConvert.SerializeObject(item, Formatting.Indented); - lgInfo($"Inizio processing plcWriteParams per {currMem.name} | valore richiesto {currMem.value}"); - lgInfo($"---------------{Environment.NewLine}UPDATED PARAM:{Environment.NewLine}{serObj}{Environment.NewLine}---------------"); + lgInfo($"Inizio processing plcWriteParams per {currMem.name} | valore richiesto {currMem.value}{Environment.NewLine}---------------UPDATED PARAM---------------{Environment.NewLine}{serObj}{Environment.NewLine}---------------"); serObj = JsonConvert.SerializeObject(currMem, Formatting.Indented); - lgInfo($"---------------{Environment.NewLine}MEMORY CONTENT:{Environment.NewLine}{serObj}{Environment.NewLine}---------------"); + lgInfo($"---------------MEMORY CONTENT---------------{Environment.NewLine}{serObj}{Environment.NewLine}---------------"); switch (currMem.tipoMem) { case plcDataType.Boolean: @@ -482,7 +481,7 @@ namespace IOB_WIN_NEXT default: break; } - lgInfo($"---------------{Environment.NewLine}MemBlock data:{Environment.NewLine}{BitConverter.ToString(MemBlock)}{Environment.NewLine}---------------"); + lgInfo($"---------------MemBlock data---------------{Environment.NewLine}{BitConverter.ToString(MemBlock)}{Environment.NewLine}--------------- END data ---------------"); if (!string.IsNullOrEmpty(memAddrWrite)) { // scrivo su siemens @@ -654,7 +653,7 @@ namespace IOB_WIN_NEXT // se passa il ping faccio il resto... if (pingStatus != IPStatus.Success) { - lgError(string.Format("Errore in testCncConn: reply Status per {0}: {1}", parametri.ipAdrr, pingStatus)); + lgError($"Errore in testCncConn: reply Status | IP: {parametri.ipAdrr} | {pingStatus} | T.Out: {parametri.pingMsTimeout}ms"); } else { @@ -1138,8 +1137,8 @@ namespace IOB_WIN_NEXT switch (errorCode) { case ErrorCode.NoError: - maybeLogWrite(memAddrWrite, $"S7WriteBB-01 Effettuata correttamente scrittura su PLC: MEMORIA {memAddrWrite} | numByte: {Value.Length} | BIN: {Value.ValToBinString()}"); answ = true; + maybeLogWrite(memAddrWrite, $"S7WriteBB-01 Effettuata correttamente scrittura su PLC: MEMORIA {memAddrWrite} | numByte: {Value.Length} | ValOriginale: {Value}"); break; case ErrorCode.WrongCPU_Type: @@ -1442,7 +1441,6 @@ namespace IOB_WIN_NEXT Buffer.BlockCopy(stringPar, 0, MemBlock, startPos, shiftStrByte); } Buffer.BlockCopy(strByte, 0, MemBlock, startPos + shiftStrByte, byteLen); - lgInfo($"saveStringOnMemBlock: Final MemBlock{Environment.NewLine}{BitConverter.ToString(MemBlock)}"); } catch (Exception exc) { @@ -1582,21 +1580,22 @@ namespace IOB_WIN_NEXT // se passa il ping faccio il resto... if (testPingMachine == IPStatus.Success) { - string szStatusConnection = ""; + string szStatusConnection = "ND"; try { // ora provo connessione... parentForm.commPlcActive = true; currPLC.Open(); + szStatusConnection = "OPEN"; parentForm.commPlcActive = false; - lgInfo("szStatusConnection: " + szStatusConnection); connectionOk = true; + lgInfo($"StatusConnection: {szStatusConnection}"); // refresh stato allarmi!!! if (connectionOk) { if (adpRunning) { - lgInfo("Connessione OK"); + lgInfo($"Connessione OK: {connectionOk} | adpRunning: {adpRunning}"); } } else @@ -1606,7 +1605,7 @@ namespace IOB_WIN_NEXT } catch (Exception exc) { - lgFatal(string.Format("Errore in TryConnect adapter SIEMENS: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc)); + lgFatal($"Errore in TryConnect adapter SIEMENS | szStatusConnection {szStatusConnection}{Environment.NewLine}{exc}"); connectionOk = false; needRefresh = true; } @@ -1617,7 +1616,7 @@ namespace IOB_WIN_NEXT connectionOk = false; if (doLog) { - lgInfo(string.Format("Attenzione: SIEMENS controllo PING fallito per IP {0}", cIobConf.cncIpAddr)); + lgInfo($"Attenzione: SIEMENS controllo PING fallito per IP {cIobConf.cncIpAddr}"); } } } diff --git a/IOB-WIN-NEXT/IobSiemensCosmap.cs b/IOB-WIN-NEXT/IobSiemensCosmap.cs index bb6da8b6..5fbcce14 100644 --- a/IOB-WIN-NEXT/IobSiemensCosmap.cs +++ b/IOB-WIN-NEXT/IobSiemensCosmap.cs @@ -229,7 +229,7 @@ namespace IOB_WIN_NEXT case taskType.setParameter: // richiedo da URL i parametri WRITE da popolare - lgInfo("Chiamata processMemWriteRequests"); + lgInfo("setParameter --> processMemWriteRequests"); taskVal = processMemWriteRequests(); // se restituiscce "" faccio altra prova... if (string.IsNullOrEmpty(taskVal)) @@ -251,6 +251,8 @@ namespace IOB_WIN_NEXT taskVal = "SKIPPED | NO EXEC"; break; } + + lgInfo($"executeTask: {tName} | {taskVal}"); // aggiungo task! taskDone.Add(item.Key, taskVal); if (!string.IsNullOrEmpty(memAddrWrite)) @@ -262,6 +264,7 @@ namespace IOB_WIN_NEXT { // aggiorno valore memoria... memMap.mMapWrite[item.Key].value = item.Value; + lgInfo($"Eseguita con successo S7WriteBB per executeTasks: {item.Key} | {item.Value}"); } else {