RouteManager.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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. }
  95. public bool IsRunning
  96. {
  97. get
  98. {
  99. return !IsInit && !IsAlarm && !IsIdle;
  100. }
  101. }
  102. private TMCycle _TMCycle;
  103. private AutoCycle _AutoCycle;
  104. private bool _isWaitUnload;
  105. public RouteManager()
  106. {
  107. Name = "System";
  108. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  109. PMA = new PMEntity(ModuleName.PMA);
  110. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  111. PMB = new PMEntity(ModuleName.PMB);
  112. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  113. PMC = new PMEntity(ModuleName.PMC);
  114. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  115. PMD = new PMEntity(ModuleName.PMD);
  116. if (ModuleHelper.IsInstalled(ModuleName.TM))
  117. TM = new TMEntity();
  118. if (ModuleHelper.IsInstalled(ModuleName.LLA))
  119. LLA = new LLEntity(ModuleName.LLA);
  120. if (ModuleHelper.IsInstalled(ModuleName.LLB))
  121. LLB = new LLEntity(ModuleName.LLB);
  122. if (ModuleHelper.IsInstalled(ModuleName.EFEM))
  123. EFEM = new EfemEntity();
  124. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 200);
  125. SubscribeOperation();
  126. SubscribeDataVariable();
  127. }
  128. public bool Check(int msg, out string reason, params object[] args)
  129. {
  130. if (!fsm.FindTransition(fsm.State, msg))
  131. {
  132. reason = String.Format("{0} is in {1} state,can not do {2}", Name, 0, (MSG)msg);
  133. return false;
  134. }
  135. if (msg == (int)MSG.StartCycle)
  136. {
  137. if (!IsAutoMode)
  138. {
  139. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  140. return false;
  141. }
  142. }
  143. reason = "";
  144. return true;
  145. }
  146. void SubscribeDataVariable()
  147. {
  148. DATA.Subscribe("Rt.Status", () => ((RtState)fsm.State).ToString());
  149. DATA.Subscribe(ModuleName.System.ToString(), "AlarmEvent", EV.GetAlarmEvent);
  150. DATA.Subscribe("System.IsAutoMode", () => IsAutoMode);
  151. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit);
  152. DATA.Subscribe("System.IsAlarm", () => IsAlarm || IsEntityError);
  153. DATA.Subscribe("System.IsBusy", () => IsRunning);
  154. DATA.Subscribe("System.IsWaitUnload", () => _isWaitUnload && IsAutoMode);
  155. DATA.Subscribe("System.IsConnectedWithHost", () => Singleton<FaManager>.Instance.IsConnected);
  156. DATA.Subscribe("EquipmentMode", () => IsAutoMode ? 0 : 1, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  157. DATA.Subscribe("EquipmentStatus", () =>
  158. {
  159. //"0 = Uninit
  160. //1 = Idle
  161. //2 = Running
  162. //3 = Error
  163. //4 = Pause
  164. //"
  165. if (IsInit) return 0;
  166. if (IsIdle) return 1;
  167. if (IsAlarm) return 3;
  168. return 2;
  169. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  170. }
  171. void SubscribeOperation()
  172. {
  173. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  174. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  175. OP.Subscribe("System.Home", (cmd, args) => CheckToPostMessage((int)MSG.HOME, args));
  176. OP.Subscribe("TMCycle.Start", (cmd, args) => CheckToPostMessage((int)MSG.TMCycle, args));
  177. OP.Subscribe("TMCycle.Abort", (cmd, args) => CheckToPostMessage((int)MSG.StopCycle, args));
  178. DATA.Subscribe("SYSTEM.FsmState", () => (((RtState)fsm.State).ToString()));
  179. DATA.Subscribe("TMCycle.CycleIndex", () => (_TMCycle?.CycleIndex));
  180. OP.Subscribe("ReturnWafer", InvokeReturnWafer);
  181. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  182. {
  183. return CheckToPostMessage((int)MSG.ReturnAllWafer, args[0], args[1], args[2], args[3]);
  184. });
  185. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  186. {
  187. if (!Enum.TryParse((string)args[0], out ModuleName source))
  188. {
  189. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  190. return false;
  191. }
  192. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  193. {
  194. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  195. return false;
  196. }
  197. return CheckToPostMessage((int)MSG.MoveWafer,
  198. source, (int)args[1],
  199. destination, (int)args[3],
  200. (bool)args[4], (int)args[5],
  201. (bool)args[6], (int)args[7], (string)args[8]);
  202. });
  203. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  204. {
  205. return CheckToPostMessage((int)MSG.HOME);
  206. });
  207. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  208. {
  209. return CheckToPostMessage((int)MSG.ABORT);
  210. });
  211. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  212. {
  213. return CheckToPostMessage((int)MSG.RESET);
  214. });
  215. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  216. {
  217. return CheckToPostMessage((int)MSG.SetAutoMode);
  218. });
  219. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  220. {
  221. return CheckToPostMessage((int)MSG.SetManualMode);
  222. });
  223. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  224. {
  225. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  226. });
  227. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  228. {
  229. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  230. });
  231. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  232. {
  233. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  234. });
  235. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  236. {
  237. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  238. });
  239. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  240. {
  241. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  242. });
  243. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  244. {
  245. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  246. });
  247. OP.Subscribe("LP1.Map", (string cmd, object[] args) =>
  248. {
  249. if (IsAutoMode)
  250. {
  251. return CheckToPostMessage((int)MSG.Map, ModuleName.LP1.ToString());
  252. }
  253. return EFEM.InvokeMap(ModuleName.LP1.ToString()) != (int)FSM_MSG.NONE;
  254. });
  255. OP.Subscribe("LP2.Map", (string cmd, object[] args) =>
  256. {
  257. if (IsAutoMode)
  258. {
  259. return CheckToPostMessage((int)MSG.Map, ModuleName.LP2.ToString());
  260. }
  261. return EFEM.InvokeMap(ModuleName.LP2.ToString()) != (int)FSM_MSG.NONE;
  262. });
  263. OP.Subscribe(RtOperation.SetConfig.ToString(), (name, args) =>
  264. {
  265. string sc_key = args[0] as string;
  266. if (!string.IsNullOrWhiteSpace(sc_key) && args.Length > 1)
  267. {
  268. SC.SetItemValue(sc_key, args[1]);
  269. }
  270. return true;
  271. });
  272. OP.Subscribe("System.ResetIdleCleanTime", (string cmd, object[] args) =>
  273. {
  274. return CheckToPostMessage((int)MSG.ResetIdleCleanTime, args[0]);
  275. });
  276. OP.Subscribe("System.ResetIdlePurgeTime", (string cmd, object[] args) =>
  277. {
  278. return CheckToPostMessage((int)MSG.ResetIdlePurgeTime, args[0]);
  279. });
  280. OP.Subscribe("System.SetWaferSize", (string cmd, object[] args) =>
  281. {
  282. string module = (string)args[0];
  283. string size = (string)args[1];
  284. switch (size)
  285. {
  286. case "3":
  287. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  288. break;
  289. case "4":
  290. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  291. break;
  292. case "6":
  293. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  294. break;
  295. default:
  296. EV.PostWarningLog("System", $"wafer size {size} not valid");
  297. break;
  298. }
  299. return true;
  300. });
  301. OP.Subscribe("System.CassetteLeave", (string cmd, object[] args) =>
  302. {
  303. return CheckToPostMessage((int)MSG.CassetteLeave);
  304. });
  305. OP.Subscribe("System.IsModuleInstalled", (string cmd, object[] args) => {
  306. return ModuleHelper.IsInstalled((ModuleName)args[0]);
  307. });
  308. }
  309. public bool CheckToPostMessage(int msg, params object[] args)
  310. {
  311. if (!fsm.FindTransition(fsm.State, msg))
  312. {
  313. LOG.Write(eEvent.WARN_FSM_WARN, ModuleName.TM, $"TM is in {(RtState)fsm.State} state,can not do {(MSG)msg}");
  314. return false;
  315. }
  316. Running = true;
  317. fsm.PostMsg(msg, args);
  318. return true;
  319. }
  320. private bool InvokeCreateWafer(string arg1, object[] args)
  321. {
  322. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  323. int slot = (int)args[1];
  324. WaferStatus state = WaferStatus.Normal;
  325. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  326. {
  327. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  328. {
  329. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  330. }
  331. else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
  332. {
  333. LOG.Write(eEvent.EV_WAFER_CREATE, ModuleName.System, chamber.ToString(), (slot + 1).ToString(), state.ToString());
  334. }
  335. }
  336. else
  337. {
  338. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  339. return false;
  340. }
  341. return true;
  342. }
  343. private bool InvokeDeleteWafer(string arg1, object[] args)
  344. {
  345. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  346. int slot = (int)args[1];
  347. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  348. {
  349. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  350. {
  351. WaferManager.Instance.DeleteWafer(chamber, slot);
  352. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  353. }
  354. else
  355. {
  356. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  357. }
  358. }
  359. else
  360. {
  361. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  362. return false;
  363. }
  364. return true;
  365. }
  366. private bool InvokeReturnWafer(string arg1, object[] args)
  367. {
  368. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  369. int slot = (int)args[1];
  370. if (ModuleHelper.IsLoadPort(target))
  371. {
  372. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  373. return false;
  374. }
  375. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  376. {
  377. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  378. return false;
  379. }
  380. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  381. if (wafer.IsEmpty)
  382. {
  383. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  384. return false;
  385. }
  386. return CheckToPostMessage((int)MSG.MoveWafer,
  387. target, slot,
  388. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  389. false, 0, false, 0, "Blade1");
  390. }
  391. public PMEntity GetPM(ModuleName mod)
  392. {
  393. if (ModuleHelper.IsInstalled(mod))
  394. {
  395. switch (mod)
  396. {
  397. case ModuleName.PMA:
  398. return PMA;
  399. case ModuleName.PMB:
  400. return PMB;
  401. case ModuleName.PMC:
  402. return PMC;
  403. case ModuleName.PMD:
  404. return PMD;
  405. }
  406. }
  407. return null;
  408. }
  409. public LLEntity GetLL(ModuleName mod)
  410. {
  411. if (ModuleHelper.IsInstalled(mod))
  412. {
  413. switch (mod)
  414. {
  415. case ModuleName.LLA:
  416. return LLA;
  417. case ModuleName.LLB:
  418. return LLB;
  419. }
  420. }
  421. return null;
  422. }
  423. public TMEntity GetTM()
  424. {
  425. return TM;
  426. }
  427. protected override bool Init()
  428. {
  429. PMA?.Initialize();
  430. PMB?.Initialize();
  431. PMC?.Initialize();
  432. PMD?.Initialize();
  433. TM?.Initialize();
  434. LLA?.Initialize();
  435. LLB?.Initialize();
  436. EFEM?.Initialize();
  437. _TMCycle = new TMCycle();
  438. _AutoCycle = new AutoCycle();
  439. BuildTransitionTable();
  440. return true;
  441. }
  442. private void BuildTransitionTable()
  443. {
  444. fsm = new StateMachine<RouteManager>(ModuleName.System.ToString(), (int)RtState.Init, 50);
  445. //Init sequence
  446. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  447. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  448. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  449. //// EnterExitTransition<RtState, FSM_MSG>(RtState.Initializing, fStartInit, FSM_MSG.NONE, null);
  450. ///
  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 (_AutoCycle.CheckJobJustDone(out string jobInfo))
  564. {
  565. EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  566. }
  567. if (_AutoCycle.CheckAllJobDone())
  568. {
  569. if (!CheckToPostMessage((int)MSG.JobDone))
  570. return false;
  571. }
  572. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  573. return ret == RState.End;
  574. }
  575. private bool FsmAbortAutoTransfer(object[] objs)
  576. {
  577. _AutoCycle.Clear();
  578. return true;
  579. }
  580. private bool FsmJobDone(object[] objs)
  581. {
  582. _isWaitUnload = true;
  583. return true;
  584. }
  585. private bool FsmCreateJob(object[] objs)
  586. {
  587. _AutoCycle.CreateJob((Dictionary<string, object>)objs[0]);
  588. return true;
  589. }
  590. private bool FsmStartJob(object[] objs)
  591. {
  592. _AutoCycle.StartJob((string)objs[0]);
  593. return true;
  594. }
  595. private bool FsmPauseJob(object[] objs)
  596. {
  597. _AutoCycle.PauseJob((string)objs[0]);
  598. return true;
  599. }
  600. private bool FsmResumeJob(object[] objs)
  601. {
  602. _AutoCycle.ResumeJob((string)objs[0]);
  603. return true;
  604. }
  605. private bool FsmStopJob(object[] objs)
  606. {
  607. _AutoCycle.StopJob((string)objs[0]);
  608. return true;
  609. }
  610. private bool FsmAbortJob(object[] objs)
  611. {
  612. _AutoCycle.AbortJob((string)objs[0]);
  613. return true;
  614. }
  615. private bool FsmMap(object[] objs)
  616. {
  617. return true;
  618. }
  619. private bool FsmResetIdleCleanTime(object[] objs)
  620. {
  621. return true;
  622. }
  623. private bool FsmResetIdlePurgeTime(object[] objs)
  624. {
  625. return true;
  626. }
  627. private bool FsmMonitorAutoIdle(object[] objs)
  628. {
  629. RState ret = _AutoCycle.Monitor();
  630. //if (_AutoCycle.CheckAllJobDone())
  631. //{
  632. // if (!CheckToPostMessage((int)MSG.JobDone))
  633. // return false;
  634. //}
  635. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  636. _debugRoutine();
  637. return ret == RState.End;
  638. }
  639. private bool FsmStartSetManualMode(object[] objs)
  640. {
  641. if (_AutoCycle.HasJobRunning)
  642. {
  643. LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
  644. return false;
  645. }
  646. return true;
  647. }
  648. private void _debugRoutine()
  649. {
  650. int flag = 0;
  651. // Test Home routine
  652. if (flag == 1)
  653. {
  654. PostMsg(MSG.HOME);
  655. }
  656. else if (flag == 2)
  657. {
  658. PostMsg(MSG.TMCycle);
  659. }
  660. else if (flag == 3)
  661. {
  662. PostMsg(MSG.SetAutoMode);
  663. }
  664. else if (flag == 4)
  665. {
  666. Dictionary<string, object> param = new Dictionary<string, object>()
  667. {
  668. {"JobId", "CJ_Local_LP1"},
  669. {"Module", "LP1"},
  670. {"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() },
  671. {"AutoStart", false},
  672. };
  673. OP.DoOperation("System.CreateJob", param);
  674. }
  675. else if(flag == 5)
  676. {
  677. PostMsg(MSG.StartJob, "CJ_Local_LP1");
  678. }
  679. }
  680. }
  681. }