RouteManager.cs 29 KB

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