diff --git a/IOB-WIN-NEXT/IobOpcUa.cs b/IOB-WIN-NEXT/IobOpcUa.cs index 45bddd7e..e763d266 100644 --- a/IOB-WIN-NEXT/IobOpcUa.cs +++ b/IOB-WIN-NEXT/IobOpcUa.cs @@ -17,6 +17,56 @@ namespace IOB_WIN_NEXT { public class IobOpcUa : IobGeneric { + #region Protected Fields + + /// + /// Struttura dove vengono memorizzati i dataitem ed i rispettivi valori x processing + /// + protected Dictionary dataItemMem = new Dictionary(); + + /// + /// Abilitazione restart (da opt par...) + /// + protected bool enableCliRestart = false; + + /// + /// Gestione filtraggio dati + /// + protected bool enableDataFilter = false; + + /// + /// Determina se ha effettuata lettura items in memoria x confronto... + /// + protected bool hasReadItems = false; + + /// + /// Ultimo current received x gestione update periodico... + /// + protected DateTime lastCurrent = DateTime.Now; + + /// + /// Oggetto MAIN x connessione OPC-UA + /// + protected UAClient UA_ref; + + /// + /// Veto controllo status x log... + /// + protected DateTime vetoCheckStatus = DateTime.Now; + + protected int WatchDog = 0; + + #endregion Protected Fields + + #region Private Fields + + /// + /// Elenco degli items da monitorare come risultato del browse iniziale + /// + private Dictionary selectedItemList = new Dictionary(); + + #endregion Private Fields + #region Public Constructors /// @@ -66,6 +116,176 @@ namespace IOB_WIN_NEXT #endregion Public Constructors + #region Protected Properties + + /// + /// Area dati raw per lettura encoded (SE presente) + /// + protected byte[] byteRawData { get; set; } = new byte[1]; + + /// + /// ProgName corrente + /// + protected string currProgName + { + get + { + string answ = ""; + if (!string.IsNullOrEmpty(opcUaParams.keyProgName)) + { + answ = getDataItemValue(opcUaParams.keyProgName); + } + return answ; + } + } + + /// + /// Indica se si debba leggere un area di tipo "encoded" (byte raw --> obj) + /// + protected bool doByteRead { get; set; } = false; + + /// + /// Verifico se abbia ALMENO un errore... + /// + protected bool hasError + { + get + { + return checkMultiCondition(opcUaParams.condError); + } + } + + /// + /// Indica se abbia emergenza ARMATA (cond normale) + /// + protected bool hasEStopArmed + { + get + { + return checkMultiCondition(opcUaParams.condEStop); + } + } + + /// + /// Indica se abbia stato POWER ON (multicondizione) + /// + protected virtual bool hasPowerOn + { + get + { + return checkMultiCondition(opcUaParams.condPowerOn); + } + } + + /// + /// Indica se abbia stato MANUAL (condizioni varie, es stopped) + /// + protected virtual bool isManual + { + get + { + return checkMultiCondition(opcUaParams.condManual); + } + } + + /// + /// Indica se abbia stato READY (condizioni varie, es ausiliari OK) + /// + protected virtual bool isReady + { + get + { + return checkMultiCondition(opcUaParams.condReady); + } + } + + /// + /// Indica se sia in stato Ssetup + /// + protected bool isSetup + { + get + { + return checkMultiCondition(opcUaParams.condSetup); + } + } + + /// + /// Indica se sia in stato WarmUp / CoolDown (riscaldamento/raffreddamento) + /// + protected bool isWarmUpCoolDown + { + get + { + return checkMultiCondition(opcUaParams.condWarmUpCoolDown); + } + } + + /// + /// Indica se sia in stato Warning + /// + protected bool isWarning + { + get + { + return checkMultiCondition(opcUaParams.condWarning); + } + } + + /// + /// Indica se abbia stato READY (condizioni varie, es ausiliari OK) + /// + 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); + } + } + + /// + /// Periodo massimo (in sec) per letture dati RAW in mancanza di eventi + /// + protected int lastCurrentMaxElapsed { get; set; } = 120; + + /// + /// Parametri specifici MTC + /// + protected OpcUaParamConf opcUaParams { get; set; } + + /// + /// URL x salvataggio elenco dataItems OpcUa + /// + 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 /// @@ -190,25 +410,6 @@ namespace IOB_WIN_NEXT return outVal; } - - /// - /// Recupero allarmi specifico x OPC-UA - /// - /// - /// - 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; - } - /// /// Effettua vero processing contapezzi /// @@ -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 - - /// - /// Struttura dove vengono memorizzati i dataitem ed i rispettivi valori x processing - /// - protected Dictionary dataItemMem = new Dictionary(); - - /// - /// Abilitazione restart (da opt par...) - /// - protected bool enableCliRestart = false; - - /// - /// Gestione filtraggio dati - /// - protected bool enableDataFilter = false; - - /// - /// Determina se ha effettuata lettura items in memoria x confronto... - /// - protected bool hasReadItems = false; - - /// - /// Ultimo current received x gestione update periodico... - /// - protected DateTime lastCurrent = DateTime.Now; - - /// - /// Oggetto MAIN x connessione OPC-UA - /// - protected UAClient UA_ref; - - /// - /// Veto controllo status x log... - /// - protected DateTime vetoCheckStatus = DateTime.Now; - - protected int WatchDog = 0; - - #endregion Protected Fields - - #region Protected Properties - - /// - /// Area dati raw per lettura encoded (SE presente) - /// - protected byte[] byteRawData { get; set; } = new byte[1]; - - /// - /// Indica se si debba leggere un area di tipo "encoded" (byte raw --> obj) - /// - protected bool doByteRead { get; set; } = false; - - /// - /// Verifico se abbia ALMENO un errore... - /// - protected bool hasError - { - get - { - return checkMultiCondition(opcUaParams.condError); - } - } - - /// - /// Indica se abbia emergenza ARMATA (cond normale) - /// - protected bool hasEStopArmed - { - get - { - return checkMultiCondition(opcUaParams.condEStop); - } - } - - /// - /// Indica se abbia stato POWER ON (multicondizione) - /// - protected virtual bool hasPowerOn - { - get - { - return checkMultiCondition(opcUaParams.condPowerOn); - } - } - - /// - /// Indica se abbia stato MANUAL (condizioni varie, es stopped) - /// - protected virtual bool isManual - { - get - { - return checkMultiCondition(opcUaParams.condManual); - } - } - - /// - /// Indica se abbia stato READY (condizioni varie, es ausiliari OK) - /// - protected virtual bool isReady - { - get - { - return checkMultiCondition(opcUaParams.condReady); - } - } - - /// - /// Indica se sia in stato Ssetup - /// - protected bool isSetup - { - get - { - return checkMultiCondition(opcUaParams.condSetup); - } - } - - /// - /// Indica se sia in stato WarmUp / CoolDown (riscaldamento/raffreddamento) - /// - protected bool isWarmUpCoolDown - { - get - { - return checkMultiCondition(opcUaParams.condWarmUpCoolDown); - } - } - - /// - /// Indica se sia in stato Warning - /// - protected bool isWarning - { - get - { - return checkMultiCondition(opcUaParams.condWarning); - } - } - - /// - /// Indica se abbia stato READY (condizioni varie, es ausiliari OK) - /// - 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); - } - } - - /// - /// ProgName corrente - /// - protected string currProgName - { - get - { - string answ = ""; - if (!string.IsNullOrEmpty(opcUaParams.keyProgName)) - { - answ = getDataItemValue(opcUaParams.keyProgName); - } - return answ; - } - } - - /// - /// Periodo massimo (in sec) per letture dati RAW in mancanza di eventi - /// - protected int lastCurrentMaxElapsed { get; set; } = 120; - - /// - /// Parametri specifici MTC - /// - protected OpcUaParamConf opcUaParams { get; set; } - - /// - /// URL x salvataggio elenco dataItems OpcUa - /// - 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 /// @@ -1134,6 +1078,24 @@ namespace IOB_WIN_NEXT } } + /// + /// Recupero allarmi specifico x OPC-UA + /// + /// + /// + 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 - - /// - /// Elenco degli items da monitorare come risultato del browse iniziale - /// - private Dictionary selectedItemList = new Dictionary(); - - #endregion Private Fields - #region Private Methods /// @@ -1287,17 +1286,19 @@ namespace IOB_WIN_NEXT Dictionary nodeIdNameList = new Dictionary(); 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... diff --git a/IOB-WIN-NEXT/IobOpcUaOmronIcoel.cs b/IOB-WIN-NEXT/IobOpcUaOmronIcoel.cs index 2dec916e..4bc4547f 100644 --- a/IOB-WIN-NEXT/IobOpcUaOmronIcoel.cs +++ b/IOB-WIN-NEXT/IobOpcUaOmronIcoel.cs @@ -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...