VpwVentPrewetRoutine.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 Aitex.Core.Util;
  6. using MECF.Framework.Common.Alarm;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.RecipeCenter;
  9. using MECF.Framework.Common.Routine;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using PunkHPX8_Core;
  12. using PunkHPX8_RT.Devices.AXIS;
  13. using PunkHPX8_RT.Devices.VpwCell;
  14. using PunkHPX8_RT.Devices.VpwMain;
  15. using PunkHPX8_RT.Modules.VpwMain;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace PunkHPX8_RT.Modules.VpwCell
  23. {
  24. public class VpwVentPrewetRoutine : RoutineBase, IRoutine
  25. {
  26. private enum PrepareStep
  27. {
  28. OpenVentValve,
  29. CheckLidReleaseVacuum,
  30. CloseVentValve,
  31. OpenCellValve,
  32. LoopStart,
  33. LoopRun,
  34. LoopEnd,
  35. End
  36. }
  37. #region 内部变量
  38. /// <summary>
  39. /// recipe
  40. /// </summary>
  41. private VpwRecipe _recipe;
  42. /// <summary>
  43. /// 设备
  44. /// </summary>
  45. private VpwCellDevice _vpwCellDevice;
  46. /// <summary>
  47. /// Main设备
  48. /// </summary>
  49. private VpwMainDevice _mainDevice;
  50. /// <summary>
  51. /// Lid Release Pressure
  52. /// </summary>
  53. private int _lidReleasePressure = 730;
  54. /// <summary>
  55. /// Lid Release Pressure
  56. /// </summary>
  57. private int _lidReleasePressureTimeout = 10000;
  58. /// <summary>
  59. /// 总时长
  60. /// </summary>
  61. private int _totalMicrosecond = 0;
  62. /// <summary>
  63. /// 步骤
  64. /// </summary>
  65. private int _stepIndex = 0;
  66. /// <summary>
  67. /// 启动步骤时间
  68. /// </summary>
  69. private DateTime _startStepTime = DateTime.Now;
  70. #endregion
  71. /// <summary>
  72. /// 构造函数
  73. /// </summary>
  74. /// <param name="module"></param>
  75. public VpwVentPrewetRoutine(string module) : base(module)
  76. {
  77. }
  78. /// <summary>
  79. /// 中止
  80. /// </summary>
  81. public void Abort()
  82. {
  83. Runner.Stop("Manual abort");
  84. }
  85. /// <summary>
  86. /// 监控
  87. /// </summary>
  88. /// <returns></returns>
  89. public RState Monitor()
  90. {
  91. Runner.Run(PrepareStep.OpenVentValve, OpenVentValve, _delay_1ms)
  92. .Wait(PrepareStep.CheckLidReleaseVacuum, CheckLidReleaseVacuum, _lidReleasePressureTimeout)
  93. .Run(PrepareStep.CloseVentValve, CloseVentValve, _delay_1ms)
  94. .Run(PrepareStep.OpenCellValve,OpenCellValve,_delay_1ms)
  95. .LoopStart(PrepareStep.LoopStart,"Loop Step",_recipe.VentRinseStep.Count,NullFun,_delay_1ms)
  96. .LoopRunWithStopStatus(PrepareStep.LoopRun, CheckStepComplete, () => { return false; }, _totalMicrosecond + 60 * 1000)//总时长再延迟1分种
  97. .LoopEnd(PrepareStep.LoopEnd,NullFun,_delay_1ms)
  98. .End(PrepareStep.End,NullFun,_delay_1ms);
  99. return Runner.Status;
  100. }
  101. /// <summary>
  102. /// 检验Lid Release真空数值
  103. /// </summary>
  104. /// <returns></returns>
  105. private bool CheckLidReleaseVacuum()
  106. {
  107. double vacuumValue = _vpwCellDevice.CommonData.VacuumPressure;
  108. return vacuumValue <= _lidReleasePressure;
  109. }
  110. /// <summary>
  111. /// open vent valve
  112. /// </summary>
  113. /// <returns></returns>
  114. private bool OpenVentValve()
  115. {
  116. bool result = _vpwCellDevice.VentValveOn();
  117. if (!result)
  118. {
  119. NotifyError(eEvent.ERR_VPW, "open vent valve failed", 0);
  120. }
  121. return result;
  122. }
  123. /// <summary>
  124. /// close vent valve
  125. /// </summary>
  126. /// <returns></returns>
  127. private bool CloseVentValve()
  128. {
  129. bool result = _vpwCellDevice.VentValveOff();
  130. if (!result)
  131. {
  132. NotifyError(eEvent.ERR_VPW, "close vent valve failed", 0);
  133. }
  134. return result;
  135. }
  136. /// <summary>
  137. /// 打开相应的cell valve
  138. /// </summary>
  139. /// <returns></returns>
  140. private bool OpenCellValve()
  141. {
  142. int count = 0;
  143. int enableCount = 0;
  144. if (_recipe.VentPrewetDripEnable)
  145. {
  146. count += _vpwCellDevice.FlowDripOn()?1:0;
  147. enableCount++;
  148. }
  149. if (_recipe.VentPrewetLargeEnable)
  150. {
  151. count += _vpwCellDevice.FlowLargeOn() ? 1 : 0;
  152. enableCount++;
  153. }
  154. if (_recipe.VentPrewetSmallEnable)
  155. {
  156. count += _vpwCellDevice.FlowSmallOn() ? 1 : 0;
  157. enableCount++;
  158. }
  159. bool result= count == enableCount;
  160. if (!result)
  161. {
  162. NotifyError(eEvent.ERR_VPW, "open cell valve failed", 0);
  163. }
  164. foreach (var item in _recipe.VentRinseStep)
  165. {
  166. _totalMicrosecond += item.DurationSeconds * 1000;
  167. }
  168. _startStepTime = DateTime.Now;
  169. _stepIndex = 0;
  170. return result;
  171. }
  172. /// <summary>
  173. /// 检验步骤是否完成
  174. /// </summary>
  175. /// <returns></returns>
  176. private bool CheckStepComplete()
  177. {
  178. _mainDevice.CellFlow = _vpwCellDevice.CommonData.DiwFlow;
  179. if (_stepIndex >= _recipe.VentRinseStep.Count)
  180. {
  181. LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} is over step count {_recipe.VentRinseStep.Count}");
  182. return true;
  183. }
  184. int length = _recipe.VentRinseStep[_stepIndex].DurationSeconds;
  185. if (DateTime.Now.Subtract(_startStepTime).TotalSeconds >= length)
  186. {
  187. _stepIndex++;
  188. _startStepTime = DateTime.Now;
  189. if (_stepIndex >= _recipe.VentRinseStep.Count)
  190. {
  191. LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} is over step count {_recipe.VentRinseStep.Count}");
  192. return true;
  193. }
  194. bool result = _vpwCellDevice.ChangeRotationSpeed(_recipe.VentRinseStep[_stepIndex].RotationSpeed*6);
  195. if (result)
  196. {
  197. LOG.WriteLog(eEvent.INFO_VPW, Module, $"vent step {_stepIndex} complete");
  198. }
  199. return result;
  200. }
  201. int firstDelay = SC.GetValue<int>($"{Module}.FlowCheckDelay") * 1000;
  202. if (DateTime.Now.Subtract(_startStepTime).TotalMilliseconds >= firstDelay)
  203. {
  204. bool abnormal = CheckDisable();
  205. if (abnormal)
  206. {
  207. return false;
  208. }
  209. }
  210. return false;
  211. }
  212. /// <summary>
  213. /// 检验数据
  214. /// </summary>
  215. /// <returns></returns>
  216. private bool CheckDisable()
  217. {
  218. double flow = _vpwCellDevice.CommonData.DiwFlow;
  219. double lowError = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowErrorPercent / 100);
  220. double upError = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowErrorPercent / 100);
  221. double lowWarn = _recipe.VentPrewetFlowSetPoint * (1 - (double)_recipe.VentPrewetFlowWarningPercent / 100);
  222. double upWarn = _recipe.VentPrewetFlowSetPoint * (1 + (double)_recipe.VentPrewetFlowWarningPercent / 100);
  223. if (flow<lowError)
  224. {
  225. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is less than {lowError} ", 0);
  226. Abort();
  227. return true;
  228. }
  229. if (flow > upError)
  230. {
  231. NotifyError(eEvent.ERR_VPW, $"{Module} cell flow {flow} is up than {upError} ", 0);
  232. Abort();
  233. return true;
  234. }
  235. if ((flow <= upError && flow >= upWarn) || (flow >= lowError && flow <= lowWarn))
  236. {
  237. string str = $"{Module} cell flow {flow} is in warning";
  238. if (AlarmListManager.Instance.AddWarn(Module, $"{Module} cell flow", str))
  239. {
  240. LOG.WriteLog(eEvent.WARN_VPW, Module, str);
  241. }
  242. }
  243. bool isSimulatorMode = SC.GetValue<bool>("System.IsSimulatorMode");
  244. if (!isSimulatorMode)
  245. {
  246. if (!_vpwCellDevice.CheckRotationRunning())
  247. {
  248. NotifyError(eEvent.ERR_VPW, $"{Module} rotation is stopped", 0);
  249. Abort();
  250. return true;
  251. }
  252. }
  253. return false;
  254. }
  255. /// <summary>
  256. /// 启动
  257. /// </summary>
  258. /// <param name="objs"></param>
  259. /// <returns></returns>
  260. public RState Start(params object[] objs)
  261. {
  262. _recipe=(VpwRecipe)objs[0];
  263. _vpwCellDevice = DEVICE.GetDevice<VpwCellDevice>(Module);
  264. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  265. _lidReleasePressure = SC.GetValue<int>($"{Module}.LidReleasePressure");
  266. _lidReleasePressureTimeout = SC.GetValue<int>($"{Module}.LidReleasePressureTimeout");
  267. _totalMicrosecond = 0;
  268. _stepIndex = 0;
  269. return Runner.Start(Module, $"{Module} vent prewet");
  270. }
  271. /// <summary>
  272. /// 重试
  273. /// </summary>
  274. /// <param name="step"></param>
  275. public RState Retry(int step)
  276. {
  277. if (_recipe == null)
  278. {
  279. NotifyError(eEvent.ERR_VPW, "recipe is null", -1);
  280. return RState.Failed;
  281. }
  282. List<Enum> preStepIds = new List<Enum>();
  283. return Runner.Retry(PrepareStep.OpenVentValve, preStepIds, Module, "Vent Prewet Retry");
  284. }
  285. }
  286. }