示例#1
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;
            }
        }
示例#2
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
                });
            }
        }