RouteManager.cs 33 KB

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