/// <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; } }
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; } }
public override void Load() { if (!Directory.Exists(@".\Config")) { Directory.CreateDirectory(@".\Config"); } //load all settings!!! try { Settings = DemoMachineSettings.Load(@".\Config\Settings.cfg"); } catch (Exception ex) { MessageBox.Show($"加载配置文件失败:{ex.Message}"); } if (Settings == null) { Settings = new DemoMachineSettings(); Settings.Save(@".\Config\Settings.cfg"); } //try //{ // Import(); //} //catch (Exception ex) //{ // MessageBox.Show($"导入设备参数失败:{ex.Message}"); //} //load drivers Motion1 = new MotionCardWrapper(new VirtualCard()); VIO = new MotionCardWrapper(new VirtualCard()); MotionExs.Add(1, Motion1); MotionExs.Add(2, VIO); //load di do axis DiExs.Add(1, new DiEx() { Driver = Motion1 }); DoExs.Add(1, new DoEx() { Driver = Motion1 }); CylinderExs.Add(1, new CylinderEx() { Driver1 = Motion1, Driver2 = Motion1 }); AxisExs.Add(1, new AxisEx() { Driver = Motion1 }); //load station task var station1 = new Station(1, "Station1", this); var testTask1 = new TestTask1(1, "Test1", station1); //bind signals if (!FrameworkManager.IsSimulate) { // todo : to add signal configs //estop DiEstop.Add(2, new DiEx() { Driver = Motion1 }); //start/stop/reset button DiStart.Add(1, new DiEx() { Driver = Motion1 }); DiStop.Add(1, new DiEx() { Driver = Motion1 }); DiReset.Add(1, new DiEx() { Driver = Motion1 }); //start/stop/reset button lamp DoLightGreen.Add(1, new DoEx() { Driver = Motion1 }); DoLightRed.Add(1, new DoEx() { Driver = Motion1 }); DoLightYellow.Add(1, new DoEx() { Driver = Motion1 }); //lamp DoLightGreen.Add(2, new DoEx() { Driver = Motion1 }); DoLightRed.Add(2, new DoEx() { Driver = Motion1 }); DoLightYellow.Add(2, new DoEx() { Driver = Motion1 }); DoBuzzer.Add(1, new DoEx() { Driver = Motion1 }); //station pause signals Stations[1].PauseSignals.Add(1, new DiEx() { Driver = Motion1 }); } }