/// <summary>
        /// 根据工站状态处理 start/stop/reset 事件: update state by events and pass to tasks
        /// </summary>
        /// <param name="e"></param>
        public void HandleEvent(UserEvent e)
        {
            if (!Enable)
            {
                return;
            }

            switch (RunState)
            {
            case RunState.ESTOP:
                break;

            case RunState.ERROR:
                break;

            case RunState.MANUAL:
                break;

            case RunState.AUTO:
                if (e.EventType == UserEventType.ESTOP)
                {
                    PassEvent(e);
                    RunningState = RunningState.WaitReset;
                    return;
                }
                switch (RunningState)
                {
                case RunningState.WaitReset:
                    if (e.EventType == UserEventType.RESET)
                    {
                        //reset to waitreset
                        foreach (var t in Tasks)
                        {
                            t.Value.RefreshState(RunningState.WaitReset);
                        }
                        PassEvent(e);
                        RunningState = RunningState.Resetting;
                    }
                    else if (e.EventType == UserEventType.STOP || e.EventType == UserEventType.MANUAL)
                    {
                        PassEvent(e);
                        RunningState = RunningState.WaitReset;
                    }
                    break;

                case RunningState.Resetting:
                    if (e.EventType == UserEventType.STOP)
                    {
                        PassEvent(e);
                        RunningState = RunningState.WaitReset;
                    }
                    break;

                case RunningState.WaitRun:
                    if (e.EventType == UserEventType.START)
                    {
                        //reset to waitrun
                        foreach (var t in Tasks)
                        {
                            t.Value.RefreshState(RunningState.WaitRun);
                        }
                        PassEvent(e);
                        RunningState = RunningState.Running;
                    }
                    else if (e.EventType == UserEventType.STOP || e.EventType == UserEventType.MANUAL)
                    {
                        PassEvent(e);
                        RunningState = RunningState.WaitReset;
                    }
                    break;

                case RunningState.Running:
                    if (e.EventType == UserEventType.PAUSE)
                    {
                        PassEvent(e);
                        RunningState = RunningState.Pause;
                    }
                    else if (e.EventType == UserEventType.STOP)
                    {
                        PassEvent(e);
                        RunningState = RunningState.WaitReset;
                    }
                    break;

                case RunningState.Pause:
                    if (e.EventType == UserEventType.START)
                    {
                        PassEvent(e);
                        RunningState = RunningState.Running;
                    }
                    else if (e.EventType == UserEventType.CONTINUE)
                    {
                        PassEvent(e);
                        RunningState = RunningState.Running;
                    }
                    else if (e.EventType == UserEventType.STOP)
                    {
                        PassEvent(e);
                        RunningState = RunningState.WaitReset;
                    }
                    break;
                }
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// 处理设备事件, pass to stations
        /// </summary>
        /// <param name="e"></param>
        public void HandleEvent(UserEvent e)
        {
            //handle event on runstate
            switch (RunState)
            {
            case RunState.ESTOP:
                if (e.EventType == UserEventType.ESTOPOFF)
                {
                    PassEvents(e);
                    RunState     = RunState.ERROR;
                    RunningState = RunningState.WaitReset;
                }
                break;

            case RunState.ERROR:
                if (e.EventType == UserEventType.ESTOP)
                {
                    PassEvents(e);
                    RunState     = RunState.ESTOP;
                    RunningState = RunningState.WaitReset;
                }
                else if (e.EventType == UserEventType.RESET)
                {
                    PassEvents(e);
                    RunState     = RunState.AUTO;
                    RunningState = RunningState.WaitReset;
                }

                break;

            case RunState.MANUAL:
                if (e.EventType == UserEventType.ESTOP)
                {
                    PassEvents(e);
                    RunState     = RunState.ESTOP;
                    RunningState = RunningState.WaitReset;
                }
                else if (e.EventType == UserEventType.AUTO)
                {
                    RunState     = RunState.AUTO;
                    RunningState = RunningState.WaitReset;
                }
                break;

            case RunState.AUTO:
                if (e.EventType == UserEventType.ESTOP)
                {
                    PassEvents(e);
                    RunState     = RunState.ESTOP;
                    RunningState = RunningState.WaitReset;
                    return;
                }

                //handle event on runstate auto
                switch (RunningState)
                {
                case RunningState.WaitReset:
                    if (e.EventType == UserEventType.MANUAL)
                    {
                        RunState     = RunState.MANUAL;
                        RunningState = RunningState.WaitReset;
                    }
                    else if (e.EventType == UserEventType.RESET)
                    {
                        PassEvents(e);
                        RunningState = RunningState.Resetting;
                    }
                    else if (e.EventType == UserEventType.STOP)
                    {
                        PassEvents(e);
                        RunningState = RunningState.WaitReset;
                    }

                    break;

                case RunningState.Resetting:
                    if (e.EventType == UserEventType.STOP || e.EventType == UserEventType.PAUSE)
                    {
                        PassEvents(e);
                        RunningState = RunningState.WaitReset;
                    }

                    break;

                case RunningState.WaitRun:
                    if (e.EventType == UserEventType.MANUAL)
                    {
                        RunState     = RunState.MANUAL;
                        RunningState = RunningState.WaitReset;
                    }
                    else if (e.EventType == UserEventType.START)
                    {
                        PassEvents(e);
                        RunningState = RunningState.Running;
                    }
                    else if (e.EventType == UserEventType.STOP)
                    {
                        PassEvents(e);
                        RunningState = RunningState.WaitReset;
                    }

                    break;

                case RunningState.Running:
                    if (e.EventType == UserEventType.PAUSE)
                    {
                        PassEvents(e);
                        RunningState = RunningState.Pause;
                    }
                    else if (e.EventType == UserEventType.STOP)
                    {
                        PassEvents(e);
                        RunningState = RunningState.WaitReset;
                    }

                    break;

                case RunningState.Pause:
                    if (e.EventType == UserEventType.CONTINUE || e.EventType == UserEventType.START)
                    {
                        PassEvents(e);
                        RunningState = RunningState.Running;
                    }
                    else if (e.EventType == UserEventType.STOP)
                    {
                        PassEvents(e);
                        RunningState = RunningState.WaitReset;
                    }

                    break;
                }
                break;
            }
        }
        /// <summary>
        /// 处理设备事件 start/stop/reset/etc
        /// </summary>
        /// <param name="e"></param>
        public void HandleEvent(UserEvent e)
        {
            if (e.EventType == UserEventType.ESTOP)
            {
                Stop();
                RunningState = RunningState.WaitReset;
            }

            switch (RunningState)
            {
            case RunningState.WaitReset:
                if (e.EventType == UserEventType.RESET)
                {
                    Reset();
                }
                else if (e.EventType == UserEventType.STOP || e.EventType == UserEventType.MANUAL)
                {
                    Stop();
                }
                break;

            case RunningState.Resetting:
                if (e.EventType == UserEventType.STOP)
                {
                    Stop();
                }
                break;

            case RunningState.WaitRun:
                if (e.EventType == UserEventType.START)
                {
                    Start();
                }
                else if (e.EventType == UserEventType.STOP || e.EventType == UserEventType.MANUAL)
                {
                    Stop();
                }
                break;

            case RunningState.Running:
                if (e.EventType == UserEventType.PAUSE)
                {
                    RunningState = RunningState.Pause;
                }
                else if (e.EventType == UserEventType.STOP)
                {
                    Stop();
                }
                break;

            case RunningState.Pause:
                if (e.EventType == UserEventType.START)
                {
                    RunningState = RunningState.Running;
                }
                else if (e.EventType == UserEventType.CONTINUE)
                {
                    RunningState = RunningState.Running;
                }
                else if (e.EventType == UserEventType.STOP)
                {
                    Stop();
                }
                break;
            }
        }