123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- 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.CommonData.Reservoir;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.TwinCat;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.Temperature;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PunkHPX8_RT.Devices.Reservoir
- {
- public class CAPumpOnRoutine : RoutineBase, IRoutine
- {
- private enum CAPumpStep
- {
- PumpSpeed,
- PumpEnable,
- Delay,
- CheckRunning,
- FlowDelay,
- CheckFlow,
- End
- }
- #region 常量
- private const string CA_PUMP_SPEED = "CaPumpSpeed";
- private const string CA_PUMP_RUNNING = "CaPumpRunning";
- private const string CA_HED_FLOW = "CaHedFlow";
- private const string CA_PUMP_ENABLE = "CaPumpEnable";
- #endregion
- #region 内部变量
- private double _caPumpSpeed = 5000;
- private int _flowFaultHoldOffTime = 10000;
- private double _caMainFlowFaultLow = 5.0;
- private ReservoirDevice _device;
- private int _caOpenValveCount = 0;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public CAPumpOnRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manual abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(CAPumpStep.PumpSpeed, () => { return CAPumpSpeed(_caPumpSpeed); }, _delay_2s)
- .Run(CAPumpStep.PumpEnable, CAPumpEnable, _delay_1ms)
- .Delay(CAPumpStep.Delay, 500)
- .Run(CAPumpStep.CheckRunning, CheckCAPumpRunning, _delay_1ms)
- .Delay(CAPumpStep.FlowDelay, _flowFaultHoldOffTime)
- .Run(CAPumpStep.CheckFlow, CheckAllFlow, _delay_1ms)
- .End(CAPumpStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// Pump Speed
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool CAPumpSpeed(double speed)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_SPEED}");
- return BeckhoffIOManager.Instance.WriteIoValue(ioName, speed);
- }
- /// <summary>
- /// Pump Enable
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- private bool CAPumpEnable()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
- return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
- }
- /// <summary>
- /// Pump disable
- /// </summary>
- /// <returns></returns>
- private bool CAPumpDisable()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
- return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
- }
- /// <summary>
- /// 检验CA Running Sensor
- /// </summary>
- /// <returns></returns>
- private bool CheckCAPumpRunning()
- {
- if(!_device.ReservoirData.CaPumpRunning)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "CA Pump Running Sensor is false");
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检验所有流量
- /// </summary>
- /// <returns></returns>
- private bool CheckAllFlow()
- {
- double flow = _device.ReservoirData.CaFlow;
- if(flow<=_caMainFlowFaultLow)
- {
- CAPumpDisable();
- DisableHed();
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {flow} is not over {_caMainFlowFaultLow}");
- return false;
- }
- else
- {
- LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {flow} is over {_caMainFlowFaultLow}");
- }
- return true;
- }
- private void DisableHed()
- {
- ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
- if (!string.IsNullOrEmpty(reservoirItem.TCID))
- {
- TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
- temperatureController.DisableOperation("",null);
- }
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _device = DEVICE.GetDevice<ReservoirDevice>(Module);
- _caPumpSpeed = SC.GetValue<double>("Reservoir.CADefaultPumpSpeed");
- _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
- _caMainFlowFaultLow = SC.GetValue<double>($"Reservoir.{Module}.CAMainFlowFaultLow");
- _caOpenValveCount = 0;
- return Runner.Start(Module, "CA Pump On");
- }
- }
- }
|