123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.TwinCat;
- using PunkHPX8_Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PunkHPX8_RT.Devices.Reservoir
- {
- public class ANPumpOnRoutine : RoutineBase, IRoutine
- {
- private enum ANPumpStep
- {
- PumpSpeed,
- PumpEnable,
- Delay,
- CheckFlow,
- End
- }
- #region 内部变量
- /// <summary>
- /// 默认泵速
- /// </summary>
- private double _anPumpSpeed = 5000;
- /// <summary>
- /// flow fault hold off时长
- /// </summary>
- private int _flowFaultHoldOffTime = 10000;
- /// <summary>
- /// 阳极最小流量
- /// </summary>
- private double _anMinFlow = 0.2;
- /// <summary>
- /// Reservoir设备
- /// </summary>
- private DMReservoirDevice _device;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public ANPumpOnRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(ANPumpStep.PumpEnable, () => { return ANPumpEnable(); }, _delay_1ms)
- .Delay(ANPumpStep.Delay, _flowFaultHoldOffTime)
- .Run(ANPumpStep.CheckFlow,CheckAllFlow,_delay_1ms)
- .End(ANPumpStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// Pump Speed
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ANPumpSpeed(double speed)
- {
- return _device.AnPumpSpeed(speed);
- }
- /// <summary>
- /// Pump enable
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool ANPumpEnable()
- {
- return _device.AnPumpOnOperation("",null);
- }
- /// <summary>
- /// 检验所有流量
- /// </summary>
- /// <returns></returns>
- private bool CheckAllFlow()
- {
- double anTotalFlow = _device.ReservoirData.AnFlow;
- if(anTotalFlow<=_anMinFlow)
- {
- _device.AnPumpOff();
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {anTotalFlow} is not over {_anMinFlow}");
- return false;
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {anTotalFlow} is over {_anMinFlow}");
- return true;
- }
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _device = DEVICE.GetDevice<DMReservoirDevice>(Module);
- _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
- return Runner.Start(Module, "AN Pump On");
- }
- }
- }
|