예제 #1
0
        public bool CheckTrigger(SignalValueTimestamp signalValueTimestamp)
        {
            if (_triggerState > _triggerStates.Count)
            {
                throw new Exception("Cannont jump to that state, it does not exsist");
            }

            //Selects the curret state of the triger
            var currentTriggerState = _triggerStates.ElementAt(_triggerState);

            //Cheks if the state is true for the signal change
            var isStateTrue = currentTriggerState.CheckTriggerState(signalValueTimestamp);

            if (isStateTrue)
            {
                //Loops through the then operations of the state e.g. IF: A1 == 0 Then: StatTrimer, GoToNextState
                foreach (TriggerStateThenOperations thenOperation in currentTriggerState.TriggerStateOptions)
                {
                    switch (thenOperation)
                    {
                    case TriggerStateThenOperations.GotoFirsState:
                        _triggerState = 0;
                        break;

                    case TriggerStateThenOperations.GotoNextState:
                        _triggerState++;
                        break;

                    // The trigger sets a start time to the statements if a timer is used for the trigger
                    case TriggerStateThenOperations.StartTimer:
                        SetStartTimeStampToTimeStatements(signalValueTimestamp.TimeStamp);
                        break;

                    case TriggerStateThenOperations.Trigger:
                        _triggerState = 0;

                        /* Logic to avoid the trigger to trigger multiple times during a conditon
                         * e.g If a the trigger is IF: A1 < 0 Then: Trigger
                         * The trigger will only trigger again after A1 has gone above 0 */
                        if (_isAlreadyTriggerd && isStateTrue)
                        {
                            isStateTrue = false;
                        }
                        else if (isStateTrue)
                        {
                            _isAlreadyTriggerd = true;
                        }

                        return(isStateTrue);

                    default:
                        throw new Exception("No Then operation has been set");
                    }
                }
            }
            _isAlreadyTriggerd = false;
            return(false);
        }
        /// <summary>
        /// Call this method when a signal change occurs
        /// </summary>
        /// <param name="signal">Signal Object</param>
        /// <param name="newValue">Value of the signal change, Can be a bool or double</param>
        /// <param name="timeStamp">Timestamp of the signal change of type Ticks</param>
        public void LogValueChange(ABB.Robotics.Paint.RobView.Database.SignalLog.Signal signal, object newValue, long timeStamp)
        {
            //Ser ut som Signalene bytter metadata underveis, workaround
            // var findsignal = _signalsList.First(x => x.Name == signal.Name);
            Signal findsignal;

            if (TriggeredUnitTest != null)
            {
                findsignal = signal;
            }
            else
            {
                findsignal = _signalsList.First(x => x.Name == signal.Name);
            }

            //  var findsignal = signal;
            if (newValue == null || !IsUsingSignal(findsignal))
            {
                return;
            }

            SignalValueTimestamp signalHandler;

            try
            {
                var value = Convert.ToDouble(newValue);


                signalHandler = new SignalValueTimestamp(findsignal, value, timeStamp);

                foreach (Trigger trigger in _triggerList)
                {
                    //var triggerd = trigger.CheckTrigger(signal, newValue);

                    if (trigger.IsUsingSignal(findsignal))
                    {
                        if (trigger.CheckTrigger(signalHandler))
                        {
                            FireTriggered(trigger.Name);
                        }
                    }
                }
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex);
                //ABB.Robotics.Paint.RobView.PluginAPI.Logger.Internal.LogException(ex);
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex);
                //ABB.Robotics.Paint.RobView.PluginAPI.Logger.Internal.LogException(ex);
            }
        }
 public bool CheckTriggerState(SignalValueTimestamp signalValueTimestamp)
 {
     foreach (TriggerForkedState triggerStateForkedStatemetn in _triggerStateForkedStatements)
     {
         if (triggerStateForkedStatemetn.CheckTriggerStateForkedStatement(signalValueTimestamp))
         {
             // Sets the then operations to the state that has been true.
             _triggerStateOptions = triggerStateForkedStatemetn.TriggerStateThenOperations;
             return(true);
         }
     }
     return(false);
 }
 public bool CheckTriggerState(SignalValueTimestamp signalValueTimestamp)
 {
     foreach (TriggerStateForkedState triggerStateForkedStatemetn in _triggerStateForkedStatements)
     {
         if (triggerStateForkedStatemetn.CheckTriggerStateForkedStatement(signalValueTimestamp))
         {
             // Sets the then operations to the state that has been true.
             _triggerStateOptions = triggerStateForkedStatemetn.TriggerStateThenOperations;
             return true;
         }
     }
     return false;
 }
예제 #5
0
        public bool CheckTrigger(SignalValueTimestamp signalValueTimestamp)
        {
            if (_triggerState > _triggerStates.Count)
                throw new Exception("Cannont jump to that state, it does not exsist");

            //Selects the curret state of the triger
            var currentTriggerState = _triggerStates.ElementAt(_triggerState);

            //Cheks if the state is true for the signal change
            var isStateTrue = currentTriggerState.CheckTriggerState(signalValueTimestamp);

            if (isStateTrue)
            {
                //Loops through the then operations of the state e.g. IF: A1 == 0 Then: StatTrimer, GoToNextState
                foreach (TriggerStateThenOperations thenOperation in currentTriggerState.TriggerStateOptions)
                {
                    switch (thenOperation)
                    {
                        case TriggerStateThenOperations.GotoFirsState:
                            _triggerState = 0;
                            break;
                        case TriggerStateThenOperations.GotoNextState:
                            _triggerState++;
                            break;
                        // The trigger sets a start time to the statements if a timer is used for the trigger
                        case TriggerStateThenOperations.StartTimer:
                            SetStartTimeStampToTimeStatements(signalValueTimestamp.TimeStamp);
                            break;
                        case TriggerStateThenOperations.Trigger:
                            _triggerState = 0;
                            /* Logic to avoid the trigger to trigger multiple times during a conditon
                             * e.g If a the trigger is IF: A1 < 0 Then: Trigger
                             * The trigger will only trigger again after A1 has gone above 0 */
                            if (_isAlreadyTriggerd && isStateTrue)
                            {
                                isStateTrue = false;
                            }
                            else if (isStateTrue)
                            {
                                _isAlreadyTriggerd = true;
                            }

                            return isStateTrue;
                        default:
                            throw new Exception("No Then operation has been set");
                    }
                }
            }
            _isAlreadyTriggerd = false;
            return false;
        }
        /// <summary>
        /// Call this method when a signal change occurs
        /// </summary>
        /// <param name="signal">Signal Object</param>
        /// <param name="newValue">Value of the signal change, Can be a bool or double</param>
        /// <param name="timeStamp">Timestamp of the signal change of type Ticks</param>
        public void LogValueChange(ABB.Robotics.Paint.RobView.Database.SignalLog.Signal signal, object newValue, long timeStamp)
        {
            //Ser ut som Signalene bytter metadata underveis, workaround
              // var findsignal = _signalsList.First(x => x.Name == signal.Name);
            Signal findsignal;

               if (TriggeredUnitTest != null)
               {
               findsignal = signal;
               }
               else
               {
               findsignal = _signalsList.First(x => x.Name == signal.Name);
               }

              //  var findsignal = signal;
            if (newValue == null || !IsUsingSignal(findsignal))
            {
                return;
            }

            SignalValueTimestamp signalHandler;

            try
            {
                var value = Convert.ToDouble(newValue);

                signalHandler = new SignalValueTimestamp(findsignal, value, timeStamp);

                foreach (Trigger trigger in _triggerList)
                {
                    //var triggerd = trigger.CheckTrigger(signal, newValue);

                    if (trigger.IsUsingSignal(findsignal))
                    {
                        if (trigger.CheckTrigger(signalHandler))
                        {
                            FireTriggered(trigger.Name);
                        }
                    }
                }
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex);
                //ABB.Robotics.Paint.RobView.PluginAPI.Logger.Internal.LogException(ex);
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex);
                //ABB.Robotics.Paint.RobView.PluginAPI.Logger.Internal.LogException(ex);
            }
        }
예제 #7
0
 public bool CheckTriggerStateForkedStatement(SignalValueTimestamp signalValueTimestamp)
 {
     return(_statement.CheckStatement(signalValueTimestamp));
 }