RouteManager.cs 31 KB

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