RouteManager.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  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 (seTM != null && VCE != null)
  425. {
  426. if (ModuleHelper.IsVCE(target))
  427. {
  428. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at vce {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  429. return false;
  430. }
  431. WaferInfo wafer = WaferManager.Instance.GetWafer(target,slot);
  432. if (wafer.IsEmpty)
  433. {
  434. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  435. return false;
  436. }
  437. return CheckToPostMessage((int)MSG.SEMoveWafer,
  438. target, slot,
  439. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  440. false, 0, false, 0, "Blade1");
  441. }
  442. else
  443. {
  444. if (ModuleHelper.IsLoadPort(target))
  445. {
  446. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  447. return false;
  448. }
  449. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  450. {
  451. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  452. return false;
  453. }
  454. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  455. if (wafer.IsEmpty)
  456. {
  457. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  458. return false;
  459. }
  460. return CheckToPostMessage((int)MSG.MoveWafer,
  461. target, slot,
  462. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  463. false, 0, false, 0, "Blade1");
  464. }
  465. }
  466. public PMEntity GetPM(ModuleName mod)
  467. {
  468. if (ModuleHelper.IsInstalled(mod))
  469. {
  470. switch (mod)
  471. {
  472. case ModuleName.PMA:
  473. return PMA;
  474. case ModuleName.PMB:
  475. return PMB;
  476. case ModuleName.PMC:
  477. return PMC;
  478. case ModuleName.PMD:
  479. return PMD;
  480. }
  481. }
  482. return null;
  483. }
  484. public LLEntity GetLL(ModuleName mod)
  485. {
  486. if (ModuleHelper.IsInstalled(mod))
  487. {
  488. switch (mod)
  489. {
  490. case ModuleName.LLA:
  491. return LLA;
  492. case ModuleName.LLB:
  493. return LLB;
  494. }
  495. }
  496. return null;
  497. }
  498. public VceEntity GetVCE(ModuleName mod)
  499. {
  500. if (ModuleHelper.IsInstalled(mod))
  501. {
  502. return VCE;
  503. }
  504. return null;
  505. }
  506. public TMEntity GetTM()
  507. {
  508. return TM;
  509. }
  510. protected override bool Init()
  511. {
  512. PMA?.Initialize();
  513. PMB?.Initialize();
  514. PMC?.Initialize();
  515. PMD?.Initialize();
  516. TM?.Initialize();
  517. LLA?.Initialize();
  518. LLB?.Initialize();
  519. EFEM?.Initialize();
  520. VCE?.Initialize();
  521. seTM?.Initialize();
  522. _TMCycle = new TMCycle();
  523. _AutoCycle = new AutoCycle();
  524. _manualTransfer = new ManualTransfer();
  525. _returnWafer = new ReturnAllWafer(_manualTransfer);
  526. _seTMCycle = new SETMCycle(ModuleName.SETM);
  527. _setransfer = new SEManualTransfer();
  528. _sereturnWafer = new SEReturnWafer(_setransfer);
  529. BuildTransitionTable();
  530. return true;
  531. }
  532. private void BuildTransitionTable()
  533. {
  534. //Init sequence
  535. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  536. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  537. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  538. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, FsmEnterAutoRunning, FSM_MSG.NONE, FsmExitAutoTransfer);
  539. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, FsmExitTransfer);
  540. EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
  541. AnyStateTransition(MSG.ERROR, FsmError, RtState.Error);
  542. Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
  543. Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
  544. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  545. Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
  546. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  547. // TM Cycle
  548. Transition(RtState.Idle, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  549. Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  550. Transition(RtState.TMCycle, MSG.StopCycle, FsmStopTMCycle, RtState.Idle);
  551. //Auto/manual
  552. Transition(RtState.Idle, MSG.SetAutoMode, FsmStartAutoTransfer, RtState.AutoIdle);
  553. Transition(RtState.AutoRunning, FSM_MSG.TIMER, FsmAutoTransfer, RtState.Idle);
  554. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbortAutoTransfer, RtState.Idle);
  555. //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  556. Transition(RtState.AutoRunning, MSG.JobDone, FsmJobDone, RtState.AutoIdle);
  557. //Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
  558. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  559. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  560. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  561. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  562. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  563. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  564. Transition(RtState.AutoRunning, MSG.MoveWafer, FsmAutoReturnWafer, RtState.AutoRunning);
  565. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  566. Transition(RtState.AutoRunning, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoRunning);
  567. Transition(RtState.AutoRunning, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoRunning);
  568. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  569. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  570. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  571. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  572. Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
  573. Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
  574. Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
  575. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  576. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  577. //Transfer
  578. Transition(RtState.Idle, MSG.MoveWafer, FsmStartTransfer, RtState.Transfer);
  579. Transition(RtState.Transfer, FSM_MSG.TIMER, FsmMonitorTransfer, RtState.Idle);
  580. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  581. //Return Wafer
  582. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  583. Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
  584. Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
  585. // SETM Cycle
  586. Transition(RtState.Idle, MSG.SETMCycle, FsmStartSETMCycle, RtState.SETMCycle);
  587. Transition(RtState.SETMCycle, FSM_MSG.TIMER, FsmMonitorSETMCycle, RtState.Idle);
  588. Transition(RtState.SETMCycle, MSG.StopSECycle, FsmStopSETMCycle, RtState.Idle);
  589. // SETM CreateCycle
  590. Transition(RtState.Idle, MSG.CreateSEJob, FsmStartCreateSEJob, RtState.Idle);
  591. // SETM StartCycle
  592. Transition(RtState.Idle, MSG.StartSEJob, FsmStartSEJob, RtState.SERunning);
  593. Transition(RtState.SERunning, FSM_MSG.TIMER, FsmSEJobMonitor, RtState.Idle);
  594. Transition(RtState.SERunning, MSG.StopSECycle, FsmStopSETMCycle, RtState.Idle);
  595. // SE Transfer
  596. Transition(RtState.Idle, MSG.SEMoveWafer, FsmStartSEMoveWafer, RtState.SETransfer);
  597. Transition(RtState.SETransfer, FSM_MSG.TIMER, FsmMonitorSEMoveWafer, RtState.Idle);
  598. Transition(RtState.SETransfer, MSG.StopSECycle, FsmSEAbort, RtState.Idle);
  599. // SE ReturnWafer
  600. Transition(RtState.Idle, MSG.SEReturnWafer, FsmStartSEReturnWafer, RtState.SEReturnWafer);
  601. Transition(RtState.SEReturnWafer, FSM_MSG.TIMER, FsmMonitorSEReturnWafer, RtState.Idle);
  602. Transition(RtState.SEReturnWafer, MSG.StopSECycle, FsmSEAbort, RtState.Idle);
  603. }
  604. private bool FsmMonitor(object[] objs)
  605. {
  606. _debugRoutine();
  607. return true;
  608. }
  609. private bool FsmStartHome(object[] objs)
  610. {
  611. PMA?.Invoke("Home");
  612. PMB?.Invoke("Home");
  613. PMC?.Invoke("Home");
  614. PMD?.Invoke("Home");
  615. TM?.Invoke("Home");
  616. LLA?.Invoke("Home");
  617. LLB?.Invoke("Home");
  618. EFEM?.Invoke("Home");
  619. seTM?.Invoke("Home");
  620. VCE?.Invoke("Home");
  621. return true;
  622. }
  623. private bool FsmMonitorHome(object[] objs)
  624. {
  625. bool CheckHomed(string name, bool bValid, bool bDone)
  626. {
  627. if (bValid && !bDone)
  628. {
  629. if (fsm.ElapsedTime > 100 * 1000)
  630. {
  631. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{name} home timeout");
  632. PostMsg(MSG.ERROR);
  633. return true;
  634. }
  635. else
  636. return false;
  637. }
  638. return true;
  639. }
  640. return CheckHomed("PMA", ModuleHelper.IsInstalled(ModuleName.PMA) && PMA != null, ModuleHelper.IsInstalled(ModuleName.PMA) && PMA != null&&PMA.IsIdle) &&
  641. CheckHomed("PMB", ModuleHelper.IsInstalled(ModuleName.PMB) && PMB != null, ModuleHelper.IsInstalled(ModuleName.PMB) && PMB != null&&PMB.IsIdle) &&
  642. CheckHomed("PMC", ModuleHelper.IsInstalled(ModuleName.PMC) && PMC != null, ModuleHelper.IsInstalled(ModuleName.PMC) && PMC != null&&PMC.IsIdle) &&
  643. CheckHomed("PMD", ModuleHelper.IsInstalled(ModuleName.PMD) && PMD != null, ModuleHelper.IsInstalled(ModuleName.PMD) && PMD != null&&PMD.IsIdle) &&
  644. CheckHomed("LLA", ModuleHelper.IsInstalled(ModuleName.LLA) && LLA != null, ModuleHelper.IsInstalled(ModuleName.LLA) && LLA != null&&LLA.IsIdle) &&
  645. CheckHomed("LLB", ModuleHelper.IsInstalled(ModuleName.LLB) && LLB != null, ModuleHelper.IsInstalled(ModuleName.LLB) && LLB != null&&LLB.IsIdle) &&
  646. CheckHomed("TM", ModuleHelper.IsInstalled(ModuleName.TM) && TM != null, ModuleHelper.IsInstalled(ModuleName.TM) && TM != null&&TM.IsIdle) &&
  647. CheckHomed("EFEM", ModuleHelper.IsInstalled(ModuleName.EFEM) && EFEM != null, ModuleHelper.IsInstalled(ModuleName.EFEM) && EFEM != null && EFEM.IsIdle) &&
  648. CheckHomed("SETM", ModuleHelper.IsInstalled(ModuleName.SETM) && seTM != null, ModuleHelper.IsInstalled(ModuleName.SETM) && seTM != null && seTM.IsIdle) &&
  649. CheckHomed("VCE1", ModuleHelper.IsInstalled(ModuleName.VCE1) && VCE != null, ModuleHelper.IsInstalled(ModuleName.VCE1) && VCE != null && VCE.IsIdle);
  650. }
  651. private bool FsmEnterAutoRunning(object[] objs)
  652. {
  653. return true;
  654. }
  655. private bool FsmExitAutoTransfer(object[] objs)
  656. {
  657. _AutoCycle.Clear();
  658. return true;
  659. }
  660. private bool FsmExitTransfer(object[] objs)
  661. {
  662. _manualTransfer.Clear();
  663. return true;
  664. }
  665. private bool FsmExitReturnWafer(object[] objs)
  666. {
  667. _returnWafer.Clear();
  668. return true;
  669. }
  670. private bool FsmError(object[] objs)
  671. {
  672. return true;
  673. }
  674. private bool FsmAbort(object[] objs)
  675. {
  676. _manualTransfer.Clear();
  677. _returnWafer.Clear();
  678. _AutoCycle.Clear();
  679. return true;
  680. }
  681. private bool FsmStartTMCycle(object[] objs)
  682. {
  683. return _TMCycle.Start(objs) == RState.Running;
  684. }
  685. private bool FsmMonitorTMCycle(object[] objs)
  686. {
  687. RState ret = _TMCycle.Monitor();
  688. if (ret == RState.Failed || ret == RState.Timeout)
  689. {
  690. PostMsg(MSG.ERROR);
  691. return false;
  692. }
  693. return ret == RState.End;
  694. }
  695. private bool FsmStopTMCycle(object[] objs)
  696. {
  697. _TMCycle.Abort();
  698. return true;
  699. }
  700. private bool FsmStartAutoTransfer(object[] objs)
  701. {
  702. return _AutoCycle.Start(objs) == RState.Running;
  703. }
  704. private bool FsmAutoTransfer(object[] objs)
  705. {
  706. RState ret = _AutoCycle.Monitor();
  707. if(ret == RState.Failed)
  708. {
  709. if (!CheckToPostMessage((int)MSG.ERROR))
  710. return false;
  711. }
  712. if (_AutoCycle.CheckJobJustDone(out string jobInfo))
  713. {
  714. EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  715. }
  716. if (_AutoCycle.CheckAllJobDone())
  717. {
  718. if (!CheckToPostMessage((int)MSG.JobDone))
  719. return false;
  720. }
  721. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  722. return ret == RState.End;
  723. }
  724. private bool FsmAbortAutoTransfer(object[] objs)
  725. {
  726. _AutoCycle.Clear();
  727. return true;
  728. }
  729. private bool FsmJobDone(object[] objs)
  730. {
  731. _isWaitUnload = true;
  732. return true;
  733. }
  734. private bool FsmCreateJob(object[] objs)
  735. {
  736. _AutoCycle.CreateJob((Dictionary<string, object>)objs[0]);
  737. return true;
  738. }
  739. private bool FsmStartJob(object[] objs)
  740. {
  741. _AutoCycle.StartJob((string)objs[0]);
  742. return true;
  743. }
  744. private bool FsmPauseJob(object[] objs)
  745. {
  746. _AutoCycle.PauseJob((string)objs[0]);
  747. return true;
  748. }
  749. private bool FsmResumeJob(object[] objs)
  750. {
  751. _AutoCycle.ResumeJob((string)objs[0]);
  752. return true;
  753. }
  754. private bool FsmStopJob(object[] objs)
  755. {
  756. _AutoCycle.StopJob((string)objs[0]);
  757. return true;
  758. }
  759. private bool FsmAbortJob(object[] objs)
  760. {
  761. _AutoCycle.AbortJob((string)objs[0]);
  762. return true;
  763. }
  764. private bool FsmStartTransfer(object[] objs)
  765. {
  766. return _manualTransfer.Start(objs) == RState.Running;
  767. }
  768. private bool FsmMonitorTransfer(object[] objs)
  769. {
  770. RState ret = _manualTransfer.Monitor();
  771. if (ret == RState.Failed || ret == RState.Timeout)
  772. {
  773. PostMsg(MSG.ERROR);
  774. return false;
  775. }
  776. return ret == RState.End;
  777. }
  778. private bool FsmStartReturnWafer(object[] objs)
  779. {
  780. return _returnWafer.Start(objs) == RState.Running;
  781. }
  782. private bool FsmMonitorReturnWafer(object[] objs)
  783. {
  784. RState ret = _returnWafer.Monitor();
  785. if (ret == RState.Failed || ret == RState.Timeout)
  786. {
  787. PostMsg(MSG.ERROR);
  788. return false;
  789. }
  790. return ret == RState.End;
  791. }
  792. private bool FsmMap(object[] objs)
  793. {
  794. return true;
  795. }
  796. private bool FsmResetIdleCleanTime(object[] objs)
  797. {
  798. return true;
  799. }
  800. private bool FsmResetIdlePurgeTime(object[] objs)
  801. {
  802. return true;
  803. }
  804. private bool FsmAutoReturnWafer(object[] objs)
  805. {
  806. return _AutoCycle.ManualReturnWafer(objs);
  807. }
  808. private bool FsmMonitorAutoIdle(object[] objs)
  809. {
  810. RState ret = _AutoCycle.Monitor();
  811. //if (_AutoCycle.CheckAllJobDone())
  812. //{
  813. // if (!CheckToPostMessage((int)MSG.JobDone))
  814. // return false;
  815. //}
  816. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  817. _debugRoutine();
  818. return ret == RState.End;
  819. }
  820. private bool FsmStartSetManualMode(object[] objs)
  821. {
  822. if (_AutoCycle.HasJobRunning)
  823. {
  824. LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
  825. return false;
  826. }
  827. return true;
  828. }
  829. private void _debugRoutine()
  830. {
  831. int flag = 0;
  832. // Test Home routine
  833. if (flag == 1)
  834. {
  835. PostMsg(MSG.HOME);
  836. }
  837. else if (flag == 2)
  838. {
  839. PostMsg(MSG.TMCycle);
  840. }
  841. else if (flag == 3)
  842. {
  843. PostMsg(MSG.SetAutoMode);
  844. }
  845. else if (flag == 4)
  846. {
  847. PostMsg(MSG.ReturnAllWafer);
  848. }
  849. else if(flag == 5)
  850. {
  851. PostMsg(MSG.StartJob, "CJ_Local_LP1");
  852. }
  853. }
  854. private bool FsmStartSETMCycle(object[] objs)
  855. {
  856. return _seTMCycle.Start(objs) == RState.Running;
  857. }
  858. private bool FsmMonitorSETMCycle(object[] objs)
  859. {
  860. RState ret = _seTMCycle.Monitor();
  861. if (ret == RState.Failed || ret == RState.Timeout)
  862. {
  863. PostMsg(MSG.ERROR);
  864. return false;
  865. }
  866. return ret == RState.End;
  867. }
  868. private bool FsmStopSETMCycle(object[] objs)
  869. {
  870. _seTMCycle.Abort();
  871. return true;
  872. }
  873. private bool FsmStartCreateSEJob(object[] objs)
  874. {
  875. _seTMCycle.CreateJob((Dictionary<string, object>)objs[0]);
  876. return true;
  877. }
  878. private bool FsmStartSEJob(object[] objs)
  879. {
  880. _seTMCycle.StartJob(objs[0].ToString());
  881. return true;
  882. }
  883. private bool FsmSEJobMonitor(object[] objs)
  884. {
  885. RState ret = _seTMCycle.Monitor();
  886. return ret == RState.End;
  887. }
  888. private bool FsmStartSEMoveWafer(object[] objs)
  889. {
  890. return _setransfer.Start(objs) == RState.Running;
  891. }
  892. private bool FsmMonitorSEMoveWafer(object[] objs)
  893. {
  894. RState ret = _setransfer.Monitor();
  895. if (ret == RState.Failed || ret == RState.Timeout)
  896. {
  897. PostMsg(MSG.ERROR);
  898. return false;
  899. }
  900. return ret == RState.End;
  901. }
  902. private bool FsmStartSEReturnWafer(object[] objs)
  903. {
  904. return _sereturnWafer.Start(objs) == RState.Running;
  905. }
  906. private bool FsmMonitorSEReturnWafer(object[] objs)
  907. {
  908. RState ret = _sereturnWafer.Monitor();
  909. if (ret == RState.Failed || ret == RState.Timeout)
  910. {
  911. PostMsg(MSG.ERROR);
  912. return false;
  913. }
  914. return ret == RState.End;
  915. }
  916. private bool FsmSEAbort(object[] objs)
  917. {
  918. _setransfer.Abort();
  919. return true;
  920. }
  921. }
  922. }