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; using PunkHPX8_RT.Devices.AXIS; namespace PunkHPX8_RT.Devices.Safety { internal class SafetyAllOnRoutine : RoutineBase, IRoutine { private enum SafetyAllOnStep { VpwCell1SwitchOn, WaitSwitchOnVpwCell1, VpwCell2SwitchOn, WaitSwitchOnVpwCell2, PlatingCell1RotationSwitchOn, WaitSwitchOnPlatingCell1Rotation, PlatingCell2RotationSwitchOn, WaitSwitchOnPlatingCell2Rotation, PlatingCell3RotationSwitchOn, WaitSwitchOnPlatingCell3Rotation, PlatingCell4RotationSwitchOn, WaitSwitchOnPlatingCell4Rotation, PlatingCell12VerticalSwitchOn, WaitSwitchOnPlatingCell12Vertical, PlatingCell34VerticalSwitchOn, WaitSwitchOnPlatingCell34Vertical, SwitchOnSRD1, WaitSwitchOnSRD1, SwitchOnSRD2, WaitSwitchOnSRD2, End } #region 内部变量 private SafetyDevice _device; private JetAxisBase _vpwCell1Rotation; private JetAxisBase _vpwCell2Rotation; private JetAxisBase _platingCell1Rotation; private JetAxisBase _platingCell2Rotation; private JetAxisBase _platingCell3Rotation; private JetAxisBase _platingCell4Rotation; private JetAxisBase _platingCell1_2Vertical; private JetAxisBase _platingCell3_4Vertical; private JetAxisBase _srd1Rotation; private JetAxisBase _srd2Rotation; #endregion /// /// 构造函数 /// /// public SafetyAllOnRoutine(string module) : base(module) { } /// /// 中止 /// public void Abort() { Runner.Stop($"Safety All On Abort"); } /// /// 监控 /// /// public RState Monitor() { Runner.RunIf(SafetyAllOnStep.VpwCell1SwitchOn,ModuleHelper.IsInstalled(ModuleName.VPW1),()=>SwitchOnAxis(_vpwCell1Rotation),_delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnVpwCell1, ModuleHelper.IsInstalled(ModuleName.VPW1), ()=>CheckSwitchOn(_vpwCell1Rotation),()=>CheckSwitchOnStopStatus(_vpwCell1Rotation)) .RunIf(SafetyAllOnStep.VpwCell2SwitchOn, ModuleHelper.IsInstalled(ModuleName.VPW2), () => SwitchOnAxis(_vpwCell2Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnVpwCell2, ModuleHelper.IsInstalled(ModuleName.VPW2), () => CheckSwitchOn(_vpwCell2Rotation), () => CheckSwitchOnStopStatus(_vpwCell2Rotation)) .RunIf(SafetyAllOnStep.PlatingCell12VerticalSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => SwitchOnAxis(_platingCell1_2Vertical), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell12Vertical, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => CheckSwitchOn(_platingCell1_2Vertical), () => CheckSwitchOnStopStatus(_platingCell1_2Vertical)) .RunIf(SafetyAllOnStep.PlatingCell34VerticalSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => SwitchOnAxis(_platingCell3_4Vertical), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell34Vertical, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => CheckSwitchOn(_platingCell3_4Vertical), () => CheckSwitchOnStopStatus(_platingCell3_4Vertical)) .RunIf(SafetyAllOnStep.PlatingCell1RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => SwitchOnAxis(_platingCell1Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell1Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell1), () => CheckSwitchOn(_platingCell1Rotation), () => CheckSwitchOnStopStatus(_platingCell1Rotation)) .RunIf(SafetyAllOnStep.PlatingCell2RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell2), () => SwitchOnAxis(_platingCell2Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell2Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell2), () => CheckSwitchOn(_platingCell2Rotation), () => CheckSwitchOnStopStatus(_platingCell2Rotation)) .RunIf(SafetyAllOnStep.PlatingCell3RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => SwitchOnAxis(_platingCell3Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell3Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell3), () => CheckSwitchOn(_platingCell3Rotation), () => CheckSwitchOnStopStatus(_platingCell3Rotation)) .RunIf(SafetyAllOnStep.PlatingCell4RotationSwitchOn, ModuleHelper.IsInstalled(ModuleName.PlatingCell4), () => SwitchOnAxis(_platingCell4Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnPlatingCell4Rotation, ModuleHelper.IsInstalled(ModuleName.PlatingCell4), () => CheckSwitchOn(_platingCell4Rotation), () => CheckSwitchOnStopStatus(_platingCell4Rotation)) .RunIf(SafetyAllOnStep.SwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1), () => SwitchOnAxis(_srd1Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1), () => CheckSwitchOn(_srd1Rotation), () => CheckSwitchOnStopStatus(_srd1Rotation)) .RunIf(SafetyAllOnStep.SwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2), () => SwitchOnAxis(_srd2Rotation), _delay_1ms) .WaitWithStopConditionIf(SafetyAllOnStep.WaitSwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2), () => CheckSwitchOn(_srd2Rotation), () => CheckSwitchOnStopStatus(_srd2Rotation)) .End(SafetyAllOnStep.End, NullFun, _delay_1ms); return Runner.Status; } /// /// 电机SwitchOn /// /// /// private bool SwitchOnAxis(JetAxisBase axis) { return axis.SwitchOn(); } /// /// 检验电机是否上电 /// /// /// private bool CheckSwitchOn(JetAxisBase axis) { return axis.IsSwitchOn && axis.Status == RState.End; } /// /// 检验电机上电是否异常 /// /// /// private bool CheckSwitchOnStopStatus(JetAxisBase axis) { return axis.Status == RState.Failed; } /// /// 启动 /// /// /// public RState Start(params object[] objs) { _device = DEVICE.GetDevice(Module); _vpwCell1Rotation = DEVICE.GetDevice($"{ModuleName.VPW1}.Rotation"); _vpwCell2Rotation = DEVICE.GetDevice($"{ModuleName.VPW2}.Rotation"); _platingCell1Rotation = DEVICE.GetDevice($"{ModuleName.PlatingCell1}.Rotation"); _platingCell2Rotation = DEVICE.GetDevice($"{ModuleName.PlatingCell2}.Rotation"); _platingCell3Rotation = DEVICE.GetDevice($"{ModuleName.PlatingCell3}.Rotation"); _platingCell4Rotation = DEVICE.GetDevice($"{ModuleName.PlatingCell4}.Rotation"); _platingCell1_2Vertical = DEVICE.GetDevice($"PlatingCell1_2.Vertical"); _platingCell3_4Vertical = DEVICE.GetDevice($"PlatingCell3_4.Vertical"); _srd1Rotation = DEVICE.GetDevice($"{ModuleName.SRD1}.Rotation"); _srd2Rotation = DEVICE.GetDevice($"{ModuleName.SRD2}.Rotation"); return Runner.Start(Module, $"Safety All On"); } } }