CAPumpOnRoutine.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.Routine;
  7. using MECF.Framework.Common.ToolLayout;
  8. using MECF.Framework.Common.TwinCat;
  9. using PunkHPX8_Core;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace PunkHPX8_RT.Devices.Reservoir
  16. {
  17. public class CAPumpOnRoutine : RoutineBase, IRoutine
  18. {
  19. private enum CAPumpStep
  20. {
  21. PumpSpeed,
  22. PumpEnable,
  23. Delay,
  24. CheckRunning,
  25. FlowDelay,
  26. CheckFlow,
  27. End
  28. }
  29. #region 常量
  30. private const string CA_PUMP_SPEED = "CAPumpSpeed";
  31. private const string CA_PUMP_RUNNING = "CAPumpRunning";
  32. private const string CA_HED_FLOW = "CAHedFlow";
  33. private const string CA_PUMP_ENABLE = "CAPumpEnable";
  34. private const string CA_BY_PASS = "CAByPass";
  35. #endregion
  36. #region 内部变量
  37. private double _caPumpSpeed = 5000;
  38. private int _flowFaultHoldOffTime = 10000;
  39. private double _caMainFlowFaultLow = 5.0;
  40. private double _caHedFlowLowLimit = 3.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. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {flow} is not over {_caMainFlowFaultLow}");
  126. return false;
  127. }
  128. else
  129. {
  130. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {flow} is over {_caMainFlowFaultLow}");
  131. }
  132. return true;
  133. }
  134. /// <summary>
  135. /// 启动
  136. /// </summary>
  137. /// <param name="objs"></param>
  138. /// <returns></returns>
  139. public RState Start(params object[] objs)
  140. {
  141. _device = DEVICE.GetDevice<ReservoirDevice>(Module);
  142. _caPumpSpeed = SC.GetValue<double>("Reservoir.CADefaultPumpSpeed");
  143. _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
  144. _caMainFlowFaultLow = SC.GetValue<double>($"Reservoir.{Module}.CAMainFlowFaultLow");
  145. _caHedFlowLowLimit = SC.GetValue<double>($"Reservoir.{Module}.HEDFlowLowLimit");
  146. _caOpenValveCount = 0;
  147. return Runner.Start(Module, "CA Pump On");
  148. }
  149. }
  150. }