LLEntity.cs 17 KB

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