PrewetProcessRoutine.cs 10 KB

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