RouteManager.cs 38 KB

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