CompactMembranFillRoutine.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 CyberX8_Core;
  6. using CyberX8_RT.Devices.Reservoir;
  7. using MECF.Framework.Common.Routine;
  8. using MECF.Framework.Common.ToolLayout;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace CyberX8_RT.Devices.Metal
  15. {
  16. public class CompactMembranFillRoutine : RoutineBase, IRoutine
  17. {
  18. private enum ANFillStep
  19. {
  20. ANPump,
  21. ANFill,
  22. Delay,
  23. CheckANLimitFlow,
  24. End,
  25. }
  26. #region 常量
  27. private const string A = "A";
  28. private const string FILLING = "Filling";
  29. private const double AN_FLOW_LIMIT = 0.2;
  30. #endregion
  31. #region 内部变量
  32. /// <summary>
  33. /// 面
  34. /// </summary>
  35. private string _side = "";
  36. /// <summary>
  37. /// Reservoir设备对象
  38. /// </summary>
  39. private CompactMembranReservoirDevice _reservoirDevice;
  40. /// <summary>
  41. /// Metal设备对象
  42. /// </summary>
  43. private CompactMembranMetalDevice _metalDevice;
  44. /// <summary>
  45. /// 延迟5S
  46. /// </summary>
  47. private int _delay = 5000;
  48. /// <summary>
  49. /// AN Pump
  50. /// </summary>
  51. private bool _anIsPumpOn = false;
  52. #endregion
  53. /// <summary>
  54. /// 构造函数
  55. /// </summary>
  56. /// <param name="module"></param>
  57. public CompactMembranFillRoutine(string module,string side) : base(module)
  58. {
  59. _side = side;
  60. }
  61. /// <summary>
  62. /// 中止
  63. /// </summary>
  64. public void Abort()
  65. {
  66. Runner.Stop("Manual Abort");
  67. }
  68. /// <summary>
  69. /// 监控
  70. /// </summary>
  71. /// <returns></returns>
  72. public RState Monitor()
  73. {
  74. Runner.RunIf(ANFillStep.ANPump,!_anIsPumpOn, ANPumpOn,_delay_1ms)
  75. .Run(ANFillStep.ANFill, ANFillOn, _delay_1ms)
  76. .Delay(ANFillStep.Delay, _delay)
  77. .Run(ANFillStep.CheckANLimitFlow, CheckAnLimitFlow, _delay_1ms)
  78. .End(ANFillStep.End, UpdateAnFlowStatus, _delay_1ms);
  79. return Runner.Status;
  80. }
  81. /// <summary>
  82. /// AN Pump On
  83. /// </summary>
  84. /// <returns></returns>
  85. private bool ANPumpOn()
  86. {
  87. return _reservoirDevice.AnPumpOnOperation("", null);
  88. }
  89. /// <summary>
  90. /// AN Fill On
  91. /// </summary>
  92. /// <returns></returns>
  93. private bool ANFillOn()
  94. {
  95. bool result = false;
  96. if(_side==A)
  97. {
  98. result= _metalDevice.AnSideAFillOn("", null);
  99. }
  100. else
  101. {
  102. result = _metalDevice.AnSideBFillOn("", null);
  103. }
  104. return result;
  105. }
  106. /// <summary>
  107. /// 校验流量是否超过最小值
  108. /// </summary>
  109. /// <returns></returns>
  110. private bool CheckAnLimitFlow()
  111. {
  112. double anFlow = 0;
  113. if (_side == A)
  114. {
  115. anFlow = _metalDevice.ANACellFlow.CounterValue;
  116. }
  117. else
  118. {
  119. anFlow=_metalDevice.ANBCellFlow.CounterValue;
  120. }
  121. if(anFlow<=AN_FLOW_LIMIT)
  122. {
  123. LOG.WriteLog(eEvent.ERR_METAL, Module, $"AN Flow {anFlow} is not over {AN_FLOW_LIMIT}");
  124. return false;
  125. }
  126. return true;
  127. }
  128. /// <summary>
  129. /// 更新AN Flow状态
  130. /// </summary>
  131. /// <returns></returns>
  132. private bool UpdateAnFlowStatus()
  133. {
  134. if (_side == A)
  135. {
  136. _metalDevice.ANACellFlow.Status = "Filling";
  137. }
  138. return true;
  139. }
  140. /// <summary>
  141. /// 启动
  142. /// </summary>
  143. /// <param name="objs"></param>
  144. /// <returns></returns>
  145. public RState Start(params object[] objs)
  146. {
  147. _reservoirDevice = GetReservoirDevice();
  148. _anIsPumpOn = _reservoirDevice.ReservoirData.ANPump != 0;
  149. _metalDevice = DEVICE.GetDevice<CompactMembranMetalDevice>(Module);
  150. if (!CheckPreCondition())
  151. {
  152. return RState.Failed;
  153. }
  154. return Runner.Start(Module, "Start AN Fill");
  155. }
  156. /// <summary>
  157. /// 获取Reservoir设备
  158. /// </summary>
  159. /// <returns></returns>
  160. private CompactMembranReservoirDevice GetReservoirDevice()
  161. {
  162. string reservoir = ReservoirItemManager.Instance.GetReservoirByMetal(Module);
  163. return DEVICE.GetDevice<CompactMembranReservoirDevice>(reservoir);
  164. }
  165. /// <summary>
  166. /// 校验前置条件
  167. /// </summary>
  168. /// <returns></returns>
  169. private bool CheckPreCondition()
  170. {
  171. if(_reservoirDevice==null)
  172. {
  173. LOG.WriteLog(eEvent.ERR_METAL, Module, "Reservoir is null");
  174. return false;
  175. }
  176. return true;
  177. }
  178. }
  179. }