PMLeakCheckRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using JetVirgoPM.Devices;
  10. using MECF.Framework.Common.CommonData;
  11. using MECF.Framework.Common.Routine;
  12. namespace JetVirgoPM.PMs.Routines
  13. {
  14. class LeakCheckRoutine : PMRoutineBase
  15. {
  16. private enum LeakCheckStep
  17. {
  18. PumpDown,
  19. CheckDoor,
  20. CheckDryPump,
  21. CloseAllValve,
  22. OpenPumpingValve,
  23. OpenPurgeValve,
  24. OpenGasFinalValve,
  25. ClosePurgeValve,
  26. CloseGasFinalValve,
  27. OpenMfc1Valve,
  28. OpenMfc2Valve,
  29. OpenMfc3Valve,
  30. OpenMfc4Valve,
  31. OpenMfc5Valve,
  32. OpenMfc6Valve,
  33. CloseMfc1Valve,
  34. CloseMfc2Valve,
  35. CloseMfc3Valve,
  36. CloseMfc4Valve,
  37. CloseMfc5Valve,
  38. CloseMfc6Valve,
  39. StartFlow,
  40. StopFlow,
  41. RecordStartPressure,
  42. RecordEndPressure,
  43. PumpDownDelay,
  44. StartPressureDelay,
  45. EndPressureDelay,
  46. ClosePumpValve,
  47. LeakCheckDelay,
  48. CalcLeakCheck,
  49. End,
  50. EndLeakCheck,
  51. AbortLeakCheck,
  52. CheckPressure,
  53. OpenVentValve,
  54. OpenN2Valve,
  55. CloseVentValve,
  56. CloseN2Valve
  57. };
  58. // Fields
  59. private double _beginPressure = 0;
  60. private double _endPressure = 0;
  61. private double _leakRate;
  62. public double LeakRate { get; private set; }
  63. private int _leakCheckPumpDownTime;
  64. private int _leakCheckWaitTime;
  65. private LeakCheckMode _mode;
  66. private bool[] _enableGasLineOrN2 = new bool[7];
  67. private string[] _gasLineName = new string[7] { "MfcGas1", "MfcGas2", "MfcGas3", "MfcGas4", "MfcGas5", "MfcGas6", "Vent N2" };
  68. private Dictionary<string, string> _leakCheckModeMapToText = new Dictionary<string, string>()
  69. {
  70. {LeakCheckMode.ChamberOnly.ToString(),"ChamberOnly" },
  71. {LeakCheckMode.ChamberAndGasLine.ToString(),"Chamber To Gasline" },
  72. {LeakCheckMode.ChamberAndGasLineAndFAC.ToString(), "Chamber To FAC" },
  73. {LeakCheckMode.ChamberAndGasBox.ToString(), "Chamber To Gas Box Manual Valve" },
  74. };
  75. private double[] _mfcFlow = new double[6];
  76. private readonly PumpDownRoutine _pumpdownRoutine;
  77. private DeviceTimer _delayTimer = new DeviceTimer();
  78. // Properties
  79. //
  80. public int ElapseTime => (int)(_delayTimer.GetElapseTime() / 1000.0);
  81. // Constructor
  82. //
  83. public LeakCheckRoutine(JetDualPM chamber, PumpDownRoutine _pdRoutine) : base(chamber)
  84. {
  85. Name = "leak check";
  86. bUINotify = true;
  87. _pumpdownRoutine = _pdRoutine;
  88. }
  89. public void Terminate()
  90. {
  91. }
  92. public RState Start(params object[] objs)
  93. {
  94. // 预检查
  95. if (CheckLid() == RState.Running &&
  96. CheckSlitDoor1() == RState.Running && CheckSlitDoor2() == RState.Running &&
  97. CheckDryPump() == RState.Running)
  98. {
  99. _enableGasLineOrN2 = new bool[7];
  100. _mfcFlow = new double[6] { 0.0, 0.0, 0.0, 0.0, 0.0 , 0.0 };
  101. Reset();
  102. _delayTimer.Start(0);
  103. try
  104. {
  105. if (objs.Length == 0)
  106. {
  107. _leakCheckPumpDownTime = SC.GetValue<int>($"{Module}.Pump.LeakCheckPumpingTime");
  108. _leakCheckWaitTime = SC.GetValue<int>($"{Module}.Pump.LeakCheckWaitTime");
  109. _leakRate = SC.GetValue<double>($"{Module}.Pump.LeakRate");
  110. _mode = LeakCheckMode.ChamberOnly;
  111. }
  112. else
  113. {
  114. _leakCheckPumpDownTime = Convert.ToInt32(objs[0].ToString());
  115. _leakCheckWaitTime = Convert.ToInt32(objs[1].ToString());
  116. _mode = (LeakCheckMode)Enum.Parse(typeof(LeakCheckMode), objs[2].ToString());
  117. _leakRate = Convert.ToSingle(objs[3].ToString());
  118. for (int i = 0; i < _enableGasLineOrN2.Length; i++)
  119. _enableGasLineOrN2[i] = Convert.ToBoolean(objs[4 + i].ToString());
  120. }
  121. for (int i = 0; i < 6; i++)
  122. {
  123. if (_enableGasLineOrN2[i]) _mfcFlow[i] = SC.GetValue<int>($"{Module}.MfcGas{i + 1}.MfcN2Scale");
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. LOG.Write(ex);
  129. return RState.Failed;
  130. }
  131. return Runner.Start(_chamber.Module.ToString(), Name);
  132. }
  133. return RState.Failed;
  134. }
  135. private string SetGasName()
  136. {
  137. if (_enableGasLineOrN2 == null || _enableGasLineOrN2.Length == 0 || _mode == LeakCheckMode.ChamberOnly)
  138. return string.Empty;
  139. var checkSBGasName = new StringBuilder();
  140. for (int i = 0; i < _enableGasLineOrN2.Length; i++)
  141. {
  142. if (_enableGasLineOrN2[i] && _gasLineName.Length > i) checkSBGasName.Append($"{_gasLineName[i]},");
  143. }
  144. return checkSBGasName.Length > 0 ? $"({checkSBGasName.ToString().Trim(',')})" : string.Empty;
  145. }
  146. public RState Monitor()
  147. {
  148. Runner.Run(LeakCheckStep.PumpDown, StartPump, CheckPump, _delay_60s)
  149. .Run(LeakCheckStep.OpenPurgeValve, HOFs.Apply(ExecPurgeOrGasFinalValve, ValveType.PURGE, true), HOFs.Apply(CheckPurgeOrGasFinalValve, ValveType.PURGE, true), _delay_50ms * 10)
  150. .Run(LeakCheckStep.OpenGasFinalValve, HOFs.Apply(ExecPurgeOrGasFinalValve, ValveType.PROCESS, true), HOFs.Apply(CheckPurgeOrGasFinalValve, ValveType.PROCESS, true), _delay_50ms * 10)
  151. .Run(LeakCheckStep.OpenMfc1Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[0], ValveType.Mfc1, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[0], ValveType.Mfc1, true), _delay_50ms * 10)
  152. .Run(LeakCheckStep.OpenMfc2Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[1], ValveType.Mfc2, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[1], ValveType.Mfc2, true), _delay_50ms * 10)
  153. .Run(LeakCheckStep.OpenMfc3Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[2], ValveType.Mfc3, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[2], ValveType.Mfc3, true), _delay_50ms * 10)
  154. .Run(LeakCheckStep.OpenMfc4Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[3], ValveType.Mfc4, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[3], ValveType.Mfc4, true), _delay_50ms * 10)
  155. .Run(LeakCheckStep.OpenMfc5Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[4], ValveType.Mfc5, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[4], ValveType.Mfc5, true), _delay_50ms * 10)
  156. .Run(LeakCheckStep.OpenMfc6Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[5], ValveType.Mfc6, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[5], ValveType.Mfc6, true), _delay_50ms * 10)
  157. .Run(LeakCheckStep.OpenVentValve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[6], ValveType.FAST_VENT, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[6], ValveType.FAST_VENT, true), _delay_50ms * 10)
  158. .Run(LeakCheckStep.OpenN2Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[6], ValveType.N2, true), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[6], ValveType.N2, true), _delay_50ms * 10)
  159. .Run(LeakCheckStep.StartFlow, StartFlowMFC, _delay_1s)
  160. .Delay(LeakCheckStep.PumpDownDelay, _leakCheckPumpDownTime * 1000)
  161. .Run(LeakCheckStep.ClosePumpValve, HOFs.Apply(OpenValve, ValveType.FAST_PUMP, false), HOFs.Apply(CheckValve, ValveType.FAST_PUMP, false), _delay_50ms * 10)
  162. .Run(LeakCheckStep.RecordStartPressure, RecordBeginPressure, _delay_1s)
  163. .Delay(LeakCheckStep.EndPressureDelay, _leakCheckWaitTime * 1000)
  164. .Run(LeakCheckStep.RecordEndPressure, RecordEndPressure, _delay_50ms)
  165. .Run(LeakCheckStep.CalcLeakCheck, CalcLeakCheck, _delay_1s)
  166. .Run(LeakCheckStep.ClosePurgeValve, HOFs.Apply(ExecPurgeOrGasFinalValve, ValveType.PURGE, false), HOFs.Apply(CheckPurgeOrGasFinalValve, ValveType.PURGE, false), _delay_50ms * 10)
  167. .Run(LeakCheckStep.CloseGasFinalValve, HOFs.Apply(ExecPurgeOrGasFinalValve, ValveType.PROCESS, false), HOFs.Apply(CheckPurgeOrGasFinalValve, ValveType.PROCESS, false), _delay_50ms * 10)
  168. .Run(LeakCheckStep.CloseMfc1Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[0], ValveType.Mfc1, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[0], ValveType.Mfc1, false), _delay_50ms * 10)
  169. .Run(LeakCheckStep.CloseMfc2Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[1], ValveType.Mfc2, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[1], ValveType.Mfc2, false), _delay_50ms * 10)
  170. .Run(LeakCheckStep.CloseMfc3Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[2], ValveType.Mfc3, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[2], ValveType.Mfc3, false), _delay_50ms * 10)
  171. .Run(LeakCheckStep.CloseMfc4Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[3], ValveType.Mfc4, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[3], ValveType.Mfc4, false), _delay_50ms * 10)
  172. .Run(LeakCheckStep.CloseMfc5Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[4], ValveType.Mfc5, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[4], ValveType.Mfc5, false), _delay_50ms * 10)
  173. .Run(LeakCheckStep.CloseMfc6Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[5], ValveType.Mfc6, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[5], ValveType.Mfc6, false), _delay_50ms * 10)
  174. .Run(LeakCheckStep.CloseVentValve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[6], ValveType.FAST_VENT, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[6], ValveType.FAST_VENT, false), _delay_50ms * 10)
  175. .Run(LeakCheckStep.CloseN2Valve, HOFs.Apply(ExecMfcValve, _enableGasLineOrN2[6], ValveType.N2, false), HOFs.Apply(CheckMfcValue, _enableGasLineOrN2[6], ValveType.N2, false), _delay_50ms * 10)
  176. .Run(LeakCheckStep.StopFlow, HOFs.WrapAction(_chamber.StopAllGases), NullFun, _delay_1s)
  177. .End(LeakCheckStep.End, EndFunc, _delay_50ms);
  178. return Runner.Status;
  179. }
  180. bool StartPump()
  181. {
  182. return _pumpdownRoutine.Start() == RState.Running;
  183. }
  184. bool CheckPump()
  185. {
  186. var result = _pumpdownRoutine.Monitor();
  187. if (result == RState.Failed || result == RState.Timeout)
  188. {
  189. Runner.Stop($"设置 Pump {_chamber.Name} failed ");
  190. return true;
  191. }
  192. return result == RState.End;
  193. }
  194. bool ExecPurgeOrGasFinalValve(ValveType vlv, bool isOpen)
  195. {
  196. if(_mode == LeakCheckMode.ChamberAndGasLine ||
  197. ((_mode == LeakCheckMode.ChamberAndGasLineAndFAC || _mode == LeakCheckMode.ChamberAndGasBox) && _enableGasLineOrN2.Take(_enableGasLineOrN2.Count() - 1).Any(p => p)))
  198. {
  199. return OpenValve(vlv, isOpen);
  200. }
  201. return true;
  202. }
  203. bool CheckPurgeOrGasFinalValve(ValveType vlv, bool isOpen)
  204. {
  205. if (_mode == LeakCheckMode.ChamberAndGasLine ||
  206. ((_mode == LeakCheckMode.ChamberAndGasLineAndFAC || _mode == LeakCheckMode.ChamberAndGasBox) && _enableGasLineOrN2.Take(_enableGasLineOrN2.Count() - 1).Any(p => p)))
  207. {
  208. return CheckValve(vlv, isOpen);
  209. }
  210. return true;
  211. }
  212. bool ExecMfcValve(bool canExec, ValveType vlv, bool isOpen)
  213. {
  214. if((_mode == LeakCheckMode.ChamberAndGasLineAndFAC || _mode == LeakCheckMode.ChamberAndGasBox) && canExec)
  215. {
  216. return OpenValve(vlv, isOpen);
  217. }
  218. return true;
  219. }
  220. bool CheckMfcValue(bool canExec, ValveType vlv, bool isOpen)
  221. {
  222. if ((_mode == LeakCheckMode.ChamberAndGasLineAndFAC || _mode == LeakCheckMode.ChamberAndGasBox) && canExec)
  223. {
  224. return CheckValve(vlv, isOpen);
  225. }
  226. return true;
  227. }
  228. bool RecordBeginPressure()
  229. {
  230. _beginPressure = _chamber.ChamberPressure;
  231. Notify($"腔体压力初始值 {_beginPressure} mt");
  232. return true;
  233. }
  234. bool RecordEndPressure()
  235. {
  236. _endPressure = _chamber.ChamberPressure;
  237. Notify($"腔体压力结束值 {_endPressure} mt");
  238. return true;
  239. }
  240. bool CalcLeakCheck( )
  241. {
  242. LeakRate = (_endPressure - _beginPressure) / (_leakCheckWaitTime / 60.0);
  243. if (LeakRate < _leakRate)
  244. {
  245. Notify($"腔体漏率 [{LeakRate}] mt/min, 低于 [{_leakRate}] mt/min");
  246. LeakCheckResultManager.Instance.AddLeakCheck(Module, DateTime.Now, ElapseTime, (int)_beginPressure, (int)_endPressure, LeakRate, LeakCheckStatus.Succeed.ToString(), _leakCheckModeMapToText[_mode.ToString()] + SetGasName());
  247. return true;
  248. }
  249. Stop($"腔体漏率 [{LeakRate}] mt/min, 高于 [{_leakRate}] mt/min");
  250. LeakCheckResultManager.Instance.AddLeakCheck(Module, DateTime.Now, ElapseTime, (int)_beginPressure, (int)_endPressure, LeakRate, LeakCheckStatus.Failed.ToString(), _leakCheckModeMapToText[_mode.ToString()] + SetGasName());
  251. return false;
  252. }
  253. bool StartFlowMFC()
  254. {
  255. if(_mode == LeakCheckMode.ChamberAndGasLineAndFAC || _mode == LeakCheckMode.ChamberAndGasBox)
  256. {
  257. for (int index = 0; index < _mfcFlow.Length; index++)
  258. {
  259. _chamber.FlowGas(index, _mfcFlow[index]);
  260. }
  261. }
  262. return true;
  263. }
  264. public void DeleteLeadCheck(object[] args)
  265. {
  266. LeakCheckResultManager.Instance.Delete(Module, args[0].ToString());
  267. }
  268. public override void Abort()
  269. {
  270. try
  271. {
  272. _chamber.CloseValves();
  273. LeakCheckResultManager.Instance.AddLeakCheck(Module, DateTime.Now, ElapseTime, (int)_beginPressure, (int)_chamber.ChamberPressure, 0, LeakCheckStatus.Aborted.ToString(), _leakCheckModeMapToText[_mode.ToString()] + SetGasName());
  274. }
  275. catch (Exception ex)
  276. {
  277. LOG.Write(ex);
  278. }
  279. }
  280. }
  281. }