| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | 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,            PlatingCell12LiftSwitchOn,            WaitSwitchOnPlatingCell12Lift,            PlatingCell34LiftSwitchOn,            WaitSwitchOnPlatingCell34Lift,            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 _platingCell12Lift;        private JetAxisBase _platingCell34Lift;        private JetAxisBase _srd1Rotation;        private JetAxisBase _srd2Rotation;        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="module"></param>        public SafetyAllOnRoutine(string module) : base(module)        {                    }        /// <summary>        /// 中止        /// </summary>        public void Abort()        {            Runner.Stop($"Safety All On Abort");        }        /// <summary>        /// 监控        /// </summary>        /// <returns></returns>        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))                .End(SafetyAllOnStep.End, NullFun, _delay_1ms);            return Runner.Status;        }        /// <summary>        /// 电机SwitchOn        /// </summary>        /// <param name="axis"></param>        /// <returns></returns>        private bool SwitchOnAxis(JetAxisBase axis)        {            return axis.SwitchOn();        }        /// <summary>        /// 检验电机是否上电        /// </summary>        /// <param name="axis"></param>        /// <returns></returns>        private bool CheckSwitchOn(JetAxisBase axis)         {            return axis.IsSwitchOn && axis.Status == RState.End;        }        /// <summary>        /// 检验电机上电是否异常        /// </summary>        /// <param name="axis"></param>        /// <returns></returns>        private bool CheckSwitchOnStopStatus(JetAxisBase axis)        {            return axis.Status == RState.Failed;        }        /// <summary>        /// 启动        /// </summary>        /// <param name="objs"></param>        /// <returns></returns>        public RState Start(params object[] objs)        {            _device = DEVICE.GetDevice<SafetyDevice>(Module);            _vpwCell1Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW1}.Rotation");            _vpwCell2Rotation = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.VPW2}.Rotation");            return Runner.Start(Module, $"Safety All On");        }    }}
 |