diff --git a/MTC_Adapter/CMSCncLib/CNC/CNC.FANUC/CNC.FANUC.vb b/MTC_Adapter/CMSCncLib/CNC/CNC.FANUC/CNC.FANUC.vb index b99c50f..6186eea 100644 --- a/MTC_Adapter/CMSCncLib/CNC/CNC.FANUC/CNC.FANUC.vb +++ b/MTC_Adapter/CMSCncLib/CNC/CNC.FANUC/CNC.FANUC.vb @@ -1902,17 +1902,17 @@ Namespace CNC Case Else : szErrorDesc = "- ERRORE PMC INESISTENTE -" End Select - 'Stampo il messaggio - If Config.Settings.Settings.Debug > 0 Then - 'If nReturn <> Focas1.EW_SOCKET Then 'tranne su errore di connessione - 'CMSCncLib.App.Runtime.Log.WW("ERR pmc_wrpmcrng on F_RW_DWord CNC.FANUC", "Return=" & nReturn, True) - MsgBox(szErrorDesc & vbLf & "Occurred in: " & Position, MsgBoxStyle.Exclamation + MsgBoxStyle.ApplicationModal, "Error on Fanuc CNC Data Window") - 'End If - End If + ''Stampo il messaggio + 'If (Config.Settings.Settings.Debug > 0) Then + ' 'If nReturn <> Focas1.EW_SOCKET Then 'tranne su errore di connessione + ' 'CMSCncLib.App.Runtime.Log.WW("ERR pmc_wrpmcrng on F_RW_DWord CNC.FANUC", "Return=" & nReturn, True) + ' MsgBox(szErrorDesc & vbLf & "Occurred in: " & Position, MsgBoxStyle.Exclamation + MsgBoxStyle.ApplicationModal, "Error on Fanuc CNC Data Window") + ' 'End If + 'End If Return True 'presenza errore - End If + End If - Return False 'assenza errori + Return False 'assenza errori End Function diff --git a/MTC_Adapter/MTC_Adapter/AdapterESA.cs b/MTC_Adapter/MTC_Adapter/AdapterESA.cs index 54dc567..7eeca41 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterESA.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterESA.cs @@ -53,6 +53,7 @@ namespace MTC_Adapter base.tryDisconnect(); // disconnetto ncDevice.Disconnect(); + connectionOk = false; } public override void tryConnect() @@ -67,6 +68,11 @@ namespace MTC_Adapter { //altrimenti disconnette... ncDevice.Disconnect(); + connectionOk = false; + } + else + { + connectionOk = true; } } } diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs index ae743f3..1edc5a6 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs @@ -117,6 +117,7 @@ namespace MTC_Adapter try { FANUC_ref.Disconnect(ref szStatusConnection); + connectionOk = false; lg.Info(szStatusConnection); lg.Info("Effettuata disconnessione adapter FANUC!"); } @@ -140,6 +141,7 @@ namespace MTC_Adapter { FANUC_ref.Connect(ref szStatusConnection); lg.Info(szStatusConnection); + connectionOk = true; // refresh stato allarmi!!! if (connectionOk) { @@ -152,7 +154,7 @@ namespace MTC_Adapter } else { - lg.Error("Impossibile effettuare refresh completo stato allarmi, connessione mancante..."); + lg.Error("Impossibile procedere, connessione mancante..."); } } catch (Exception exc) diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index c3412b5..49a0be0 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -556,6 +556,14 @@ namespace MTC_Adapter /// protected bool adpRunning; /// + /// valore booleano (richiesta di riavvio automatico) + /// + protected bool adpTryRestart; + /// + /// porta x adapter (x restart) + /// + protected int adpPortNum; + /// /// DataOra ultimo avvio adapter x watchdog /// protected DateTime adpStartRun; @@ -1280,8 +1288,10 @@ namespace MTC_Adapter loadSubMode(); loadOtherFile(); - // Start the adapter lib with the port number in the text box + // salvo porta! mAdapter.Port = port; + adpPortNum = port; + // avvio! mAdapter.Start(); // setto status a ON @@ -1394,6 +1404,7 @@ namespace MTC_Adapter mAlarmCNC.Normal(); mAlarmPLC.Normal(); mAlarmGeneral.Normal(); + adpTryRestart = true; parentForm.displayTaskAndWait("Adapter Started!"); } /// @@ -1409,10 +1420,12 @@ namespace MTC_Adapter /// /// ferma l'adapter... /// - public void stopAdapter() + /// indica se si debba tentare di riavviare l'adapter (con caduta connessione viene fermato in automatico) + public void stopAdapter(bool tryRestart) { parentForm.displayTaskAndWait("Stopping adapter..."); - mStatus.Value = "OFF"; + adpTryRestart = false; + mStatus.Value = "INACTIVE"; // faccio una chiamata extra ad ogni metodo di check... gaterAndSend(gatherCycle.HF); gaterAndSend(gatherCycle.MF); @@ -1432,7 +1445,11 @@ namespace MTC_Adapter lg.Error(exc, "Eccezione in chiusura Adapter"); } dtStopAdp = DateTime.Now; - parentForm.displayTaskAndWait("Adapter Stopped!"); + adpPortNum = mAdapter.Port; + adpTryRestart = tryRestart; + // chiudo! + parentForm.resetProgBar(); + parentForm.displayTaskAndWait("Adapter Stopped."); } /// @@ -1464,54 +1481,64 @@ namespace MTC_Adapter } if (adpRunning) { - // processing degli strobes di allarme (da ULTIMA rappresentazione vettore dell'ADP) - processAlarm(); - // processo e svuoto eventuali code di invio per Codici M/S/T - trySendCodMST(); - - // ciclo HF: recupero update status & strobes vari - if (ciclo == gatherCycle.HF) + // try / catch generale altrimenti segno che è disconnesso... + try { - // parte che eseguo SEMPRE: RECUPERO stato di tutti gli strobe/status e degli ack attualmente noti - getStrobeAndAckStatus(); + // processing degli strobes di allarme (da ULTIMA rappresentazione vettore dell'ADP) + processAlarm(); + // processo e svuoto eventuali code di invio per Codici M/S/T + trySendCodMST(); - // faccio refresh degli allarmi segnalati (da strobe su vettore locale) - refreshAlarmState(STRB_DW0, true); - // acquisizione degli status - processStatus(); - // processing degli strobes - processStrobe(); + + // ciclo HF: recupero update status & strobes vari + if (ciclo == gatherCycle.HF) + { + // parte che eseguo SEMPRE: RECUPERO stato di tutti gli strobe/status e degli ack attualmente noti + getStrobeAndAckStatus(); + + // faccio refresh degli allarmi segnalati (da strobe su vettore locale) + refreshAlarmState(STRB_DW0, true); + // acquisizione degli status + processStatus(); + // processing degli strobes + processStrobe(); + } + else if (ciclo == gatherCycle.MF) + { + // leggo parametri a media freq (dati globali, path, assi, Unità Operatrice) + getGlobalData(); + getUnOp(); + getPath(); + getAxis(); + } + // ciclo lento + else if (ciclo == gatherCycle.LF) + { + // leggo EVENTUALI parametri da config file + getConfigParam(); + ///acquisisco dati su programma in esecuzione e dati generali (stato, orologio, power...) + getSlowChangingData(); + + // eventuale log! + if (utils.CRB("recTime")) logTimeResults(); + } + // ciclo lentissimo + else if (ciclo == gatherCycle.VLF) + { + lg.Info("Richiesta lettura completa allarmi attivi"); + // faccio comunque rilettura completa allarmi... + forceAlarmCheck(); + } + + // INVIO dati variati! + mAdapter.SendChanged(); } - else if (ciclo == gatherCycle.MF) + catch (Exception exc) { - // leggo parametri a media freq (dati globali, path, assi, Unità Operatrice) - getGlobalData(); - getUnOp(); - getPath(); - getAxis(); + // segnalo eccezione e indico disconnesso... + lg.Error(exc, "Errore in gestione ciclo principale ADP, fermo adapter"); + parentForm.fermaAdapter(true); } - // ciclo lento - else if (ciclo == gatherCycle.LF) - { - // leggo EVENTUALI parametri da config file - getConfigParam(); - ///acquisisco dati su programma in esecuzione e dati generali (stato, orologio, power...) - getSlowChangingData(); - - // eventuale log! - if (utils.CRB("recTime")) logTimeResults(); - } - // ciclo lentissimo - else if (ciclo == gatherCycle.VLF) - { - lg.Info("Richiesta lettura completa allarmi attivi"); - // faccio comunque rilettura completa allarmi... - forceAlarmCheck(); - } - - // INVIO dati variati! - mAdapter.SendChanged(); - // tolgo flag running adpRunning = false; } @@ -1537,8 +1564,8 @@ namespace MTC_Adapter { // log connessione KO lg.Error("CicloMF - Connessione non disponibile, provo a riconnettere"); - // provo a riconnettere... - tryConnect(); + // provo a riconnettere SE abilitato tryRestart... + if(adpTryRestart) tryConnect(); } if (eh_refreshed != null) { @@ -1615,15 +1642,20 @@ namespace MTC_Adapter { } + protected bool _connOk = false; /// - /// Dummy method: verifica stato conensisone OK + /// Salva verifica stato connessione OK /// /// public virtual bool connectionOk { get { - return true; + return _connOk; + } + set + { + _connOk = value; } } diff --git a/MTC_Adapter/MTC_Adapter/MainForm.Designer.cs b/MTC_Adapter/MTC_Adapter/MainForm.Designer.cs index 48ddbfa..ee35267 100644 --- a/MTC_Adapter/MTC_Adapter/MainForm.Designer.cs +++ b/MTC_Adapter/MTC_Adapter/MainForm.Designer.cs @@ -1051,9 +1051,9 @@ this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.lblApp, - this.lblStatus, + this.lblVers, this.MainProgrBar, - this.lblVers}); + this.lblStatus}); this.statusStrip1.Location = new System.Drawing.Point(0, 716); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new System.Drawing.Size(785, 25); @@ -1471,7 +1471,7 @@ this.tbConf.Location = new System.Drawing.Point(4, 22); this.tbConf.Name = "tbConf"; this.tbConf.Padding = new System.Windows.Forms.Padding(3); - this.tbConf.Size = new System.Drawing.Size(777, 636); + this.tbConf.Size = new System.Drawing.Size(777, 640); this.tbConf.TabIndex = 1; this.tbConf.Text = "XML CONFIG"; // @@ -1481,7 +1481,7 @@ this.wbXmlConf.Location = new System.Drawing.Point(3, 3); this.wbXmlConf.MinimumSize = new System.Drawing.Size(20, 20); this.wbXmlConf.Name = "wbXmlConf"; - this.wbXmlConf.Size = new System.Drawing.Size(771, 630); + this.wbXmlConf.Size = new System.Drawing.Size(771, 634); this.wbXmlConf.TabIndex = 0; // // tpSIM @@ -1501,7 +1501,7 @@ this.tpSIM.Controls.Add(this.groupBox12); this.tpSIM.Location = new System.Drawing.Point(4, 22); this.tpSIM.Name = "tpSIM"; - this.tpSIM.Size = new System.Drawing.Size(777, 636); + this.tpSIM.Size = new System.Drawing.Size(777, 640); this.tpSIM.TabIndex = 2; this.tpSIM.Text = "SIMULATION"; // diff --git a/MTC_Adapter/MTC_Adapter/MainForm.cs b/MTC_Adapter/MTC_Adapter/MainForm.cs index dbd9193..65a11bb 100644 --- a/MTC_Adapter/MTC_Adapter/MainForm.cs +++ b/MTC_Adapter/MTC_Adapter/MainForm.cs @@ -438,7 +438,7 @@ namespace MTC_Adapter avviaAdapter(); } - private void avviaAdapter() + public void avviaAdapter() { displayTaskAndWait("Adapter starting"); @@ -468,7 +468,7 @@ namespace MTC_Adapter slowCount = utils.CRI("slowCount"); alarmSyncCount = utils.CRI("alarmSyncCount"); - displayTaskAndWait("Timers Ready"); + displayTaskAndWait("Adapter Running..."); } /// @@ -478,7 +478,15 @@ namespace MTC_Adapter /// private void stop_Click(object sender, EventArgs e) { - agObj.stopAdapter(); + fermaAdapter(false); + } + /// + /// Ferma l'adapter + /// + /// determina se si debba tentare riavvio automatico (per caduta connessione) + public void fermaAdapter(bool tryRestart) + { + agObj.stopAdapter(tryRestart); // salvo! savePersistLayer(defPersLayerFile); savePersistLayer(histPersLayerFile); @@ -516,6 +524,11 @@ namespace MTC_Adapter } } + public void resetProgBar() + { + MainProgrBar.Value = 0; + } + private void checkAlarmSync() { alarmSyncCount--; @@ -1538,7 +1551,7 @@ namespace MTC_Adapter private void closeAdapter() { - agObj.stopAdapter(); + agObj.stopAdapter(false); // salvo! savePersistLayer(defPersLayerFile); savePersistLayer(histPersLayerFile); diff --git a/MTC_Adapter/MTC_Adapter/MainForm.resx b/MTC_Adapter/MTC_Adapter/MainForm.resx index 018cda4..8196fcb 100644 --- a/MTC_Adapter/MTC_Adapter/MainForm.resx +++ b/MTC_Adapter/MTC_Adapter/MainForm.resx @@ -138,24 +138,6 @@ True - - True - - - True - - - True - - - True - - - True - - - True - 104, 17