From f5372c33ac3a802f39151f3b666b2b0656ad5396 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 7 Dec 2016 16:17:21 +0100 Subject: [PATCH] Completato test: si ferma e riavvia da solo SE si interrompe connessione con PLC!!! --- MTC_Adapter/MTC_Adapter/AdapterESA.cs | 2 +- MTC_Adapter/MTC_Adapter/AdapterFanuc.cs | 2 +- MTC_Adapter/MTC_Adapter/AdapterGeneric.cs | 26 ++++---- MTC_Adapter/MTC_Adapter/App.config | 3 +- MTC_Adapter/MTC_Adapter/MainForm.cs | 73 +++++++++++++++-------- 5 files changed, 67 insertions(+), 39 deletions(-) diff --git a/MTC_Adapter/MTC_Adapter/AdapterESA.cs b/MTC_Adapter/MTC_Adapter/AdapterESA.cs index 7eeca41..ea91afd 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterESA.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterESA.cs @@ -552,7 +552,7 @@ namespace MTC_Adapter if (utils.CRB("verbose")) { - sb.AppendLine(string.Format("Asse {0}: PosAct:{1:N3}, ToGo:{2:N3}{3}, Dir: {4}", i, (double)(newPos) / utils.CRI("fattdecimale"), i, 0, direzione)); + sb.AppendLine(string.Format("Asse {0}: PosAct:{1:N3}, ToGo:{2:N3}{3} | {4}", i, (double)(newPos) / utils.CRI("fattdecimale"), i, 0, direzione)); } // salvo valori vettore prec... diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs index 1edc5a6..d907f97 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs @@ -1638,7 +1638,7 @@ namespace MTC_Adapter if (utils.CRB("verbose")) { - sb.AppendLine(string.Format("Asse {0}: PosAct:{1:N3}, ToGo:{2:N3}{3}, Dir: {4}", valPos.abs.name, (double)(valPos.abs.data) / Math.Pow(10, valPos.abs.dec), valPos.dist.name, (double)(valPos.dist.data) / Math.Pow(10, valPos.dist.dec), direzione)); + sb.AppendLine(string.Format("Asse {0}: PosAct:{1:N3}, ToGo:{2:N3}{3} | {4}", valPos.abs.name, (double)(valPos.abs.data) / Math.Pow(10, valPos.abs.dec), valPos.dist.name, (double)(valPos.dist.data) / Math.Pow(10, valPos.dist.dec), direzione)); } // salvo valori vettore prec... diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index b33a4d1..b5e3aa3 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -552,13 +552,17 @@ namespace MTC_Adapter /// public static Logger lg; /// - /// valore booleano di check se sia running + /// valore booleano di check se sia in fase di COMUNICAZIONE ATTIVA con il PLC/NC /// - protected bool adpRunning; + protected bool adpCommAct; + /// + /// valore booleano di check se sia stato AVVIATO l'adapter (Running) + /// + public bool adpRunning; /// /// valore booleano (richiesta di riavvio automatico) /// - protected bool adpTryRestart; + public bool adpTryRestart; /// /// porta x adapter (x restart) /// @@ -1282,6 +1286,7 @@ namespace MTC_Adapter public virtual void startAdapter(int port) { lg.Info("Starting adapter..."); + adpRunning = true; dtAvvioAdp = DateTime.Now; // inizializzo vettori di utility.. loadAllarmi(); @@ -1298,7 +1303,7 @@ namespace MTC_Adapter mStatus.Value = "ON"; // resetto running flag... - adpRunning = false; + adpCommAct = false; // carico valori da adapter x i conteggi contOreMaccOn = currAdpConf.ContOreMaccOn; @@ -1447,6 +1452,7 @@ namespace MTC_Adapter dtStopAdp = DateTime.Now; adpPortNum = mAdapter.Port; adpTryRestart = tryRestart; + adpRunning = false; // chiudo! parentForm.resetProgBar(); parentForm.dataMonitor = "... not connected, waiting for data ..."; @@ -1463,7 +1469,7 @@ namespace MTC_Adapter if (connectionOk) { // controllo non sia già in esecuzione... - if (!adpRunning) + if (!adpCommAct) { // provo ad avviare try @@ -1471,16 +1477,16 @@ namespace MTC_Adapter // avvio fase raccolta dati mAdapter.Begin(); // imposto flag adapter running.. - adpRunning = true; + adpCommAct = true; adpStartRun = DateTime.Now; } catch (Exception exc) { parentForm.displayTaskAndWait(string.Format("Adapter NOT STARTED!!!{0}{1}", Environment.NewLine, exc)); - adpRunning = false; + adpCommAct = false; adpStartRun = DateTime.Now; } - if (adpRunning) + if (adpCommAct) { // try / catch generale altrimenti segno che è disconnesso... try @@ -1541,7 +1547,7 @@ namespace MTC_Adapter parentForm.fermaAdapter(true); } // tolgo flag running - adpRunning = false; + adpCommAct = false; } else { @@ -1556,7 +1562,7 @@ namespace MTC_Adapter if (DateTime.Now.Subtract(adpStartRun).TotalSeconds > utils.CRI("maxAdapterLockSec")) { // tolgo flag running - adpRunning = false; + adpCommAct = false; adpStartRun = DateTime.Now; } } diff --git a/MTC_Adapter/MTC_Adapter/App.config b/MTC_Adapter/MTC_Adapter/App.config index d01efc7..0bffc5e 100644 --- a/MTC_Adapter/MTC_Adapter/App.config +++ b/MTC_Adapter/MTC_Adapter/App.config @@ -46,10 +46,11 @@ - + + diff --git a/MTC_Adapter/MTC_Adapter/MainForm.cs b/MTC_Adapter/MTC_Adapter/MainForm.cs index 65a11bb..9702d95 100644 --- a/MTC_Adapter/MTC_Adapter/MainForm.cs +++ b/MTC_Adapter/MTC_Adapter/MainForm.cs @@ -48,6 +48,10 @@ namespace MTC_Adapter /// timer base in avvio /// protected int startTimerMs; + /// + /// ultimo tentativo riavvio... + /// + protected DateTime lastStartTry; #endregion @@ -120,6 +124,8 @@ namespace MTC_Adapter InitializeComponent(); lblStatus.Text = "Loading"; + lastStartTry = DateTime.Now; + // fix icon! Icon = Icon.ExtractAssociatedIcon(defIconFilePath); notifyIcon1.Icon = Icon.ExtractAssociatedIcon(defIconFilePath); @@ -151,6 +157,10 @@ namespace MTC_Adapter loadAdapterType(); displayTaskAndWait("Waiting for config file selection"); } + + // Start timer periodico + gather.Interval = utils.CRI("timerIntMs"); + gather.Enabled = true; displayTaskAndWait("Running"); createTrayMenu(); @@ -458,10 +468,6 @@ namespace MTC_Adapter } displayTaskAndWait("Start Timers"); - - // Start timer periodico - gather.Interval = utils.CRI("timerIntMs"); - gather.Enabled = true; // inizializzo contatori fast/mid/slow fastCount = utils.CRI("fastCount"); normCount = utils.CRI("normCount"); @@ -494,33 +500,48 @@ namespace MTC_Adapter stop.Enabled = false; dump.Enabled = false; start.Enabled = true; - gather.Enabled = false; + //gather.Enabled = false; } private void gather_Tick(object sender, EventArgs e) { - // inizio a riportare che sto eseguendo.. - MainProgrBar.PerformStep(); - - // eseguo eventuali simulazioni x dati/flags SE RICHIESTO - simulateData(); - - // check esecuzione FastTask - checkFastTask(); - - // check esecuzione NormTask - checkNormTask(); - - // check esecuzione SlowTask - checkSlowTask(); - - // check esecuzione AlarmSync - checkAlarmSync(); - - // se è arrivato a MAX resetto... - if (MainProgrBar.Value >= MainProgrBar.Maximum) + + // eseguo cicli attivi SOLO se adapter è in EFFETTIVO running... + if (agObj.adpRunning) { - MainProgrBar.Value = 0; + // inizio a riportare che sto eseguendo.. + MainProgrBar.PerformStep(); + + // eseguo eventuali simulazioni x dati/flags SE RICHIESTO + simulateData(); + + // check esecuzione FastTask + checkFastTask(); + + // check esecuzione NormTask + checkNormTask(); + + // check esecuzione SlowTask + checkSlowTask(); + + // check esecuzione AlarmSync + checkAlarmSync(); + + // se è arrivato a MAX resetto... + if (MainProgrBar.Value >= MainProgrBar.Maximum) + { + MainProgrBar.Value = 0; + } + } + else + { + // verifico SE debba tentare il riavvio, ovvero NON running ma tryReconn e non ho riprovato x oltre waitRecMSec + int currWait = DateTime.Now.Subtract(lastStartTry).Milliseconds; + if (agObj.adpTryRestart && currWait> utils.CRI("waitRecSec")) + { + lastStartTry = DateTime.Now; + avviaAdapter(); + } } }