RouteManager.cs 39 KB

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