ANPumpOnRoutine.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. Delay,
  23. CheckFlow,
  24. End
  25. }
  26. #region 内部变量
  27. /// <summary>
  28. /// 默认泵速
  29. /// </summary>
  30. private double _anPumpSpeed = 5000;
  31. /// <summary>
  32. /// flow fault hold off时长
  33. /// </summary>
  34. private int _flowFaultHoldOffTime = 10000;
  35. /// <summary>
  36. /// 阳极最小流量
  37. /// </summary>
  38. private double _anMinFlow = 0.2;
  39. /// <summary>
  40. /// Reservoir设备
  41. /// </summary>
  42. private DMReservoirDevice _device;
  43. #endregion
  44. /// <summary>
  45. /// 构造函数
  46. /// </summary>
  47. /// <param name="module"></param>
  48. public ANPumpOnRoutine(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(ANPumpStep.PumpSpeed, () => { return ANPumpSpeed(_anPumpSpeed); }, _delay_1ms)
  65. .Delay(ANPumpStep.Delay, _flowFaultHoldOffTime)
  66. .Run(ANPumpStep.CheckFlow,CheckAllFlow,_delay_1ms)
  67. .End(ANPumpStep.End, NullFun, _delay_1ms);
  68. return Runner.Status;
  69. }
  70. /// <summary>
  71. /// Pump Speed
  72. /// </summary>
  73. /// <param name="speed"></param>
  74. /// <returns></returns>
  75. private bool ANPumpSpeed(double speed)
  76. {
  77. return _device.AnPumpSpeed(speed);
  78. }
  79. /// <summary>
  80. /// 检验所有流量
  81. /// </summary>
  82. /// <returns></returns>
  83. private bool CheckAllFlow()
  84. {
  85. double anTotalFlow = _device.ReservoirData.AnFlow;
  86. if(anTotalFlow<=_anMinFlow)
  87. {
  88. _device.AnPumpOff();
  89. LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, $"total flow {anTotalFlow} is not over {_anMinFlow}");
  90. return false;
  91. }
  92. else
  93. {
  94. LOG.WriteLog(eEvent.INFO_RESERVOIR, Module, $"total flow {anTotalFlow} is over {_anMinFlow}");
  95. return true;
  96. }
  97. }
  98. /// <summary>
  99. /// 启动
  100. /// </summary>
  101. /// <param name="objs"></param>
  102. /// <returns></returns>
  103. public RState Start(params object[] objs)
  104. {
  105. _device = DEVICE.GetDevice<DMReservoirDevice>(Module);
  106. _anPumpSpeed = SC.GetValue<double>("Reservoir.ANDefaultPumpSpeed");
  107. _flowFaultHoldOffTime = SC.GetValue<int>($"Reservoir.{Module}.FlowFaultHoldOffTime");
  108. return Runner.Start(Module, "AN Pump On");
  109. }
  110. }
  111. }