LLEntity.cs 14 KB

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