LLEntity.cs 14 KB

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