PrewetKeepWetRoutine.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Devices.LinMot;
  6. using CyberX8_RT.Devices.Prewet;
  7. using MECF.Framework.Common.Alarm;
  8. using MECF.Framework.Common.Routine;
  9. namespace CyberX8_RT.Modules.Prewet
  10. {
  11. public class PrewetKeepWetRoutine : RoutineBase, IRoutine
  12. {
  13. private enum KeepwetStep
  14. {
  15. Idle_KeepwetPrepare,
  16. Idle_KeepwetPrepareWait,
  17. Idle_KeepWetStart,
  18. Idle_KeepWetScan,
  19. Idle_KeepWetPause,
  20. End
  21. }
  22. #region 内部变量
  23. /// <summary>
  24. /// prewet设备
  25. /// </summary>
  26. private PrewetDevice _prewetDevice;
  27. /// <summary>
  28. /// linmot axis
  29. /// </summary>
  30. private LinMotAxis _linMotAxis;
  31. #endregion
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. /// <param name="module"></param>
  36. public PrewetKeepWetRoutine(string module,LinMotAxis linMotAxis) : base(module)
  37. {
  38. _linMotAxis= linMotAxis;
  39. }
  40. /// <summary>
  41. /// 中止
  42. /// </summary>
  43. public void Abort()
  44. {
  45. _linMotAxis.StopOperation("", null);
  46. if (_prewetDevice != null)
  47. {
  48. _prewetDevice.PumpValveClose();
  49. }
  50. Runner.Stop("Manual Abort");
  51. }
  52. /// <summary>
  53. /// 监控
  54. /// </summary>
  55. /// <returns></returns>
  56. public RState Monitor()
  57. {
  58. Runner.Run(KeepwetStep.Idle_KeepwetPrepare, ResetLinmot, _delay_1ms)
  59. .WaitWithStopCondition(KeepwetStep.Idle_KeepwetPrepareWait, CheckResetLinmotEndStatus, CheckResetLinmotStopStatus)
  60. .Run(KeepwetStep.Idle_KeepWetStart, ExecuteWetScan, _delay_1ms)
  61. .WaitWithStopCondition(KeepwetStep.Idle_KeepWetScan,CheckLinmotScanEndStatus,CheckLinmotScanStopStatus)
  62. .Run(KeepwetStep.Idle_KeepWetPause, KeepWetComplete, _delay_1ms)
  63. .End(KeepwetStep.End, NullFun, _delay_1ms);
  64. return Runner.Status;
  65. }
  66. /// <summary>
  67. /// Reset Linmot
  68. /// </summary>
  69. /// <param name="param"></param>
  70. /// <returns></returns>
  71. private bool ResetLinmot()
  72. {
  73. bool result = _linMotAxis.ResetOperation("", false);
  74. if (!result)
  75. {
  76. return false;
  77. }
  78. return true;
  79. }
  80. /// <summary>
  81. /// 检验Reset Linmot状态
  82. /// </summary>
  83. /// <param name="param"></param>
  84. /// <returns></returns>
  85. private bool CheckResetLinmotEndStatus()
  86. {
  87. return _linMotAxis.Status == RState.End;
  88. }
  89. /// <summary>
  90. /// 检验Reset Linmot停止状态
  91. /// </summary>
  92. /// <returns></returns>
  93. private bool CheckResetLinmotStopStatus()
  94. {
  95. return _linMotAxis.Status == RState.Failed || _linMotAxis.Status == RState.Timeout;
  96. }
  97. /// <summary>
  98. /// execute Keep Wet Scan
  99. /// </summary>
  100. /// <param name="param"></param>
  101. /// <returns></returns>
  102. private bool ExecuteWetScan()
  103. {
  104. bool pumpValveResult = _prewetDevice.PumpValveOpen();
  105. if (!pumpValveResult)
  106. {
  107. LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve open error");
  108. return false;
  109. }
  110. //bool pumpEnableResult = _prewetDevice.PumpEnableOperation("", null);
  111. //bool pumpEnableResult = _prewetDevice.PumpEnable();
  112. //if (!pumpEnableResult)
  113. //{
  114. // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump enable error");
  115. // return false;
  116. //}
  117. bool result = _linMotAxis.StartPosition("", new object[] { 1 });
  118. if (!result)
  119. {
  120. return false;
  121. }
  122. return true;
  123. }
  124. /// <summary>
  125. /// 检验Linomot扫描结束状态
  126. /// </summary>
  127. /// <returns></returns>
  128. private bool CheckLinmotScanEndStatus()
  129. {
  130. return _linMotAxis.Status == RState.End;
  131. }
  132. /// <summary>
  133. /// 检验Linmot Scan停止状态
  134. /// </summary>
  135. /// <returns></returns>
  136. private bool CheckLinmotScanStopStatus()
  137. {
  138. bool result=_linMotAxis.Status==RState.Failed||_linMotAxis.Status==RState.Timeout;
  139. if(!result)
  140. {
  141. //Pressure
  142. if (_prewetDevice.PrewetPumpData.PumpPressureData.IsError)
  143. {
  144. _linMotAxis.StopOperation("", null);
  145. _prewetDevice.PumpValveClose();
  146. LOG.WriteLog(eEvent.ERR_PREWET, Module, $"Pump pressure {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in error");
  147. return true;
  148. }
  149. else if (_prewetDevice.PrewetPumpData.PumpPressureData.IsWarning)
  150. {
  151. string str = $"Pump pressure {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in warning";
  152. if (AlarmListManager.Instance.AddWarn(Module, "Pump Pressure", str))
  153. {
  154. LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
  155. }
  156. }
  157. //Flow
  158. if (_prewetDevice.PrewetPumpData.PumpFlowData.IsError)
  159. {
  160. LOG.WriteLog(eEvent.ERR_PREWET, Module, $"Pump flow {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in error");
  161. _linMotAxis.StopOperation("", null);
  162. _prewetDevice.PumpValveClose();
  163. return true;
  164. }
  165. else if (_prewetDevice.PrewetPumpData.PumpFlowData.IsWarning)
  166. {
  167. string str = $"Pump flow {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in warning";
  168. if (AlarmListManager.Instance.AddWarn(Module, "Pump Flow", str))
  169. {
  170. LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
  171. }
  172. }
  173. return false;
  174. }
  175. else
  176. {
  177. _prewetDevice.PumpValveClose();
  178. return true;
  179. }
  180. }
  181. /// <summary>
  182. /// Wait execute WetScan
  183. /// </summary>
  184. /// <param name="param"></param>
  185. /// <returns></returns>
  186. private bool WaitExecuteWetScan(object param)
  187. {
  188. //linmot完成一次scan
  189. if (_linMotAxis.Status == RState.End)
  190. {
  191. return true;
  192. }
  193. return false;
  194. }
  195. /// <summary>
  196. /// Keep wet scan完成
  197. /// </summary>
  198. /// <param name="param"></param>
  199. /// <returns></returns>
  200. private bool KeepWetComplete()
  201. {
  202. bool result = _prewetDevice.PumpValveClose();
  203. if (!result)
  204. {
  205. LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve close error");
  206. return false;
  207. }
  208. result = _linMotAxis.SwitchOff();
  209. if (!result)
  210. {
  211. LOG.WriteLog(eEvent.ERR_PREWET, Module, "linmot disable error");
  212. return false;
  213. }
  214. return true;
  215. }
  216. /// <summary>
  217. /// 启动
  218. /// </summary>
  219. /// <param name="objs"></param>
  220. /// <returns></returns>
  221. public RState Start(params object[] objs)
  222. {
  223. _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module);
  224. return Runner.Start(Module, "Start Keepwet");
  225. }
  226. }
  227. }