using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.Util; using PunkHPX8_Core; using PunkHPX8_RT.Modules; using PunkHPX8_RT.Modules.SRD; using PunkHPX8_RT.Modules.Transporter; using MECF.Framework.Common.Beckhoff.ModuleIO; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Routine; using MECF.Framework.Common.Utilities; using System.Runtime.InteropServices; namespace PunkHPX8_RT.Devices.Safety { internal class SafetyNewAllOnRoutine : RoutineBase, IRoutine { private enum SafetyAllOnStep { Ready, SwitchOnProcessTransporter, WaitSwitchOnProcessTransporter, SwitchOnLoaderTransporter, WaitSwitchOnLoaderTransporter, SwitchOnLoader, WaitSwitchOnLoader, SwitchOnPuf1, WaitSwitchOnPuf1, SwitchOnPuf2, WaitSwitchOnPuf2, SwitchOnSRD1, WaitSwitchOnSRD1, SwitchOnSRD2, WaitSwitchOnSRD2, End } #region 内部变量 private SafetyDevice _device; private SRDSwitchOnRoutine _srd1SwitchOnRoutine; private SRDSwitchOnRoutine _srd2SwitchOnRoutine; #endregion /// /// 构造函数 /// /// public SafetyNewAllOnRoutine(string module) : base(module) { } /// /// 中止 /// public void Abort() { Runner.Stop($"Safety All On Abort"); } /// /// 监控 /// /// public RState Monitor() { Runner.RunIf(SafetyAllOnStep.SwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1), SwitchOnSRD1, _delay_1ms) .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnSRD1, CheckSwitchOnSRD1Complete, CheckSwitchOnSRD1Error) .RunIf(SafetyAllOnStep.SwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2), SwitchOnSRD2, _delay_1ms) .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnSRD2, CheckSwitchOnSRD2Complete, CheckSwitchOnSRD2Error) .End(SafetyAllOnStep.End, NullFun, _delay_1ms); return Runner.Status; } #region SRD1 /// /// Switch on SRD1 Motors /// /// private bool SwitchOnSRD1() { return _srd1SwitchOnRoutine.Start() == RState.Running; } /// /// 检查SRD1 Motors switchon是否完成 /// /// private bool CheckSwitchOnSRD1Complete() { if (!ModuleHelper.IsInstalled(ModuleName.SRD1)) { return true; } return CommonFunction.CheckRoutineEndState(_srd1SwitchOnRoutine); } /// /// 检查SRD1 Motors switchon是否出错 /// /// private bool CheckSwitchOnSRD1Error() { if (!ModuleHelper.IsInstalled(ModuleName.SRD1)) { return false; } return CommonFunction.CheckRoutineStopState(_srd1SwitchOnRoutine); } #endregion #region SRD2 /// /// Switch on SRD2 Motors /// /// private bool SwitchOnSRD2() { return _srd2SwitchOnRoutine.Start()==RState.Running; } /// /// 检查SRD2 Motors switchon是否完成 /// /// private bool CheckSwitchOnSRD2Complete() { if (!ModuleHelper.IsInstalled(ModuleName.SRD2)) { return true; } return CommonFunction.CheckRoutineEndState(_srd2SwitchOnRoutine); } /// /// 检查SRD2 Motors switchon是否出错 /// /// private bool CheckSwitchOnSRD2Error() { if (!ModuleHelper.IsInstalled(ModuleName.SRD2)) { return true; } return CommonFunction.CheckRoutineStopState(_srd2SwitchOnRoutine); } #endregion /// /// 启动 /// /// /// public RState Start(params object[] objs) { _srd1SwitchOnRoutine = new SRDSwitchOnRoutine(ModuleName.SRD1.ToString()); _srd2SwitchOnRoutine = new SRDSwitchOnRoutine(ModuleName.SRD2.ToString()); _device = DEVICE.GetDevice(Module); return Runner.Start(Module, $"Safety All On"); } } }