RouteManager.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Fsm;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.Routine;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using VirgoCommon;
  14. using VirgoRT.HostWrapper;
  15. using VirgoRT.Instances;
  16. using VirgoRT.Module;
  17. namespace VirgoRT.Modules
  18. {
  19. class RouteManager : Entity, IEntity
  20. {
  21. public enum MSG
  22. {
  23. MoveWafer,
  24. ReturnWafer,
  25. HomeUnit,
  26. PauseAuto,
  27. ResumeAuto,
  28. Stop,
  29. StartCycle,
  30. HOME,
  31. RESET,
  32. ABORT,
  33. ERROR,
  34. SetAutoMode,
  35. SetManualMode,
  36. ResetIdleCleanTime,
  37. ResetIdlePurgeTime,
  38. CreateJob,
  39. PauseJob,
  40. ResumeJob,
  41. StartJob,
  42. StopJob,
  43. AbortJob,
  44. JobDone,
  45. CassetteLeave, //For unload light control off afer job done
  46. Map,
  47. ReturnAllWafer,
  48. }
  49. //public LoadPortEntity LP1 { get; private set; }
  50. //public LoadPortEntity LP2 { get; private set; }
  51. //public CoolingStorageEntity Aligner { get; private set; }
  52. public EfemEntity EFEM { get; private set; }
  53. public PMEntity PMA { get; private set; }
  54. public PMEntity PMB { get; private set; }
  55. //routine
  56. public bool IsAutoMode
  57. {
  58. get
  59. {
  60. return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle;
  61. }
  62. }
  63. public string Name { get; set; }
  64. public bool IsInit
  65. {
  66. get { return fsm.State == (int)RtState.Init; }
  67. }
  68. public bool IsIdle
  69. {
  70. get { return fsm.State == (int)RtState.Idle || fsm.State == (int)RtState.AutoIdle; }
  71. }
  72. public bool IsAlarm
  73. {
  74. get { return fsm.State == (int)RtState.Error; }
  75. }
  76. public bool IsEntityError
  77. {
  78. get
  79. {
  80. return (EFEM?.IsError ?? false)
  81. || (PMA?.IsError ?? false)
  82. || (PMB?.IsError ?? false);
  83. }
  84. }
  85. public bool IsRunning
  86. {
  87. get
  88. {
  89. return !IsInit && !IsAlarm && !IsIdle;
  90. }
  91. }
  92. private ManualTransfer _manualTransfer;
  93. private AutoTransfer _auto = null;
  94. private ReturnAllWafer _returnWafer;
  95. private HomeAll _homeAll = new HomeAll();
  96. private bool _isWaitUnload;
  97. public RouteManager()
  98. {
  99. Name = "System";
  100. //LP1 = new LoadPortEntity(ModuleName.LP1);
  101. //LP2 = new LoadPortEntity(ModuleName.LP2);
  102. //Aligner = new CoolingStorageEntity(ModuleName.Aligner);
  103. EFEM = new EfemEntity();
  104. if (SC.GetValue<bool>("System.PMAIsInstalled"))
  105. PMA = new PMEntity(ModuleName.PMA);
  106. if (SC.GetValue<bool>("System.PMBIsInstalled"))
  107. PMB = new PMEntity(ModuleName.PMB);
  108. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 50);
  109. BuildTransitionTable();
  110. SubscribeDataVariable();
  111. SubscribeOperation();
  112. Running = true;
  113. }
  114. private void BuildTransitionTable()
  115. {
  116. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, fEnterAutoRunning, FSM_MSG.NONE, fExitAutoTransfer);
  117. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, fExitTransfer);
  118. EnterExitTransition<RtState, FSM_MSG>(RtState.Idle, fEnterIdle, FSM_MSG.NONE, fExitIdle);
  119. EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
  120. //Init sequence
  121. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  122. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  123. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  124. // EnterExitTransition<RtState, FSM_MSG>(RtState.Initializing, fStartInit, FSM_MSG.NONE, null);
  125. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  126. Transition(RtState.Initializing, MSG.ERROR, fError, RtState.Error);
  127. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  128. //Reset
  129. AnyStateTransition(MSG.RESET, fStartReset, RtState.Idle);
  130. AnyStateTransition(MSG.ERROR, fError, RtState.Error);
  131. AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)RtState.Error);
  132. //Auto/manual
  133. Transition(RtState.Idle, MSG.SetAutoMode, fStartAutoTransfer, RtState.AutoIdle);
  134. Transition(RtState.AutoRunning, FSM_MSG.TIMER, fAutoTransfer, RtState.Idle);
  135. Transition(RtState.AutoRunning, MSG.ABORT, fAbortAutoTransfer, RtState.Idle);
  136. //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  137. Transition(RtState.AutoRunning, MSG.JobDone, fJobDone, RtState.AutoIdle);
  138. Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
  139. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  140. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  141. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  142. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  143. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  144. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  145. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  146. Transition(RtState.AutoRunning, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoRunning);
  147. Transition(RtState.AutoRunning, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoRunning);
  148. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  149. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  150. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  151. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  152. Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
  153. Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
  154. Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
  155. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  156. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  157. Transition(RtState.AutoIdle, MSG.CassetteLeave, fCassetteLeave, RtState.AutoIdle); //For unload light control off afer job done
  158. Transition(RtState.AutoIdle, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoIdle);
  159. Transition(RtState.AutoIdle, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoIdle);
  160. //Transfer
  161. Transition(RtState.Idle, MSG.MoveWafer, fStartTransfer, RtState.Transfer);
  162. Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
  163. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  164. //Return Wafer
  165. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  166. Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
  167. Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
  168. }
  169. void SubscribeDataVariable()
  170. {
  171. DATA.Subscribe("Rt.Status", () => ((RtState)fsm.State).ToString());
  172. DATA.Subscribe(ModuleName.System.ToString(), "AlarmEvent", EV.GetAlarmEvent);
  173. DATA.Subscribe("System.IsAutoMode", () => IsAutoMode);
  174. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit);
  175. DATA.Subscribe("System.IsAlarm", () => IsAlarm || IsEntityError);
  176. DATA.Subscribe("System.IsBusy", () => IsRunning);
  177. DATA.Subscribe("System.IsWaitUnload", () => _isWaitUnload && IsAutoMode);
  178. DATA.Subscribe("System.IsConnectedWithHost", () => Singleton<FaManager>.Instance.IsConnected);
  179. DATA.Subscribe("EquipmentMode", () => IsAutoMode ? 0 : 1, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  180. DATA.Subscribe("EquipmentStatus", () =>
  181. {
  182. //"0 = Uninit
  183. //1 = Idle
  184. //2 = Running
  185. //3 = Error
  186. //4 = Pause
  187. //"
  188. if (IsInit) return 0;
  189. if (IsIdle) return 1;
  190. if (IsAlarm) return 3;
  191. return 2;
  192. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  193. }
  194. void SubscribeOperation()
  195. {
  196. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  197. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  198. OP.Subscribe("ReturnWafer", InvokeReturnWafer);
  199. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  200. {
  201. return CheckToPostMessage((int)MSG.ReturnAllWafer, args[0], args[1]);
  202. });
  203. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  204. {
  205. if (!Enum.TryParse((string)args[0], out ModuleName source))
  206. {
  207. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  208. return false;
  209. }
  210. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  211. {
  212. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  213. return false;
  214. }
  215. return CheckToPostMessage((int)MSG.MoveWafer,
  216. source, (int)args[1],
  217. destination, (int)args[3],
  218. (bool)args[4], (int)args[5],
  219. (bool)args[6], (int)args[7]);
  220. });
  221. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  222. {
  223. return CheckToPostMessage((int)MSG.HOME);
  224. });
  225. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  226. {
  227. return CheckToPostMessage((int)MSG.ABORT);
  228. });
  229. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  230. {
  231. return CheckToPostMessage((int)MSG.RESET);
  232. });
  233. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  234. {
  235. return CheckToPostMessage((int)MSG.SetAutoMode);
  236. });
  237. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  238. {
  239. return CheckToPostMessage((int)MSG.SetManualMode);
  240. });
  241. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  242. {
  243. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  244. });
  245. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  246. {
  247. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  248. });
  249. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  250. {
  251. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  252. });
  253. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  254. {
  255. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  256. });
  257. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  258. {
  259. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  260. });
  261. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  262. {
  263. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  264. });
  265. OP.Subscribe("LP1.Map", (string cmd, object[] args) =>
  266. {
  267. if (IsAutoMode)
  268. {
  269. return CheckToPostMessage((int)MSG.Map, ModuleName.LP1.ToString());
  270. }
  271. return EFEM.InvokeMap(ModuleName.LP1.ToString())!= (int)FSM_MSG.NONE;
  272. });
  273. OP.Subscribe("LP2.Map", (string cmd, object[] args) =>
  274. {
  275. if (IsAutoMode)
  276. {
  277. return CheckToPostMessage((int)MSG.Map, ModuleName.LP2.ToString());
  278. }
  279. return EFEM.InvokeMap(ModuleName.LP2.ToString()) != (int)FSM_MSG.NONE;
  280. });
  281. OP.Subscribe(RtOperation.SetConfig.ToString(), (name, args) =>
  282. {
  283. string sc_key = args[0] as string;
  284. if (!string.IsNullOrWhiteSpace(sc_key) && args.Length > 1)
  285. {
  286. SC.SetItemValue(sc_key, args[1]);
  287. }
  288. return true;
  289. });
  290. OP.Subscribe("System.ResetIdleCleanTime", (string cmd, object[] args) =>
  291. {
  292. return CheckToPostMessage((int)MSG.ResetIdleCleanTime, args[0]);
  293. });
  294. OP.Subscribe("System.ResetIdlePurgeTime", (string cmd, object[] args) =>
  295. {
  296. return CheckToPostMessage((int)MSG.ResetIdlePurgeTime, args[0]);
  297. });
  298. OP.Subscribe("System.SetWaferSize", (string cmd, object[] args) =>
  299. {
  300. string module = (string)args[0];
  301. string size = (string)args[1];
  302. switch (size)
  303. {
  304. case "3":
  305. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  306. break;
  307. case "4":
  308. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  309. break;
  310. case "6":
  311. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  312. break;
  313. default:
  314. EV.PostWarningLog("System", $"wafer size {size} not valid");
  315. break;
  316. }
  317. return true;
  318. });
  319. OP.Subscribe("System.CassetteLeave", (string cmd, object[] args) =>
  320. {
  321. return CheckToPostMessage((int)MSG.CassetteLeave);
  322. });
  323. }
  324. public bool CheckToPostMessage(int msg, params object[] args)
  325. {
  326. if (!fsm.FindTransition(fsm.State, msg))
  327. {
  328. EV.PostWarningLog(Name, $"{Name} is in { (RtState)fsm.State} state,can not do {(MSG)msg}");
  329. return false;
  330. }
  331. fsm.PostMsg(msg, args);
  332. return true;
  333. }
  334. public bool Check(int msg, out string reason, params object[] args)
  335. {
  336. if (!fsm.FindTransition(fsm.State, msg))
  337. {
  338. reason = String.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg);
  339. return false;
  340. }
  341. if (msg == (int)MSG.StartCycle)
  342. {
  343. if (!IsAutoMode)
  344. {
  345. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  346. return false;
  347. }
  348. }
  349. reason = "";
  350. return true;
  351. }
  352. protected override bool Init()
  353. {
  354. _manualTransfer = new ManualTransfer();
  355. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  356. EFEM.Initialize();
  357. //Aligner.Initialize();
  358. //LP1.Initialize();
  359. //LP2.Initialize();
  360. PMA?.Initialize();
  361. PMB?.Initialize();
  362. _auto = new AutoTransfer();
  363. _returnWafer = new ReturnAllWafer();
  364. return true;
  365. }
  366. private void Instance_OnAlarmEvent(EventItem obj)
  367. {
  368. FSM_MSG msg = FSM_MSG.NONE;
  369. if (obj.Level == EventLevel.Warning)
  370. msg = FSM_MSG.WARNING;
  371. else if (obj.Level == EventLevel.Alarm)
  372. msg = FSM_MSG.ALARM;
  373. switch (obj.Source)
  374. {
  375. case "PMA":
  376. PMA?.PostMsg(msg, obj.Id, obj.Description);
  377. break;
  378. case "PMB":
  379. PMB?.PostMsg(msg, obj.Id, obj.Description);
  380. break;
  381. case "EFEM":
  382. EFEM?.PostMsg(msg, obj.Id, obj.Description);
  383. break;
  384. //case "System":
  385. // PostMsg(msg, obj.Id, obj.Description);
  386. // break;
  387. }
  388. }
  389. protected override void Term()
  390. {
  391. PMA?.Terminate();
  392. PMB?.Terminate();
  393. //LP2.Terminate();
  394. //LP1.Terminate();
  395. EFEM.Terminate();
  396. }
  397. #region Init
  398. private bool FsmStartHome(object[] objs)
  399. {
  400. return _homeAll.Start() == Result.RUN;
  401. }
  402. private bool FsmMonitorHome(object[] objs)
  403. {
  404. Result ret = _homeAll.Monitor();
  405. if (ret == Result.DONE)
  406. {
  407. _homeAll.Clear();
  408. return true;
  409. }
  410. if (ret == Result.FAIL)
  411. {
  412. _homeAll.Clear();
  413. PostMsg(MSG.ERROR);
  414. }
  415. return false;
  416. }
  417. private bool fError(object[] objs)
  418. {
  419. if (fsm.State == (int)RtState.Transfer)
  420. {
  421. _manualTransfer.Clear();
  422. }
  423. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.RED, LightStatus.ON);
  424. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.YELLOW, LightStatus.OFF);
  425. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.GREEN, LightStatus.OFF);
  426. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BLUE, LightStatus.OFF);
  427. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BUZZER1, LightStatus.ON);
  428. return true;
  429. }
  430. private bool fEnterIdle(object[] param)
  431. {
  432. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.RED, LightStatus.OFF);
  433. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.YELLOW, LightStatus.ON);
  434. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.GREEN, LightStatus.OFF);
  435. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BLUE, LightStatus.OFF);
  436. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BUZZER1, LightStatus.OFF);
  437. return true;
  438. }
  439. private bool fExitIdle(object[] param)
  440. {
  441. return true;
  442. }
  443. #endregion Init
  444. #region AutoTransfer
  445. private bool FsmMonitorAutoIdle(object[] param)
  446. {
  447. Result ret = _auto.Monitor();
  448. if (!_auto.CheckAllJobDone())
  449. {
  450. return false;
  451. }
  452. _isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  453. return ret == Result.DONE;
  454. }
  455. private bool FsmStartSetManualMode(object[] objs)
  456. {
  457. if (_auto.HasJobRunning)
  458. {
  459. EV.PostWarningLog("System", "Can not change to manual mode, abort running job first");
  460. return false;
  461. }
  462. return true;
  463. }
  464. private bool fStartAutoTransfer(object[] objs)
  465. {
  466. Result ret = _auto.Start(objs);
  467. return ret == Result.RUN;
  468. }
  469. private bool fAutoTransfer(object[] objs)
  470. {
  471. Result ret = _auto.Monitor();
  472. if (_auto.CheckJobJustDone(out string jobInfo))
  473. {
  474. EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  475. }
  476. if (_auto.CheckAllJobDone())
  477. {
  478. if (!CheckToPostMessage((int)MSG.JobDone))
  479. return false;
  480. }
  481. _isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  482. return ret == Result.DONE;
  483. }
  484. private bool fEnterAutoRunning(object[] objs)
  485. {
  486. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.RED, LightStatus.OFF);
  487. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.GREEN, LightStatus.ON);
  488. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.YELLOW, LightStatus.OFF);
  489. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BLUE, LightStatus.OFF);
  490. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BUZZER1, LightStatus.OFF);
  491. return true;
  492. }
  493. private bool fExitAutoTransfer(object[] objs)
  494. {
  495. _auto.Clear();
  496. return true;
  497. }
  498. private bool fJobDone(object[] objs)
  499. {
  500. //Unload light control on
  501. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.RED, LightStatus.OFF);
  502. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.GREEN, LightStatus.BLINK);
  503. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.YELLOW, LightStatus.OFF);
  504. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BLUE, LightStatus.OFF);
  505. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BUZZER1, LightStatus.OFF);
  506. _isWaitUnload = true;
  507. return true;
  508. }
  509. private bool fCassetteLeave(object[] objs)
  510. {
  511. //Unload light control off,light as idle & autoidle mode
  512. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.RED, LightStatus.OFF);
  513. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.GREEN, LightStatus.OFF);
  514. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.YELLOW, LightStatus.ON);
  515. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BLUE, LightStatus.OFF);
  516. //EFEM.PostMsg(EfemEntity.MSG.LED, LightType.BUZZER1, LightStatus.OFF);
  517. _isWaitUnload = false;
  518. return true;
  519. }
  520. private bool fAbortAutoTransfer(object[] objs)
  521. {
  522. _auto.Clear();
  523. return true;
  524. }
  525. #endregion AutoTransfer
  526. #region return wafer
  527. private bool FsmStartReturnWafer(object[] objs)
  528. {
  529. Result ret = _returnWafer.Start(objs);
  530. if (ret == Result.FAIL || ret == Result.DONE)
  531. return false;
  532. return ret == Result.RUN;
  533. }
  534. private bool FsmMonitorReturnWafer(object[] objs)
  535. {
  536. Result ret = _returnWafer.Monitor(objs);
  537. if (ret == Result.FAIL)
  538. {
  539. PostMsg(MSG.ERROR);
  540. return false;
  541. }
  542. return ret == Result.DONE;
  543. }
  544. private bool FsmExitReturnWafer(object[] objs)
  545. {
  546. _returnWafer.Clear();
  547. return true;
  548. }
  549. #endregion cycle
  550. #region Transfer
  551. private bool fStartTransfer(object[] objs)
  552. {
  553. Result ret = _manualTransfer.Start(objs);
  554. if (ret == Result.FAIL || ret == Result.DONE)
  555. return false;
  556. return ret == Result.RUN;
  557. }
  558. private bool fTransfer(object[] objs)
  559. {
  560. Result ret = _manualTransfer.Monitor(objs);
  561. if (ret == Result.FAIL)
  562. {
  563. PostMsg(MSG.ERROR);
  564. return false;
  565. }
  566. return ret == Result.DONE;
  567. }
  568. private bool fExitTransfer(object[] objs)
  569. {
  570. _manualTransfer.Clear();
  571. return true;
  572. }
  573. #endregion Transfer
  574. #region reset
  575. private bool fStartReset(object[] objs)
  576. {
  577. //LP1.InvokeReset();
  578. //LP2.InvokeReset();
  579. //Aligner.InvokeReset();
  580. EFEM.InvokeReset();
  581. PMA?.InvokeReset();
  582. PMB?.InvokeReset();
  583. Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
  584. Singleton<FaManager>.Instance.ClearAlarm(null);
  585. if (fsm.State == (int)RtState.Error)
  586. return true;
  587. return false;
  588. }
  589. #endregion reset
  590. private bool FsmMap(object[] param)
  591. {
  592. _auto.Map((string)param[0]);
  593. return true;
  594. }
  595. public bool CheckRecipeUsedInJob(string pathName)
  596. {
  597. if (!IsAutoMode)
  598. return false;
  599. return _auto.CheckRecipeUsedInJob(pathName);
  600. }
  601. public bool CheckSequenceUsedInJob(string pathName)
  602. {
  603. if (!IsAutoMode)
  604. return false;
  605. return _auto.CheckSequenceUsedInJob(pathName);
  606. }
  607. private bool FsmCreateJob(object[] param)
  608. {
  609. _auto.CreateJob((Dictionary<string, object>)param[0]);
  610. return true;
  611. }
  612. private bool FsmAbortJob(object[] param)
  613. {
  614. _auto.AbortJob((string)param[0]);
  615. return true;
  616. }
  617. private bool FsmStopJob(object[] param)
  618. {
  619. _auto.StopJob((string)param[0]);
  620. return true;
  621. }
  622. private bool FsmResumeJob(object[] param)
  623. {
  624. _auto.ResumeJob((string)param[0]);
  625. return true;
  626. }
  627. private bool FsmPauseJob(object[] param)
  628. {
  629. _auto.PauseJob((string)param[0]);
  630. return true;
  631. }
  632. private bool FsmStartJob(object[] param)
  633. {
  634. _auto.StartJob((string)param[0]);
  635. return true;
  636. }
  637. private bool FsmAbort(object[] param)
  638. {
  639. if (fsm.State == (int)RtState.Transfer)
  640. {
  641. _manualTransfer.Clear();
  642. }
  643. if (fsm.State == (int)RtState.AutoRunning)
  644. {
  645. _auto.Clear();
  646. }
  647. if (fsm.State == (int)RtState.ReturnWafer)
  648. {
  649. _returnWafer.Clear();
  650. }
  651. return true;
  652. }
  653. private bool FsmResetIdlePurgeTime(object[] param)
  654. {
  655. _auto.ResetIdlePurgeTime((string)param[0]);
  656. return true;
  657. }
  658. private bool FsmResetIdleCleanTime(object[] param)
  659. {
  660. _auto.ResetIdleCleanTime((string)param[0]);
  661. return true;
  662. }
  663. private bool InvokeReturnWafer(string arg1, object[] args)
  664. {
  665. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  666. int slot = (int)args[1];
  667. if (ModuleHelper.IsLoadPort(target))
  668. {
  669. EV.PostInfoLog("System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  670. return false;
  671. }
  672. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  673. {
  674. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  675. return false;
  676. }
  677. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  678. if (wafer.IsEmpty)
  679. {
  680. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  681. return false;
  682. }
  683. return CheckToPostMessage((int)MSG.MoveWafer,
  684. target, slot,
  685. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  686. false, 0, false, 0 );
  687. }
  688. private bool InvokeDeleteWafer(string arg1, object[] args)
  689. {
  690. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  691. int slot = (int)args[1];
  692. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  693. {
  694. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  695. {
  696. WaferManager.Instance.DeleteWafer(chamber, slot);
  697. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  698. }
  699. else
  700. {
  701. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  702. }
  703. }
  704. else
  705. {
  706. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  707. return false;
  708. }
  709. return true;
  710. }
  711. private bool InvokeCreateWafer(string arg1, object[] args)
  712. {
  713. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  714. int slot = (int)args[1];
  715. WaferStatus state = WaferStatus.Normal;
  716. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  717. {
  718. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  719. {
  720. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  721. }
  722. else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
  723. {
  724. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  725. }
  726. }
  727. else
  728. {
  729. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  730. return false;
  731. }
  732. return true;
  733. }
  734. }
  735. }