RouteManager.cs 33 KB

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