Merge branch 'release/FixPingCosmap'

This commit is contained in:
Samuele Locatelli
2021-09-10 17:19:07 +02:00
3 changed files with 56 additions and 18 deletions
+2
View File
@@ -52,6 +52,8 @@ DISABLE_PZCOUNT=FALSE
ENABLE_SEND_PZC_BLOCK=TRUE
MIN_SEND_PZC_BLOCK=0
MAX_SEND_PZC_BLOCK=100
; gestione custom timer
timerIntMs=30
; GEST DATI DYN
ENABLE_DYN_DATA=TRUE
FORCE_DYN_DATA=TRUE
+6 -1
View File
@@ -1860,6 +1860,10 @@ namespace IOB_WIN_NEXT
// scrivo valore!
lgInfo("Chiamate processMem2Write --> plcWriteParams");
plcWriteParams(updatedPar);
// invio su cloud parametri!
string rawData = JsonConvert.SerializeObject(updatedPar);
utils.callUrl($"{urlUpdateWriteParams}", rawData);
lgInfo("Notifica a server scrittura parametri");
}
}
@@ -2709,6 +2713,7 @@ namespace IOB_WIN_NEXT
plcWriteParams(updatedPar);
// invio su cloud parametri!
string rawData = JsonConvert.SerializeObject(updatedPar);
lgInfo("Notifica a server scrittura parametri");
utils.callUrl($"{urlUpdateWriteParams}", rawData);
}
}
@@ -3550,7 +3555,7 @@ namespace IOB_WIN_NEXT
DateTime dtVeto = lastConnectTry.AddMilliseconds(waitRecMSec);
if (DateTime.Now > dtVeto)
{
lgInfo($"Retry Time Elapsed (waited for {waitRecMSec} ms)--> NOW tryConnect");
lgInfo($"Veto Time Elapsed | lastConnectTry: {lastConnectTry} | waitRecMSec {waitRecMSec} ms) | NOW tryConnect");
lastConnectTry = DateTime.Now;
tryConnect();
}
+48 -17
View File
@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading;
namespace IOB_WIN_NEXT
{
@@ -28,6 +29,16 @@ namespace IOB_WIN_NEXT
/// </summary>
protected Plc currPLC;
/// <summary>
/// Ultimo controllo ping x evitare ping flood...
/// </summary>
protected DateTime lastPingConn = DateTime.Now.AddMinutes(-10);
/// <summary>
/// Esito ultimo ping
/// </summary>
protected bool lastPingOk = false;
/// <summary>
/// Lungh massima stringhe
/// </summary>
@@ -648,39 +659,59 @@ namespace IOB_WIN_NEXT
protected bool testCncConn()
{
bool answ = false;
IPStatus pingStatus = testPingMachine;
// se passa il ping faccio il resto...
if (pingStatus != IPStatus.Success)
// riduco i controlli ping.. li faccio solo ogni 5 ping period se precedente positivo...
DateTime adesso = DateTime.Now;
if (lastPingOk && adesso.Subtract(lastPingConn).TotalMilliseconds < 5 * parametri.pingMsTimeout)
{
lgError($"Errore in testCncConn: reply Status | IP: {parametri.ipAdrr} | {pingStatus} | T.Out: {parametri.pingMsTimeout}ms");
answ = lastPingOk;
}
else
{
if (!currPLC.IsConnected)
{
currPLC.Open();
}
IPStatus pingStatus = testPingMachine;
if (!currPLC.IsAvailable)
// se non ok riprovo 1 volta dopo attesa
if (pingStatus != IPStatus.Success)
{
lgError(string.Format("PLC Siemens NON disponibile:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString));
currPLC.ClearLastError();
Thread.Sleep(2 * cIobConf.pingMsTimeout);
pingStatus = testPingMachine;
}
// se non passa ancora errore!
if (pingStatus != IPStatus.Success)
{
lgError($"Errore in testCncConn | reply Status {pingStatus} | IP: {parametri.ipAdrr} | T.Out: {parametri.pingMsTimeout}ms");
}
// se passa il ping faccio il resto...
else
{
if (!currPLC.IsConnected && !pingDisabled)
if (!currPLC.IsConnected)
{
lgError(string.Format("PLC Siemens NON connesso:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString));
currPLC.Open();
}
if (!currPLC.IsAvailable)
{
lgError($"PLC Siemens NON disponibile:{currPLC.LastErrorCode} | {currPLC.LastErrorString}");
currPLC.ClearLastError();
parentForm.updateComStats("NO connection");
}
else
{
parentForm.updateComStats("Connection OK");
answ = true;
if (!currPLC.IsConnected)
{
lgError($"PLC Siemens NON connesso:{currPLC.LastErrorCode} | {currPLC.LastErrorString}");
currPLC.ClearLastError();
parentForm.updateComStats("NO connection");
}
else
{
// tutto ok
parentForm.updateComStats("Connection OK");
answ = true;
}
}
}
// salvo stato ping
lastPingOk = answ;
lastPingConn = adesso;
}
return answ;