160 lines
5.0 KiB
C#
160 lines
5.0 KiB
C#
using IOB_UT_NEXT;
|
|
using MapoSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IOB_WIN_NEXT
|
|
{
|
|
public class IobPing : IobGeneric
|
|
{
|
|
#region Protected Fields
|
|
|
|
protected int PoweroffTimeoutSec = 100;
|
|
|
|
/// <summary>
|
|
/// Veto controllo status x log...
|
|
/// </summary>
|
|
protected DateTime vetoCheckStatus = DateTime.Now;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Estende l'init della classe base
|
|
/// <param name="caller"></param>
|
|
/// <param name="IOBConf"></param>
|
|
public IobPing(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
lgInfo("NEW IobPing (WatchDog)");
|
|
// init datetime counters
|
|
DateTime adesso = DateTime.Now;
|
|
lastPzCountSend = adesso;
|
|
lastWarnODL = adesso;
|
|
vetoCheckStatus = adesso;
|
|
var POWEROFF_TIMEOUT_SEC = getOptPar("POWEROFF_TIMEOUT_SEC");
|
|
if (!string.IsNullOrEmpty(POWEROFF_TIMEOUT_SEC))
|
|
{
|
|
int.TryParse(POWEROFF_TIMEOUT_SEC, out PoweroffTimeoutSec);
|
|
}
|
|
lgInfo($"L'adapter effettuera' PING di controllo all'indirizzo {IOBConf.cncIpAddr} per forzare stato poweroff dopo {PoweroffTimeoutSec} sec");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// metodo controllo ping lento, override AutoODL
|
|
/// </summary>
|
|
public override void processDisconnectedTask()
|
|
{
|
|
// effettuo check ping!
|
|
DateTime adesso = DateTime.Now;
|
|
if (adesso.Subtract(lastPING).TotalSeconds >= PoweroffTimeoutSec)
|
|
{
|
|
// invio poweroff!
|
|
newDisplayData currDispData = new newDisplayData();
|
|
readSemafori(ref currDispData);
|
|
// SOLO SE ho poweroff da inviare...
|
|
if (B_output == 0)
|
|
{
|
|
accodaSigIN(ref currDispData);
|
|
// reset last ping...
|
|
lastPING = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua lettura semafori principale
|
|
/// <paramref name="currDispData">Parametri da aggiornare x display in form</paramref>
|
|
/// </summary>
|
|
public override void readSemafori(ref newDisplayData currDispData)
|
|
{
|
|
byte[] MemBlock = new byte[2];
|
|
try
|
|
{
|
|
currDispData.semIn = Semaforo.SV;
|
|
|
|
// se passa il ping faccio il resto...
|
|
if (testPingMachine == IPStatus.Success)
|
|
{
|
|
// in primis salvo data ping...
|
|
lastPING = DateTime.Now;
|
|
connectionOk = true;
|
|
}
|
|
else
|
|
{
|
|
connectionOk = false;
|
|
}
|
|
|
|
if (connectionOk)
|
|
{
|
|
B_input = 1;
|
|
}
|
|
else
|
|
{
|
|
B_input = 0;
|
|
}
|
|
// annullo lettura bit signal IN pre/post x evitare invio automatico...
|
|
B_output = B_input;
|
|
B_previous = B_input;
|
|
}
|
|
catch
|
|
{
|
|
currDispData.semIn = Semaforo.SR;
|
|
}
|
|
}
|
|
|
|
/// Override connessione
|
|
/// </summary>
|
|
public override void tryConnect()
|
|
{
|
|
bool doLog = (verboseLog || periodicLog);
|
|
lgInfo("PING: tryConnect step 01");
|
|
if (!connectionOk)
|
|
{
|
|
// controllo che il ping sia stato tentato almeno pingTestSec fa...
|
|
if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
|
|
{
|
|
if (doLog)
|
|
{
|
|
lgInfo("PING: ConnKO - tryConnect");
|
|
}
|
|
lgInfo("PING: tryConnect step 04");
|
|
|
|
// se passa il ping faccio il resto...
|
|
if (testPingMachine == IPStatus.Success)
|
|
{
|
|
// in primis salvo data ping...
|
|
lastPING = DateTime.Now;
|
|
connectionOk = true;
|
|
lgInfo("PING OK");
|
|
}
|
|
else
|
|
{
|
|
// loggo no risposta ping ...
|
|
connectionOk = false;
|
|
lgInfo("PING KO");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override disconnessione
|
|
/// </summary>
|
|
public override void tryDisconnect()
|
|
{
|
|
lgInfo("Richiesta disconnessione adapter PING!");
|
|
connectionOk = false;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |