RouteManager.cs 40 KB

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