From 35916ff80c3756006858fc9984407c71a44992a3 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 23 Jan 2025 16:34:52 +0100 Subject: [PATCH] Update MTC x condizioni errore e mancanza dati (ex Jetco) - aggiunta variabili come OPC-UA x check ultima conn - aggiunta check errori --- IOB-UT-NEXT/Iob/BaseObj.cs | 15 ++- IOB-WIN-FORM/Iob/BaseObj.cs | 162 +++++++++++++++-------- IOB-WIN-FORM/Iob/Generic.cs | 10 ++ IOB-WIN-MTC/DATA/CONF/3024.ini | 6 +- IOB-WIN-MTC/IOB-WIN-MTC.csproj | 24 +--- IOB-WIN-MTC/Iob/MTConn.cs | 97 +++++++++++--- IOB-WIN-MTC/postBuildTgt.bat | 45 ------- IOB-WIN-OPC-UA/IobOpc/OpcUa.cs | 23 +++- IOB-WIN-OPC-UA/IobOpc/OpcUaKpw.cs | 11 +- IOB-WIN-OPC-UA/IobOpc/OpcUaMBH.cs | 11 +- IOB-WIN-OPC-UA/IobOpc/OpcUaMBHCimolai.cs | 11 +- 11 files changed, 269 insertions(+), 146 deletions(-) diff --git a/IOB-UT-NEXT/Iob/BaseObj.cs b/IOB-UT-NEXT/Iob/BaseObj.cs index d5fe8ac6..daa47373 100644 --- a/IOB-UT-NEXT/Iob/BaseObj.cs +++ b/IOB-UT-NEXT/Iob/BaseObj.cs @@ -545,7 +545,7 @@ namespace IOB_UT_NEXT.Iob #endregion Protected Properties - #region Private Methods + #region Protected Methods /// /// Verifica se ci sia veto log attivo e gestisce casistiche @@ -553,7 +553,7 @@ namespace IOB_UT_NEXT.Iob /// /// /// - private bool checkLogVeto(int vetoSec, ref string message) + protected bool checkLogVeto(int vetoSec, ref string message) { //verifico SE si debba fare log, altrimenti metto in coda... bool doVeto = true; @@ -584,12 +584,19 @@ namespace IOB_UT_NEXT.Iob // primo --> loggo doVeto = false; VetoLog.Add(message, adesso.AddSeconds(vetoSec)); - VetoLogCount.Add(message, 0); + if (VetoLogCount.ContainsKey(message)) + { + VetoLogCount[message]++; + } + else + { + VetoLogCount.Add(message, 0); + } } // restituisco esito! return doVeto; } - #endregion Private Methods + #endregion Protected Methods } } \ No newline at end of file diff --git a/IOB-WIN-FORM/Iob/BaseObj.cs b/IOB-WIN-FORM/Iob/BaseObj.cs index 50ed3097..e45f6a3c 100644 --- a/IOB-WIN-FORM/Iob/BaseObj.cs +++ b/IOB-WIN-FORM/Iob/BaseObj.cs @@ -15,6 +15,34 @@ namespace IOB_WIN_FORM.Iob /// public class BaseObj : IOB_UT_NEXT.Iob.BaseObj { + #region Public Methods + + /// + /// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere... + /// + /// + /// + public void lgError(string message, params object[] args) + { + try + { + bool doVeto = checkLogVeto(2, ref message); + // se non ho veto --> loggo + if (!doVeto) + { + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; + lg.Error(message, args); + sendToLogWatch("ERROR", message, args); + } + } + catch + { + readErrorCurr++; + } + } + + #endregion Public Methods + #region Protected Fields /// @@ -22,6 +50,20 @@ namespace IOB_WIN_FORM.Iob /// protected AdapterForm parentForm; + /// + /// Num errori lettura correnti + /// + protected int readErrorCurr = 0; + + /// + /// Max num errori lettura prima di disconnettere + /// + protected int readErrorMax = 10; + + /// + /// + protected int readErrorSleepTime = 15000; + #endregion Protected Fields #region Protected Methods @@ -68,33 +110,23 @@ namespace IOB_WIN_FORM.Iob /// protected void lgError(string message, bool sendToForm = true) { - bool doVeto = checkLogVeto(2, ref message); - // se non ho veto --> loggo - if (!doVeto) + try { - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; - lg.Error(message); - if (sendToForm) + bool doVeto = checkLogVeto(2, ref message); + // se non ho veto --> loggo + if (!doVeto) { - sendToLogWatch("ERROR", message); + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; + lg.Error(message); + if (sendToForm) + { + sendToLogWatch("ERROR", message); + } } } - } - - /// - /// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere... - /// - /// - /// - public void lgError(string message, params object[] args) - { - bool doVeto = checkLogVeto(2, ref message); - // se non ho veto --> loggo - if (!doVeto) + catch { - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; - lg.Error(message, args); - sendToLogWatch("ERROR", message, args); + readErrorCurr++; } } @@ -106,13 +138,20 @@ namespace IOB_WIN_FORM.Iob /// protected void lgError(Exception exception, string message, params object[] args) { - bool doVeto = checkLogVeto(2, ref message); - // se non ho veto --> loggo - if (!doVeto) + try { - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; - lg.Error(exception, message, args); - sendToLogWatch("ERROR", message, exception, args); + bool doVeto = checkLogVeto(2, ref message); + // se non ho veto --> loggo + if (!doVeto) + { + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; + lg.Error(exception, message, args); + sendToLogWatch("ERROR", message, exception, args); + } + } + catch + { + readErrorCurr++; } } @@ -122,17 +161,24 @@ namespace IOB_WIN_FORM.Iob /// protected void lgFatal(string message, bool sendToForm = true) { - bool doVeto = checkLogVeto(1, ref message); - // se non ho veto --> loggo - if (!doVeto) + try { - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; - lg.Fatal(message); - if (sendToForm) + bool doVeto = checkLogVeto(1, ref message); + // se non ho veto --> loggo + if (!doVeto) { - sendToLogWatch("FATAL", message); + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; + lg.Fatal(message); + if (sendToForm) + { + sendToLogWatch("FATAL", message); + } } } + catch + { + readErrorCurr++; + } } /// @@ -142,13 +188,20 @@ namespace IOB_WIN_FORM.Iob /// protected void lgFatal(string message, params object[] args) { - bool doVeto = checkLogVeto(1, ref message); - // se non ho veto --> loggo - if (!doVeto) + try { - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; - lg.Fatal(message, args); - sendToLogWatch("FATAL", message, args); + bool doVeto = checkLogVeto(1, ref message); + // se non ho veto --> loggo + if (!doVeto) + { + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; + lg.Fatal(message, args); + sendToLogWatch("FATAL", message, args); + } + } + catch + { + readErrorCurr++; } } @@ -160,13 +213,20 @@ namespace IOB_WIN_FORM.Iob /// protected void lgFatal(Exception exception, string message, params object[] args) { - bool doVeto = checkLogVeto(1, ref message); - // se non ho veto --> loggo - if (!doVeto) + try { - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; - lg.Fatal(exception, message, args); - sendToLogWatch("FATAL", message, exception, args); + bool doVeto = checkLogVeto(1, ref message); + // se non ho veto --> loggo + if (!doVeto) + { + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.filenameIOB; + lg.Fatal(exception, message, args); + sendToLogWatch("FATAL", message, exception, args); + } + } + catch + { + readErrorCurr++; } } @@ -350,15 +410,14 @@ namespace IOB_WIN_FORM.Iob #endregion Protected Methods - #region Private Methods - +#if false /// /// Verifica se ci sia veto log attivo e gestisce casistiche /// /// /// /// - private bool checkLogVeto(int vetoSec, ref string message) + protected bool checkLogVeto(int vetoSec, ref string message) { //verifico SE si debba fare log, altrimenti metto in coda... bool doVeto = true; @@ -394,7 +453,6 @@ namespace IOB_WIN_FORM.Iob // restituisco esito! return doVeto; } - - #endregion Private Methods +#endif } } \ No newline at end of file diff --git a/IOB-WIN-FORM/Iob/Generic.cs b/IOB-WIN-FORM/Iob/Generic.cs index c4b987da..b5159a07 100644 --- a/IOB-WIN-FORM/Iob/Generic.cs +++ b/IOB-WIN-FORM/Iob/Generic.cs @@ -4443,6 +4443,11 @@ namespace IOB_WIN_FORM.Iob /// protected bool ENABLE_MEM_REWRITE = true; + /// + /// Abilitazione restart (da opt par...) + /// + protected bool enableCliRestart = false; + /// /// Boolean x indicare contapezzi abilitato a livello di conf apoplicazione /// @@ -4528,6 +4533,11 @@ namespace IOB_WIN_FORM.Iob /// protected DateTime lastConnectTry; + /// + /// Periodo massimo (in sec) per letture dati RAW in mancanza di eventi + /// + protected int lastCurrentMaxElapsed = 120; + /// /// Dizionario ULTIMI valori impostati x produzione /// diff --git a/IOB-WIN-MTC/DATA/CONF/3024.ini b/IOB-WIN-MTC/DATA/CONF/3024.ini index 8eaa585b..60c1ec70 100644 --- a/IOB-WIN-MTC/DATA/CONF/3024.ini +++ b/IOB-WIN-MTC/DATA/CONF/3024.ini @@ -1,4 +1,4 @@ -;Configurazione IOB-WIN +;Configurazione IOB-WIN [IOB] ;Tornio Biglia 438 controllo Mitsubishi MTConnect CNCTYPE=MTConnect @@ -61,6 +61,10 @@ ENABLE_DATA_FILTER=TRUE ENABLE_MTC_RESTART=TRUE VETO_QUEUE_IN=15 DISABLE_SEND_WDST=TRUE +ENABLE_CLI_RESTART=TRUE +MAX_ELAPSED_TIME_SEC=60 +READ_ERROR_MAX=10 +READ_ERROR_SLEEP_TIME=30000 ; conf parametri memoria READ/WRITE MTC_PARAM_CONF=3024.json diff --git a/IOB-WIN-MTC/IOB-WIN-MTC.csproj b/IOB-WIN-MTC/IOB-WIN-MTC.csproj index 66efca5e..7c65f3bd 100644 --- a/IOB-WIN-MTC/IOB-WIN-MTC.csproj +++ b/IOB-WIN-MTC/IOB-WIN-MTC.csproj @@ -293,12 +293,8 @@ - - Always - - - Always - + + Always @@ -315,18 +311,10 @@ Always - - Always - - - Always - - - Always - - - Always - + + + + Always diff --git a/IOB-WIN-MTC/Iob/MTConn.cs b/IOB-WIN-MTC/Iob/MTConn.cs index 8dfe3c74..fae968b9 100644 --- a/IOB-WIN-MTC/Iob/MTConn.cs +++ b/IOB-WIN-MTC/Iob/MTConn.cs @@ -51,6 +51,26 @@ namespace IOB_WIN_MTC.Iob enablePzCountByIob = (getOptPar("ENABLE_PZCOUNT") == "TRUE"); disablePzCountByIob = (getOptPar("DISABLE_PZCOUNT") == "TRUE"); + // gestione restart OpcUa client... + if (!string.IsNullOrEmpty(getOptPar("ENABLE_CLI_RESTART"))) + { + bool.TryParse(getOptPar("ENABLE_CLI_RESTART"), out enableCliRestart); + } + // init lastCurrentMaxElapsed + if (!string.IsNullOrEmpty(getOptPar("MAX_ELAPSED_TIME_SEC"))) + { + int.TryParse(getOptPar("MAX_ELAPSED_TIME_SEC"), out lastCurrentMaxElapsed); + } + // init gestione reset errori lettura + if (!string.IsNullOrEmpty(getOptPar("READ_ERROR_MAX"))) + { + int.TryParse(getOptPar("READ_ERROR_MAX"), out readErrorMax); + } + if (!string.IsNullOrEmpty(getOptPar("READ_ERROR_SLEEP_TIME"))) + { + int.TryParse(getOptPar("READ_ERROR_SLEEP_TIME"), out readErrorSleepTime); + } + // init datetime counters DateTime adesso = DateTime.Now; lastPzCountSend = adesso; @@ -177,6 +197,19 @@ namespace IOB_WIN_MTC.Iob // decodifica document gestione decodeToBaseBitmap(); reportRawInput(ref currDispData); + + // controllo read error ed eventuale disconnect + if (readErrorCurr > readErrorMax) + { + lgError($"Effettuo disconnessione x superamento errori lettura UA_ref.ReadNodeString, sleetp 15 sec"); + tryDisconnect(); + Thread.Sleep(readErrorSleepTime); + readErrorCurr = 0; + } + else if (readErrorCurr > 0) + { + readErrorCurr--; + } } catch (Exception exc) { @@ -765,58 +798,67 @@ namespace IOB_WIN_MTC.Iob /// Effettua log di un elenco componenti /// /// - protected void logComponentsList(List elencoComponenti) + protected int logComponentsList(List elencoComponenti) { + int found = 0; if (elencoComponenti != null) { foreach (var item in elencoComponenti) { - lgInfo($"Component data | ID: {item.Id} | Name: {item.Name} | Type: {item.Type} | # items: {item.DataItems.Count()}"); + lgTrace($"Component data | ID: {item.Id} | Name: {item.Name} | Type: {item.Type} | # items: {item.DataItems.Count()}"); + found++; // se ho sottocomponenti richiamo... if (item.Components != null) { if (item.Components.Count() > 0) { - logComponentsList(item.GetComponents().ToList()); + found += logComponentsList(item.GetComponents().ToList()); } } if (item.DataItems.Count() > 0) { - logDataItemList(item.GetDataItems().ToList()); + found += logDataItemList(item.GetDataItems().ToList()); } } } + return found; } /// /// Effettua log di un elenco composizioni /// /// - protected void logCompositionList(List elencoComposizioni) + protected int logCompositionList(List elencoComposizioni) { + int found = 0; if (elencoComposizioni != null) { foreach (var item in elencoComposizioni) { - lgInfo($"Composition data | ID: {item.Id} | Name: {item.Name} | Type: {item.Type} | # items: {item.DataItems.Count()} | path: {item.IdPath}"); + lgTrace($"Composition data | ID: {item.Id} | Name: {item.Name} | Type: {item.Type} | # items: {item.DataItems.Count()} | path: {item.IdPath}"); + found++; } } + return found; } /// /// Log elenco DataItems /// /// - protected void logDataItemList(List elencoItems) + protected int logDataItemList(List elencoItems) { + int found = 0; if (elencoItems != null) { // loggo devices principali... foreach (var item in elencoItems) { - lgInfo($"Device data | ID: {item.Id} | Name: {item.Name} | Category: {item.Category} | # Type: {item.Type} | Path: {item.IdPath}"); + lgTrace($"Device data | ID: {item.Id} | Name: {item.Name} | Category: {item.Category} | # Type: {item.Type} | Path: {item.IdPath}"); + found++; } } + return found; } /// @@ -827,25 +869,31 @@ namespace IOB_WIN_MTC.Iob { if (listDevices != null) { + int numCom = 0; + int numDev = 0; + int numItm = 0; // loggo devices principali... foreach (var device in listDevices) { - lgInfo($"Device data | ID: {device.Id} | Name: {device.Name} | UUID: {device.Uuid} | # items: {device.DataItems.Count()}"); + lgTrace($"Device data | ID: {device.Id} | Name: {device.Name} | UUID: {device.Uuid} | # items: {device.DataItems.Count()}"); // se ho subItems descrivo pure loro... if (device.DataItems.Count() > 0) { - logDataItemList(device.GetDataItems().ToList()); + numItm += logDataItemList(device.GetDataItems().ToList()); } if (device.Components.Count() > 0) { - logComponentsList(device.GetComponents().ToList()); + numCom += logComponentsList(device.GetComponents().ToList()); } // All Compositions (traverse the entire Device model) if (device.Compositions.Count() > 0) { - logCompositionList(device.GetCompositions().ToList()); + numCom += logCompositionList(device.GetCompositions().ToList()); } } + lgInfo(lineSep); + lgInfo($"Effettuata lettura | Components: {numCom} | Devices: {numDev} | DataItems: {numItm}"); + lgInfo(lineSep); } } @@ -922,6 +970,21 @@ namespace IOB_WIN_MTC.Iob * B5: emergenza (dipende da state machine se riportare 1 = armata/premuta, vedere conf mtcParams.emergencyArmedTrue) ----------------------------------------------------- */ + DateTime adesso = DateTime.Now; + // controllo se non ho dati buoni da > lastCurrentMaxElapsed sec --> disconnetto + if (adesso.Subtract(lastCurrent).TotalSeconds > lastCurrentMaxElapsed) + { + if (enableCliRestart) + { + lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter MTConnect!"); + tryDisconnect(); + } + else + { + lgError($"Attenzione: superato periodo di mancata comunicazione da oltre {lastCurrentMaxElapsed} sec ma enableCliRestart non permesso"); + } + } + // Controllo booleano PING document POWERON... string currPowerOn = getDataItemValue(mtcParams.condPowerOn.keyName); // se valido il check ping lo eseguo... altrimenti lo do x buono @@ -991,7 +1054,6 @@ namespace IOB_WIN_MTC.Iob } } - DateTime adesso = DateTime.Now; int vFactor = 1; // controllo SE HO dati per fare verifiche... if (string.IsNullOrEmpty(currRun)) @@ -1006,7 +1068,7 @@ namespace IOB_WIN_MTC.Iob // stop... lgInfo("Fermato MTC_ref per mancanza dati current"); MTC_ref.Stop(); - Thread.Sleep(1000); + Thread.Sleep(3000); // restart lgInfo("Riavviato MTC_ref per mancanza dati current"); MTC_ref.Start(); @@ -1382,6 +1444,7 @@ namespace IOB_WIN_MTC.Iob lgInfo("ASSET received"); queueInEnabCurr = true; connectionOk = true; + lastCurrent = DateTime.Now; foreach (var asset in doc.Assets) { // Print AssetId to the Console @@ -1392,6 +1455,7 @@ namespace IOB_WIN_MTC.Iob private void MTC_ref_ClientStarted(object sender, EventArgs e) { lgInfo($"Client Started!"); + lastCurrent = DateTime.Now; } private void MTC_ref_ClientStopped(object sender, EventArgs e) @@ -1418,6 +1482,7 @@ namespace IOB_WIN_MTC.Iob lgInfo("CURRENT received"); queueInEnabCurr = true; connectionOk = true; + lastCurrent = DateTime.Now; if (document != null) { if (document.Streams != null) @@ -1440,6 +1505,7 @@ namespace IOB_WIN_MTC.Iob private void MTC_ref_ObservationReceived(object sender, MTConnect.Observations.IObservation observ) { connectionOk = true; + lastCurrent = DateTime.Now; processObservation(observ, false); } @@ -1452,6 +1518,7 @@ namespace IOB_WIN_MTC.Iob { queueInEnabCurr = true; connectionOk = true; + lastCurrent = DateTime.Now; lgInfo("STEP 01 DevicesSuccessful reached!"); MtcDataItemExt currDataItem = null; machDataItem currMapoDataItem = null; @@ -1521,6 +1588,7 @@ namespace IOB_WIN_MTC.Iob private void MTC_ref_SampleReceived(object sender, MTConnect.Streams.IStreamsResponseDocument document) { connectionOk = true; + lastCurrent = DateTime.Now; lgTrace("SAMPLE received"); checkAndSend(document, false); } @@ -1705,6 +1773,5 @@ namespace IOB_WIN_MTC.Iob } #endregion Private Methods - } } \ No newline at end of file diff --git a/IOB-WIN-MTC/postBuildTgt.bat b/IOB-WIN-MTC/postBuildTgt.bat index e2530148..b1a65667 100644 --- a/IOB-WIN-MTC/postBuildTgt.bat +++ b/IOB-WIN-MTC/postBuildTgt.bat @@ -1,51 +1,6 @@ @echo off echo Inizio processing After Build: configurazione %1 , directory %2 -RD /S /Q %2"\lib\ar" -RD /S /Q %2"\lib\cs" -RD /S /Q %2"\lib\da" -RD /S /Q %2"\lib\de" -RD /S /Q %2"\lib\es" -RD /S /Q %2"\lib\fr" -RD /S /Q %2"\lib\it" -RD /S /Q %2"\lib\ja-JP" -RD /S /Q %2"\lib\ko" -RD /S /Q %2"\lib\lv" -RD /S /Q %2"\lib\nl" -RD /S /Q %2"\lib\pl" -RD /S /Q %2"\lib\pt" -RD /S /Q %2"\lib\pt-BR" -RD /S /Q %2"\lib\ru" -RD /S /Q %2"\lib\sk" -RD /S /Q %2"\lib\sv" -RD /S /Q %2"\lib\th" -RD /S /Q %2"\lib\tr" -RD /S /Q %2"\lib\zh" -RD /S /Q %2"\lib\zh-TW" - -MOVE /Y %2"ar" %2"lib\" -MOVE /Y %2"cs" %2"lib\" -MOVE /Y %2"da" %2"lib\" -MOVE /Y %2"de" %2"lib\" -MOVE /Y %2"es" %2"lib\" -MOVE /Y %2"fr" %2"lib\" -MOVE /Y %2"it" %2"lib\" -MOVE /Y %2"ja-JP" %2"lib\" -MOVE /Y %2"ko" %2"lib\" -MOVE /Y %2"lv" %2"lib\" -MOVE /Y %2"nl" %2"lib\" -MOVE /Y %2"pl" %2"lib\" -MOVE /Y %2"pt" %2"lib\" -MOVE /Y %2"pt-BR" %2"lib\" -MOVE /Y %2"ru" %2"lib\" -MOVE /Y %2"sk" %2"lib\" -MOVE /Y %2"sv" %2"lib\" -MOVE /Y %2"th" %2"lib\" -MOVE /Y %2"tr" %2"lib\" -MOVE /Y %2"zh" %2"lib\" -MOVE /Y %2"zh-TW" %2"lib\" - - if %1 == "Release" goto ReleaseExec if %1 == Release goto ReleaseExec if %1 == "Debug" goto DebugExec diff --git a/IOB-WIN-OPC-UA/IobOpc/OpcUa.cs b/IOB-WIN-OPC-UA/IobOpc/OpcUa.cs index 53247bab..8c684c7e 100644 --- a/IOB-WIN-OPC-UA/IobOpc/OpcUa.cs +++ b/IOB-WIN-OPC-UA/IobOpc/OpcUa.cs @@ -1151,10 +1151,12 @@ namespace IOB_WIN_OPC_UA.IobOpc /// protected Dictionary dataItemMem = new Dictionary(); +#if false /// /// Abilitazione restart (da opt par...) /// - protected bool enableCliRestart = false; + protected bool enableCliRestart = false; +#endif /// /// Gestione filtraggio dati @@ -1171,10 +1173,12 @@ namespace IOB_WIN_OPC_UA.IobOpc /// protected DateTime lastCurrent = DateTime.Now; +#if false /// /// Periodo massimo (in sec) per letture dati RAW in mancanza di eventi /// - protected int lastCurrentMaxElapsed = 120; + protected int lastCurrentMaxElapsed = 120; +#endif /// /// Oggetto MAIN x connessione OPC-UA @@ -1653,8 +1657,15 @@ namespace IOB_WIN_OPC_UA.IobOpc // controllo se non ho dati buoni da > lastCurrentMaxElapsed sec --> disconnetto if (adesso.Subtract(lastCurrent).TotalSeconds > lastCurrentMaxElapsed) { - lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); - tryDisconnect(); + if (enableCliRestart) + { + lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); + tryDisconnect(); + } + else + { + lgError($"Attenzione: superato periodo di mancata comunicazione da oltre {lastCurrentMaxElapsed} sec ma enableCliRestart non permesso"); + } } // solo se non ho veto check @@ -1983,6 +1994,7 @@ namespace IOB_WIN_OPC_UA.IobOpc #region Private Fields +#if false /// /// Num errori lettura correnti /// @@ -1995,7 +2007,8 @@ namespace IOB_WIN_OPC_UA.IobOpc /// /// - private int readErrorSleepTime = 15000; + private int readErrorSleepTime = 15000; +#endif /// /// Elenco degli items da monitorare come risultato del browse iniziale diff --git a/IOB-WIN-OPC-UA/IobOpc/OpcUaKpw.cs b/IOB-WIN-OPC-UA/IobOpc/OpcUaKpw.cs index 54c978cc..c9d79f24 100644 --- a/IOB-WIN-OPC-UA/IobOpc/OpcUaKpw.cs +++ b/IOB-WIN-OPC-UA/IobOpc/OpcUaKpw.cs @@ -248,8 +248,15 @@ namespace IOB_WIN_OPC_UA.IobOpc // controllo se non ho dati buoni da > lastCurrentMaxElapsed sec --> disconnetto if (adesso.Subtract(lastCurrent).TotalSeconds > lastCurrentMaxElapsed) { - lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); - tryDisconnect(); + if (enableCliRestart) + { + lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); + tryDisconnect(); + } + else + { + lgError($"Attenzione: superato periodo di mancata comunicazione da oltre {lastCurrentMaxElapsed} sec ma enableCliRestart non permesso"); + } } // solo se non ho veto check diff --git a/IOB-WIN-OPC-UA/IobOpc/OpcUaMBH.cs b/IOB-WIN-OPC-UA/IobOpc/OpcUaMBH.cs index e8228f0a..9217f28d 100644 --- a/IOB-WIN-OPC-UA/IobOpc/OpcUaMBH.cs +++ b/IOB-WIN-OPC-UA/IobOpc/OpcUaMBH.cs @@ -256,8 +256,15 @@ namespace IOB_WIN_OPC_UA.IobOpc // controllo se non ho dati buoni da > lastCurrentMaxElapsed sec --> disconnetto if (adesso.Subtract(lastCurrent).TotalSeconds > lastCurrentMaxElapsed) { - lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); - tryDisconnect(); + if (enableCliRestart) + { + lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); + tryDisconnect(); + } + else + { + lgError($"Attenzione: superato periodo di mancata comunicazione da oltre {lastCurrentMaxElapsed} sec ma enableCliRestart non permesso"); + } } // solo se non ho veto check diff --git a/IOB-WIN-OPC-UA/IobOpc/OpcUaMBHCimolai.cs b/IOB-WIN-OPC-UA/IobOpc/OpcUaMBHCimolai.cs index 6618e677..02552ef7 100644 --- a/IOB-WIN-OPC-UA/IobOpc/OpcUaMBHCimolai.cs +++ b/IOB-WIN-OPC-UA/IobOpc/OpcUaMBHCimolai.cs @@ -467,8 +467,15 @@ namespace IOB_WIN_OPC_UA.IobOpc // controllo se non ho dati buoni da > lastCurrentMaxElapsed sec --> disconnetto if (adesso.Subtract(lastCurrent).TotalSeconds > lastCurrentMaxElapsed) { - lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); - tryDisconnect(); + if (enableCliRestart) + { + lgInfo($"Timeout per mancata comunicazione da oltre {lastCurrentMaxElapsed} sec --> disconnessione adapter OpcUa!"); + tryDisconnect(); + } + else + { + lgError($"Attenzione: superato periodo di mancata comunicazione da oltre {lastCurrentMaxElapsed} sec ma enableCliRestart non permesso"); + } } // solo se non ho veto check