PMLeakCheckRoutine.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. using System;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using VirgoCommon;
  6. using VirgoRT.Devices;
  7. namespace VirgoRT.Modules.PMs
  8. {
  9. class LeakCheckRoutine : PMRoutineBase
  10. {
  11. private enum LeakCheckStep
  12. {
  13. PumpDown,
  14. CheckDoor,
  15. CheckDryPump,
  16. CloseAllValve,
  17. OpenPumpingValve,
  18. OpenGasFinalValve,
  19. CloseGasFinalValve,
  20. OpenMfc1Valve,
  21. OpenMfc2Valve,
  22. OpenMfc3Valve,
  23. OpenMfc4Valve,
  24. OpenMfc5Valve,
  25. CloseMfc1Valve,
  26. CloseMfc2Valve,
  27. CloseMfc3Valve,
  28. CloseMfc4Valve,
  29. CloseMfc5Valve,
  30. StartFlow,
  31. StopFlow,
  32. RecordStartPressure,
  33. RecordEndPressure,
  34. PumpDownDelay,
  35. StartPressureDelay,
  36. EndPressureDelay,
  37. ClosePumpValve,
  38. LeakCheckDelay,
  39. CalcLeakCheck,
  40. End,
  41. EndLeakCheck,
  42. AbortLeakCheck,
  43. CheckPressure
  44. };
  45. // Fields
  46. private double _beginPressure = 0;
  47. private double _endPressure = 0;
  48. private double _leakRate;
  49. public double LeakRate { get; private set; }
  50. private int _leakCheckPumpDownTime;
  51. private int _leakCheckWaitTime;
  52. private LeakCheckMode _mode;
  53. private bool[] _enableGasLine = new bool[5];
  54. private double[] _mfcFlow = new double[5];
  55. private readonly PumpDownRoutine _pumpdownRoutine;
  56. // Properties
  57. //
  58. public int ElapseTime => (int)(delayTimer.GetElapseTime() / 1000.0);
  59. // Constructor
  60. //
  61. public LeakCheckRoutine(JetPM chamber, PumpDownRoutine _pdRoutine) : base(chamber)
  62. {
  63. Name = "leak check";
  64. bUINotify = true;
  65. _pumpdownRoutine = _pdRoutine;
  66. }
  67. public void Terminate()
  68. {
  69. }
  70. public Result Start(params object[] objs)
  71. {
  72. // 预检查
  73. if (CheckLid() == Result.RUN &&
  74. CheckSlitDoor() == Result.RUN &&
  75. CheckDryPump() == Result.RUN)
  76. {
  77. _enableGasLine = new bool[5] { false, false, false, false, false };
  78. _mfcFlow = new double[5] { 0.0, 0.0, 0.0, 0.0, 0.0 };
  79. Reset();
  80. delayTimer.Start(0);
  81. try
  82. {
  83. if (objs.Length == 0)
  84. {
  85. _leakCheckPumpDownTime = SC.GetValue<int>($"{Module}.Pump.LeakCheckPumpingTime");
  86. _leakCheckWaitTime = SC.GetValue<int>($"{Module}.Pump.LeakCheckWaitTime");
  87. _leakRate = SC.GetValue<double>($"{Module}.Pump.LeakRate");
  88. _mode = LeakCheckMode.ChamberOnly;
  89. }
  90. else
  91. {
  92. _leakCheckPumpDownTime = Convert.ToInt32(objs[0].ToString());
  93. _leakCheckWaitTime = Convert.ToInt32(objs[1].ToString());
  94. _mode = (LeakCheckMode)Enum.Parse(typeof(LeakCheckMode), objs[2].ToString());
  95. _leakRate = Convert.ToInt32(objs[3].ToString());
  96. for (int i = 0; i < 5; i++)
  97. _enableGasLine[i] = Convert.ToBoolean(objs[4 + i].ToString());
  98. }
  99. for (int i = 0; i < 5; i++)
  100. {
  101. if (_enableGasLine[i]) _mfcFlow[i] = SC.GetValue<int>($"{Module}.MfcGas{i + 1}.MfcN2Scale");
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. LOG.Write(ex);
  107. return Result.FAIL;
  108. }
  109. return Result.RUN;
  110. }
  111. return Result.FAIL;
  112. }
  113. public Result Monitor()
  114. {
  115. try
  116. {
  117. ExecuteRoutine((int)LeakCheckStep.PumpDown, _pumpdownRoutine);
  118. if (_mode == LeakCheckMode.ChamberOnly)
  119. {
  120. ;
  121. }
  122. else if (_mode == LeakCheckMode.ChamberAndGasLine)
  123. {
  124. SetValve((int)LeakCheckStep.OpenGasFinalValve, ValveType.PROCESS, true);
  125. if (_enableGasLine[0]) SetValve((int)LeakCheckStep.OpenMfc1Valve, ValveType.Mfc1, true);
  126. if (_enableGasLine[1]) SetValve((int)LeakCheckStep.OpenMfc2Valve, ValveType.Mfc2, true);
  127. if (_enableGasLine[2]) SetValve((int)LeakCheckStep.OpenMfc3Valve, ValveType.Mfc3, true);
  128. if (_enableGasLine[3]) SetValve((int)LeakCheckStep.OpenMfc4Valve, ValveType.Mfc4, true);
  129. if (_enableGasLine[4]) SetValve((int)LeakCheckStep.OpenMfc5Valve, ValveType.Mfc5, true);
  130. }
  131. else if (_mode == LeakCheckMode.ChamberAndGasLineAndFAC)
  132. {
  133. SetValve((int)LeakCheckStep.OpenGasFinalValve, ValveType.PROCESS, true);
  134. if (_enableGasLine[0]) SetValve((int)LeakCheckStep.OpenMfc1Valve, ValveType.Mfc1, true);
  135. if (_enableGasLine[1]) SetValve((int)LeakCheckStep.OpenMfc2Valve, ValveType.Mfc2, true);
  136. if (_enableGasLine[2]) SetValve((int)LeakCheckStep.OpenMfc3Valve, ValveType.Mfc3, true);
  137. if (_enableGasLine[3]) SetValve((int)LeakCheckStep.OpenMfc4Valve, ValveType.Mfc4, true);
  138. if (_enableGasLine[4]) SetValve((int)LeakCheckStep.OpenMfc5Valve, ValveType.Mfc5, true);
  139. StartFlowMFC((int)LeakCheckStep.StartFlow, _mfcFlow);
  140. }
  141. TimeDelay((int)LeakCheckStep.PumpDownDelay, _leakCheckPumpDownTime);
  142. SetValve((int)LeakCheckStep.ClosePumpValve, ValveType.FAST_PUMP, false);
  143. //记录腔体Start pressure P1
  144. RecordBeginPressure((int)LeakCheckStep.RecordStartPressure);
  145. //pump down delay
  146. TimeDelay((int)LeakCheckStep.EndPressureDelay, _leakCheckWaitTime);
  147. //记录腔体End pressure P2
  148. RecordEndPressure((int)LeakCheckStep.RecordEndPressure);
  149. CalcLeakCheck((int)LeakCheckStep.CalcLeakCheck, _leakRate, _leakCheckWaitTime, 0);
  150. if (_mode == LeakCheckMode.ChamberOnly)
  151. {
  152. ;
  153. }
  154. else if (_mode == LeakCheckMode.ChamberAndGasLine)
  155. {
  156. SetValve((int)LeakCheckStep.CloseGasFinalValve, ValveType.PROCESS, false);
  157. if (_enableGasLine[0]) SetValve((int)LeakCheckStep.CloseMfc1Valve, ValveType.Mfc1, false);
  158. if (_enableGasLine[1]) SetValve((int)LeakCheckStep.CloseMfc2Valve, ValveType.Mfc2, false);
  159. if (_enableGasLine[2]) SetValve((int)LeakCheckStep.CloseMfc3Valve, ValveType.Mfc3, false);
  160. if (_enableGasLine[3]) SetValve((int)LeakCheckStep.CloseMfc4Valve, ValveType.Mfc4, false);
  161. if (_enableGasLine[4]) SetValve((int)LeakCheckStep.CloseMfc5Valve, ValveType.Mfc5, false);
  162. }
  163. else if (_mode == LeakCheckMode.ChamberAndGasLineAndFAC)
  164. {
  165. SetValve((int)LeakCheckStep.CloseGasFinalValve, ValveType.PROCESS, false);
  166. if (_enableGasLine[0]) SetValve((int)LeakCheckStep.CloseMfc1Valve, ValveType.Mfc1, false);
  167. if (_enableGasLine[1]) SetValve((int)LeakCheckStep.CloseMfc2Valve, ValveType.Mfc2, false);
  168. if (_enableGasLine[2]) SetValve((int)LeakCheckStep.CloseMfc3Valve, ValveType.Mfc3, false);
  169. if (_enableGasLine[3]) SetValve((int)LeakCheckStep.CloseMfc4Valve, ValveType.Mfc4, false);
  170. if (_enableGasLine[4]) SetValve((int)LeakCheckStep.CloseMfc5Valve, ValveType.Mfc5, false);
  171. StopFlowMFC((int)LeakCheckStep.StopFlow);
  172. }
  173. End((int)LeakCheckStep.End);
  174. //ExecuteRoutine((int)LeakCheckStep.EndLeakCheck, _pumpDownRoutine);
  175. }
  176. catch (RoutineBreakException)
  177. {
  178. return Result.RUN;
  179. }
  180. catch (RoutineFaildException)
  181. {
  182. return Result.FAIL;
  183. }
  184. return Result.DONE;
  185. }
  186. public void DelayLeakCheck(int id, string name, double time)
  187. {
  188. bool Func()
  189. {
  190. Notify(name);
  191. return true;
  192. }
  193. Tuple<bool, Result> ret = Delay(id, Func, time * 1000);
  194. if (ret.Item1)
  195. {
  196. if (ret.Item2 == Result.RUN)
  197. {
  198. throw new RoutineBreakException();
  199. }
  200. }
  201. }
  202. public void CheckChamberPressure(int id, double target, out double pressure, int time)
  203. {
  204. bool Func()
  205. {
  206. return true;
  207. }
  208. bool? Check1()
  209. {
  210. if (_chamber.ChamberPressure < target)
  211. {
  212. Notify($"腔体压力 [{_chamber.ChamberPressure}] mt, 低于 [{target}] mt");
  213. return true;
  214. }
  215. Stop($"腔体压力 [{_chamber.ChamberPressure}], 高于 [{target}]");
  216. return false;
  217. }
  218. pressure = _chamber.ChamberPressure;
  219. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, time * 1000);
  220. if (ret.Item1)
  221. {
  222. if (ret.Item2 == Result.FAIL)
  223. {
  224. throw new RoutineFaildException();
  225. }
  226. if (ret.Item2 == Result.TIMEOUT)
  227. {
  228. throw new RoutineFaildException();
  229. }
  230. throw new RoutineBreakException();
  231. }
  232. }
  233. public void RecordBeginPressure(int id)
  234. {
  235. bool Func()
  236. {
  237. _beginPressure = _chamber.ChamberPressure;
  238. Notify($"腔体压力初始值 {_beginPressure} mt");
  239. return true;
  240. }
  241. bool? Check1()
  242. {
  243. return true;
  244. }
  245. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, 1 * 1000);
  246. if (ret.Item1)
  247. {
  248. if (ret.Item2 == Result.FAIL)
  249. {
  250. throw new RoutineFaildException();
  251. }
  252. if (ret.Item2 == Result.TIMEOUT)
  253. {
  254. throw new RoutineFaildException();
  255. }
  256. throw new RoutineBreakException();
  257. }
  258. }
  259. public void RecordEndPressure(int id)
  260. {
  261. bool Func()
  262. {
  263. _endPressure = _chamber.ChamberPressure;
  264. Notify($"腔体压力结束值 {_endPressure} mt");
  265. return true;
  266. }
  267. bool? Check1()
  268. {
  269. return true;
  270. }
  271. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, 1 * 1000);
  272. if (ret.Item1)
  273. {
  274. if (ret.Item2 == Result.FAIL)
  275. {
  276. throw new RoutineFaildException();
  277. }
  278. if (ret.Item2 == Result.TIMEOUT)
  279. {
  280. throw new RoutineFaildException();
  281. }
  282. throw new RoutineBreakException();
  283. }
  284. }
  285. public void CalcLeakCheck(int id, double target, int timeRate, int time)
  286. {
  287. bool Func()
  288. {
  289. return true;
  290. }
  291. bool? Check1()
  292. {
  293. LeakRate = (_endPressure - _beginPressure) / (timeRate / 60.0);
  294. if (LeakRate < target)
  295. {
  296. Notify($"腔体漏率 [{LeakRate}] mt/min, 低于 [{target}] mt/min");
  297. LeakCheckResultManager.Instance.AddLeakCheck(Module, DateTime.Now, ElapseTime, (double)_beginPressure, (double)_endPressure, LeakRate, LeakCheckStatus.Succeed.ToString(), _mode.ToString());
  298. return true;
  299. }
  300. Stop($"腔体漏率 [{LeakRate}] mt/min, 高于 [{target}] mt/min");
  301. LeakCheckResultManager.Instance.AddLeakCheck(Module, DateTime.Now, ElapseTime, (double)_beginPressure, (double)_endPressure, LeakRate, LeakCheckStatus.Failed.ToString(), _mode.ToString());
  302. return false;
  303. }
  304. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, time * 1000);
  305. if (ret.Item1)
  306. {
  307. if (ret.Item2 == Result.FAIL)
  308. {
  309. throw new RoutineFaildException();
  310. }
  311. if (ret.Item2 == Result.TIMEOUT)
  312. {
  313. throw new RoutineFaildException();
  314. }
  315. throw new RoutineBreakException();
  316. }
  317. }
  318. public void StopFlowMFC(int id)
  319. {
  320. bool Func()
  321. {
  322. _chamber.StopAllGases();
  323. return true;
  324. }
  325. bool? Check1()
  326. {
  327. return true;
  328. }
  329. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, 1 * 1000);
  330. if (ret.Item1)
  331. {
  332. if (ret.Item2 == Result.FAIL)
  333. {
  334. throw new RoutineFaildException();
  335. }
  336. if (ret.Item2 == Result.TIMEOUT)
  337. {
  338. throw new RoutineFaildException();
  339. }
  340. throw new RoutineBreakException();
  341. }
  342. }
  343. public void StartFlowMFC(int id, double[] mfcValues)
  344. {
  345. bool Func()
  346. {
  347. for (int index = 0; index < mfcValues.Length; index++)
  348. {
  349. _chamber.FlowGas(index, mfcValues[index]);
  350. }
  351. return true;
  352. }
  353. bool? Check1()
  354. {
  355. return true;
  356. }
  357. Tuple<bool, Result> ret = ExecuteAndWait(id, Func, Check1, 1 * 1000);
  358. if (ret.Item1)
  359. {
  360. if (ret.Item2 == Result.FAIL)
  361. {
  362. throw new RoutineFaildException();
  363. }
  364. if (ret.Item2 == Result.TIMEOUT)
  365. {
  366. throw new RoutineFaildException();
  367. }
  368. throw new RoutineBreakException();
  369. }
  370. }
  371. public void DeleteLeadCheck(object[] args)
  372. {
  373. LeakCheckResultManager.Instance.Delete(Module, args[0].ToString());
  374. }
  375. public override void Abort()
  376. {
  377. try
  378. {
  379. _chamber.CloseValves();
  380. LeakCheckResultManager.Instance.AddLeakCheck(Module, DateTime.Now, ElapseTime, (double)_beginPressure, (double)_chamber.ChamberPressure, 0, LeakCheckStatus.Aborted.ToString(), _mode.ToString());
  381. }
  382. catch (Exception ex)
  383. {
  384. LOG.Write(ex);
  385. }
  386. }
  387. }
  388. }