Example #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;
            }
        }
Example #2
0
 public state()
 {
     this._defaultcond = new condition();
 }
Example #3
0
 public static bool LoadFromFile(string fileName, out condition obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Example #4
0
 /// <summary>
 /// Deserializes xml markup from file into an condition object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output condition 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 condition obj, out System.Exception exception)
 {
     exception = null;
     obj = default(condition);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Example #5
0
 public static bool Deserialize(string input, out condition obj)
 {
     System.Exception exception = null;
     return Deserialize(input, out obj, out exception);
 }
Example #6
0
 /// <summary>
 /// Deserializes workflow markup into an condition object
 /// </summary>
 /// <param name="input">string workflow markup to deserialize</param>
 /// <param name="obj">Output condition 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 condition obj, out System.Exception exception)
 {
     exception = null;
     obj = default(condition);
     try
     {
         obj = Deserialize(input);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }