GasFlowRoutine.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 Virgo_DRT.Devices;
  7. namespace Virgo_DRT.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[4];
  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.OpenValve(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.OpenValve(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.OpenValve(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. _chamber.SwitchOnBuzzerAndRed();
  126. throw new RoutineFaildException();
  127. }
  128. else
  129. throw new RoutineBreakException();
  130. }
  131. }
  132. [Obsolete]
  133. public void StopGasFlow(int id)
  134. {
  135. Tuple<bool, Result> ret = Execute(id, () =>
  136. {
  137. Notify("Close valve and stop to flow MFC");
  138. string reason = string.Empty;
  139. _chamber.OpenValve(ValveType.PROCESS, false);
  140. _chamber.StopAllGases();
  141. return true;
  142. });
  143. if (ret.Item1)
  144. {
  145. if (ret.Item2 == Result.FAIL)
  146. {
  147. _chamber.StopAllGases();
  148. throw new RoutineFaildException();
  149. }
  150. else
  151. throw new RoutineBreakException();
  152. }
  153. }
  154. public void CheckStable(int id, string name, int alarmTime)
  155. {
  156. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  157. {
  158. Notify(name);
  159. delayTimer.Start(0);
  160. return true;
  161. },
  162. () =>
  163. {
  164. if (_chamber.PressureMode == PressureCtrlMode.TVPressureCtrl)
  165. {
  166. return _chamber.TargetPressure < _chamber.ChamberPressure;
  167. }
  168. return delayTimer.GetElapseTime() / 1000 > 10;
  169. }, alarmTime * 1000);
  170. if (ret.Item1)
  171. {
  172. if (ret.Item2 == Result.FAIL)
  173. {
  174. throw new RoutineFaildException();
  175. }
  176. else if (ret.Item2 == Result.TIMEOUT)
  177. {
  178. EV.PostAlarmLog(Module, $"Gas flow pressure not stable in {alarmTime} seconds");
  179. _chamber.SwitchOnBuzzerAndRed();
  180. throw new RoutineFaildException();
  181. }
  182. else
  183. throw new RoutineBreakException();
  184. }
  185. }
  186. public override void Abort()
  187. {
  188. this.StopFlow2();
  189. _gasStatus = false;
  190. }
  191. }
  192. }