ANPumpOnRoutine.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 ANPumpOnRoutine : RoutineBase, IRoutine
  18. {
  19. private enum ANPumpStep
  20. {
  21. PumpSpeed,
  22. PumpEnable,
  23. Delay,
  24. CheckFlow,
  25. End
  26. }
  27. #region 内部变量
  28. /// <summary>
  29. /// 默认泵速
  30. /// </summary>
  31. private double _anPumpSpeed = 5000;
  32. /// <summary>
  33. /// flow fault hold off时长
  34. /// </summary>
  35. private int _flowFaultHoldOffTime = 10000;
  36. /// <summary>
  37. /// 阳极最小流量
  38. /// </summary>
  39. private double _anMinFlow = 0.2;
  40. /// <summary>
  41. /// Reservoir设备
  42. /// </summary>
  43. private DMReservoirDevice _device;
  44. #endregion
  45. /// <summary>
  46. /// 构造函数
  47. /// </summary>
  48. /// <param name="module"></param>
  49. public ANPumpOnRoutine(string module) : base(module)
  50. {
  51. }
  52. /// <summary>
  53. /// 中止
  54. /// </summary>
  55. public void Abort()
  56. {
  57. Runner.Stop("Manual abort");
  58. }
  59. /// <summary>
  60. /// 监控
  61. /// </summary>
  62. /// <returns></returns>
  63. public RState Monitor()
  64. {
  65. Runner.Run(ANPumpStep.PumpEnable, () => { return ANPumpEnable(); }, _delay_1ms)
  66. .Delay(ANPumpStep.Delay, _flowFaultHoldOffTime)
  67. .Run(ANPumpStep.CheckFlow,CheckAllFlow,_delay_1ms)
  68. .End(ANPumpStep.End, NullFun, _delay_1ms);
  69. return Runner.Status;
  70. }
  71. /// <summary>
  72. /// Pump Speed
  73. /// </summary>
  74. /// <param name="speed"></param>
  75. /// <returns></returns>
  76. private bool ANPumpSpeed(double speed)
  77. {
  78. return _device.AnPumpSpeed(speed);
  79. }
  80. /// <summary>
  81. /// Pump enable
  82. /// </summary>
  83. /// <param name="speed"></param>
  84. /// <returns></returns>
  85. private bool ANPumpEnable()
  86. {
  87. return _device.AnPumpOnOperation("",null);
  88. }
  89. /// <summary>
  90. /// 检验所有流量
  91. /// </summary>
  92. /// <returns></returns>
  93. private bool CheckAllFlow()
  94. {
  95. double anTotalFlow = _device.ReservoirData.AnFlow;
  96. if(anTotalFlow<=_anMinFlow)
  97. {
  98. _device.AnPumpOff();
  99. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {anTotalFlow} is not over {_anMinFlow}");
  100. return false;
  101. }
  102. else
  103. {
  104. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {anTotalFlow} is over {_anMinFlow}");
  105. return true;
  106. }
  107. }
  108. /// <summary>
  109. /// 启动
  110. /// </summary>
  111. /// <param name="objs"></param>
  112. /// <returns></returns>
  113. public RState Start(params object[] objs)
  114. {
  115. _device = DEVICE.GetDevice<DMReservoirDevice>(Module);
  116. _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
  117. return Runner.Start(Module, "AN Pump On");
  118. }
  119. }
  120. }