PMRoutineBase.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Virgo_DCommon;
  6. //using Virgo_D.Common;
  7. using Virgo_DRT.Devices;
  8. namespace Virgo_DRT.Modules.PMs
  9. {
  10. public enum MonitorStepState
  11. {
  12. Continue,
  13. Failed,
  14. Break,
  15. }
  16. class PMRoutineBase : ModuleRoutine
  17. {
  18. // ----------------------------Fields--------------------------
  19. //
  20. //private SCConfigItem scOpenGasValveTimeout = null;
  21. private int dOpenGasValveTimeout = 1; //1S
  22. //private SCConfigItem scCloseGasValveTimeout = null;
  23. public int dCloseGasValveTimeout = 2; //2s
  24. //private SCConfigItem scOpenCloseSlitValveTimeout = null;
  25. protected int valveOpenCloseTimeout = 2; //2s
  26. protected int _PressureTrip1 = 80;
  27. protected bool bUINotify;
  28. public static Guid RecipeRunGuid;
  29. protected readonly JetPM _chamber;
  30. // --------------------------Properties------------------------
  31. //
  32. public string Display { get; set; }
  33. // Constructor
  34. protected PMRoutineBase(JetPM chamber)
  35. {
  36. this.Module = chamber.Module.ToString();
  37. _chamber = chamber;
  38. bUINotify = true;
  39. dOpenGasValveTimeout = SC.GetValue<int>($"{Module}.OpenGasValveTimeout");
  40. dCloseGasValveTimeout = SC.GetValue<int>($"{Module}.TimeLimitOfCloseGasValve");
  41. valveOpenCloseTimeout = SC.GetValue<int>($"{Module}.OpenCloseSlitValveTimeout");
  42. }
  43. public Result CheckLid()
  44. {
  45. if (!_chamber.IsLidClosed)
  46. {
  47. this.Stop("Chamber 盖子必须关");
  48. return Result.FAIL;
  49. }
  50. return Result.RUN;
  51. }
  52. protected Result CheckSlitDoor()
  53. {
  54. if (!_chamber.IsSlitDoorClosed)
  55. {
  56. Stop("传送门必须关");
  57. return Result.FAIL;
  58. }
  59. return Result.RUN;
  60. }
  61. protected Result CheckDryPump()
  62. {
  63. if (!_chamber.IsPumpRunning)
  64. {
  65. Stop("泵没有启动");
  66. return Result.FAIL;
  67. }
  68. if (_chamber.HasPumpError)
  69. {
  70. Stop("泵状态有错误");
  71. return Result.FAIL;
  72. }
  73. return Result.RUN;
  74. }
  75. public void CheckThrottleValveFullOpen(int id)
  76. {
  77. bool execute()
  78. {
  79. Notify("完全打开蝶阀");
  80. _chamber.FullOpenTV();
  81. return true;
  82. }
  83. bool? Check1()
  84. {
  85. if (_chamber.TVPosition >= 98)
  86. {
  87. Notify("蝶阀已经完全打开");
  88. return true;
  89. }
  90. return false;
  91. }
  92. Tuple<bool, Result> ret = ExecuteAndWait(id, execute, Check1, 20 * 1000);
  93. if (ret.Item1)
  94. {
  95. if (ret.Item2 == Result.FAIL)
  96. {
  97. Stop("无法打开蝶阀");
  98. throw new RoutineFaildException();
  99. }
  100. if (ret.Item2 == Result.TIMEOUT)
  101. {
  102. Stop("启动蝶阀超时");
  103. throw new RoutineFaildException();
  104. }
  105. throw new RoutineBreakException();
  106. }
  107. }
  108. protected Result CheckCDA()
  109. {
  110. if (!_chamber.IsCDA_OK)
  111. {
  112. Stop("CDA 压力信号不正确");
  113. return Result.FAIL;
  114. }
  115. return Result.RUN;
  116. }
  117. protected void CloseAllValve(int id, int time)
  118. {
  119. bool execute()
  120. {
  121. Notify("关闭所有的阀门");
  122. _chamber.CloseValves();
  123. return true;
  124. }
  125. Tuple<bool, Result> ret = ExecuteAndWait(id, execute, () => true, time * 1000);
  126. if (ret.Item1)
  127. {
  128. if (ret.Item2 == Result.FAIL)
  129. {
  130. throw new RoutineFaildException();
  131. }
  132. if (ret.Item2 == Result.TIMEOUT)
  133. {
  134. throw new RoutineFaildException();
  135. }
  136. throw new RoutineBreakException();
  137. }
  138. }
  139. protected void OpenValve(int id, ValveType vlv, bool bOpen)
  140. {
  141. bool exec()
  142. {
  143. _chamber.OpenValve(vlv, bOpen);
  144. Notify($"{(bOpen ? "打开" : "关闭")} {vlv} 阀");
  145. return true;
  146. }
  147. var res = ExecuteAndWait(id, exec, () => true, 500);
  148. if (res.Item1)
  149. {
  150. throw new RoutineBreakException();
  151. }
  152. }
  153. protected void CheckATM2(int id, bool on, int time)
  154. {
  155. bool? check()
  156. {
  157. //if (!_chamber.IsATM)
  158. //{
  159. // Notify("ATM is OFF");
  160. //}
  161. return on ? _chamber.IsATM : !_chamber.IsATM;
  162. }
  163. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  164. {
  165. Notify($"等待 ATM 信号 {(on ? "ON" : "OFF")}");
  166. return true;
  167. }, check, time * 1000);
  168. if (ret.Item1)
  169. {
  170. if (ret.Item2 == Result.FAIL || ret.Item2 == Result.TIMEOUT)
  171. {
  172. Stop($"ATM 信号仍然 {(_chamber.IsATM ? "ON" : "OFF")}");
  173. throw new RoutineFaildException();
  174. }
  175. throw new RoutineBreakException();
  176. }
  177. }
  178. protected void CheckPressure(int id, int targetPressure, bool morethan, int time)
  179. {
  180. bool? Check1()
  181. {
  182. bool res = morethan ? _chamber.ChamberPressure > targetPressure : _chamber.ChamberPressure < targetPressure;
  183. if (res)
  184. {
  185. Notify($"压力已经到达 {targetPressure:N} mTorr");
  186. }
  187. return res;
  188. }
  189. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  190. {
  191. Notify($"等待压力{(morethan ? "上升" : "下降")} 到 {targetPressure:N} mTorr");
  192. return true;
  193. }, Check1, time * 1000);
  194. if (ret.Item1)
  195. {
  196. if (ret.Item2 == Result.FAIL)
  197. {
  198. Stop($"当前压力 [{_chamber.ChamberPressure}], 无法到达 [{targetPressure}]");
  199. throw new RoutineFaildException();
  200. }
  201. if (ret.Item2 == Result.TIMEOUT)
  202. {
  203. Stop($"检测压力超时, 当前压力 [{_chamber.ChamberPressure*0.001:F2}] Torr");
  204. throw new RoutineFaildException();
  205. }
  206. throw new RoutineBreakException();
  207. }
  208. }
  209. protected void CheckForeline(int id, uint target, int time)
  210. {
  211. bool Func()
  212. {
  213. Notify($"Check foreline pressure, 目标 {target} mTorr");
  214. return true;
  215. }
  216. bool? Check1()
  217. {
  218. return _chamber.ForelinePressure < target;
  219. }
  220. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, time * 1000);
  221. if (ret.Item1)
  222. {
  223. if (ret.Item2 == Result.FAIL)
  224. {
  225. throw new RoutineFaildException();
  226. }
  227. if (ret.Item2 == Result.TIMEOUT)
  228. {
  229. Stop($"检查Foreline 压力超时, 当前Foreline 压力值 {_chamber.ForelinePressure}");
  230. throw new RoutineFaildException();
  231. }
  232. throw new RoutineBreakException();
  233. }
  234. }
  235. protected void CheckVAC(int id, double targetPressure, int time)
  236. {
  237. bool? Check1()
  238. {
  239. if (_chamber.ChamberPressure < targetPressure)
  240. {
  241. Notify($"Pump below [{targetPressure}]");
  242. return true;
  243. }
  244. return false;
  245. }
  246. Tuple<bool, Result> ret = ExecuteAndWait(id, () => true, Check1, time * 1000);
  247. if (ret.Item1)
  248. {
  249. if (ret.Item2 == Result.FAIL)
  250. {
  251. throw new RoutineFaildException();
  252. }
  253. if (ret.Item2 == Result.TIMEOUT) //timeout
  254. {
  255. //Warning($"Can not pump to base pressure {target} in {time} seconds");
  256. throw new RoutineFaildException();
  257. }
  258. throw new RoutineBreakException();
  259. }
  260. }
  261. protected void CheckVAC(int id, int time)
  262. {
  263. Tuple<bool, Result> ret = ExecuteAndWait(id, () => true, () => _chamber.IsVAC, time * 1000);
  264. if (ret.Item1)
  265. {
  266. if (ret.Item2 == Result.FAIL)
  267. {
  268. Stop("VAC真空信号 NOT ON");
  269. throw new RoutineFaildException();
  270. }
  271. if (Result.TIMEOUT == ret.Item2)
  272. {
  273. Stop($"VAC 真空信号超时, 当前压力 {_chamber.ChamberPressure}");
  274. throw new RoutineFaildException();
  275. }
  276. throw new RoutineBreakException();
  277. }
  278. }
  279. public void SetLiftPinUpDown(int id, bool isUp, int timeout)
  280. {
  281. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  282. {
  283. Notify($"设置 lift pin {_chamber.Name} " + (isUp ? "升" : "降"));
  284. if (!_chamber.SetLiftPin(isUp ? MovementPosition.Up : MovementPosition.Down, out string reason))
  285. {
  286. Stop(reason);
  287. return false;
  288. }
  289. return true;
  290. }, () => isUp ? _chamber.CheckLiftUp() : _chamber.CheckLiftDown(), timeout * 1000);
  291. if (ret.Item1)
  292. {
  293. if (ret.Item2 == Result.FAIL)
  294. {
  295. throw new RoutineFaildException();
  296. }
  297. else if (ret.Item2 == Result.TIMEOUT) //timeout
  298. {
  299. Stop($"无法 {(isUp ? "Up" : "Down")} lift pin in {timeout} seconds");
  300. throw new RoutineFaildException();
  301. }
  302. else
  303. throw new RoutineBreakException();
  304. }
  305. }
  306. protected void End(int id)
  307. {
  308. bool Func()
  309. {
  310. double duration_min = counter.GetElapseTime();
  311. TimeSpan ts = TimeSpan.FromMilliseconds(duration_min);
  312. string info = $"完成 in {ts.Minutes} minutes {ts.Seconds} seconds";
  313. Notify(info);
  314. //if (bUINotify)
  315. // EV.PostPopDialogMessage(EventLevel.Information, Name, $"{Module} {info} Finished");
  316. return true;
  317. }
  318. Tuple<bool, Result> ret = Execute(id, Func);
  319. }
  320. public virtual void Abort()
  321. {
  322. _chamber.GeneratorPowerOn(false);
  323. _chamber.StopAllGases();
  324. }
  325. public void CloseValve(int stepId, int timeVent)
  326. {
  327. bool Func()
  328. {
  329. Notify("Vent End Close Vent Valve");
  330. _chamber.OpenValve(ValveType.PURGE, false);
  331. _chamber.OpenValve(ValveType.FAST_VENT, false);
  332. _chamber.OpenValve(ValveType.PROCESS, false);
  333. //_chamber.OpenValve(ValveType.SOFT_PUMP, true);
  334. //_chamber.OpenValve(ValveType.FAST_PUMP, true);
  335. return true;
  336. }
  337. Tuple<bool, Result> ret = Delay(stepId, Func, timeVent * 1000);
  338. if (ret.Item1)
  339. {
  340. if (ret.Item2 == Result.FAIL)
  341. {
  342. throw new RoutineFaildException();
  343. }
  344. throw new RoutineBreakException();
  345. }
  346. }
  347. public void VentToPrecision(int stepId, int timeVent)
  348. {
  349. bool Func()
  350. {
  351. Notify("Vent to precision");
  352. _chamber.OpenValve(ValveType.SOFT_PUMP, false);
  353. _chamber.OpenValve(ValveType.PURGE, true);
  354. return true;
  355. }
  356. Tuple<bool, Result> ret = Delay(stepId, Func, timeVent * 1000);
  357. if (ret.Item1)
  358. {
  359. if (ret.Item2 == Result.FAIL)
  360. {
  361. throw new RoutineFaildException();
  362. }
  363. throw new RoutineBreakException();
  364. }
  365. }
  366. protected void StartLoop(int id, string name, int count, Action<string> notify, Action<string> error)
  367. {
  368. bool Func()
  369. {
  370. Notify($"{name} 循环 {LoopCounter + 1}");
  371. return true;
  372. }
  373. Tuple<bool, Result> ret = Loop(id, Func, count);
  374. if (ret.Item1)
  375. {
  376. if (ret.Item2 == Result.FAIL)
  377. throw new RoutineFaildException();
  378. }
  379. }
  380. protected void EndLoop(int id, Action<string> notify, Action<string> error)
  381. {
  382. Tuple<bool, Result> ret = EndLoop(id, () => true);
  383. if (ret.Item1)
  384. {
  385. if (ret.Item2 == Result.FAIL)
  386. throw new RoutineFaildException();
  387. throw new RoutineBreakException();
  388. }
  389. }
  390. protected void CyclePump(int id, int target, int timeLimit, bool isStopPumpOnceDone)
  391. {
  392. bool Func()
  393. {
  394. Notify($"Pumping to {target} mTorr");
  395. _chamber.OpenValve(ValveType.PROCESS, false);
  396. _chamber.OpenValve(ValveType.PURGE, false);
  397. _chamber.OpenValve(ValveType.FAST_VENT, false);
  398. _chamber.OpenValve(ValveType.FAST_PUMP, true);
  399. return true;
  400. }
  401. bool? Check1()
  402. {
  403. if (_chamber.ChamberPressure < target)
  404. {
  405. if (isStopPumpOnceDone)
  406. {
  407. _chamber.OpenValve(ValveType.FAST_PUMP, false);
  408. }
  409. return true;
  410. }
  411. return true;
  412. }
  413. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, timeLimit * 1000);
  414. if (ret.Item1)
  415. {
  416. if (ret.Item2 == Result.FAIL)
  417. {
  418. throw new RoutineFaildException();
  419. }
  420. if (ret.Item2 == Result.TIMEOUT)
  421. {
  422. Stop($"Pump 压力无法到达 {target} in time {timeLimit}");
  423. throw new RoutineFaildException();
  424. }
  425. throw new RoutineBreakException();
  426. }
  427. }
  428. protected void CycleVent(int id, int target, int timeLimit, bool isStopVentOnceDone)
  429. {
  430. bool Func()
  431. {
  432. Notify($"Venting to {target} mTorr");
  433. _chamber.OpenValve(ValveType.FAST_PUMP, false);
  434. _chamber.OpenValve(ValveType.PROCESS, true);
  435. _chamber.OpenValve(ValveType.PURGE, true);
  436. return true;
  437. }
  438. bool? Check1()
  439. {
  440. if (_chamber.ChamberPressurePressure > target)
  441. {
  442. if (isStopVentOnceDone)
  443. {
  444. _chamber.OpenValve(ValveType.PROCESS, false);
  445. _chamber.OpenValve(ValveType.PURGE, false);
  446. _chamber.OpenValve(ValveType.FAST_VENT, false);
  447. }
  448. return true;
  449. }
  450. return false;
  451. }
  452. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, timeLimit * 1000);
  453. if (ret.Item1)
  454. {
  455. if (ret.Item2 == Result.FAIL)
  456. {
  457. throw new RoutineFaildException();
  458. }
  459. if (ret.Item2 == Result.TIMEOUT) //timeout
  460. {
  461. Stop($"Purge 压力无法到达 {target} in purge time {timeLimit}");
  462. if (isStopVentOnceDone)
  463. {
  464. _chamber.OpenValve(ValveType.PROCESS, false);
  465. _chamber.OpenValve(ValveType.PURGE, false);
  466. _chamber.OpenValve(ValveType.FAST_VENT, false);
  467. }
  468. throw new RoutineFaildException();
  469. }
  470. throw new RoutineBreakException();
  471. }
  472. }
  473. protected void CheckSubstrateTemp(int id, double target, int time, double tolerance)
  474. {
  475. bool Func()
  476. {
  477. if (_chamber.SubstrateTempFB > target)
  478. {
  479. Notify($"当前温度{_chamber.SubstrateTempFB} ℃, 大于目标 {target.ToString()} ℃");
  480. //return true;
  481. }
  482. _chamber.HeatSubstrate(target);
  483. Notify($"检查底座温度值,当前温度{_chamber.SubstrateTempFB} ℃, 目标 {target.ToString()} ℃");
  484. return true;
  485. }
  486. bool? Check1()
  487. {
  488. if (Math.Abs(_chamber.SubstrateTempFB - target) <= tolerance) return true;
  489. else return false;
  490. }
  491. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, time * 1000);
  492. if (ret.Item1)
  493. {
  494. if (ret.Item2 == Result.FAIL)
  495. {
  496. throw new RoutineFaildException();
  497. }
  498. if (ret.Item2 == Result.TIMEOUT)
  499. {
  500. Stop($"检查底座温度超时, 当前底座温度值 {_chamber.SubstrateTempFB}");
  501. throw new RoutineFaildException();
  502. }
  503. throw new RoutineBreakException();
  504. }
  505. }
  506. protected void SetSlitDoor(int id, bool isOpen, int timeout)
  507. {
  508. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  509. {
  510. Notify($"设置传送门 {_chamber.Name} " + (isOpen ? "开" : "关"));
  511. _chamber.SetSlitDoor(isOpen, out _);
  512. return true;
  513. }, () => isOpen ? _chamber.CheckSlitDoorOpen() : _chamber.CheckSlitDoorClose(), timeout * 1000);
  514. if (ret.Item1)
  515. {
  516. if (ret.Item2 == Result.FAIL)
  517. {
  518. throw new RoutineFaildException();
  519. }
  520. else if (ret.Item2 == Result.TIMEOUT) //timeout
  521. {
  522. Stop($"无法 {(isOpen ? "开" : "关")} 传送门 in {timeout} seconds");
  523. throw new RoutineFaildException();
  524. }
  525. else
  526. throw new RoutineBreakException();
  527. }
  528. }
  529. }
  530. }