RouteManager.cs 32 KB

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