Пример #1
0
        private StateMachine Light(UserEventType e)
        {
            //buzzer
            switch (e)
            {
            case UserEventType.ESTOP:
                _estopBeepCount  = 0;
                _estopFlashCount = 0;
                DoBuzzer.All(d => d.Value.SetDo(true));
                break;

            case UserEventType.ESTOPOFF:
                _estopBeepCount  = 0;
                _estopFlashCount = 0;
                DoBuzzer.All(d => d.Value.SetDo(false));
                break;

            case UserEventType.STOP:
                //Beep();
                break;
            }

            //light
            switch (e)
            {
            case UserEventType.START:
            case UserEventType.CONTINUE:
                _runningFlashCount = 0;
                DoLightRed.All(d => d.Value.SetDo(false));
                DoLightYellow.All(d => d.Value.SetDo(false));
                DoLightGreen.All(d => d.Value.SetDo(true));
                break;

            case UserEventType.ESTOP:
            case UserEventType.ESTOPOFF:
            case UserEventType.STOP:
            case UserEventType.AUTO:
                DoLightRed.All(d => d.Value.SetDo(true));
                DoLightYellow.All(d => d.Value.SetDo(false));
                DoLightGreen.All(d => d.Value.SetDo(false));
                break;

            case UserEventType.PAUSE:
                DoLightRed.All(d => d.Value.SetDo(false));
                DoLightYellow.All(d => d.Value.SetDo(false));
                DoLightGreen.All(d => d.Value.SetDo(true));
                break;

            case UserEventType.RESET:
            case UserEventType.MANUAL:
                _resettingFlashCount = 0;
                DoLightRed.All(d => d.Value.SetDo(false));
                DoLightYellow.All(d => d.Value.SetDo(true));
                DoLightGreen.All(d => d.Value.SetDo(false));
                break;
            }

            return(this);
        }
Пример #2
0
 public void Beep()
 {
     lock (this)
     {
         DoBuzzer.All(d => d.Value.SetDo(true));
         Thread.Sleep(500);
         DoBuzzer.All(d => d.Value.SetDo(false));
     }
 }
Пример #3
0
        /// <summary>
        /// 初始化, 开启主线程
        /// </summary>
        public virtual void Initialize()
        {
            DoLightRed.All(d => d.Value.SetDo(false));
            DoLightYellow.All(d => d.Value.SetDo());
            DoLightGreen.All(d => d.Value.SetDo(false));
            DoBuzzer.All(d => d.Value.SetDo(false));

            _isrunning  = true;
            _mainThread = new Thread(runStateMachineLoop);
            _mainThread.IsBackground = true;
            _mainThread.Start();
        }
Пример #4
0
        /// <summary>
        /// 终止, 结束主线程
        /// </summary>
        public virtual void Terminate()
        {
            PostEvent(UserEventType.STOP, this);


            //make sure all events handled
            _isrunning = false;
            if (_mainThread.IsAlive)
            {
                _mainThread.Join();
            }
            DoLightRed.All(d => d.Value.SetDo(false));
            DoLightYellow.All(d => d.Value.SetDo(false));
            DoLightGreen.All(d => d.Value.SetDo(false));
            DoBuzzer.All(d => d.Value.SetDo(false));
        }
Пример #5
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;
            }
        }
Пример #6
0
        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
                });
            }
        }