LLEntity.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. using System;
  2. using Aitex.Core.Util;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using Venus_RT.Modules.TM;
  8. using Venus_RT.Devices;
  9. using Venus_Core;
  10. namespace Venus_RT.Modules
  11. {
  12. class LLEntity : Entity, IEntity, IModuleEntity
  13. {
  14. public enum LLStatus
  15. {
  16. Not_Ready,
  17. Ready_For_TM,
  18. Ready_For_EFEM,
  19. }
  20. public enum STATE
  21. {
  22. Unknown,
  23. Init,
  24. Initializing,
  25. Idle,
  26. Error,
  27. Pumping,
  28. Venting,
  29. Purging,
  30. LeakCheck,
  31. Prepare_For_TM,
  32. Prepare_For_EFEM,
  33. Ready_For_TM,
  34. Ready_For_EFEM,
  35. }
  36. public enum MSG
  37. {
  38. Home,
  39. Online,
  40. Offline,
  41. Pump,
  42. Vent,
  43. Purge,
  44. CyclePurge,
  45. LeakCheck,
  46. Prepare_TM,
  47. Prepare_EFEM,
  48. TM_Exchange_Ready,
  49. EFEM_Exchange_Ready,
  50. Error,
  51. Abort,
  52. }
  53. public ModuleName Module { get; private set; }
  54. public LLStatus Status { get; private set; }
  55. public bool Check(int msg, out string reason, params object[] args)
  56. {
  57. throw new NotImplementedException();
  58. }
  59. public bool IsIdle
  60. {
  61. get { return fsm.State == (int)STATE.Idle; }
  62. }
  63. public bool IsError
  64. {
  65. get { return fsm.State == (int)STATE.Error; }
  66. }
  67. public bool IsInit
  68. {
  69. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  70. }
  71. public bool IsBusy
  72. {
  73. get { return !IsInit && !IsError && !IsIdle; }
  74. }
  75. public bool IsOnline { get; internal set; }
  76. private readonly JetTM _JetTM;
  77. private readonly MFPumpRoutine _pumpingRoutine;
  78. private readonly MFVentRoutine _ventingRoutine;
  79. private readonly MFLeakCheckRoutine _leakCheckRoutine;
  80. private readonly MFPurgeRoutine _purgeRoutine;
  81. public LLEntity(ModuleName module)
  82. {
  83. Module = module;
  84. _JetTM = Singleton<JetTM>.Instance;
  85. _pumpingRoutine = new MFPumpRoutine(_JetTM, Module);
  86. _ventingRoutine = new MFVentRoutine(_JetTM, Module);
  87. _leakCheckRoutine = new MFLeakCheckRoutine(_JetTM, Module);
  88. _purgeRoutine = new MFPurgeRoutine(_JetTM, Module);
  89. WaferManager.Instance.SubscribeLocation(Module, 4);
  90. InitFsmMap();
  91. }
  92. private void InitFsmMap()
  93. {
  94. fsm = new StateMachine<LLEntity>(Module.ToString(), (int)STATE.Init, 50);
  95. fsm.EnableRepeatedMsg(true);
  96. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_TM, fnEnterTMReady, FSM_MSG.NONE, fnExitTMReady);
  97. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_EFEM, fnEnterEFEMReady, FSM_MSG.NONE, fnExitEFEMReady);
  98. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  99. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  100. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  101. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  102. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  103. // Home
  104. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  105. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  106. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  107. //vent sequence
  108. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  109. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  110. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  111. //Pump sequence
  112. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  113. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  114. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  115. // Purge sequence
  116. Transition(STATE.Idle, MSG.CyclePurge, FnStartPurge, STATE.Purging);
  117. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  118. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  119. // Leak check sequence
  120. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.LeakCheck);
  121. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  122. Transition(STATE.LeakCheck, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  123. // Prepare TM Transfer
  124. Transition(STATE.Idle, MSG.Prepare_TM, FnStartPrepareTM, STATE.Prepare_For_TM);
  125. Transition(STATE.Prepare_For_TM, FSM_MSG.TIMER, FnPreparaTMTimeout, STATE.Ready_For_TM);
  126. Transition(STATE.Ready_For_TM, MSG.TM_Exchange_Ready, null, STATE.Idle);
  127. // Prepare EFEM Transfer
  128. Transition(STATE.Idle, MSG.Prepare_EFEM, FnStartPrepareEFEM, STATE.Prepare_For_EFEM);
  129. Transition(STATE.Prepare_For_EFEM, FSM_MSG.TIMER, FnPrepareEFEMTimeout, STATE.Ready_For_EFEM);
  130. Transition(STATE.Ready_For_EFEM, MSG.EFEM_Exchange_Ready, null, STATE.Idle);
  131. Running = true;
  132. }
  133. public int Invoke(string function, params object[] args)
  134. {
  135. switch (function)
  136. {
  137. case "Home":
  138. CheckToPostMessage((int)MSG.Home);
  139. return (int)MSG.Home;
  140. }
  141. return (int)FSM_MSG.NONE;
  142. }
  143. public bool CheckAcked(int msg)
  144. {
  145. return fsm.CheckExecuted(msg);
  146. }
  147. public bool CheckToPostMessage(int msg, params object[] args)
  148. {
  149. if (!fsm.FindTransition(fsm.State, msg))
  150. {
  151. LOG.Write(eEvent.WARN_FSM_WARN, Module, $"{Module} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  152. return false;
  153. }
  154. Running = true;
  155. fsm.PostMsg(msg, args);
  156. return true;
  157. }
  158. private bool fnEnterTMReady(object[] param)
  159. {
  160. Status = LLStatus.Ready_For_TM;
  161. return true;
  162. }
  163. private bool fnExitTMReady(object[] param)
  164. {
  165. Status = LLStatus.Not_Ready;
  166. return true;
  167. }
  168. private bool fnEnterEFEMReady(object[] param)
  169. {
  170. Status = LLStatus.Ready_For_EFEM;
  171. return true;
  172. }
  173. private bool fnExitEFEMReady(object[] param)
  174. {
  175. Status = LLStatus.Not_Ready;
  176. return true;
  177. }
  178. private bool fnMonitor(object[] param)
  179. {
  180. _debugRoutine();
  181. return true;
  182. }
  183. private bool fnError(object[] param)
  184. {
  185. IsOnline = false;
  186. return true;
  187. }
  188. private bool fnOnline(object[] param)
  189. {
  190. IsOnline = true;
  191. return true;
  192. }
  193. private bool fnOffline(object[] param)
  194. {
  195. IsOnline = false;
  196. return true;
  197. }
  198. private bool fnAbort(object[] param)
  199. {
  200. return true;
  201. }
  202. private bool fnHome(object[] param)
  203. {
  204. return true;
  205. }
  206. private bool fnHoming(object[] param)
  207. {
  208. return true;
  209. }
  210. private bool FnStartVent(object[] param)
  211. {
  212. return _ventingRoutine.Start() == RState.Running;
  213. }
  214. private bool FnVentTimeout(object[] param)
  215. {
  216. RState ret = _ventingRoutine.Monitor();
  217. if (ret == RState.Failed || ret == RState.Timeout)
  218. {
  219. PostMsg(MSG.Error);
  220. return false;
  221. }
  222. return ret == RState.End;
  223. }
  224. private bool FnAbortVent(object[] param)
  225. {
  226. _ventingRoutine.Abort();
  227. return true;
  228. }
  229. private bool FnStartPump(object[] param)
  230. {
  231. return _pumpingRoutine.Start() == RState.Running;
  232. }
  233. private bool FnPumpTimeout(object[] param)
  234. {
  235. RState ret = _pumpingRoutine.Monitor();
  236. if (ret == RState.Failed || ret == RState.Timeout)
  237. {
  238. PostMsg(MSG.Error);
  239. return false;
  240. }
  241. return ret == RState.End;
  242. }
  243. private bool FnAbortPump(object[] param)
  244. {
  245. _pumpingRoutine.Abort();
  246. return true;
  247. }
  248. private bool FnStartPurge(object[] param)
  249. {
  250. return _purgeRoutine.Start() == RState.Running;
  251. }
  252. private bool FnPurgeTimeout(object[] param)
  253. {
  254. RState ret = _purgeRoutine.Monitor();
  255. if (ret == RState.Failed || ret == RState.Timeout)
  256. {
  257. PostMsg(MSG.Error);
  258. return false;
  259. }
  260. return ret == RState.End;
  261. }
  262. private bool FnAbortPurge(object[] param)
  263. {
  264. _purgeRoutine.Abort();
  265. return true;
  266. }
  267. private bool FnStartLeakCheck(object[] param)
  268. {
  269. return _leakCheckRoutine.Start() == RState.Running;
  270. }
  271. private bool FnLeakCheckTimeout(object[] param)
  272. {
  273. RState ret = _leakCheckRoutine.Monitor();
  274. if (ret == RState.Failed || ret == RState.Timeout)
  275. {
  276. PostMsg(MSG.Error);
  277. return false;
  278. }
  279. return ret == RState.End;
  280. }
  281. private bool FnAbortLeakCheck(object[] param)
  282. {
  283. _leakCheckRoutine.Abort();
  284. return true;
  285. }
  286. private bool FnStartPrepareTM(object[] param)
  287. {
  288. return _pumpingRoutine.Start() == RState.Running;
  289. }
  290. private bool FnPreparaTMTimeout(object[] param)
  291. {
  292. RState ret = _pumpingRoutine.Monitor();
  293. if (ret == RState.Failed || ret == RState.Timeout)
  294. {
  295. PostMsg(MSG.Error);
  296. return false;
  297. }
  298. return ret == RState.End;
  299. }
  300. private bool FnStartPrepareEFEM(object[] param)
  301. {
  302. return _ventingRoutine.Start() == RState.Running;
  303. }
  304. private bool FnPrepareEFEMTimeout(object[] param)
  305. {
  306. RState ret = _ventingRoutine.Monitor();
  307. if (ret == RState.Failed || ret == RState.Timeout)
  308. {
  309. PostMsg(MSG.Error);
  310. return false;
  311. }
  312. return ret == RState.End;
  313. }
  314. private void _debugRoutine()
  315. {
  316. int flag = 0;
  317. // Test Home routine
  318. if (flag == 1)
  319. {
  320. PostMsg(MSG.Home);
  321. }
  322. else if (flag == 2)
  323. {
  324. PostMsg(MSG.Vent);
  325. }
  326. else if (flag == 3)
  327. {
  328. PostMsg(MSG.Pump);
  329. }
  330. //else if (flag == 4)
  331. //{
  332. // PostMsg(MSG.PumpLoadLock);
  333. //}
  334. //else if (flag == 5)
  335. //{
  336. // PostMsg(MSG.VentLoadLock);
  337. //}
  338. //else if (flag == 6)
  339. //{
  340. // PostMsg(MSG.PurgeLoadLock);
  341. //}
  342. //else if (flag == 7)
  343. //{
  344. // PostMsg(MSG.LaunchPump);
  345. //}
  346. //else if (flag == 8)
  347. //{
  348. // PostMsg(MSG.LaunchTurboPump);
  349. //}
  350. //else if (flag == 9)
  351. //{
  352. // PostMsg(MSG.LoadLockLeakCheck);
  353. //}
  354. else if (flag == 10)
  355. {
  356. PostMsg(MSG.CyclePurge);
  357. }
  358. //else if (flag == 11)
  359. //{
  360. // PostMsg(MSG.GasLinePurge);
  361. //}
  362. //else if (flag == 12)
  363. //{
  364. // PostMsg(MSG.LeakCheck);
  365. //}
  366. //else if (flag == 13)
  367. //{
  368. // PostMsg(MSG.GasLeakCheck);
  369. //}
  370. //else if (flag == 14)
  371. //{
  372. // PostMsg(MSG.LLPlace);
  373. //}
  374. //else if (flag == 15)
  375. //{
  376. // PostMsg(MSG.LLPick);
  377. //}
  378. //else if (flag == 16)
  379. //{
  380. // PostMsg(MSG.RunRecipe, "7777");
  381. //}
  382. //else if (flag == 17)
  383. //{
  384. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  385. //}
  386. }
  387. }
  388. }