RouteManager.cs 33 KB

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