PrewetKeepWetRoutine.cs 7.6 KB

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