diff --git a/IOB-WIN-FANUC/DATA/CONF/MAIN.ini b/IOB-WIN-FANUC/DATA/CONF/MAIN.ini
index 5b64abf8..397d0fe7 100644
--- a/IOB-WIN-FANUC/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-FANUC/DATA/CONF/MAIN.ini
@@ -34,4 +34,3 @@ CLI_INST=SteamWareSim
STARTLIST=SIMUL_02
MAXCNC=10
-
diff --git a/IOB-WIN-FORM/AdapterForm.cs b/IOB-WIN-FORM/AdapterForm.cs
index 0f9c84d1..1e2da517 100644
--- a/IOB-WIN-FORM/AdapterForm.cs
+++ b/IOB-WIN-FORM/AdapterForm.cs
@@ -35,18 +35,6 @@ namespace IOB_WIN_FORM
#endregion Public Fields
-
- public void ForceUpdateUI()
- {
- // aggiorna UI (log, grid, label…)
- this.UIThread(delegate
- {
- bIN.BackColor = decSemaforo(_sIN);
- bOUT.BackColor = decSemaforo(_sOUT);
- });
- }
-
-
#region Public Constructors
///
@@ -165,10 +153,6 @@ namespace IOB_WIN_FORM
public string counterIob
{
- get
- {
- return lblPzCountIob.Text;
- }
set
{
this.UIThread(delegate
@@ -180,10 +164,6 @@ namespace IOB_WIN_FORM
public string counterMac
{
- get
- {
- return lblPzCountMac.Text;
- }
set
{
this.UIThread(delegate
@@ -198,12 +178,9 @@ namespace IOB_WIN_FORM
///
public string dataProcLabel
{
- get
- {
- return lblDataProc.Text;
- }
set
{
+ if (!ShouldUpdateUI()) return;
this.UIThread(delegate
{
lblDataProc.Text = value;
@@ -221,18 +198,18 @@ namespace IOB_WIN_FORM
///
public int nLine2show
{
- get
- {
- int answ = 5;
- Int32.TryParse(nLines.Text, out answ);
- return answ;
- }
+ get => _nLine2show = 5;
set
{
- this.UIThread(delegate
+ if (_nLine2show != value)
{
- nLines.Text = value.ToString();
- });
+ _nLine2show = value;
+ if (!ShouldUpdateUI()) return;
+ this.UIThread(delegate
+ {
+ nLines.Text = value.ToString();
+ });
+ }
}
}
@@ -283,10 +260,18 @@ namespace IOB_WIN_FORM
}
}
}
+
///
- /// Coda messaggi task
+ /// tipo di adapter prescelto...
///
- private readonly Queue logTaskQueue = new Queue();
+ public tipoAdapter tipoScelto
+ {
+ get => IOBConfFull != null ? IOBConfFull.General.IobType : tipoAdapter.ND;
+ }
+
+ #endregion Public Properties
+
+ #region Public Methods
///
/// Task watcher (in modalità "accodamento in testa" ultimi messaggi...)
@@ -301,8 +286,7 @@ namespace IOB_WIN_FORM
logTaskQueue.Enqueue(value);
- if (!ShouldUpdateUI())
- return;
+ if (!ShouldUpdateUI()) return;
// snapshot + reverse per mostrare latest in alto
var text = string.Join(
@@ -324,18 +308,6 @@ namespace IOB_WIN_FORM
}
}
- ///
- /// tipo di adapter prescelto...
- ///
- public tipoAdapter tipoScelto
- {
- get => IOBConfFull != null ? IOBConfFull.General.IobType : tipoAdapter.ND;
- }
-
- #endregion Public Properties
-
- #region Public Methods
-
///
/// Registra variazione error delay in caso di errori o successi
///
@@ -395,6 +367,17 @@ namespace IOB_WIN_FORM
fermaTutto(false, tryRestart, forceDequeue, updateForm);
}
+ public void ForceUpdateUI()
+ {
+ // aggiorna UI (log, grid, label…)
+ this.UIThread(delegate
+ {
+ bIN.BackColor = decSemaforo(_sIN);
+ bOUT.BackColor = decSemaforo(_sOUT);
+ refreshFormData();
+ });
+ }
+
///
/// Mostra update delle statistiche di comunicazione (numero chiamate, tempo medio...)
///
@@ -517,6 +500,19 @@ namespace IOB_WIN_FORM
///
protected DateTime lastStartTry;
+ protected long maxAlQueue = 0;
+ protected long maxEvQueue = 0;
+ protected long maxFlQueue = 0;
+ protected long maxMsQueue = 0;
+ protected long maxRwTrQueue = 0;
+ protected long maxUlQueue = 0;
+ protected long qAlLen = 0;
+ protected long qEvLen = 0;
+ protected long qFlLen = 0;
+ protected long qMsLen = 0;
+ protected long qRTrLen = 0;
+ protected long qUlLen = 0;
+
///
/// Generatore numeri random
///
@@ -566,8 +562,6 @@ namespace IOB_WIN_FORM
set
{
qAlLen = value;
- lblQueueAlarmLen.Text = qAlLen.ToString();
- showQueueData();
// se supero max precedente, ed è > 10... loggo!
if (qAlLen > maxAlQueue && qAlLen > 10)
{
@@ -579,6 +573,9 @@ namespace IOB_WIN_FORM
maxAlQueue--;
maxAlQueue = maxAlQueue < qAlLen ? qAlLen : maxAlQueue;
}
+ if (!ShouldUpdateUI()) return;
+ lblQueueAlarmLen.Text = qAlLen.ToString();
+ showQueueData();
}
get
{
@@ -642,53 +639,17 @@ namespace IOB_WIN_FORM
///
protected DateTime logWatchWriteVeto { get; set; } = DateTime.Now;
- protected long maxAlQueue { get; set; }
-
- protected long maxEvQueue { get; set; }
-
- protected long maxFlQueue { get; set; }
-
- protected long maxMsQueue { get; set; }
-
- protected long maxRwTrQueue { get; set; }
-
- protected long maxUlQueue { get; set; }
-
- protected long qAlLen { get; set; }
-
- protected long qEvLen { get; set; }
-
- protected long qFlLen { get; set; }
-
- protected long qMsLen { get; set; }
-
- protected long qRTrLen { get; set; }
-
- protected long qUlLen { get; set; }
-
- protected long totQueue
- {
- get
- {
- return qEvLen + qFlLen + qAlLen + qMsLen + qUlLen;
- }
- }
+ protected long totQueue => qEvLen + qFlLen + qAlLen + qMsLen + qUlLen;
///
/// URL per salvare i file dell'IOB (SENZA IOB)
///
- protected string urlUploadFile
- {
- get => $"http://{IOBConfFull.MapoMes.IpAddr}{IOBConfFull.MapoMes.BaseAppUrl}IOB/uploadFile/";
- }
+ protected string urlUploadFile => $"http://{IOBConfFull.MapoMes.IpAddr}{IOBConfFull.MapoMes.BaseAppUrl}IOB/uploadFile/";
///
/// URL per salvare i file dell'IOB su CLOUD (SENZA IOB)
///
- protected string urlUploadFileCloud
- {
- get => $"{baseUrl}IOB/uploadFile/";
- }
+ protected string urlUploadFileCloud => $"{baseUrl}IOB/uploadFile/";
#endregion Protected Properties
@@ -740,22 +701,6 @@ namespace IOB_WIN_FORM
});
}
-
- private IDisposable _scopeIOB;
-
- ///
- /// Salvo IOB e scope x NLog management
- ///
- ///
- private void SetIOB(string newIOB)
- {
- CurrIOB = newIOB;
- _scopeIOB?.Dispose(); // rimuove il vecchio valore
-
- _scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
- }
-
-
///
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
///
@@ -885,6 +830,7 @@ namespace IOB_WIN_FORM
///
protected void showQueueData()
{
+ if (!ShouldUpdateUI()) return;
lblQueueLenTop.Text = totQueue == 0 ? "realtime" : $"ev: {qEvLen} | flog: {qFlLen} | tot: {totQueue}";
}
@@ -893,9 +839,6 @@ namespace IOB_WIN_FORM
///
protected void UpdateDisplTypeIobSel()
{
- lblCNC.Text = $"CNC: {IOBConfFull.General.IobType} [{IOBConfFull.Device.Connect.IpAddr}:{IOBConfFull.Device.Connect.Port}]";
- lblSrvUrlText = $"SRV: {IOBConfFull.MapoMes.IpAddr} | BaseURL: {IOBConfFull.MapoMes.ApiUrl("")}";
-
// aggancio evento refresh
iobObj.eh_refreshed -= IobObj_eh_refreshed;
iobObj.eh_refreshed += IobObj_eh_refreshed;
@@ -904,6 +847,10 @@ namespace IOB_WIN_FORM
setDefaults();
displayTaskAndLog($"Caricata conf per adapter {tipoScelto}");
+
+ if (!ShouldUpdateUI()) return;
+ lblCNC.Text = $"CNC: {IOBConfFull.General.IobType} [{IOBConfFull.Device.Connect.IpAddr}:{IOBConfFull.Device.Connect.Port}]";
+ lblSrvUrl.Text = $"SRV: {IOBConfFull.MapoMes.IpAddr} | BaseURL: {IOBConfFull.MapoMes.ApiUrl("")}";
}
#endregion Protected Methods
@@ -934,6 +881,11 @@ namespace IOB_WIN_FORM
private readonly object _threadLock = new object();
+ ///
+ /// Coda messaggi task
+ ///
+ private readonly Queue logTaskQueue = new Queue();
+
///
/// Cancellation token x processi verso macchina
///
@@ -958,10 +910,10 @@ namespace IOB_WIN_FORM
private bool _isSuspended = false;
private FormWindowState _lastState = FormWindowState.Minimized;
-
private Thread _machineThread;
-
+ private int _nLine2show = 5;
private Task _redisTask;
+ private IDisposable _scopeIOB;
private Task _workerTask;
@@ -1012,35 +964,17 @@ namespace IOB_WIN_FORM
///
/// File configurazione default
///
- private string defConfFilePath
- {
- get
- {
- return Path.Combine(utils.confDir, $"{CurrIOB}.ini");
- }
- }
+ private string defConfFilePath => Path.Combine(utils.confDir, $"{CurrIOB}.ini");
///
/// File configurazione json (completo) se presente
///
- private string defConfFilePathJson
- {
- get
- {
- return Path.Combine(utils.confDir, $"{CurrIOB}.json");
- }
- }
+ private string defConfFilePathJson => Path.Combine(utils.confDir, $"{CurrIOB}.json");
///
/// File configurazione yaml (completo) se presente
///
- private string defConfFilePathYaml
- {
- get
- {
- return Path.Combine(utils.confDir, $"{CurrIOB}.yaml");
- }
- }
+ private string defConfFilePathYaml => Path.Combine(utils.confDir, $"{CurrIOB}.yaml");
private bool enableEditMes2Plc { get; set; }
@@ -1049,8 +983,6 @@ namespace IOB_WIN_FORM
set
{
qEvLen = value;
- lblQueueLen.Text = qEvLen.ToString();
- showQueueData();
// se supero max precedente, ed è > 10... loggo!
if (qEvLen > maxEvQueue && qEvLen > 10)
{
@@ -1062,6 +994,10 @@ namespace IOB_WIN_FORM
maxEvQueue--;
maxEvQueue = maxEvQueue < qEvLen ? qEvLen : maxEvQueue;
}
+
+ if (!ShouldUpdateUI()) return;
+ lblQueueLen.Text = qEvLen.ToString();
+ showQueueData();
}
get
{
@@ -1074,8 +1010,6 @@ namespace IOB_WIN_FORM
set
{
qFlLen = value;
- lblQueueFLogLen.Text = qFlLen.ToString();
- showQueueData();
// se supero max precedente, ed è > 10... loggo!
if (qFlLen > maxFlQueue && qFlLen > 10)
{
@@ -1087,6 +1021,10 @@ namespace IOB_WIN_FORM
maxFlQueue--;
maxFlQueue = maxFlQueue < qFlLen ? qFlLen : maxFlQueue;
}
+
+ if (!ShouldUpdateUI()) return;
+ lblQueueFLogLen.Text = qFlLen.ToString();
+ showQueueData();
}
get
{
@@ -1094,18 +1032,6 @@ namespace IOB_WIN_FORM
}
}
- private string lblCncText
- {
- get => lblCNC.Text;
- set => lblCNC.Text = value;
- }
-
- private string lblSrvUrlText
- {
- get => lblSrvUrl.Text;
- set => lblSrvUrl.Text = value;
- }
-
private long msQueueLen
{
set
@@ -1373,8 +1299,7 @@ namespace IOB_WIN_FORM
if (logWatchWriteVeto >= now)
return;
- if (!ShouldUpdateUI())
- return;
+ if (!ShouldUpdateUI()) return;
logWatchWriteVeto = now.AddMilliseconds(delayShowLogMs);
@@ -1844,7 +1769,6 @@ namespace IOB_WIN_FORM
/// indica se si debba aggiornare la form (no se si sta chiudendo...)
private void fermaTutto(bool stopTimer, bool tryRestart, bool forceDequeue, bool updateForm)
{
-
if (iobObj == null)
return;
@@ -1864,7 +1788,7 @@ namespace IOB_WIN_FORM
btnStart.Enabled = true;
restart.Enabled = false;
});
- _isSuspended = true;
+ _isSuspended = true;
Task.Run(async () =>
{
if (stopTimer)
@@ -2115,8 +2039,7 @@ namespace IOB_WIN_FORM
OpenFileDialog openFileDial = new OpenFileDialog();
// directory iniziale
- openFileDial.InitialDirectory = utils.confDir; // string.Format(@"{0}\{1}", Application.StartupPath, utils.CRS("dataConfPath"));
- // Set filter options and filter index.
+ openFileDial.InitialDirectory = utils.confDir;
openFileDial.Filter = "INI Files (.ini)|*.ini|All Files (*.*)|*.*";
openFileDial.FilterIndex = 1;
// altre opzioni
@@ -2147,41 +2070,31 @@ namespace IOB_WIN_FORM
{
if (iobObj != null)
{
- // 1. Estrazione dati dalle code (operazione logica)
- long alQueueLen = iobObj.QHelp.QueueAlarm.Count;
- long evQueueLen = iobObj.QHelp.QueueIN.Count;
- long flQueueLen = iobObj.QHelp.QueueFLog.Count;
- long msQueueLen = iobObj.QHelp.QueueMessages.Count;
- long rtrQueueLen = iobObj.QHelp.QueueRawTransf.Count;
- long ulQueueLen = iobObj.QHelp.QueueULog.Count;
-
- var setPar = new Dictionary
- {
- { "IP", iobObj.IOBConfFull.Device.Connect.IpAddr },
- { "PORT", iobObj.IOBConfFull.Device.Connect.Port }
- };
-
IobWinStatus currIobStatus = new IobWinStatus()
{
CodIob = iobObj.IOBConfFull.General.FilenameIOB,
IobType = $"{iobObj.IOBConfFull.General.IobType}",
- queueAlLen = alQueueLen,
- queueEvLen = evQueueLen,
- queueFlLen = flQueueLen,
- queueMsLen = msQueueLen,
- queueRawTransfLen = rtrQueueLen,
- queueUlLen = ulQueueLen,
+ queueAlLen = iobObj.QHelp.QueueAlarm.Count,
+ queueEvLen = iobObj.QHelp.QueueIN.Count,
+ queueFlLen = iobObj.QHelp.QueueFLog.Count,
+ queueMsLen = iobObj.QHelp.QueueMessages.Count,
+ queueRawTransfLen = iobObj.QHelp.QueueRawTransf.Count,
+ queueUlLen = iobObj.QHelp.QueueULog.Count,
counterIOB = iobObj.contapezziIOB,
counterMAC = iobObj.contapezziPLC,
lastUpdate = lastIobStatus.lastUpdate > iobObj.DtHelp.lastWatchDog ? lastIobStatus.lastUpdate : iobObj.DtHelp.lastWatchDog,
online = utils.IOB_Online,
lastDataIn = iobObj.DtHelp.lastReadPLC,
lastDataOut = iobObj.DtHelp.lastIobOnline,
- setupParams = setPar,
+ setupParams = new Dictionary
+ {
+ { "IP", iobObj.IOBConfFull.Device.Connect.IpAddr },
+ { "PORT", iobObj.IOBConfFull.Device.Connect.Port }
+ },
freeNotes = $"{iobObj.IOBConfFull.General.FilenameIOB} | DT ultimo avvio: {iobObj.DtHelp.AvvioAdp}"
};
- // 2. Logica di salvataggio su REDIS (Rete -> Thread di background!)
+ // Logica di salvataggio su REDIS (Rete -> Thread di background!)
if (!currIobStatus.Equals(lastIobStatus))
{
currIobStatus.lastUpdate = DateTime.Now;
@@ -2332,6 +2245,18 @@ namespace IOB_WIN_FORM
}
}
+ ///
+ /// Salvo IOB e scope x NLog management
+ ///
+ ///
+ private void SetIOB(string newIOB)
+ {
+ CurrIOB = newIOB;
+ _scopeIOB?.Dispose(); // rimuove il vecchio valore
+
+ _scopeIOB = ScopeContext.PushProperty("codIOB", newIOB);
+ }
+
///
/// Indica se debba aggiornare o meno la UI perché minimizzata o meno
///
@@ -2446,15 +2371,25 @@ namespace IOB_WIN_FORM
lgInfo("UNLOAD Adapter");
}
- // Metodo per fermare tutto (es. nel Form_Closing o Dispose)
+ ///
+ /// Metodo per fermare tutto (es. nel Form_Closing o Dispose)
+ ///
+ ///
private async Task StopWorker()
{
if (_ctsServer == null) return;
+ _ctsMachine.Cancel();
+ _ctsRedis.Cancel();
_ctsServer.Cancel();
try
{
+ if (_redisTask != null)
+ {
+ await _redisTask;
+ }
+
// Opzionale: attendi che il task finisca davvero prima di fare il dispose
if (_workerTask != null)
{
@@ -2464,11 +2399,29 @@ namespace IOB_WIN_FORM
catch (OperationCanceledException) { /* Normale amministrazione */ }
finally
{
+ if (_ctsMachine != null)
+ {
+ _ctsMachine.Dispose();
+ _ctsMachine = null;
+ }
+ if (_ctsRedis != null)
+ {
+ _ctsRedis.Dispose();
+ _ctsRedis = null;
+ }
if (_ctsServer != null)
{
_ctsServer.Dispose();
_ctsServer = null;
}
+ if (_machineThread != null)
+ {
+ _machineThread = null;
+ }
+ if (_redisTask != null)
+ {
+ _redisTask = null;
+ }
if (_workerTask != null)
{
_workerTask = null;
diff --git a/IOB-WIN-FTP/DATA/CONF/MAIN.ini b/IOB-WIN-FTP/DATA/CONF/MAIN.ini
index 2cb4f81c..ebc0bef6 100644
--- a/IOB-WIN-FTP/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-FTP/DATA/CONF/MAIN.ini
@@ -20,4 +20,3 @@ CLI_INST=SteamWareSim
STARTLIST=FTP_SONATEST
MAXCNC=10
-
diff --git a/IOB-WIN-MTC/DATA/CONF/MAIN.ini b/IOB-WIN-MTC/DATA/CONF/MAIN.ini
index 39a789eb..084f3aef 100644
--- a/IOB-WIN-MTC/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-MTC/DATA/CONF/MAIN.ini
@@ -27,4 +27,3 @@ CLI_INST=SteamWareSim
STARTLIST=SIMUL_01
MAXCNC=10
-
diff --git a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini
index a9d47506..72bea7db 100644
--- a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini
@@ -34,4 +34,3 @@ STARTLIST=SIMUL_01
;STARTLIST=3026
MAXCNC=10
-
diff --git a/IOB-WIN-PING/DATA/CONF/MAIN.ini b/IOB-WIN-PING/DATA/CONF/MAIN.ini
index 14fc4c91..01bdf429 100644
--- a/IOB-WIN-PING/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-PING/DATA/CONF/MAIN.ini
@@ -20,4 +20,3 @@ STARTLIST=SIMUL_01
;STARTLIST=3023-PING
MAXCNC=10
-
diff --git a/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini b/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini
index babafa34..41774edf 100644
--- a/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini
@@ -42,4 +42,3 @@ CLI_INST=SteamWareSim
STARTLIST=3010
MAXCNC=10
-
diff --git a/IOB-WIN-WPS/DATA/CONF/MAIN.ini b/IOB-WIN-WPS/DATA/CONF/MAIN.ini
index 5b0016e5..a81dc4b2 100644
--- a/IOB-WIN-WPS/DATA/CONF/MAIN.ini
+++ b/IOB-WIN-WPS/DATA/CONF/MAIN.ini
@@ -24,4 +24,3 @@ STARTLIST=3018
;STARTLIST=SIMUL_06
MAXCNC=10
-