Merge branch 'release/UpdateCallMTC_02'

This commit is contained in:
Samuele Locatelli
2026-05-09 09:38:53 +02:00
2 changed files with 115 additions and 29 deletions
+8 -1
View File
@@ -149,7 +149,7 @@ namespace IOB_WIN_FORM.Iob
/// <summary>
/// DataOra x veto all'invio dataItem
/// </summary>
protected DateTime dtVetoSenDataItem= DateTime.Now;
protected DateTime dtVetoSenDataItem = DateTime.Now;
/// <summary>
/// Boolean x indicare contapezzi abilitato a livello di conf applicazione
@@ -698,6 +698,13 @@ namespace IOB_WIN_FORM.Iob
/// </summary>
protected Dictionary<string, string> RecipeReplRules { get; set; } = new Dictionary<string, string>();
/// <summary>
/// Chiave ultima condition registrata redis (da aggiungere eventuale ID specifico condition)
/// </summary>
protected string redKeyLastCondition
{
get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:Condition");
}
protected string redKeyLogfileAct
{
get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:LogFile:Act");
+107 -28
View File
@@ -1104,8 +1104,18 @@ namespace IOB_WIN_MTC.Iob
{
if (enableCliRestart)
{
lgInfo($"Timeout per mancata comunicazione da oltre {MaxSecReload} sec --> disconnessione adapter MTConnect!");
tryDisconnect();
if (checkAdapterAlive())
{
lgInfo($"Mancanza innovazioni da oltre {MaxSecReload} sec | Alive Test Success | NON riavviamo, impostato lastCurrent");
lastCurrent = adesso;
}
else
{
lgInfo($"Timeout per mancata comunicazione da oltre {MaxSecReload} sec | Alive Test Failed | --> disconnessione adapter MTConnect!");
tryDisconnect();
}
}
else
{
@@ -1241,6 +1251,43 @@ namespace IOB_WIN_MTC.Iob
}
}
/// <summary>
/// Verifica stato Alive per adapter:
/// - test ping
/// - test probe
/// </summary>
/// <returns></returns>
private bool checkAdapterAlive()
{
bool isPingOk = testPingMachine == IPStatus.Success;
// test probe!
bool probeOk = TestProbe(mtcUrlCall, true);
return isPingOk && probeOk;
}
/// <summary>
/// URL completo x chiamate MTC
/// </summary>
private string mtcUrlCall
{
get
{
return $"{IOBConfFull.Device.Connect.IpAddr}:{mtcPort}";
}
}
private short mtcPort
{
get
{
short port = 5000;
short.TryParse(IOBConfFull.Device.Connect.Port, out port);
return port;
}
}
/// <summary>
/// Vera connessione ad MTC
/// </summary>
@@ -1252,27 +1299,13 @@ namespace IOB_WIN_MTC.Iob
// reset memoria dataItem..
dataItemMem = new Dictionary<string, MtcDataItemExt>();
// predisposizione conf oggetto di comunicazione MTC
short port = 5000;
short.TryParse(IOBConfFull.Device.Connect.Port, out port);
string callUrl = $"{IOBConfFull.Device.Connect.IpAddr}:{port}";
string callUrl = mtcUrlCall;
// test probe!
try
{
lgInfo($"Test Probe MTC Client: {callUrl}");
var prbClient = new MTConnectHttpProbeClient(callUrl);
//var prbClient = new MTConnectHttpProbeClient(cIobConf.cncIpAddr, port);
prbClient.Timeout = mtcParams.reqTOutMs;
var prbDoc = prbClient.Get();
// se valido loggo!
if (prbDoc != null)
{
// anche se non del tutto vero...
connectionOk = true;
lgInfo($"Effettuata correttamente PROBE per device MTC all'URL {callUrl}");
lgInfo($"---------------- Elenco Devices ----------------");
// loggo devices principali...
logProbeDevices(prbDoc.Devices.ToList());
}
// anche se non del tutto vero...
connectionOk = TestProbe(callUrl, true);
}
catch (Exception exc)
{
@@ -1284,7 +1317,7 @@ namespace IOB_WIN_MTC.Iob
try
{
lgInfo($"Chiamata apertura MTC Client: {callUrl}");
MTC_ref = new MTConnectHttpClient(IOBConfFull.Device.Connect.IpAddr, port);
MTC_ref = new MTConnectHttpClient(IOBConfFull.Device.Connect.IpAddr, mtcPort);
//MTC_ref = new MTConnectHttpClient(callUrl);
// sample interval
MTC_ref.Interval = mtcParams.clientSampleIntMs;
@@ -1327,6 +1360,40 @@ namespace IOB_WIN_MTC.Iob
isConnecting = false;
}
/// <summary>
/// Test di chiamata metodo PROBE con log info
/// </summary>
/// <param name="callUrl"></param>
private bool TestProbe(string callUrl, bool doLogDevices)
{
bool testOk = false;
lgInfo($"Test Probe MTC Client: {callUrl}");
try
{
var prbClient = new MTConnectHttpProbeClient(callUrl);
//var prbClient = new MTConnectHttpProbeClient(cIobConf.cncIpAddr, port);
prbClient.Timeout = mtcParams.reqTOutMs;
var prbDoc = prbClient.Get();
// se valido loggo!
if (prbDoc != null)
{
testOk = true;
lgInfo($"Effettuata correttamente PROBE per device MTC all'URL {callUrl}");
if (doLogDevices)
{
lgInfo($"---------------- Elenco Devices ----------------");
// loggo devices principali...
logProbeDevices(prbDoc.Devices.ToList());
}
}
}
catch (Exception exc)
{
lgError($"Eccezione durante TestProbe:{Environment.NewLine}{exc}");
}
return testOk;
}
/// <summary>
/// Formatta un dataitem da uno stream SAMPLE
/// </summary>
@@ -1814,17 +1881,29 @@ namespace IOB_WIN_MTC.Iob
// verifico veto...
if (!doVeto)
{
// verifico se salvare
bool changed = checkSaveCondition(observ, fullMsg);
if (changed || forceSend)
// verifico se sia variato valore e dataora da ultimo salvataggio redis...
string redKey = $"{redKeyLastCondition}:{observ.DataItemId}";
string redisLastCond = redisMan.getRSV(redKey);
string currCond = $"{observ.Timestamp}|{fullMsg}";
if (currCond.Equals(redisLastCond))
{
// accodare ed invia nella coda ALARMS (che POI salva in document
// MongoDB anche ultimi x minuti di FluxLog...)
accodaAlarmLog(sVal, qEncodeFLog(time2, descr, fullMsg));
lgInfo($"Verifca condition | nessuna variazione da ultima registata | {redisLastCond}");
}
else
{
lgTrace(sVal);
redisMan.setRSV(redKey, currCond);
// verifico se salvare
bool changed = checkSaveCondition(observ, fullMsg);
if (changed || forceSend)
{
// accodare ed invia nella coda ALARMS (che POI salva in document
// MongoDB anche ultimi x minuti di FluxLog...)
accodaAlarmLog(sVal, qEncodeFLog(time2, descr, fullMsg));
}
else
{
lgTrace(sVal);
}
}
}
else