CAPumpOnRoutine.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Beckhoff.ModuleIO;
  6. using MECF.Framework.Common.CommonData.Reservoir;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.ToolLayout;
  9. using MECF.Framework.Common.TwinCat;
  10. using PunkHPX8_Core;
  11. using PunkHPX8_RT.Devices.Temperature;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace PunkHPX8_RT.Devices.Reservoir
  18. {
  19. public class CAPumpOnRoutine : RoutineBase, IRoutine
  20. {
  21. private enum CAPumpStep
  22. {
  23. PumpSpeed,
  24. PumpEnable,
  25. Delay,
  26. CheckRunning,
  27. FlowDelay,
  28. CheckFlow,
  29. End
  30. }
  31. #region 常量
  32. private const string CA_PUMP_SPEED = "CaPumpSpeed";
  33. private const string CA_PUMP_RUNNING = "CaPumpRunning";
  34. private const string CA_HED_FLOW = "CaHedFlow";
  35. private const string CA_PUMP_ENABLE = "CaPumpEnable";
  36. #endregion
  37. #region 内部变量
  38. private double _caPumpSpeed = 5000;
  39. private int _flowFaultHoldOffTime = 10000;
  40. private double _caMainFlowFaultLow = 5.0;
  41. private ReservoirDevice _device;
  42. private int _caOpenValveCount = 0;
  43. #endregion
  44. /// <summary>
  45. /// 构造函数
  46. /// </summary>
  47. /// <param name="module"></param>
  48. public CAPumpOnRoutine(string module) : base(module)
  49. {
  50. }
  51. /// <summary>
  52. /// 中止
  53. /// </summary>
  54. public void Abort()
  55. {
  56. Runner.Stop("Manual abort");
  57. }
  58. /// <summary>
  59. /// 监控
  60. /// </summary>
  61. /// <returns></returns>
  62. public RState Monitor()
  63. {
  64. Runner.Run(CAPumpStep.PumpSpeed, () => { return CAPumpSpeed(_caPumpSpeed); }, _delay_2s)
  65. .Run(CAPumpStep.PumpEnable, CAPumpEnable, _delay_1ms)
  66. .Delay(CAPumpStep.Delay, 500)
  67. .Run(CAPumpStep.CheckRunning, CheckCAPumpRunning, _delay_1ms)
  68. .Delay(CAPumpStep.FlowDelay, _flowFaultHoldOffTime)
  69. .Run(CAPumpStep.CheckFlow, CheckAllFlow, _delay_1ms)
  70. .End(CAPumpStep.End, NullFun, _delay_1ms);
  71. return Runner.Status;
  72. }
  73. /// <summary>
  74. /// Pump Speed
  75. /// </summary>
  76. /// <param name="speed"></param>
  77. /// <returns></returns>
  78. private bool CAPumpSpeed(double speed)
  79. {
  80. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_SPEED}");
  81. return BeckhoffIOManager.Instance.WriteIoValue(ioName, speed);
  82. }
  83. /// <summary>
  84. /// Pump Enable
  85. /// </summary>
  86. /// <param name="speed"></param>
  87. /// <returns></returns>
  88. private bool CAPumpEnable()
  89. {
  90. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
  91. return BeckhoffIOManager.Instance.WriteIoValue(ioName, true);
  92. }
  93. /// <summary>
  94. /// Pump disable
  95. /// </summary>
  96. /// <returns></returns>
  97. private bool CAPumpDisable()
  98. {
  99. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CA_PUMP_ENABLE}");
  100. return BeckhoffIOManager.Instance.WriteIoValue(ioName, false);
  101. }
  102. /// <summary>
  103. /// 检验CA Running Sensor
  104. /// </summary>
  105. /// <returns></returns>
  106. private bool CheckCAPumpRunning()
  107. {
  108. if(!_device.ReservoirData.CaPumpRunning)
  109. {
  110. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "CA Pump Running Sensor is false");
  111. return false;
  112. }
  113. return true;
  114. }
  115. /// <summary>
  116. /// 检验所有流量
  117. /// </summary>
  118. /// <returns></returns>
  119. private bool CheckAllFlow()
  120. {
  121. double flow = _device.ReservoirData.CaFlow;
  122. if(flow<=_caMainFlowFaultLow)
  123. {
  124. CAPumpDisable();
  125. DisableHed();
  126. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {flow} is not over {_caMainFlowFaultLow}");
  127. return false;
  128. }
  129. else
  130. {
  131. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {flow} is over {_caMainFlowFaultLow}");
  132. }
  133. return true;
  134. }
  135. private void DisableHed()
  136. {
  137. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(Module);
  138. if (!string.IsNullOrEmpty(reservoirItem.TCID))
  139. {
  140. TemperatureController temperatureController = DEVICE.GetDevice<TemperatureController>(reservoirItem.TCID);
  141. temperatureController.DisableOperation("",null);
  142. }
  143. }
  144. /// <summary>
  145. /// 启动
  146. /// </summary>
  147. /// <param name="objs"></param>
  148. /// <returns></returns>
  149. public RState Start(params object[] objs)
  150. {
  151. _device = DEVICE.GetDevice<ReservoirDevice>(Module);
  152. _caPumpSpeed = SC.GetValue<double>("Reservoir.CADefaultPumpSpeed");
  153. _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
  154. _caMainFlowFaultLow = SC.GetValue<double>($"Reservoir.{Module}.CAMainFlowFaultLow");
  155. _caOpenValveCount = 0;
  156. return Runner.Start(Module, "CA Pump On");
  157. }
  158. }
  159. }