Esempio n. 1
0
        private void runRunningStateMachine()
        {
            switch (RunningState)
            {
            case RunningState.WaitReset:
                //check user event
                if (DiReset.Count > 0 && DiReset.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.RESET, this);
                    OnShowAlarmEvent(string.Empty, LogLevel.None);
                    return;
                }
                else if (DiStop.Count > 0 && DiStop.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.STOP, this);
                    return;
                }
                else if (DiAuto.Count > 0 && !DiAuto.All(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.MANUAL, this);
                    return;
                }

                //pull up stations state
                if (Stations.All(s => !s.Value.Enable || s.Value.RunningState == RunningState.Resetting))
                {
                    _resettingFlashCount = 0;
                    Light(UserEventType.RESET);
                    RunningState = RunningState.Resetting;
                    return;
                }
                break;

            case RunningState.Resetting:
                //check user event
                if (DiStop.Count > 0 && DiStop.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.STOP, this);
                    return;
                }
                else if (DiPauseSignal.Count > 0 && DiPauseSignal.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.STOP, this);
                    OnShowAlarmEvent($"{RunState} 安全信号 {string.Join(",", DiPauseSignal.Select(d => d.Value.Description))} 某一信号触发", LogLevel.Error);
                    return;
                }

                //pull up stations state
                if (Stations.All(s => !s.Value.Enable || s.Value.RunningState == RunningState.WaitRun))
                {
                    Light(UserEventType.START);
                    RunningState = RunningState.WaitRun;
                    return;
                }
                else if (Stations.Any(s => s.Value.Enable && s.Value.RunningState == RunningState.WaitReset))
                {
                    //some station not reset success
                    PostEvent(UserEventType.STOP, this);
                    Beep();
                    return;
                }

                if (_resettingFlashCount++ > 40)
                {
                    _resettingFlashCount = 0;
                    DoLightRed.All(d => d.Value.SetDo(false));
                    DoLightYellow.All(d => d.Value.Toggle());
                    DoLightGreen.All(d => d.Value.SetDo(false));
                }
                break;

            case RunningState.WaitRun:
                //check user event
                if (DiStart.Count > 0 && DiStart.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.START, this);
                    OnShowAlarmEvent(string.Empty, LogLevel.None);
                    return;
                }
                else if (DiStop.Count > 0 && DiStop.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.STOP, this);
                    return;
                }
                else if (DiAuto.Count > 0 && !DiAuto.All(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.MANUAL, this);
                    return;
                }

                //pull up stations state
                if (Stations.All(s => !s.Value.Enable || s.Value.RunningState == RunningState.Running))
                {
                    _runningFlashCount = 0;
                    Light(UserEventType.START);
                    RunningState = RunningState.Running;
                }
                else if (Stations.Any(s => s.Value.Enable && s.Value.RunningState == RunningState.WaitReset))
                {
                    PostEvent(UserEventType.STOP, this);
                    return;
                }
                break;

            case RunningState.Running:
                //check user event
                if (DiStop.Count > 0 && DiStop.Any(e => e.Value.GetDiSts()))
                {
                    //stop button to pause, need manual continue
                    _isPauseSignal = false;
                    PostEvent(UserEventType.PAUSE, this);
                    return;
                }
                else if (DiPauseSignal.Count > 0 && DiPauseSignal.Any(e => e.Value.GetDiSts()))
                {
                    //pause button to pause, auto continue when reset
                    _isPauseSignal = true;
                    PostEvent(UserEventType.PAUSE, this);
                    OnShowAlarmEvent($"{RunState} 暂停信号 {string.Join(",", DiPauseSignal.Values.Select(d => d.Description))} 某一信号触发", LogLevel.Warning);
                    return;
                }

                //pull up stations state
                if (Stations.Any(s => s.Value.Enable && s.Value.RunningState == RunningState.WaitReset))
                {
                    //some station run error
                    PostEvent(UserEventType.STOP, this);
                    Beep();
                    return;
                }
                else if (Stations.Any(s => s.Value.Enable && s.Value.RunningState == RunningState.Pause))
                {
                    //some station pause
                    Light(UserEventType.PAUSE);
                    RunningState = RunningState.Pause;
                    return;
                }

                if (_runningFlashCount++ > 40)
                {
                    _runningFlashCount = 0;
                    DoLightRed.All(d => d.Value.SetDo(false));
                    DoLightYellow.All(d => d.Value.SetDo(false));
                    DoLightGreen.All(d => d.Value.Toggle());
                }
                break;

            case RunningState.Pause:
                //long press stop to change pause to stop
                if (DiStop.Count > 0 && DiStop.Any(e => e.Value.GetDiSts()))
                {
                    if (_pauseStoppingCount++ > 30)
                    {
                        PostEvent(UserEventType.STOP, this);
                        return;
                    }
                }
                else
                {
                    _pauseStoppingCount = 0;
                }

                //check user event
                if (_isPauseSignal && DiPauseSignal.Count > 0 && DiPauseSignal.All(e => !e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.CONTINUE, this);
                    return;
                }
                else if (DiStart.Count > 0 && DiStart.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.CONTINUE, this);
                    OnShowAlarmEvent(string.Empty, LogLevel.None);
                    return;
                }
                else if (DiReset.Count > 0 && DiReset.Any(e => e.Value.GetDiSts()))
                {
                    //press reset to change pause to stop
                    PostEvent(UserEventType.STOP, this);
                    return;
                }

                //pull up stations state
                if (Stations.All(s => !s.Value.Enable || s.Value.RunningState == RunningState.Running))
                {
                    _runningFlashCount = 0;
                    RunningState       = RunningState.Running;
                }
                else if (Stations.Any(s => s.Value.Enable && s.Value.RunningState == RunningState.WaitReset))
                {
                    //if any station run fail
                    PostEvent(UserEventType.STOP, this);
                    return;
                }
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新设备状态
        /// </summary>
        private void runRunStateMachine()
        {
            switch (RunState)
            {
            case RunState.ESTOP:
                if (DiEstop.Count > 0 && DiEstop.All(e => !e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.ESTOPOFF, this);
                    return;
                }

                //stop estop buzzer on timeout
                if (_estopBeepCount++ > 100)
                {
                    _estopBeepCount = 100;
                    DoBuzzer.All(d => d.Value.SetDo(false));
                }
                if (_estopFlashCount++ > 40)
                {
                    _estopFlashCount = 0;
                    DoLightRed.All(d => d.Value.Toggle());
                    DoLightYellow.All(d => d.Value.SetDo(false));
                    DoLightGreen.All(d => d.Value.SetDo(false));
                }
                break;

            case RunState.ERROR:
                if (DiEstop.Count > 0 && DiEstop.Any(e => e.Value.GetDiSts()))
                {
                    _estopBeepCount = 0;
                    PostEvent(UserEventType.ESTOP, this);
                    OnShowAlarmEvent($"{RunState} 急停信号 {string.Join(",", DiEstop.Select(d => d.Value.Description))} 某一信号触发", LogLevel.Error);
                    return;
                }
                else if (DiReset.Count > 0 && DiReset.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.RESET, this);
                    return;
                }
                break;

            case RunState.MANUAL:
                if (DiEstop.Count > 0 && DiEstop.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.ESTOP, this);
                    OnShowAlarmEvent($"{RunState} 急停信号 {string.Join(",", DiEstop.Select(d => d.Value.Description))} 某一信号触发", LogLevel.Error);
                    return;
                }
                else if (DiAuto.Count > 0 && DiAuto.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.AUTO, this);
                    return;
                }

                if (_resettingFlashCount++ > 40)
                {
                    _resettingFlashCount = 0;
                    DoLightRed.All(d => d.Value.SetDo(false));
                    DoLightYellow.All(d => d.Value.Toggle());
                    DoLightGreen.All(d => d.Value.SetDo(false));
                }
                break;

            case RunState.AUTO:
                if (DiEstop.Count > 0 && DiEstop.Any(e => e.Value.GetDiSts()))
                {
                    PostEvent(UserEventType.ESTOP, this);
                    OnShowAlarmEvent($"{RunState} 急停信号 {string.Join(",", DiEstop.Select(d => d.Value.Description))} 某一信号触发", LogLevel.Error);
                    return;
                }
                runRunningStateMachine();
                break;
            }
        }