RouteManager.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.RT.Fsm;
  8. using Aitex.Core.Common;
  9. using Aitex.Core.RT.DataCenter;
  10. using Aitex.Core.RT.Event;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Routine;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.Util;
  15. using MECF.Framework.Common.Equipment;
  16. using MECF.Framework.Common.SubstrateTrackings;
  17. using Venus_Core;
  18. using Venus_RT.Modules.PMs;
  19. using Aitex.Core.RT.Log;
  20. using Venus_RT.HostWrapper;
  21. namespace Venus_RT.Modules
  22. {
  23. class RouteManager : Entity, IEntity
  24. {
  25. public enum MSG
  26. {
  27. MoveWafer,
  28. ReturnWafer,
  29. HomeUnit,
  30. PauseAuto,
  31. ResumeAuto,
  32. Stop,
  33. StartCycle,
  34. StopCycle,
  35. HOME,
  36. RESET,
  37. ABORT,
  38. ERROR,
  39. SetAutoMode,
  40. SetManualMode,
  41. ResetIdleCleanTime,
  42. ResetIdlePurgeTime,
  43. CreateJob,
  44. PauseJob,
  45. ResumeJob,
  46. StartJob,
  47. StopJob,
  48. AbortJob,
  49. JobDone,
  50. CassetteLeave, //For unload light control off afer job done
  51. Map,
  52. ReturnAllWafer,
  53. TMCycle,
  54. }
  55. public PMEntity PMA { get; private set; }
  56. public PMEntity PMB { get; private set; }
  57. public PMEntity PMC { get; private set; }
  58. public PMEntity PMD { get; private set; }
  59. public TMEntity TM { get; private set; }
  60. public LLEntity LLA { get; private set; }
  61. public LLEntity LLB { get; private set; }
  62. public EfemEntity EFEM { get; private set; }
  63. public string Name { get; set; }
  64. public bool IsAutoMode
  65. {
  66. get
  67. {
  68. return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle;
  69. }
  70. }
  71. public bool IsInit
  72. {
  73. get { return fsm.State == (int)RtState.Init; }
  74. }
  75. public bool IsIdle
  76. {
  77. get { return fsm.State == (int)RtState.Idle || fsm.State == (int)RtState.AutoIdle; }
  78. }
  79. public bool IsAlarm
  80. {
  81. get { return fsm.State == (int)RtState.Error; }
  82. }
  83. public bool IsEntityError
  84. {
  85. get
  86. {
  87. return (EFEM?.IsError ?? false)
  88. || (PMA?.IsError ?? false)
  89. || (PMB?.IsError ?? false)
  90. || (PMC?.IsError ?? false)
  91. || (PMD?.IsError ?? false);
  92. }
  93. }
  94. public bool IsRunning
  95. {
  96. get
  97. {
  98. return !IsInit && !IsAlarm && !IsIdle;
  99. }
  100. }
  101. public static bool IsATMMode
  102. {
  103. get
  104. {
  105. if(_isATMMode == -1)
  106. {
  107. _isATMMode = SC.GetValue<bool>("System.IsATMMode") ? 1 : 0;
  108. }
  109. return _isATMMode == 1;
  110. }
  111. }
  112. private TMCycle _TMCycle;
  113. private AutoCycle _AutoCycle;
  114. private ManualTransfer _manualTransfer;
  115. private ReturnAllWafer _returnWafer;
  116. private bool _isWaitUnload;
  117. private static int _isATMMode = -1;
  118. public RouteManager()
  119. {
  120. Name = "System";
  121. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  122. PMA = new PMEntity(ModuleName.PMA);
  123. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  124. PMB = new PMEntity(ModuleName.PMB);
  125. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  126. PMC = new PMEntity(ModuleName.PMC);
  127. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  128. PMD = new PMEntity(ModuleName.PMD);
  129. if (ModuleHelper.IsInstalled(ModuleName.TM))
  130. TM = new TMEntity();
  131. if (ModuleHelper.IsInstalled(ModuleName.LLA))
  132. LLA = new LLEntity(ModuleName.LLA);
  133. if (ModuleHelper.IsInstalled(ModuleName.LLB))
  134. LLB = new LLEntity(ModuleName.LLB);
  135. if (ModuleHelper.IsInstalled(ModuleName.EFEM))
  136. EFEM = new EfemEntity();
  137. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 200);
  138. SubscribeOperation();
  139. SubscribeDataVariable();
  140. }
  141. public bool Check(int msg, out string reason, params object[] args)
  142. {
  143. if (!fsm.FindTransition(fsm.State, msg))
  144. {
  145. reason = String.Format("{0} is in {1} state,can not do {2}", Name, 0, (MSG)msg);
  146. return false;
  147. }
  148. if (msg == (int)MSG.StartCycle)
  149. {
  150. if (!IsAutoMode)
  151. {
  152. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  153. return false;
  154. }
  155. }
  156. reason = "";
  157. return true;
  158. }
  159. void SubscribeDataVariable()
  160. {
  161. DATA.Subscribe("Rt.Status", () => ((RtState)fsm.State).ToString());
  162. DATA.Subscribe(ModuleName.System.ToString(), "AlarmEvent", EV.GetAlarmEvent);
  163. DATA.Subscribe("System.IsAutoMode", () => IsAutoMode);
  164. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit);
  165. DATA.Subscribe("System.IsAlarm", () => IsAlarm || IsEntityError);
  166. DATA.Subscribe("System.IsBusy", () => IsRunning);
  167. DATA.Subscribe("System.IsWaitUnload", () => _isWaitUnload && IsAutoMode);
  168. DATA.Subscribe("System.IsConnectedWithHost", () => Singleton<FaManager>.Instance.IsConnected);
  169. DATA.Subscribe("EquipmentMode", () => IsAutoMode ? 0 : 1, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  170. DATA.Subscribe("EquipmentStatus", () =>
  171. {
  172. //"0 = Uninit
  173. //1 = Idle
  174. //2 = Running
  175. //3 = Error
  176. //4 = Pause
  177. //"
  178. if (IsInit) return 0;
  179. if (IsIdle) return 1;
  180. if (IsAlarm) return 3;
  181. return 2;
  182. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  183. }
  184. void SubscribeOperation()
  185. {
  186. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  187. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  188. OP.Subscribe("System.Home", (cmd, args) => CheckToPostMessage((int)MSG.HOME, args));
  189. OP.Subscribe("TMCycle.Start", (cmd, args) => CheckToPostMessage((int)MSG.TMCycle, args));
  190. OP.Subscribe("TMCycle.Abort", (cmd, args) => CheckToPostMessage((int)MSG.StopCycle, args));
  191. DATA.Subscribe("SYSTEM.FsmState", () => (((RtState)fsm.State).ToString()));
  192. DATA.Subscribe("TMCycle.CycleIndex", () => (_TMCycle?.CycleIndex));
  193. OP.Subscribe("ReturnWafer", InvokeReturnWafer);
  194. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  195. {
  196. return CheckToPostMessage((int)MSG.ReturnAllWafer, args[0], args[1], args[2], args[3]);
  197. });
  198. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  199. {
  200. if (!Enum.TryParse((string)args[0], out ModuleName source))
  201. {
  202. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  203. return false;
  204. }
  205. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  206. {
  207. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  208. return false;
  209. }
  210. return CheckToPostMessage((int)MSG.MoveWafer,
  211. source, (int)args[1],
  212. destination, (int)args[3],
  213. (bool)args[4], (int)args[5],
  214. (bool)args[6], (int)args[7], (string)args[8]);
  215. });
  216. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  217. {
  218. return CheckToPostMessage((int)MSG.HOME);
  219. });
  220. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  221. {
  222. return CheckToPostMessage((int)MSG.ABORT);
  223. });
  224. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  225. {
  226. return CheckToPostMessage((int)MSG.RESET);
  227. });
  228. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  229. {
  230. return CheckToPostMessage((int)MSG.SetAutoMode);
  231. });
  232. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  233. {
  234. return CheckToPostMessage((int)MSG.SetManualMode);
  235. });
  236. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  237. {
  238. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  239. });
  240. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  241. {
  242. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  243. });
  244. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  245. {
  246. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  247. });
  248. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  249. {
  250. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  251. });
  252. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  253. {
  254. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  255. });
  256. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  257. {
  258. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  259. });
  260. OP.Subscribe("LP1.Map", (string cmd, object[] args) =>
  261. {
  262. if (IsAutoMode)
  263. {
  264. return CheckToPostMessage((int)MSG.Map, ModuleName.LP1.ToString());
  265. }
  266. return EFEM.InvokeMap(ModuleName.LP1.ToString()) != (int)FSM_MSG.NONE;
  267. });
  268. OP.Subscribe("LP2.Map", (string cmd, object[] args) =>
  269. {
  270. if (IsAutoMode)
  271. {
  272. return CheckToPostMessage((int)MSG.Map, ModuleName.LP2.ToString());
  273. }
  274. return EFEM.InvokeMap(ModuleName.LP2.ToString()) != (int)FSM_MSG.NONE;
  275. });
  276. OP.Subscribe(RtOperation.SetConfig.ToString(), (name, args) =>
  277. {
  278. string sc_key = args[0] as string;
  279. if (!string.IsNullOrWhiteSpace(sc_key) && args.Length > 1)
  280. {
  281. SC.SetItemValue(sc_key, args[1]);
  282. }
  283. return true;
  284. });
  285. OP.Subscribe("System.ResetIdleCleanTime", (string cmd, object[] args) =>
  286. {
  287. return CheckToPostMessage((int)MSG.ResetIdleCleanTime, args[0]);
  288. });
  289. OP.Subscribe("System.ResetIdlePurgeTime", (string cmd, object[] args) =>
  290. {
  291. return CheckToPostMessage((int)MSG.ResetIdlePurgeTime, args[0]);
  292. });
  293. OP.Subscribe("System.SetWaferSize", (string cmd, object[] args) =>
  294. {
  295. string module = (string)args[0];
  296. string size = (string)args[1];
  297. switch (size)
  298. {
  299. case "3":
  300. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  301. break;
  302. case "4":
  303. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  304. break;
  305. case "6":
  306. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  307. break;
  308. default:
  309. EV.PostWarningLog("System", $"wafer size {size} not valid");
  310. break;
  311. }
  312. return true;
  313. });
  314. OP.Subscribe("System.CassetteLeave", (string cmd, object[] args) =>
  315. {
  316. return CheckToPostMessage((int)MSG.CassetteLeave);
  317. });
  318. OP.Subscribe("System.IsModuleInstalled", (string cmd, object[] args) => {
  319. return ModuleHelper.IsInstalled((ModuleName)args[0]);
  320. });
  321. }
  322. public bool CheckToPostMessage(int msg, params object[] args)
  323. {
  324. if (!fsm.FindTransition(fsm.State, msg))
  325. {
  326. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"System is in {(RtState)fsm.State} state,can not do {(MSG)msg}");
  327. return false;
  328. }
  329. Running = true;
  330. fsm.PostMsg(msg, args);
  331. return true;
  332. }
  333. private bool InvokeCreateWafer(string arg1, object[] args)
  334. {
  335. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  336. int slot = (int)args[1];
  337. WaferStatus state = WaferStatus.Normal;
  338. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  339. {
  340. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  341. {
  342. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  343. }
  344. else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
  345. {
  346. LOG.Write(eEvent.EV_WAFER_CREATE, ModuleName.System, chamber.ToString(), (slot + 1).ToString(), state.ToString());
  347. }
  348. }
  349. else
  350. {
  351. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  352. return false;
  353. }
  354. return true;
  355. }
  356. private bool InvokeDeleteWafer(string arg1, object[] args)
  357. {
  358. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  359. int slot = (int)args[1];
  360. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  361. {
  362. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  363. {
  364. WaferManager.Instance.DeleteWafer(chamber, slot);
  365. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  366. }
  367. else
  368. {
  369. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  370. }
  371. }
  372. else
  373. {
  374. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  375. return false;
  376. }
  377. return true;
  378. }
  379. private bool InvokeReturnWafer(string arg1, object[] args)
  380. {
  381. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  382. int slot = (int)args[1];
  383. if (ModuleHelper.IsLoadPort(target))
  384. {
  385. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  386. return false;
  387. }
  388. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  389. {
  390. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  391. return false;
  392. }
  393. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  394. if (wafer.IsEmpty)
  395. {
  396. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  397. return false;
  398. }
  399. return CheckToPostMessage((int)MSG.MoveWafer,
  400. target, slot,
  401. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  402. false, 0, false, 0, "Blade1");
  403. }
  404. public PMEntity GetPM(ModuleName mod)
  405. {
  406. if (ModuleHelper.IsInstalled(mod))
  407. {
  408. switch (mod)
  409. {
  410. case ModuleName.PMA:
  411. return PMA;
  412. case ModuleName.PMB:
  413. return PMB;
  414. case ModuleName.PMC:
  415. return PMC;
  416. case ModuleName.PMD:
  417. return PMD;
  418. }
  419. }
  420. return null;
  421. }
  422. public LLEntity GetLL(ModuleName mod)
  423. {
  424. if (ModuleHelper.IsInstalled(mod))
  425. {
  426. switch (mod)
  427. {
  428. case ModuleName.LLA:
  429. return LLA;
  430. case ModuleName.LLB:
  431. return LLB;
  432. }
  433. }
  434. return null;
  435. }
  436. public TMEntity GetTM()
  437. {
  438. return TM;
  439. }
  440. protected override bool Init()
  441. {
  442. PMA?.Initialize();
  443. PMB?.Initialize();
  444. PMC?.Initialize();
  445. PMD?.Initialize();
  446. TM?.Initialize();
  447. LLA?.Initialize();
  448. LLB?.Initialize();
  449. EFEM?.Initialize();
  450. _TMCycle = new TMCycle();
  451. _AutoCycle = new AutoCycle();
  452. _manualTransfer = new ManualTransfer();
  453. _returnWafer = new ReturnAllWafer(_manualTransfer);
  454. BuildTransitionTable();
  455. return true;
  456. }
  457. private void BuildTransitionTable()
  458. {
  459. fsm = new StateMachine<RouteManager>(ModuleName.System.ToString(), (int)RtState.Init, 50);
  460. //Init sequence
  461. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  462. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  463. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  464. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, FsmEnterAutoRunning, FSM_MSG.NONE, FsmExitAutoTransfer);
  465. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, FsmExitTransfer);
  466. EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
  467. AnyStateTransition(MSG.ERROR, FsmError, RtState.Error);
  468. Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
  469. Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
  470. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  471. Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
  472. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  473. // TM Cycle
  474. Transition(RtState.Idle, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  475. Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  476. Transition(RtState.TMCycle, MSG.StopCycle, FsmStopTMCycle, RtState.Idle);
  477. //Auto/manual
  478. Transition(RtState.Idle, MSG.SetAutoMode, FsmStartAutoTransfer, RtState.AutoIdle);
  479. Transition(RtState.AutoRunning, FSM_MSG.TIMER, FsmAutoTransfer, RtState.Idle);
  480. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbortAutoTransfer, RtState.Idle);
  481. //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  482. Transition(RtState.AutoRunning, MSG.JobDone, FsmJobDone, RtState.AutoIdle);
  483. //Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
  484. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  485. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  486. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  487. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  488. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  489. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  490. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  491. Transition(RtState.AutoRunning, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoRunning);
  492. Transition(RtState.AutoRunning, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoRunning);
  493. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  494. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  495. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  496. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  497. Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
  498. Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
  499. Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
  500. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  501. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  502. //Transfer
  503. Transition(RtState.Idle, MSG.MoveWafer, FsmStartTransfer, RtState.Transfer);
  504. Transition(RtState.Transfer, FSM_MSG.TIMER, FsmMonitorTransfer, RtState.Idle);
  505. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  506. //Return Wafer
  507. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  508. Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
  509. Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
  510. }
  511. private bool FsmMonitor(object[] objs)
  512. {
  513. _debugRoutine();
  514. return true;
  515. }
  516. private bool FsmStartHome(object[] objs)
  517. {
  518. PMA?.Invoke("Home");
  519. PMB?.Invoke("Home");
  520. PMC?.Invoke("Home");
  521. PMD?.Invoke("Home");
  522. TM?.Invoke("Home");
  523. LLA?.Invoke("Home");
  524. LLB?.Invoke("Home");
  525. EFEM?.Invoke("Home");
  526. return true;
  527. }
  528. private bool FsmMonitorHome(object[] objs)
  529. {
  530. bool CheckHomed(string name, bool bValid, bool bDone)
  531. {
  532. if (bValid && !bDone)
  533. {
  534. if (fsm.ElapsedTime > 100 * 1000)
  535. {
  536. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{name} home timeout");
  537. PostMsg(MSG.ERROR);
  538. return true;
  539. }
  540. else
  541. return false;
  542. }
  543. return true;
  544. }
  545. return CheckHomed("PMA", ModuleHelper.IsInstalled(ModuleName.PMA) && PMA != null, ModuleHelper.IsInstalled(ModuleName.PMA) && PMA != null&&PMA.IsIdle) &&
  546. CheckHomed("PMB", ModuleHelper.IsInstalled(ModuleName.PMB) && PMB != null, ModuleHelper.IsInstalled(ModuleName.PMB) && PMB != null&&PMB.IsIdle) &&
  547. CheckHomed("PMC", ModuleHelper.IsInstalled(ModuleName.PMC) && PMC != null, ModuleHelper.IsInstalled(ModuleName.PMC) && PMC != null&&PMC.IsIdle) &&
  548. CheckHomed("PMD", ModuleHelper.IsInstalled(ModuleName.PMD) && PMD != null, ModuleHelper.IsInstalled(ModuleName.PMD) && PMD != null&&PMD.IsIdle) &&
  549. CheckHomed("LLA", ModuleHelper.IsInstalled(ModuleName.LLA) && LLA != null, ModuleHelper.IsInstalled(ModuleName.LLA) && LLA != null&&LLA.IsIdle) &&
  550. CheckHomed("LLB", ModuleHelper.IsInstalled(ModuleName.LLB) && LLB != null, ModuleHelper.IsInstalled(ModuleName.LLB) && LLB != null&&LLB.IsIdle) &&
  551. CheckHomed("TM", ModuleHelper.IsInstalled(ModuleName.TM) && TM != null, ModuleHelper.IsInstalled(ModuleName.TM) && TM != null&&TM.IsIdle) &&
  552. CheckHomed("EFEM", ModuleHelper.IsInstalled(ModuleName.EFEM) && EFEM != null, ModuleHelper.IsInstalled(ModuleName.EFEM) && EFEM != null && EFEM.IsIdle);
  553. }
  554. private bool FsmEnterAutoRunning(object[] objs)
  555. {
  556. return true;
  557. }
  558. private bool FsmExitAutoTransfer(object[] objs)
  559. {
  560. _AutoCycle.Clear();
  561. return true;
  562. }
  563. private bool FsmExitTransfer(object[] objs)
  564. {
  565. _manualTransfer.Clear();
  566. return true;
  567. }
  568. private bool FsmExitReturnWafer(object[] objs)
  569. {
  570. _returnWafer.Clear();
  571. return true;
  572. }
  573. private bool FsmError(object[] objs)
  574. {
  575. return true;
  576. }
  577. private bool FsmAbort(object[] objs)
  578. {
  579. _manualTransfer.Clear();
  580. _returnWafer.Clear();
  581. _AutoCycle.Clear();
  582. return true;
  583. }
  584. private bool FsmStartTMCycle(object[] objs)
  585. {
  586. return _TMCycle.Start(objs) == RState.Running;
  587. }
  588. private bool FsmMonitorTMCycle(object[] objs)
  589. {
  590. RState ret = _TMCycle.Monitor();
  591. if (ret == RState.Failed || ret == RState.Timeout)
  592. {
  593. PostMsg(MSG.ERROR);
  594. return false;
  595. }
  596. return ret == RState.End;
  597. }
  598. private bool FsmStopTMCycle(object[] objs)
  599. {
  600. _TMCycle.Abort();
  601. return true;
  602. }
  603. private bool FsmStartAutoTransfer(object[] objs)
  604. {
  605. return _AutoCycle.Start(objs) == RState.Running;
  606. }
  607. private bool FsmAutoTransfer(object[] objs)
  608. {
  609. RState ret = _AutoCycle.Monitor();
  610. if(ret == RState.Failed)
  611. {
  612. if (!CheckToPostMessage((int)MSG.ERROR))
  613. return false;
  614. }
  615. if (_AutoCycle.CheckJobJustDone(out string jobInfo))
  616. {
  617. EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  618. }
  619. if (_AutoCycle.CheckAllJobDone())
  620. {
  621. if (!CheckToPostMessage((int)MSG.JobDone))
  622. return false;
  623. }
  624. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  625. return ret == RState.End;
  626. }
  627. private bool FsmAbortAutoTransfer(object[] objs)
  628. {
  629. _AutoCycle.Clear();
  630. return true;
  631. }
  632. private bool FsmJobDone(object[] objs)
  633. {
  634. _isWaitUnload = true;
  635. return true;
  636. }
  637. private bool FsmCreateJob(object[] objs)
  638. {
  639. _AutoCycle.CreateJob((Dictionary<string, object>)objs[0]);
  640. return true;
  641. }
  642. private bool FsmStartJob(object[] objs)
  643. {
  644. _AutoCycle.StartJob((string)objs[0]);
  645. return true;
  646. }
  647. private bool FsmPauseJob(object[] objs)
  648. {
  649. _AutoCycle.PauseJob((string)objs[0]);
  650. return true;
  651. }
  652. private bool FsmResumeJob(object[] objs)
  653. {
  654. _AutoCycle.ResumeJob((string)objs[0]);
  655. return true;
  656. }
  657. private bool FsmStopJob(object[] objs)
  658. {
  659. _AutoCycle.StopJob((string)objs[0]);
  660. return true;
  661. }
  662. private bool FsmAbortJob(object[] objs)
  663. {
  664. _AutoCycle.AbortJob((string)objs[0]);
  665. return true;
  666. }
  667. private bool FsmStartTransfer(object[] objs)
  668. {
  669. return _manualTransfer.Start(objs) == RState.Running;
  670. }
  671. private bool FsmMonitorTransfer(object[] objs)
  672. {
  673. RState ret = _manualTransfer.Monitor();
  674. if (ret == RState.Failed || ret == RState.Timeout)
  675. {
  676. PostMsg(MSG.ERROR);
  677. return false;
  678. }
  679. return ret == RState.End;
  680. }
  681. private bool FsmStartReturnWafer(object[] objs)
  682. {
  683. return _returnWafer.Start(objs) == RState.Running;
  684. }
  685. private bool FsmMonitorReturnWafer(object[] objs)
  686. {
  687. RState ret = _returnWafer.Monitor();
  688. if (ret == RState.Failed || ret == RState.Timeout)
  689. {
  690. PostMsg(MSG.ERROR);
  691. return false;
  692. }
  693. return ret == RState.End;
  694. }
  695. private bool FsmMap(object[] objs)
  696. {
  697. return true;
  698. }
  699. private bool FsmResetIdleCleanTime(object[] objs)
  700. {
  701. return true;
  702. }
  703. private bool FsmResetIdlePurgeTime(object[] objs)
  704. {
  705. return true;
  706. }
  707. private bool FsmMonitorAutoIdle(object[] objs)
  708. {
  709. RState ret = _AutoCycle.Monitor();
  710. //if (_AutoCycle.CheckAllJobDone())
  711. //{
  712. // if (!CheckToPostMessage((int)MSG.JobDone))
  713. // return false;
  714. //}
  715. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  716. _debugRoutine();
  717. return ret == RState.End;
  718. }
  719. private bool FsmStartSetManualMode(object[] objs)
  720. {
  721. if (_AutoCycle.HasJobRunning)
  722. {
  723. LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
  724. return false;
  725. }
  726. return true;
  727. }
  728. private void _debugRoutine()
  729. {
  730. int flag = 0;
  731. // Test Home routine
  732. if (flag == 1)
  733. {
  734. PostMsg(MSG.HOME);
  735. }
  736. else if (flag == 2)
  737. {
  738. PostMsg(MSG.TMCycle);
  739. }
  740. else if (flag == 3)
  741. {
  742. PostMsg(MSG.SetAutoMode);
  743. }
  744. else if (flag == 4)
  745. {
  746. PostMsg(MSG.ReturnAllWafer);
  747. }
  748. else if(flag == 5)
  749. {
  750. PostMsg(MSG.StartJob, "CJ_Local_LP1");
  751. }
  752. }
  753. }
  754. }