RouteManager.cs 32 KB

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