RouteManager.cs 32 KB

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