diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs index b2b7d7a..c5d66d7 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs @@ -160,6 +160,8 @@ namespace MTC_Adapter catch (Exception exc) { lg.Fatal(exc, "Errore nella connessione all'adapter FANUC", szStatusConnection); + connectionOk = false; + lg.Info(string.Format("Segnalo Adapter NON running, pausa di {0} msec prima di ulteriori tentativi di riconnessione", utils.CRI("waitRecMSec"))); } } } diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index c21e513..b40bd3f 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -12,6 +12,7 @@ namespace MTC_Adapter using System.Diagnostics; using System.Globalization; using System.IO; + using System.Threading; using System.Windows.Forms; @@ -1607,8 +1608,10 @@ namespace MTC_Adapter // log connessione KO lg.Error("CicloMF - Connessione non disponibile, provo a riconnettere"); // provo a riconnettere SE abilitato tryRestart... - if (adpTryRestart) + if (adpTryRestart && !connectionOk) { + //// aspetto un tempo di wait adatto + //Thread.Sleep(utils.CRI("waitRecMSec")); tryConnect(); } } diff --git a/MTC_Adapter/MTC_Adapter/App.config b/MTC_Adapter/MTC_Adapter/App.config index bb70dd9..8116af3 100644 --- a/MTC_Adapter/MTC_Adapter/App.config +++ b/MTC_Adapter/MTC_Adapter/App.config @@ -44,7 +44,7 @@ - + diff --git a/MTC_Adapter/MTC_Adapter/MainForm.cs b/MTC_Adapter/MTC_Adapter/MainForm.cs index a7f3f31..79254e3 100644 --- a/MTC_Adapter/MTC_Adapter/MainForm.cs +++ b/MTC_Adapter/MTC_Adapter/MainForm.cs @@ -139,18 +139,18 @@ namespace MTC_Adapter startTimerMs = utils.CRI("startTimerMs"); #if DEBUG - // Setup the logging view for Sentinel - http://sentinel.codeplex.com - var sentinalTarget = new NLogViewerTarget() - { - Name = "sentinal", - Address = "udp://127.0.0.1:9999", - IncludeNLogData = false - }; - var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget); - LogManager.Configuration.AddTarget("sentinal", sentinalTarget); - LogManager.Configuration.LoggingRules.Add(sentinalRule); + // Setup the logging view for Sentinel - http://sentinel.codeplex.com + var sentinalTarget = new NLogViewerTarget() + { + Name = "sentinal", + Address = "udp://127.0.0.1:9999", + IncludeNLogData = false + }; + var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget); + LogManager.Configuration.AddTarget("sentinal", sentinalTarget); + LogManager.Configuration.LoggingRules.Add(sentinalRule); + - #endif LogManager.ReconfigExistingLoggers(); @@ -530,22 +530,35 @@ namespace MTC_Adapter { // inizio a riportare che sto eseguendo.. MainProgrBar.PerformStep(); + if (agObj.connectionOk) + { - // eseguo eventuali simulazioni x dati/flags SE RICHIESTO - simulateData(); + // eseguo eventuali simulazioni x dati/flags SE RICHIESTO + simulateData(); - // check esecuzione FastTask - checkFastTask(); + // check esecuzione FastTask + checkFastTask(); - // check esecuzione NormTask - checkNormTask(); + // check esecuzione NormTask + checkNormTask(); - // check esecuzione SlowTask - checkSlowTask(); + // check esecuzione SlowTask + checkSlowTask(); - // check esecuzione AlarmSync - checkAlarmSync(); + // check esecuzione AlarmSync + checkAlarmSync(); + } + else + { + double currWait = DateTime.Now.Subtract(lastStartTry).TotalMilliseconds; + if (agObj.adpTryRestart && currWait > utils.CRI("waitRecMSec")) + { + lastStartTry = DateTime.Now; + agObj.tryConnect(); + agObj.loadPersData(); + } + } // se รจ arrivato a MAX resetto... if (MainProgrBar.Value >= MainProgrBar.Maximum) { @@ -556,7 +569,7 @@ namespace MTC_Adapter { // verifico SE debba tentare il riavvio, ovvero NON running ma tryReconn e non ho riprovato x oltre waitRecMSec double currWait = DateTime.Now.Subtract(lastStartTry).TotalMilliseconds; - if (agObj.adpTryRestart && currWait > utils.CRI("waitRecSec")) + if (agObj.adpTryRestart && currWait > utils.CRI("waitRecMSec")) { lastStartTry = DateTime.Now; avviaAdapter();