GasFlowRoutine.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System;
  2. using Aitex.Core.RT.Device.Unit;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Platform;
  7. using Aitex.RT.Properties;
  8. using Aitex.Triton160.Common;
  9. using Aitex.Triton160.RT.Device;
  10. namespace Aitex.Triton160.RT.Routine.PM
  11. {
  12. public class GasFlowRoutine : CommonRoutine
  13. {
  14. private enum RoutineStep
  15. {
  16. CheckPressure,
  17. FlowMfc,
  18. CheckStable,
  19. End,
  20. };
  21. private double _pressureAlarmRange;
  22. private double _pressureAlarmTime;
  23. //private double _gasFlowAlarmRange;
  24. //private double _gasFlowAlarmTime;
  25. private double[] _mfcSetPoint = new double[6];
  26. public GasFlowRoutine(string module, string name)
  27. {
  28. Module = module;
  29. Name = name;
  30. Display = Resources.GasFlowRoutine_GasFlowRoutine_GasFlow;
  31. bUINotify = true;
  32. }
  33. public bool Initialize()
  34. {
  35. InitCommon();
  36. return true;
  37. }
  38. public void Terminate()
  39. {
  40. }
  41. public Result Start(params object[] objs)
  42. {
  43. Reset();
  44. UpdateSCValue();
  45. _pressureAlarmRange = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmRange).Value;
  46. _pressureAlarmTime = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmTime).Value;
  47. //_gasFlowAlarmRange = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmRange).Value;
  48. // _pressureAlarmTime = SC.GetSC<double>(SCName.System_GasFlowPressureAlarmTime).Value;
  49. int i = 0;
  50. foreach (object o in objs)
  51. {
  52. _mfcSetPoint[i++] = (double)o;
  53. }
  54. if (!DeviceModel.ValveChamberPumping.Status )
  55. {
  56. EV.PostMessage(ModuleNameString.System, EventEnum.DefaultWarning, string.Format(Resources.GasFlowRoutine_Start_PumpingValveNotOpenOpenPumpValveFirst));
  57. return Result.FAIL;
  58. }
  59. return Result.RUN;
  60. }
  61. public Result Monitor()
  62. {
  63. try
  64. {
  65. FlowMfc((int)RoutineStep.FlowMfc, Resources.GasFlowRoutine_Monitor_OpenValveAndFlowMfc, _mfcSetPoint, 10, Notify, Stop);
  66. //CheckPressure((int)RoutineStep.CheckPressure, "Wait for pressure normally", (int)_pressureAlarmTime, Notify, Stop);
  67. End((int)RoutineStep.End, Resources.GasFlowRoutine_Monitor_GasFlowCompleted, Notify, Stop);
  68. }
  69. catch (RoutineBreakException)
  70. {
  71. return Result.RUN;
  72. }
  73. catch (RoutineFaildException)
  74. {
  75. return Result.FAIL;
  76. }
  77. return Result.DONE;
  78. }
  79. public void FlowMfc(int id, string name, double[] mfcValues, int time, Action<string> notify, Action<string> error)
  80. {
  81. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  82. {
  83. notify(name);
  84. string reason = string.Empty;
  85. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3 , DeviceModel.ValveMfc4 , DeviceModel.ValveMfc5 };
  86. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  87. if (mfcValues.Length>=5 && mfcValues[5] > 0 )
  88. {
  89. error(reason);
  90. return false;
  91. }
  92. if (DeviceModel.ValveProcessGasFinal!= null && !DeviceModel.ValveProcessGasFinal.TurnValve(true, out reason))
  93. {
  94. error(reason);
  95. return false;
  96. }
  97. for (int i=0; i<mfcs.Length && i<valves.Length; i++)
  98. {
  99. if (mfcs[i] == null)
  100. continue;
  101. if (valves[i]!=null && !valves[i].TurnValve(mfcValues[i] > 0, out reason))
  102. {
  103. error(reason);
  104. return false;
  105. }
  106. if (mfcValues[i] <= 0)
  107. continue;
  108. if (mfcs[i] != null)
  109. mfcs[i].Ramp(mfcValues[i], 0);
  110. }
  111. return true;
  112. }, () =>
  113. {
  114. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  115. foreach (IoMfc mfc in mfcs)
  116. {
  117. if (mfc != null && mfc.IsOutOfTolerance)
  118. return false;
  119. }
  120. return true;
  121. }, time * 1000);
  122. if (ret.Item1)
  123. {
  124. if (ret.Item2 == Result.FAIL)
  125. {
  126. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3 , DeviceModel.ValveMfc4 , DeviceModel.ValveMfc5 };
  127. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  128. string reason = string.Empty;
  129. for (int i = 0; i < mfcs.Length && i<valves.Length; i++)
  130. {
  131. if (valves[i] != null)
  132. valves[i].TurnValve(false, out reason);
  133. if (mfcs[i] != null)
  134. mfcs[i].Ramp(0,0);
  135. }
  136. if (DeviceModel.ValveProcessGasFinal != null)
  137. DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
  138. throw (new RoutineFaildException());
  139. }
  140. else if (ret.Item2 == Result.TIMEOUT) //timeout
  141. {
  142. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3 , DeviceModel.ValveMfc4 , DeviceModel.ValveMfc5 };
  143. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  144. string reason = string.Empty;
  145. for (int i = 0; i < mfcs.Length && i<valves.Length; i++)
  146. {
  147. if (valves[i] != null)
  148. valves[i].TurnValve(false, out reason);
  149. if (mfcs[i] != null)
  150. mfcs[i].Ramp(0, 0);
  151. }
  152. if (DeviceModel.ValveProcessGasFinal != null)
  153. DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
  154. error(string.Format("MFC not flow noramlly in {0} seconds", time));
  155. throw (new RoutineFaildException());
  156. }
  157. else
  158. throw (new RoutineBreakException());
  159. }
  160. }
  161. public void CheckStable(int id, string name, int alarmTime, Action<string> notify, Action<string> error)
  162. {
  163. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  164. {
  165. notify(name);
  166. delayTimer.Start(0);
  167. return true;
  168. }, () =>
  169. {
  170. if (DeviceModel.ThrottleValve != null)
  171. {
  172. if (DeviceModel.ThrottleValve.PressureMode == PressureCtrlMode.TVPressureCtrl)
  173. return DeviceModel.PressureMeterChamber.Value < DeviceModel.ThrottleValve.PressureSetpoint;
  174. }
  175. return (delayTimer.GetElapseTime()/1000 > 10);
  176. }, alarmTime * 1000);
  177. if (ret.Item1)
  178. {
  179. if (ret.Item2 == Result.FAIL)
  180. {
  181. throw (new RoutineFaildException());
  182. }
  183. else if (ret.Item2 == Result.TIMEOUT) //timeout
  184. {
  185. error(string.Format(Resources.GasFlowRoutine_CheckStable_GasFlowPressureNotStableIn0Seconds, alarmTime));
  186. throw (new RoutineFaildException());
  187. }
  188. else
  189. throw (new RoutineBreakException());
  190. }
  191. }
  192. }
  193. }