RouteManager.cs 33 KB

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