RouteManager.cs 31 KB

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