233 lines
8.2 KiB
C#
233 lines
8.2 KiB
C#
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 IobOpcUaEwon : IobOpcUa
|
|
{
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Modalità cambio ODL
|
|
/// </summary>
|
|
protected string CHANGE_ODL_MODE = "";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Estende l'init della classe base, impiegando il pacchetto Nuget OPC-UA foundation con la gestione specifica per EWON (es Monti, Tenditalia)
|
|
/// https://github.com/OPCFoundation/UA-.NETStandard
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="IOBConf"></param>
|
|
public IobOpcUaEwon(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
// inizializzo calsse base...
|
|
if (!string.IsNullOrEmpty(getOptPar("CHANGE_ODL_MODE")))
|
|
{
|
|
CHANGE_ODL_MODE = getOptPar("CHANGE_ODL_MODE");
|
|
}
|
|
// impostazioni specifiche Ewon di Monti
|
|
forceResetInRun = true;
|
|
sendKeyRichiesta = true;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
|
|
/// </summary>
|
|
protected override void decodeToBaseBitmap()
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
// init a zero...
|
|
B_input = 0;
|
|
|
|
/* -----------------------------------------------------
|
|
* STATE MACHINE 60 STD / SIMULA
|
|
*------------------------------------------------------
|
|
* bitmap MAPO
|
|
* B0: POWER_ON
|
|
* B1: RUN
|
|
* B2: pzCount
|
|
* B3: allarme
|
|
* B4: manuale
|
|
* B5: SlowTC (NON gestito qui)
|
|
* B6: warm-up / cool-down
|
|
* B7: emergenza
|
|
---------------------------------------------------- */
|
|
|
|
// se valido il check ping lo eseguo... altrimenti lo do x buono
|
|
bool checkPing = !opcUaParams.pingAsPowerOn;
|
|
string currRun = "";
|
|
if (!checkPing)
|
|
{
|
|
checkPing = (testPingMachine == IPStatus.Success);
|
|
}
|
|
// bit 0 (poweron) imposto a 1 SE pingo + PowerOn=="ON"...
|
|
bool powerOnOk = checkPing && hasPowerOn;
|
|
// procedo SOLO SE mi da ping OK...
|
|
if (checkPing)
|
|
{
|
|
B_input = powerOnOk ? 1 : 0;
|
|
|
|
// variabili RUN...
|
|
currRun = getDataItemValue(opcUaParams.keyRunMode);
|
|
|
|
// salvo running come = working...
|
|
isRunning = isWorking;
|
|
|
|
// se ho emergenza premuta --> emergenza!
|
|
if (hasEStopArmed)
|
|
{
|
|
B_input += (1 << 7);
|
|
}
|
|
// se ho emergenza premuta --> emergenza!
|
|
if (isWarmUpCoolDown)
|
|
{
|
|
B_input += (1 << 6);
|
|
}
|
|
// se ho almeno 1 allarme E NON SONO IN AUTO --> ALARM!
|
|
if (hasError)
|
|
{
|
|
B_input += (1 << 3);
|
|
}
|
|
if (isWorking)
|
|
{
|
|
// RUN = LAVORA!
|
|
B_input += (1 << 1);
|
|
}
|
|
else if (powerOnOk && (!isReady || isManual))
|
|
{
|
|
// se NON ready --> manual
|
|
B_input += (1 << 4);
|
|
}
|
|
}
|
|
|
|
// controllo se sono poweroff e se non ho dati buoni da > 2 minuti --> disconnetto
|
|
if (adesso.Subtract(lastCurrent).TotalMinutes > 2)
|
|
{
|
|
tryDisconnect();
|
|
}
|
|
|
|
// solo se non ho veto check
|
|
int vFactor = 2;
|
|
if (vetoCheckStatus < adesso)
|
|
{
|
|
lgInfo($"Stato variabili checkPing: {testPingMachine}");
|
|
// imposto veto per vetoSeconds...
|
|
vetoCheckStatus = adesso.AddSeconds(vetoSeconds * vFactor);
|
|
}
|
|
|
|
// log opzionale!
|
|
if (verboseLog)
|
|
{
|
|
lgInfo($"Trasformazione checkPing: {checkPing} | hasPowerOn: {hasPowerOn} | B_input: {B_input} | currRun = {currRun}");
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Processo i task richiesti e li elimino dalla coda 1:1
|
|
/// </summary>
|
|
/// <param name="task2exe"></param>
|
|
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
|
|
{
|
|
// uso metodo base x ora
|
|
return base.executeTasks(task2exe);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua vero processing contapezzi
|
|
/// </summary>
|
|
public override void processContapezzi()
|
|
{
|
|
if (utils.CRB("enableContapezzi"))
|
|
{
|
|
// check condizione validazione
|
|
if (checkMultiCondition(opcUaParams.condCountEnabled.checkList, opcUaParams.condCountEnabled.checkMode) || opcUaParams.condCountEnabled.checkList.Count == 0)
|
|
{
|
|
// cerco parametro contapezzi...
|
|
string currPzCount = getDataItemValue(opcUaParams.keyPartCount);
|
|
|
|
// se ho un contapezzi... processo...
|
|
if (!string.IsNullOrEmpty(currPzCount))
|
|
{
|
|
int newVal = -1;
|
|
bool fatto = Int32.TryParse(currPzCount, out newVal);
|
|
|
|
if (fatto)
|
|
{
|
|
// gestione decremento contapezzi: viene "messo via" solo SE c'è un effettivo decremento contapezzi...
|
|
if (newVal < contapezziPLC)
|
|
{
|
|
pzCountResetted = true;
|
|
// incremento contatore richiesta
|
|
countKeyRichiesta = countKeyRichiesta + 1;
|
|
// log
|
|
lgInfo("Contapezzi resettato (PLC) --> pzCountResetted = true");
|
|
}
|
|
|
|
// salvo nuovo valore contapezziPLC
|
|
contapezziPLC = newVal > -1 ? newVal : contapezziPLC;
|
|
}
|
|
else
|
|
{
|
|
lgError($"Errore in decodifica valore contapezzi, valore rilevato: {currPzCount}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError("Errore in decodifica valore contapezzi, valore vuoto!");
|
|
}
|
|
}
|
|
|
|
if (CHANGE_ODL_MODE == "PZCOUNT_RESET")
|
|
{
|
|
// controllo comunque, se è ZERO il contapezzi, e sul server è maggiore il valore x ODL e NON abilitato il trigger reset --> abilito trigger...
|
|
if (!pzCountResetted && contapezziPLC == 0 && contapezziIOB > 0)
|
|
{
|
|
pzCountResetted = true;
|
|
// incremento contatore richiesta
|
|
countKeyRichiesta = countKeyRichiesta + 1;
|
|
// log
|
|
lgInfo("Contapezzi resettato (PLC==0 e IOB>PLC) --> pzCountResetted = true");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua reset del contapezzi, NON POSSIBILE in questa versione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool resetcontapezziPLC()
|
|
{
|
|
bool answ = false;
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua IMPOSTAZIONE FORZATA del contapezzi, NON POSSIBILE in questa versione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool setcontapezziPLC(int newPzCount)
|
|
{
|
|
bool answ = false;
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |