update verbosità opc-ua x variazioni parametri

This commit is contained in:
Samuele E. Locatelli
2022-12-15 17:01:37 +01:00
parent cf19510bae
commit 2c40dfc38d
2 changed files with 290 additions and 289 deletions
+289 -288
View File
@@ -17,6 +17,56 @@ namespace IOB_WIN_NEXT
{
public class IobOpcUa : IobGeneric
{
#region Protected Fields
/// <summary>
/// Struttura dove vengono memorizzati i dataitem ed i rispettivi valori x processing
/// </summary>
protected Dictionary<string, OpcUaDataItemExt> dataItemMem = new Dictionary<string, OpcUaDataItemExt>();
/// <summary>
/// Abilitazione restart (da opt par...)
/// </summary>
protected bool enableCliRestart = false;
/// <summary>
/// Gestione filtraggio dati
/// </summary>
protected bool enableDataFilter = false;
/// <summary>
/// Determina se ha effettuata lettura items in memoria x confronto...
/// </summary>
protected bool hasReadItems = false;
/// <summary>
/// Ultimo current received x gestione update periodico...
/// </summary>
protected DateTime lastCurrent = DateTime.Now;
/// <summary>
/// Oggetto MAIN x connessione OPC-UA
/// </summary>
protected UAClient UA_ref;
/// <summary>
/// Veto controllo status x log...
/// </summary>
protected DateTime vetoCheckStatus = DateTime.Now;
protected int WatchDog = 0;
#endregion Protected Fields
#region Private Fields
/// <summary>
/// Elenco degli items da monitorare come risultato del browse iniziale
/// </summary>
private Dictionary<string, string> selectedItemList = new Dictionary<string, string>();
#endregion Private Fields
#region Public Constructors
/// <summary>
@@ -66,6 +116,176 @@ namespace IOB_WIN_NEXT
#endregion Public Constructors
#region Protected Properties
/// <summary>
/// Area dati raw per lettura encoded (SE presente)
/// </summary>
protected byte[] byteRawData { get; set; } = new byte[1];
/// <summary>
/// ProgName corrente
/// </summary>
protected string currProgName
{
get
{
string answ = "";
if (!string.IsNullOrEmpty(opcUaParams.keyProgName))
{
answ = getDataItemValue(opcUaParams.keyProgName);
}
return answ;
}
}
/// <summary>
/// Indica se si debba leggere un area di tipo "encoded" (byte raw --&gt; obj)
/// </summary>
protected bool doByteRead { get; set; } = false;
/// <summary>
/// Verifico se abbia ALMENO un errore...
/// </summary>
protected bool hasError
{
get
{
return checkMultiCondition(opcUaParams.condError);
}
}
/// <summary>
/// Indica se abbia emergenza ARMATA (cond normale)
/// </summary>
protected bool hasEStopArmed
{
get
{
return checkMultiCondition(opcUaParams.condEStop);
}
}
/// <summary>
/// Indica se abbia stato POWER ON (multicondizione)
/// </summary>
protected virtual bool hasPowerOn
{
get
{
return checkMultiCondition(opcUaParams.condPowerOn);
}
}
/// <summary>
/// Indica se abbia stato MANUAL (condizioni varie, es stopped)
/// </summary>
protected virtual bool isManual
{
get
{
return checkMultiCondition(opcUaParams.condManual);
}
}
/// <summary>
/// Indica se abbia stato READY (condizioni varie, es ausiliari OK)
/// </summary>
protected virtual bool isReady
{
get
{
return checkMultiCondition(opcUaParams.condReady);
}
}
/// <summary>
/// Indica se sia in stato Ssetup
/// </summary>
protected bool isSetup
{
get
{
return checkMultiCondition(opcUaParams.condSetup);
}
}
/// <summary>
/// Indica se sia in stato WarmUp / CoolDown (riscaldamento/raffreddamento)
/// </summary>
protected bool isWarmUpCoolDown
{
get
{
return checkMultiCondition(opcUaParams.condWarmUpCoolDown);
}
}
/// <summary>
/// Indica se sia in stato Warning
/// </summary>
protected bool isWarning
{
get
{
return checkMultiCondition(opcUaParams.condWarning);
}
}
/// <summary>
/// Indica se abbia stato READY (condizioni varie, es ausiliari OK)
/// </summary>
protected bool isWorking
{
get
{
// cerco SE HO cond OPC Ua o classica... nel caso creo e salvo
if (opcUaParams.condWorkOpc.checkList == null || opcUaParams.condWorkOpc.checkList.Count == 0)
{
opcUaParams.condWorkOpc = new diCheckCondSetup()
{
checkList = opcUaParams.condWork,
checkMode = boolCheckMode.AND,
negateValue = false
};
}
return checkMultiCondition(opcUaParams.condWorkOpc);
}
}
/// <summary>
/// Periodo massimo (in sec) per letture dati RAW in mancanza di eventi
/// </summary>
protected int lastCurrentMaxElapsed { get; set; } = 120;
/// <summary>
/// Parametri specifici MTC
/// </summary>
protected OpcUaParamConf opcUaParams { get; set; }
/// <summary>
/// URL x salvataggio elenco dataItems OpcUa
/// </summary>
protected string urlSaveDataItems
{
get
{
string answ = "";
try
{
string machineName = Environment.MachineName;
answ = $@"{cIobConf.serverData.TRANSP}://{cIobConf.serverData.MPIP}{cIobConf.serverData.MPURL}{cIobConf.serverData.CMDALIVE}/saveDataItems/{cIobConf.codIOB}";
}
catch (Exception exc)
{
lgError(exc, "Errore in composizione urlSaveDataItems");
}
return answ;
}
}
#endregion Protected Properties
#region Public Methods
/// <summary>
@@ -190,25 +410,6 @@ namespace IOB_WIN_NEXT
return outVal;
}
/// <summary>
/// Recupero allarmi specifico x OPC-UA
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
protected override int getAlarmStatus(BaseAlarmConf item)
{
int answ = 0;
// recupero valore in formato stringa...
string currStatus = getDataItemValue(item.memAddr);
// se non nullo --> recupero int
if (!string.IsNullOrEmpty(currStatus))
{
int.TryParse(currStatus, out answ);
}
return answ;
}
/// <summary>
/// Effettua vero processing contapezzi
/// </summary>
@@ -437,7 +638,7 @@ namespace IOB_WIN_NEXT
DateTime locTStamp = DateTime.Now;
descr = itemTranslation("OPC", MonIt.DisplayName);
sVal = $"Change 01: {locTStamp.ToString()} | descr: {descr} | Id: {MonIt.StartNodeId} | Val: {NotifyValue}";
lgInfo(sVal);
lgDebug(sVal);
// verifico se salvare
changed = checkSaveValue(MonIt, NotifyValue, true);
@@ -513,7 +714,7 @@ namespace IOB_WIN_NEXT
DateTime locTStamp = DateTime.Now;
descr = itemTranslation("OPC", MonIt.DisplayName);
sVal = $"Change 02: {locTStamp.ToString()} | descr: {descr} | Id: {MonIt.StartNodeId} | Val: {currVal}";
lgInfo(sVal);
lgDebug(sVal);
// verifico se salvare
changed = checkSaveValue(MonIt, currVal, true) || forceSend;
@@ -547,52 +748,6 @@ namespace IOB_WIN_NEXT
return changed;
}
protected virtual void procRunMode(ref string currRun)
{
// variabili RUN... se richiesto invio runMode
if (opcUaParams.runModeSend)
{
bool hasVetoLK = false;
bool hasVetoLKV = false;
if (!string.IsNullOrEmpty(opcUaParams.keyRunMode))
{
currRun = getDataItemValue(opcUaParams.keyRunMode);
if (!string.IsNullOrEmpty(currRun))
{
// se ho valore --> invio
string sVal = "";
string descr = $"RunModeVal";
DateTime locTStamp = DateTime.Now;
sVal = $"Change 03: {locTStamp.ToString()} | descr: {descr} | Id: {opcUaParams.keyRunMode} | Val: {currRun}";
// cerco se sia un dato/valore
hasVetoLK = opcUaParams.fluxLogKeyValVeto.ContainsKey(descr);
if (hasVetoLK)
{
// se c'è controllo il valore...
var valList = opcUaParams.fluxLogKeyValVeto[descr];
hasVetoLKV = valList.Contains(currRun);
}
if (hasVetoLKV)
{
lgTrace($"NON ACCODATO sample: veto trovato per {descr}/{currRun} in fluxLogKeyValVeto ", false);
}
else
{
accodaFLog(sVal, qEncodeFLog(descr, currRun));
// se richiesto provo a tradurre
if (opcUaParams.runModeTrad)
{
string RunModeDescr = itemTranslation("RunMode", currRun);
descr = $"RunMode";
accodaFLog(sVal, qEncodeFLog(descr, RunModeDescr));
}
}
}
}
}
}
internal void sendDataItemListToServer(NodeId StartNodeId)
{
// converto gli attuali nell'elenco dataitem...
@@ -645,217 +800,6 @@ namespace IOB_WIN_NEXT
#endregion Internal Methods
#region Protected Fields
/// <summary>
/// Struttura dove vengono memorizzati i dataitem ed i rispettivi valori x processing
/// </summary>
protected Dictionary<string, OpcUaDataItemExt> dataItemMem = new Dictionary<string, OpcUaDataItemExt>();
/// <summary>
/// Abilitazione restart (da opt par...)
/// </summary>
protected bool enableCliRestart = false;
/// <summary>
/// Gestione filtraggio dati
/// </summary>
protected bool enableDataFilter = false;
/// <summary>
/// Determina se ha effettuata lettura items in memoria x confronto...
/// </summary>
protected bool hasReadItems = false;
/// <summary>
/// Ultimo current received x gestione update periodico...
/// </summary>
protected DateTime lastCurrent = DateTime.Now;
/// <summary>
/// Oggetto MAIN x connessione OPC-UA
/// </summary>
protected UAClient UA_ref;
/// <summary>
/// Veto controllo status x log...
/// </summary>
protected DateTime vetoCheckStatus = DateTime.Now;
protected int WatchDog = 0;
#endregion Protected Fields
#region Protected Properties
/// <summary>
/// Area dati raw per lettura encoded (SE presente)
/// </summary>
protected byte[] byteRawData { get; set; } = new byte[1];
/// <summary>
/// Indica se si debba leggere un area di tipo "encoded" (byte raw --&gt; obj)
/// </summary>
protected bool doByteRead { get; set; } = false;
/// <summary>
/// Verifico se abbia ALMENO un errore...
/// </summary>
protected bool hasError
{
get
{
return checkMultiCondition(opcUaParams.condError);
}
}
/// <summary>
/// Indica se abbia emergenza ARMATA (cond normale)
/// </summary>
protected bool hasEStopArmed
{
get
{
return checkMultiCondition(opcUaParams.condEStop);
}
}
/// <summary>
/// Indica se abbia stato POWER ON (multicondizione)
/// </summary>
protected virtual bool hasPowerOn
{
get
{
return checkMultiCondition(opcUaParams.condPowerOn);
}
}
/// <summary>
/// Indica se abbia stato MANUAL (condizioni varie, es stopped)
/// </summary>
protected virtual bool isManual
{
get
{
return checkMultiCondition(opcUaParams.condManual);
}
}
/// <summary>
/// Indica se abbia stato READY (condizioni varie, es ausiliari OK)
/// </summary>
protected virtual bool isReady
{
get
{
return checkMultiCondition(opcUaParams.condReady);
}
}
/// <summary>
/// Indica se sia in stato Ssetup
/// </summary>
protected bool isSetup
{
get
{
return checkMultiCondition(opcUaParams.condSetup);
}
}
/// <summary>
/// Indica se sia in stato WarmUp / CoolDown (riscaldamento/raffreddamento)
/// </summary>
protected bool isWarmUpCoolDown
{
get
{
return checkMultiCondition(opcUaParams.condWarmUpCoolDown);
}
}
/// <summary>
/// Indica se sia in stato Warning
/// </summary>
protected bool isWarning
{
get
{
return checkMultiCondition(opcUaParams.condWarning);
}
}
/// <summary>
/// Indica se abbia stato READY (condizioni varie, es ausiliari OK)
/// </summary>
protected bool isWorking
{
get
{
// cerco SE HO cond OPC Ua o classica... nel caso creo e salvo
if (opcUaParams.condWorkOpc.checkList == null || opcUaParams.condWorkOpc.checkList.Count == 0)
{
opcUaParams.condWorkOpc = new diCheckCondSetup()
{
checkList = opcUaParams.condWork,
checkMode = boolCheckMode.AND,
negateValue = false
};
}
return checkMultiCondition(opcUaParams.condWorkOpc);
}
}
/// <summary>
/// ProgName corrente
/// </summary>
protected string currProgName
{
get
{
string answ = "";
if (!string.IsNullOrEmpty(opcUaParams.keyProgName))
{
answ = getDataItemValue(opcUaParams.keyProgName);
}
return answ;
}
}
/// <summary>
/// Periodo massimo (in sec) per letture dati RAW in mancanza di eventi
/// </summary>
protected int lastCurrentMaxElapsed { get; set; } = 120;
/// <summary>
/// Parametri specifici MTC
/// </summary>
protected OpcUaParamConf opcUaParams { get; set; }
/// <summary>
/// URL x salvataggio elenco dataItems OpcUa
/// </summary>
protected string urlSaveDataItems
{
get
{
string answ = "";
try
{
string machineName = Environment.MachineName;
answ = $@"{cIobConf.serverData.TRANSP}://{cIobConf.serverData.MPIP}{cIobConf.serverData.MPURL}{cIobConf.serverData.CMDALIVE}/saveDataItems/{cIobConf.codIOB}";
}
catch (Exception exc)
{
lgError(exc, "Errore in composizione urlSaveDataItems");
}
return answ;
}
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
@@ -1134,6 +1078,24 @@ namespace IOB_WIN_NEXT
}
}
/// <summary>
/// Recupero allarmi specifico x OPC-UA
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
protected override int getAlarmStatus(BaseAlarmConf item)
{
int answ = 0;
// recupero valore in formato stringa...
string currStatus = getDataItemValue(item.memAddr);
// se non nullo --> recupero int
if (!string.IsNullOrEmpty(currStatus))
{
int.TryParse(currStatus, out answ);
}
return answ;
}
protected byte[] getByteRaw(DataValue obj)
{
if (obj == null)
@@ -1228,17 +1190,54 @@ namespace IOB_WIN_NEXT
//reader.Dispose();
}
protected virtual void procRunMode(ref string currRun)
{
// variabili RUN... se richiesto invio runMode
if (opcUaParams.runModeSend)
{
bool hasVetoLK = false;
bool hasVetoLKV = false;
if (!string.IsNullOrEmpty(opcUaParams.keyRunMode))
{
currRun = getDataItemValue(opcUaParams.keyRunMode);
if (!string.IsNullOrEmpty(currRun))
{
// se ho valore --> invio
string sVal = "";
string descr = $"RunModeVal";
DateTime locTStamp = DateTime.Now;
sVal = $"Change 03: {locTStamp.ToString()} | descr: {descr} | Id: {opcUaParams.keyRunMode} | Val: {currRun}";
// cerco se sia un dato/valore
hasVetoLK = opcUaParams.fluxLogKeyValVeto.ContainsKey(descr);
if (hasVetoLK)
{
// se c'è controllo il valore...
var valList = opcUaParams.fluxLogKeyValVeto[descr];
hasVetoLKV = valList.Contains(currRun);
}
if (hasVetoLKV)
{
lgTrace($"NON ACCODATO sample: veto trovato per {descr}/{currRun} in fluxLogKeyValVeto ", false);
}
else
{
accodaFLog(sVal, qEncodeFLog(descr, currRun));
// se richiesto provo a tradurre
if (opcUaParams.runModeTrad)
{
string RunModeDescr = itemTranslation("RunMode", currRun);
descr = $"RunMode";
accodaFLog(sVal, qEncodeFLog(descr, RunModeDescr));
}
}
}
}
}
}
#endregion Protected Methods
#region Private Fields
/// <summary>
/// Elenco degli items da monitorare come risultato del browse iniziale
/// </summary>
private Dictionary<string, string> selectedItemList = new Dictionary<string, string>();
#endregion Private Fields
#region Private Methods
/// <summary>
@@ -1287,17 +1286,19 @@ namespace IOB_WIN_NEXT
Dictionary<string, string> nodeIdNameList = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(opcUaParams.BrowseFullVal))
{
lgInfo($"Start browse da BrowseFullVal: {opcUaParams.BrowseFullVal}");
try
{
UA_ref.Browse(opcUaParams.BrowseFullVal, opcUaParams.filterItemsNodeId, ref nodeIdNameList);
}
catch(Exception exc)
catch (Exception exc)
{
lgError($"Eccezione in browsing BrowseFullVal:{Environment.NewLine}{exc}");
}
}
else
{
lgInfo($"Start browse | BrowseNSIndex: {opcUaParams.BrowseNSIndex} | BrowseValue: {opcUaParams.BrowseValue} | filterItemsNodeId: {opcUaParams.filterItemsNodeId} | ");
UA_ref.Browse(opcUaParams.BrowseNSIndex, opcUaParams.BrowseValue, opcUaParams.filterItemsNodeId, ref nodeIdNameList);
}
// loggo elenco degli item sottocrivibili...
+1 -1
View File
@@ -507,7 +507,7 @@ namespace IOB_WIN_NEXT
string descr = "";
descr = itemTranslation("OPC", MonIt.DisplayName);
sVal = $"Change: {locTStamp.ToString()} | descr: {descr} | Id: {MonIt.StartNodeId} | Val: {NotifyValue}";
lgInfo($"TSP | {sVal}");
lgDebug($"TSP | {sVal}");
changed = checkSaveValue(MonIt, NotifyValue, false);
// cerco se non sia un dato filtrato in FLUXLOG...