RouteManager.cs 33 KB

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