PrewetProcessRoutine.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.RecipeCenter;
  9. using MECF.Framework.Common.Routine;
  10. namespace CyberX8_RT.Modules.Prewet
  11. {
  12. public class PrewetProcessRoutine : RoutineBase, IRoutine
  13. {
  14. private enum ProcessStep
  15. {
  16. Process_Start,
  17. Process_StartScanning,
  18. Process_WaitPumpOnEnd,
  19. Process_WaitFirstScanComplete,
  20. Process_WaitScanComplete,
  21. Process_Complete,
  22. End
  23. }
  24. #region 内部变量
  25. /// <summary>
  26. /// prewet设备
  27. /// </summary>
  28. private PrewetDevice _prewetDevice;
  29. /// <summary>
  30. /// linmot axis
  31. /// </summary>
  32. private LinMotAxis _linMotAxis;
  33. /// <summary>
  34. /// Prewet recipe
  35. /// </summary>
  36. private PwtRecipe _recipe;
  37. #endregion
  38. /// <summary>
  39. /// 构造函数
  40. /// </summary>
  41. /// <param name="module"></param>
  42. public PrewetProcessRoutine(string module, LinMotAxis linMotAxis) : base(module)
  43. {
  44. this._linMotAxis = linMotAxis;
  45. }
  46. /// <summary>
  47. /// 中止
  48. /// </summary>
  49. public void Abort()
  50. {
  51. _linMotAxis.StopOperation("", null);
  52. _prewetDevice.PumpValveClose();
  53. Runner.Stop("Manual Abort");
  54. }
  55. /// <summary>
  56. /// 监控
  57. /// </summary>
  58. /// <returns></returns>
  59. public RState Monitor()
  60. {
  61. Runner.Run(ProcessStep.Process_Start, NullFun, _delay_1ms)
  62. .Run(ProcessStep.Process_StartScanning, ProcessStartScan, _delay_1ms)
  63. .WaitWithStopCondition(ProcessStep.Process_WaitPumpOnEnd, WaitProcessEndStatus, CheckProcessFailedStatus, _delay_60s)
  64. .Run(ProcessStep.Process_WaitFirstScanComplete, StartScan, _delay_1ms)
  65. .WaitWithStopCondition(ProcessStep.Process_WaitScanComplete, WaitScanComplete, CheckScanStopEnd)
  66. .Run(ProcessStep.Process_Complete, ProcessComplete, CheckPumpValveClose,_delay_3s)
  67. .End(ProcessStep.End, NullFun, _delay_1ms);
  68. return Runner.Status;
  69. }
  70. /// <summary>
  71. /// Process Start Scan
  72. /// </summary>
  73. /// <returns></returns>
  74. private bool ProcessStartScan()
  75. {
  76. bool result = _linMotAxis.ResetOperation("", false);
  77. if (!result)
  78. {
  79. LOG.WriteLog(eEvent.ERR_PREWET, Module, "reset linmot error");
  80. return false;
  81. }
  82. //_prewetDevice.PrewetPumpData.PumpSpeedAuto = true;
  83. //更新Pump status状态
  84. //string statusContent = _prewetDevice.PrewetPumpData.PumpStatus ? "On" : "Off";
  85. //_prewetDevice.PrewetPumpData.PumpModel = "Auto";
  86. //_prewetDevice.PrewetPumpData.PumpStatusContent = $"{_prewetDevice.PrewetPumpData.PumpModel}: {statusContent}";
  87. //result = _prewetDevice.PumpSpeed();
  88. //if (!result)
  89. //{
  90. // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump speed error");
  91. // return false;
  92. //}
  93. bool pumpEnableResult = _prewetDevice.PumpValveOpen();
  94. if (!pumpEnableResult)
  95. {
  96. LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve open error");
  97. return false;
  98. }
  99. return true;
  100. }
  101. /// <summary>
  102. /// 等待结束状态
  103. /// </summary>
  104. /// <returns></returns>
  105. private bool WaitProcessEndStatus()
  106. {
  107. if (_linMotAxis.Status == RState.End)
  108. {
  109. return true;
  110. }
  111. return false;
  112. }
  113. /// <summary>
  114. /// 检验错误状态
  115. /// </summary>
  116. /// <returns></returns>
  117. private bool CheckProcessFailedStatus()
  118. {
  119. //if (_prewetDevice.Status == RState.Failed)
  120. //{
  121. // LOG.WriteLog(eEvent.ERR_PREWET, Module, "prewet device status is error");
  122. // return true;
  123. //}
  124. if (_linMotAxis.Status == RState.Failed)
  125. {
  126. LOG.WriteLog(eEvent.ERR_PREWET, Module, "linmot status is error");
  127. return true;
  128. }
  129. return false;
  130. }
  131. /// <summary>
  132. /// 自动调速
  133. /// </summary>
  134. private bool StartAdjustSpeed()
  135. {
  136. //_prewetDevice.IsStartAutoSpeed = true;
  137. return true;
  138. }
  139. /// <summary>
  140. /// 开始Scan
  141. /// </summary>
  142. /// <param name="param"></param>
  143. /// <returns></returns>
  144. private bool StartScan()
  145. {
  146. if (!_linMotAxis.IsHomed)
  147. {
  148. LOG.WriteLog(eEvent.ERR_PREWET, Module, "limot is not ready");
  149. return false;
  150. }
  151. //if (!_prewetDevice.PrewetPumpData.PumpStatus)
  152. //{
  153. // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump status if off");
  154. // return false;
  155. //}
  156. bool result = _linMotAxis.StartPosition("", new object[] { _recipe.NumberOfScans });
  157. if (!result)
  158. {
  159. _prewetDevice.PumpValveClose();
  160. LOG.WriteLog(eEvent.ERR_PREWET, Module, "linmot start scan error");
  161. return false;
  162. }
  163. return result;
  164. }
  165. /// <summary>
  166. /// 等待Scan结束
  167. /// </summary>
  168. /// <param name="param"></param>
  169. /// <returns></returns>
  170. private bool WaitScanComplete()
  171. {
  172. //linmot完成一次scan
  173. if (_linMotAxis.Status == RState.End)
  174. {
  175. return true;
  176. }
  177. return false;
  178. }
  179. /// <summary>
  180. /// 检验Prewet停止状态
  181. /// </summary>
  182. /// <returns></returns>
  183. private bool CheckScanStopEnd()
  184. {
  185. if (_linMotAxis.Status == RState.Failed||_linMotAxis.Status==RState.Timeout)
  186. {
  187. _prewetDevice.PumpValveClose();
  188. return true;
  189. }
  190. //Pressure
  191. if (_prewetDevice.PrewetPumpData.PumpPressureData.IsError)
  192. {
  193. _linMotAxis.StopOperation("",null);
  194. _prewetDevice.PumpValveClose();
  195. LOG.WriteLog(eEvent.ERR_PREWET, Module, $"Pump pressure {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in error");
  196. return true;
  197. }
  198. else if (_prewetDevice.PrewetPumpData.PumpPressureData.IsWarning)
  199. {
  200. string str = $"Pump pressure {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in warning";
  201. if (AlarmListManager.Instance.AddWarn(Module, "Pump Pressure", str))
  202. {
  203. LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
  204. }
  205. }
  206. //Flow
  207. if (_prewetDevice.PrewetPumpData.PumpFlowData.IsError)
  208. {
  209. LOG.WriteLog(eEvent.ERR_PREWET, Module, $"Pump flow {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in error");
  210. _linMotAxis.StopOperation("", null);
  211. _prewetDevice.PumpValveClose();
  212. return true;
  213. }
  214. else if (_prewetDevice.PrewetPumpData.PumpFlowData.IsWarning)
  215. {
  216. string str = $"Pump flow {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in warning";
  217. if (AlarmListManager.Instance.AddWarn(Module, "Pump Flow", str))
  218. {
  219. LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
  220. }
  221. }
  222. return false;
  223. }
  224. /// <summary>
  225. /// Process scan完成
  226. /// </summary>
  227. /// <param name="param"></param>
  228. /// <returns></returns>
  229. private bool ProcessComplete()
  230. {
  231. bool result = _prewetDevice.PumpValveClose();
  232. if (!result)
  233. {
  234. LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve close error");
  235. return false;
  236. }
  237. //result = _prewetDevice.PumpDisable();
  238. //if (!result)
  239. //{
  240. // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump enable close");
  241. // return false;
  242. //}
  243. //bool result = _prewetDevice.PumpDisableOperation("pump disable",null);
  244. return true;
  245. }
  246. private bool CheckPumpValveClose()
  247. {
  248. bool result = !_prewetDevice.PrewetPumpData.PumpValve;
  249. return result;
  250. }
  251. /// <summary>
  252. /// 启动
  253. /// </summary>
  254. /// <param name="objs"></param>
  255. /// <returns></returns>
  256. public RState Start(params object[] objs)
  257. {
  258. //清除lotTrack数据
  259. _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module);
  260. _recipe = objs[0] as PwtRecipe;
  261. if (_recipe == null)
  262. {
  263. LOG.WriteLog(eEvent.ERR_PREWET, Module, "recipe is null");
  264. return RState.Failed;
  265. }
  266. return Runner.Start(Module, "Start Process Recipe");
  267. }
  268. }
  269. }