RouteManager.cs 36 KB

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