PMBaseRoutine.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using System;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  5. namespace FurnaceRT.Equipments.PMs.Routines
  6. {
  7. public class PMBaseRoutine : ModuleRoutine, IRoutine
  8. {
  9. protected PMModule PMModule
  10. {
  11. get { return _pm; }
  12. }
  13. private PMModule _pm;
  14. public PMBaseRoutine(ModuleName module, PMModule pm)
  15. {
  16. Module = module.ToString();
  17. _pm = pm;
  18. }
  19. public virtual Result Start(params object[] objs)
  20. {
  21. return Result.DONE;
  22. }
  23. public virtual Result Monitor()
  24. {
  25. return Result.DONE;
  26. }
  27. public virtual void Abort()
  28. {
  29. }
  30. protected void TurnPumpOn(int id, PMModule pm, int timeout)
  31. {
  32. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  33. {
  34. Notify($"Turn on {pm.Name} pump");
  35. //if (!pm.MainPump.SetPump(out string reason, 0, true))
  36. //{
  37. // Stop(reason);
  38. // return false;
  39. //}
  40. return true;
  41. }, () =>
  42. {
  43. return true/*pm.MainPump.IsRunning*/;
  44. }, timeout * 1000);
  45. if (ret.Item1)
  46. {
  47. if (ret.Item2 == Result.FAIL)
  48. {
  49. throw (new RoutineFaildException());
  50. }
  51. else
  52. {
  53. throw (new RoutineBreakException());
  54. }
  55. }
  56. }
  57. protected void StopAllGasFlow(int id, PMModule pm)
  58. {
  59. Tuple<bool, Result> ret = Execute (id, () =>
  60. {
  61. Notify($"Turn off all {pm.Name} gas flow");
  62. string reason = "";
  63. foreach(var stick in PMModule.GasSticks)
  64. {
  65. if (!stick.SetFlow(out reason, 0, 0))
  66. {
  67. Stop(reason);
  68. return false;
  69. }
  70. }
  71. return true;
  72. } );
  73. if (ret.Item1)
  74. {
  75. if (ret.Item2 == Result.FAIL)
  76. {
  77. throw (new RoutineFaildException());
  78. }
  79. else
  80. throw (new RoutineBreakException());
  81. }
  82. }
  83. protected void PumpToHighVacuum(int id, string stepName, PM pm, double pumpHighVacuumPressure, int tvPosition, int timeout)
  84. {
  85. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  86. {
  87. Notify($"Run {pm.Name} fast pump to {pumpHighVacuumPressure:F2} Torr");
  88. //if (!pm.FastPump(tvPosition, out string reason))
  89. //{
  90. // Stop(reason);
  91. // return false;
  92. //}
  93. _stepSpan = new TimeSpan(0, 0, 0, (int)timeout);
  94. _stepStartTime = DateTime.Now;
  95. _stepName = stepName;
  96. return true;
  97. }, () =>
  98. {
  99. if (pm.IsError)
  100. {
  101. Stop($"{pm.Name} error");
  102. return null;
  103. }
  104. return pm.ChamberPressure < pumpHighVacuumPressure;
  105. }, timeout * 1000);
  106. if (ret.Item1)
  107. {
  108. if (ret.Item2 == Result.FAIL)
  109. {
  110. throw (new RoutineFaildException());
  111. }
  112. else if (ret.Item2 == Result.TIMEOUT) //timeout
  113. {
  114. Stop($"{pm.Name} pump to gas line pump pressure timeout, over {timeout} seconds");
  115. throw (new RoutineFaildException());
  116. }
  117. else
  118. throw (new RoutineBreakException());
  119. }
  120. }
  121. protected void CheckForelinePressure(int id, string stepName, PM pm, double forelineBasePressure, int timeout)
  122. {
  123. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  124. {
  125. Notify($"Run {pm.Name} check foreline pressure lower than {forelineBasePressure:F2} Torr");
  126. _stepSpan = new TimeSpan(0, 0, 0, (int)timeout);
  127. _stepStartTime = DateTime.Now;
  128. _stepName = stepName;
  129. return true;
  130. }, () =>
  131. {
  132. if (pm.IsError)
  133. {
  134. Stop($"{pm.Name} error");
  135. return null;
  136. }
  137. return pm.ForelinePressure <= forelineBasePressure;
  138. }, timeout * 1000);
  139. if (ret.Item1)
  140. {
  141. if (ret.Item2 == Result.FAIL)
  142. {
  143. throw (new RoutineFaildException());
  144. }
  145. else if (ret.Item2 == Result.TIMEOUT) //timeout
  146. {
  147. Stop($"{pm.Name} wait foreline lower than {forelineBasePressure:F2} Torr timeout, over {timeout} seconds");
  148. throw (new RoutineFaildException());
  149. }
  150. else
  151. throw (new RoutineBreakException());
  152. }
  153. }
  154. protected void CheckChamberOk(int id, PMModuleBase pm)
  155. {
  156. Tuple<bool, Result> ret = Execute(id, () =>
  157. {
  158. Notify($"Run {pm.Name} check chamber running no error");
  159. if (pm.IsError)
  160. {
  161. Stop($"{pm.Name} error");
  162. return false;
  163. }
  164. return true;
  165. });
  166. if (ret.Item1)
  167. {
  168. if (ret.Item2 == Result.FAIL)
  169. {
  170. throw (new RoutineFaildException());
  171. }
  172. else
  173. {
  174. throw (new RoutineBreakException());
  175. }
  176. }
  177. }
  178. public void ToReadyProcessState(int id, PMModule pm,int timeout)
  179. {
  180. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  181. {
  182. Notify($"prepare chamber {pm.Name} ready to run process");
  183. string reason = "";
  184. //if (!pm.ChamberDoor.Close(out string reason))
  185. //{
  186. // Stop(reason);
  187. // return false;
  188. //}
  189. foreach (var stick in PMModule.GasSticks)
  190. {
  191. if (!stick.SetFlow(out reason, 0, 0))
  192. {
  193. Stop(reason);
  194. return false;
  195. }
  196. }
  197. return true;
  198. }, () =>
  199. {
  200. return true/*pm.ChamberDoor.IsClose*/;
  201. }, timeout * 1000);
  202. if (ret.Item1)
  203. {
  204. if (ret.Item2 == Result.FAIL)
  205. {
  206. throw (new RoutineFaildException());
  207. }
  208. else if (ret.Item2 == Result.TIMEOUT) //timeout
  209. {
  210. Stop($"{pm.Name} prepare process timeout, over {timeout} seconds");
  211. throw (new RoutineFaildException());
  212. }
  213. else
  214. {
  215. throw (new RoutineBreakException());
  216. }
  217. }
  218. }
  219. public void MovePinDown(int id, PMModule pm, int timeout)
  220. {
  221. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  222. {
  223. Notify($"move {pm.Name} lift pin down");
  224. //if (!pm.ChamberLiftPin.MoveDown(out string reason))
  225. //{
  226. // Stop(reason);
  227. // return false;
  228. //}
  229. return true;
  230. }, () =>
  231. {
  232. return true/*pm.ChamberLiftPin.IsDown*/;
  233. }, timeout * 1000);
  234. if (ret.Item1)
  235. {
  236. if (ret.Item2 == Result.FAIL)
  237. {
  238. throw (new RoutineFaildException());
  239. }
  240. else if (ret.Item2 == Result.TIMEOUT) //timeout
  241. {
  242. Stop($"{pm.Name} move lift pin timeout, over {timeout} seconds");
  243. throw (new RoutineFaildException());
  244. }
  245. else
  246. {
  247. throw (new RoutineBreakException());
  248. }
  249. }
  250. }
  251. public void MovePinUp(int id, PMModule pm, int timeout)
  252. {
  253. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  254. {
  255. Notify($"move {pm.Name} lift pin up");
  256. //if (!pm.ChamberLiftPin.MoveUp(out string reason))
  257. //{
  258. // Stop(reason);
  259. // return false;
  260. //}
  261. return true;
  262. }, () =>
  263. {
  264. return true/*pm.ChamberLiftPin.IsUp*/;
  265. }, timeout * 1000);
  266. if (ret.Item1)
  267. {
  268. if (ret.Item2 == Result.FAIL)
  269. {
  270. throw (new RoutineFaildException());
  271. }
  272. else if (ret.Item2 == Result.TIMEOUT) //timeout
  273. {
  274. Stop($"{pm.Name} move lift pin timeout, over {timeout} seconds");
  275. throw (new RoutineFaildException());
  276. }
  277. else
  278. {
  279. throw (new RoutineBreakException());
  280. }
  281. }
  282. }
  283. }
  284. }