RouteManager.cs 27 KB

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