RouteManager.cs 32 KB

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