RouteManager.cs 32 KB

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