RouteManager.cs 40 KB

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