//subroutine used when conditions change to pull date from the condition's internal state data into the //HMI Namespace for either CondCur or Last private void setCondition(condition _condition, IDCTagNS_HMI _nsHMI, state _state) { //set starting time of when condition entered conditionStartDate = System.DateTime.Now; //STATE INFO _nsHMI.StateTime.valueLong = 0; _nsHMI.StateCode.valueLong = (LONG)_state.statecode; _nsHMI.StateName.valueString = _state.statename; _nsHMI.StateTextColor.valueLong = BitConverter.ToInt16(_state.textcoloractive, 0); _nsHMI.StateFillColor.valueLong = BitConverter.ToInt16(_state.fillcoloractive, 0); //LOCAL REASON CODE switch (_condition.localreasontype.ToString()) { case "CONST": _nsHMI.LocReasonCode.valueLong = _condition._cstate.locreasoncode; _nsHMI.LocReasonName.valueString = _condition._cstate.locreasonname; break; case "LIST": _nsHMI.LocReasonCode.valueLong = _condition._cstate.locreasoncode; _nsHMI.LocReasonName.valueString = _condition._cstate.locreasonname; break; case "REF": opcitem _item; if (_condition.rootreasontype.ToString() == "CRITICAL") { asset _remoteAsset = IDCService.IDCConfig.model.assets.Find(x => x.name == _condition.rootassetref); _item = _remoteAsset.items.Find(x => x.name == _condition.localreasonitemref); } else if (_condition.localreasonitemrefasset != null) { asset _remoteAsset = IDCService.IDCConfig.model.assets.Find(x => x.name == _condition.localreasonitemrefasset); _item = _remoteAsset.items.Find(x => x.name == _condition.localreasonitemref || x.alias == _condition.localreasonitemref); } else { _item = _items.Find(x => x.name == _condition.localreasonitemref || x.alias == _condition.localreasonitemref); } _nsHMI.LocReasonCode.valueLong = ((LONG)_item.value + (LONG)_condition.localreasonoffset); _nsHMI.LocReasonName.valueString = _condition.name; // MB 07-12-2016 - Need to Enhance so Reference Value is captured when logic goes true not when condition becomes active break; } //find associated asset reason list and find reason corresponding to faultcode if (_astate.reasons != null) { reason _reason = _astate.reasons.reason.Find(x => x.opccode == _nsHMI.LocReasonCode.valueLong); if (_reason != null) { _nsHMI.LocReasonListText.valueString = assembleReasonListString(_reason); } else { _nsHMI.LocReasonListText.valueString = ""; } } else { _nsHMI.LocReasonListText.valueString = ""; } //ROOT REASON CODE switch (_condition.rootreasontype.ToString()) { //CLEAR is handled by a timer within the condition evaluation scripting case "LOCAL": //if rootreasoncode exists, use it, otherwise use default if (_condition.rootreasoncode != 0) { //find associated asset reason list and find reason corresponding to faultcode if (_astate.reasons != null) { reason _reason = _astate.reasons.reason.Find(x => x.opccode == (LONG)_condition.rootreasoncode); if (_reason != null) { _nsHMI.RootReasonListText.valueString = assembleReasonListString(_reason); } else { _nsHMI.RootReasonListText.valueString = ""; } } else { _nsHMI.LocReasonListText.valueString = ""; } _nsHMI.RootReasonCode.valueLong = (LONG)_condition.rootreasoncode; _nsHMI.RootReasonName.valueString = _condition._cstate.locreasonname; } else { _nsHMI.RootReasonCode.valueLong = _nsHMI.LocReasonCode.valueLong; _nsHMI.RootReasonName.valueString = _nsHMI.LocReasonName.valueString; _nsHMI.RootReasonListText.valueString = _nsHMI.LocReasonListText.valueString; } break; case "REMOTE": //find asset referenced by condition to pull in active condition info asset _asset = IDCService.IDCConfig.model.assets.Find(x => x.name == _condition.rootassetref); //if remote root reason code == 0 then use local reason information for root reason unless rootcode is set if ((_asset.CondCur.RootReasonCode.valueLong != 0) & (_asset._astate.stateActive.statekey.ToString() != "RUN")) { _nsHMI.RootReasonCode.valueLong = _asset.CondCur.RootReasonCode.valueLong; _nsHMI.RootReasonName.valueString = _asset.CondCur.RootReasonName.valueString; _nsHMI.RootReasonListText.valueString = _asset.CondCur.RootReasonListText.valueString; } else { if (_condition.rootreasoncode != 0) { //find associated asset reason list and find reason corresponding to faultcode if (_astate.reasons != null) { reason _reason = _astate.reasons.reason.Find(x => x.opccode == (LONG)_condition.rootreasoncode); if (_reason != null) { _nsHMI.RootReasonListText.valueString = assembleReasonListString(_reason); } else { _nsHMI.RootReasonListText.valueString = ""; } } else { _nsHMI.LocReasonListText.valueString = ""; } _nsHMI.RootReasonCode.valueLong = (LONG)_condition.rootreasoncode; _nsHMI.RootReasonName.valueString = _condition._cstate.locreasonname; } else { _nsHMI.RootReasonCode.valueLong = _nsHMI.LocReasonCode.valueLong; _nsHMI.RootReasonName.valueString = _nsHMI.LocReasonName.valueString; _nsHMI.RootReasonListText.valueString = _nsHMI.LocReasonListText.valueString; } } break; } }
//called when timer complete for rootreasontype == "CLEAR" during condition evaluation public void clearRootCondition(IDCTagNS_HMI _nsHMI) { _nsHMI.RootReasonCode.valueLong = 0; _nsHMI.RootReasonName.valueString = ""; _nsHMI.RootReasonListText.valueString = ""; }
private void copyHMINamespace(IDCTagNS_HMI _in, IDCTagNS_HMI _out) { _out.StateTime.valueLong = _in.StateTime.valueLong; _out.StateTextColor.valueLong = _in.StateTextColor.valueLong; _out.StateName.valueString = _in.StateName.valueString; _out.StateFillColor.valueLong = _in.StateFillColor.valueLong; _out.StateCode.valueLong = _in.StateCode.valueLong; _out.RootReasonName.valueString = _in.RootReasonName.valueString; _out.RootReasonListText.valueString = _in.RootReasonListText.valueString; _out.RootReasonCode.valueLong = _in.RootReasonCode.valueLong; _out.LocReasonName.valueString = _in.LocReasonName.valueString; _out.LocReasonListText.valueString = _in.LocReasonListText.valueString; _out.LocReasonCode.valueLong = _in.LocReasonCode.valueLong; }