RouteManager.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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. return _seTMCycle.StartJob(objs[0].ToString()) == RState.Running;
  881. }
  882. private bool FsmSEJobMonitor(object[] objs)
  883. {
  884. RState ret = _seTMCycle.Monitor();
  885. return ret == RState.End;
  886. }
  887. private bool FsmStartSEMoveWafer(object[] objs)
  888. {
  889. return _setransfer.Start(objs) == RState.Running;
  890. }
  891. private bool FsmMonitorSEMoveWafer(object[] objs)
  892. {
  893. RState ret = _setransfer.Monitor();
  894. if (ret == RState.Failed || ret == RState.Timeout)
  895. {
  896. PostMsg(MSG.ERROR);
  897. return false;
  898. }
  899. return ret == RState.End;
  900. }
  901. private bool FsmStartSEReturnWafer(object[] objs)
  902. {
  903. return _sereturnWafer.Start(objs) == RState.Running;
  904. }
  905. private bool FsmMonitorSEReturnWafer(object[] objs)
  906. {
  907. RState ret = _sereturnWafer.Monitor();
  908. if (ret == RState.Failed || ret == RState.Timeout)
  909. {
  910. PostMsg(MSG.ERROR);
  911. return false;
  912. }
  913. return ret == RState.End;
  914. }
  915. private bool FsmSEAbort(object[] objs)
  916. {
  917. _setransfer.Abort();
  918. return true;
  919. }
  920. }
  921. }