GasFlowRoutine.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using Aitex.Core.Common.DeviceData;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using VirgoRT.Devices;
  7. namespace VirgoRT.Modules.PMs
  8. {
  9. class GasFlowRoutine : PMRoutineBase, IRoutine
  10. {
  11. private enum RoutineStep
  12. {
  13. CheckPressure,
  14. StartFlow,
  15. StopFlow,
  16. CheckStable,
  17. End,
  18. };
  19. public bool _gasStatus = false;
  20. private double _pressureAlarmRange;
  21. private double _pressureAlarmTime;
  22. //private double _gasFlowAlarmRange;
  23. //private double _gasFlowAlarmTime;
  24. private double[] _mfcSetPoint = new double[5];
  25. public GasFlowRoutine(JetPM chamber) : base(chamber)
  26. {
  27. Name = "Flow gas";
  28. bUINotify = true;
  29. }
  30. public Result Start(params object[] objs)
  31. {
  32. if (!_chamber.IsFastPumpOpened)
  33. {
  34. StopFlow2();
  35. Stop("Pump 阀没有打开");
  36. return Result.FAIL;
  37. }
  38. Reset();
  39. _pressureAlarmRange = SC.GetValue<double>($"{Module}.GasFlowPressureAlarmRange");
  40. _pressureAlarmTime = SC.GetValue<double>($"{Module}.GasFlowPressureAlarmTime");
  41. // open process final valve and flow
  42. Notify("Open valve and flow mfc");
  43. _chamber.SetValveOnOff(ValveType.PROCESS, true);
  44. int i = 0;
  45. foreach (object o in objs)
  46. {
  47. _mfcSetPoint[i++] = (double)o;
  48. }
  49. FlowMfc2((int)RoutineStep.StartFlow, _mfcSetPoint);
  50. _gasStatus = true;
  51. return Result.RUN;
  52. }
  53. public Result Monitor()
  54. {
  55. try
  56. {
  57. //CheckPressure((int)RoutineStep.CheckPressure, "Wait for pressure normally", (int)_pressureAlarmTime, Notify, Stop);
  58. if (_chamber.HasGasOutOfRange)
  59. {
  60. Stop("流气率越界");
  61. _gasStatus = false;
  62. return Result.FAIL;
  63. }
  64. End((int)RoutineStep.End);
  65. }
  66. catch (RoutineBreakException)
  67. {
  68. return Result.RUN;
  69. }
  70. catch (RoutineFaildException)
  71. {
  72. _gasStatus = false;
  73. return Result.FAIL;
  74. }
  75. catch (Exception ex)
  76. {
  77. Stop(ex.Message);
  78. _gasStatus = false;
  79. return Result.FAIL;
  80. }
  81. return Result.DONE;
  82. }
  83. public void FlowMfc2(int id, double[] mfcValues)
  84. {
  85. string reason = string.Empty;
  86. for (int index = 0; index < mfcValues.Length; index++)
  87. {
  88. _chamber.FlowGas(index, mfcValues[index]);
  89. }
  90. }
  91. public void StopFlow2()
  92. {
  93. Notify("Close valve and stop to flow MFC");
  94. _chamber.SetValveOnOff(ValveType.PROCESS, false);
  95. _chamber.StopAllGases();
  96. }
  97. [Obsolete]
  98. public void FlowMfc(int id, double[] mfcValues, int time)
  99. {
  100. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  101. {
  102. Notify("Open valve and flow mfc");
  103. string reason = string.Empty;
  104. _chamber.SetValveOnOff(ValveType.PROCESS, true);
  105. for (int index = 0; index < mfcValues.Length; index++)
  106. {
  107. if (mfcValues[index] > 0)
  108. {
  109. _chamber.FlowGas(index, mfcValues[index]);
  110. }
  111. }
  112. return true;
  113. }, () => { return _chamber.HasGasOutOfRange; }, time * 1000);
  114. if (ret.Item1)
  115. {
  116. if (ret.Item2 == Result.FAIL)
  117. {
  118. _chamber.StopAllGases();
  119. throw new RoutineFaildException();
  120. }
  121. else if (ret.Item2 == Result.TIMEOUT) //timeout
  122. {
  123. _chamber.StopAllGases();
  124. EV.PostAlarmLog(Module, $"MFC not flow normally in {time} seconds");
  125. throw new RoutineFaildException();
  126. }
  127. else
  128. throw new RoutineBreakException();
  129. }
  130. }
  131. [Obsolete]
  132. public void StopGasFlow(int id)
  133. {
  134. Tuple<bool, Result> ret = Execute(id, () =>
  135. {
  136. Notify("Close valve and stop to flow MFC");
  137. string reason = string.Empty;
  138. _chamber.SetValveOnOff(ValveType.PROCESS, false);
  139. _chamber.StopAllGases();
  140. return true;
  141. });
  142. if (ret.Item1)
  143. {
  144. if (ret.Item2 == Result.FAIL)
  145. {
  146. _chamber.StopAllGases();
  147. throw new RoutineFaildException();
  148. }
  149. else
  150. throw new RoutineBreakException();
  151. }
  152. }
  153. public void CheckStable(int id, string name, int alarmTime)
  154. {
  155. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  156. {
  157. Notify(name);
  158. delayTimer.Start(0);
  159. return true;
  160. },
  161. () =>
  162. {
  163. if (_chamber.PressureMode == PressureCtrlMode.TVPressureCtrl)
  164. {
  165. return _chamber.TargetPressure < _chamber.ChamberPressure;
  166. }
  167. return delayTimer.GetElapseTime() / 1000 > 10;
  168. }, alarmTime * 1000);
  169. if (ret.Item1)
  170. {
  171. if (ret.Item2 == Result.FAIL)
  172. {
  173. throw new RoutineFaildException();
  174. }
  175. else if (ret.Item2 == Result.TIMEOUT)
  176. {
  177. EV.PostAlarmLog(Module, $"Gas flow pressure not stable in {alarmTime} seconds");
  178. throw new RoutineFaildException();
  179. }
  180. else
  181. throw new RoutineBreakException();
  182. }
  183. }
  184. public override void Abort()
  185. {
  186. this.StopFlow2();
  187. _gasStatus = false;
  188. }
  189. }
  190. }