Пример #1
0
        //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;
            }
        }
Пример #2
0
        //validate and initialize states
        public int validate(string _assetName, int index)
        {
            logger.Debug("Validating condition: " + _name);

            //set index within condition tree
            _cstate.index = index;

            //find if state exists in System.States
            _state = IDCService.ValidateIDCConfig.system.states.Find(x => x.statekey.Equals(_statekey));

            //if no match, then error
            if(_state == null)
            {
                logger.Error("Condition " + _name + ": reference does not exist");
                configOK = false;
                enabled = false;
                return -1;
            }

            //local reason item ref
            if(_localreasontype.ToString() == "REF")
            {
                //find if asset exists in System.Assets
                asset _asset;
                opcitem _item;

                if (localreasonitemrefasset != null)
                {
                    _asset = IDCService.ValidateIDCConfig.model.assets.Find(x => x.name == localreasonitemrefasset);
                    _item = _asset.items.Find(x => x.name == _localreasonitemref || x.alias == _localreasonitemref);
                }
                else
                {
                    _asset = IDCService.ValidateIDCConfig.model.assets.Find(x => x.name == _assetName);
                    _item = _asset.items.Find(x => x.name == _localreasonitemref || x.alias == _localreasonitemref);
                }

                //if no match, then error
                if (_item == null)
                {
                    logger.Error("Condition " + _name + ": invalid LocalReasonItemRef when LocalReasonType is REF");
                    configOK = false;
                    enabled = false;
                    return -1;
                }
            }

            //invalid root asset ref
            //if RootReason == "REMOTE"
            if ((_rootreasontype.ToString() =="REMOTE") || (_rootreasontype.ToString() == "CRITICAL"))
            {
                if(_rootassetref != null)
                {
                    //find if asset exists in System.Assets
                    asset _asset = IDCService.ValidateIDCConfig.model.assets.Find(x => x.name == _rootassetref);

                    //if no match, then error
                    if(_asset == null)
                    {
                        logger.Error("Condition " + _name + ": invalid RootAssetRef when RootReasonType is " + _rootreasontype.ToString());
                        configOK = false;
                        enabled = false;
                        return -1;
                    }
                }
                else
                {
                    logger.Error("Condition " + _name + ": invalid RootAssetRef when RootReasonType is " + _rootreasontype.ToString());
                    configOK = false;
                    enabled = false;
                    return -1;
                }
            }

            //validate logic for condition
            foreach(logic logic in _logic)
            {
                //logger.Debug("Validating logic for condition: {0}, itemref {1}", _name, logic.itemref);

                //pass in assetName to find local OPCItem
                try
                {
                    if (logic.validate(_assetName) < 0)
                    {
                        configOK = false;
                        enabled = false;
                        return -1;
                    }
                }
                catch (Exception e)
                {
                    e.Data["LOGIC"] = logic.type + " " + logic.itemref;
                    throw e;
                }
            }

            return 0;
        }
Пример #3
0
 public static bool Deserialize(string input, out state obj)
 {
     System.Exception exception = null;
     return Deserialize(input, out obj, out exception);
 }
Пример #4
0
 /// <summary>
 /// Deserializes workflow markup into an state object
 /// </summary>
 /// <param name="input">string workflow markup to deserialize</param>
 /// <param name="obj">Output state object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string input, out state obj, out System.Exception exception)
 {
     exception = null;
     obj = default(state);
     try
     {
         obj = Deserialize(input);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Пример #5
0
 public static bool LoadFromFile(string fileName, out state obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Пример #6
0
 /// <summary>
 /// Deserializes xml markup from file into an state object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output state object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out state obj, out System.Exception exception)
 {
     exception = null;
     obj = default(state);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }