RouteManager.cs 36 KB

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