RouteManager.cs 31 KB

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