EquipmentManager.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Fsm;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.RT.Routine;
  10. using Aitex.Core.Util;
  11. using Aitex.Core.Utilities;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using MECF.Framework.RT.Core.Applications;
  15. using MECF.Framework.RT.Core.IoProviders;
  16. using MECF.Framework.RT.ModuleLibrary.Commons;
  17. using MECF.Framework.RT.ModuleLibrary.SystemModules.Routines;
  18. using Venus_Core;
  19. namespace MECF.Framework.RT.ModuleLibrary.SystemModules
  20. {
  21. public enum RtState
  22. {
  23. Init,
  24. Initializing,
  25. Idle,
  26. Transfer,
  27. AutoRunning,
  28. AutoIdle,
  29. ReturnAllWafer,
  30. Error,
  31. }
  32. public class EquipmentManager : FsmDevice
  33. {
  34. public enum MSG
  35. {
  36. MoveWafer,
  37. ReturnAllWafer,
  38. Stop,
  39. HOME,
  40. RESET,
  41. ABORT,
  42. ERROR,
  43. ToInit,
  44. SetAutoMode,
  45. SetManualMode,
  46. CreateJob,
  47. PauseJob,
  48. ResumeJob,
  49. StartJob,
  50. StopJob,
  51. AbortJob,
  52. JobDone,
  53. ModuleError,
  54. Map,
  55. }
  56. public static Dictionary<ModuleName, ModuleFsmDevice> Modules { get; set; }
  57. public bool IsAutoMode
  58. {
  59. get
  60. {
  61. return FsmState == (int)RtState.AutoRunning || FsmState == (int)RtState.AutoIdle;
  62. }
  63. }
  64. public bool IsInit
  65. {
  66. get { return FsmState == (int)RtState.Init; }
  67. }
  68. public bool IsIdle
  69. {
  70. get { return FsmState == (int)RtState.Idle; }
  71. }
  72. public bool IsAlarm
  73. {
  74. get { return FsmState == (int)RtState.Error; }
  75. }
  76. public bool IsRunning
  77. {
  78. get
  79. {
  80. return !IsAlarm && !IsIdle && !IsInit && (FsmState != (int)RtState.AutoIdle);
  81. }
  82. }
  83. private bool _isInited;
  84. protected IRoutine _manualTransfer;
  85. protected IAutoTransfer _auto;
  86. protected IRoutine _homeAll;
  87. protected IRoutine _returnAll;
  88. private List<string> _modules;
  89. public EquipmentManager()
  90. {
  91. Module = "System";
  92. Name = "System";
  93. Modules = new Dictionary<ModuleName, ModuleFsmDevice>();
  94. _modules = new List<string>() { "System" };
  95. }
  96. public override bool Initialize()
  97. {
  98. InitDevices();
  99. InitModules();
  100. EnumLoop<RtState>.ForEach((item) =>
  101. {
  102. MapState((int)item, item.ToString());
  103. });
  104. EnumLoop<MSG>.ForEach((item) =>
  105. {
  106. MapMessage((int)item, item.ToString());
  107. });
  108. EnableFsm(100, RtState.Init);
  109. BuildTransitionTable();
  110. SubscribeDataVariable();
  111. SubscribeOperation();
  112. InitRoutine();
  113. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  114. return true;
  115. }
  116. protected void BuildModules(params ModuleFsmDevice[] modules)
  117. {
  118. if (modules != null && modules.Length > 0)
  119. {
  120. foreach (var moduleFsmDevice in modules)
  121. {
  122. Modules[ModuleHelper.Converter(moduleFsmDevice.Module)] = moduleFsmDevice;
  123. }
  124. foreach (var modulesKey in Modules.Keys)
  125. {
  126. _modules.Add(modulesKey.ToString());
  127. }
  128. foreach (var modulesValue in Modules.Values)
  129. {
  130. modulesValue.Initialize();
  131. }
  132. }
  133. }
  134. protected virtual void InitRoutine()
  135. {
  136. }
  137. protected virtual void InitModules()
  138. {
  139. }
  140. protected virtual void InitDevices()
  141. {
  142. }
  143. //private PeriodicJob _job1;
  144. //Stopwatch _sw = new Stopwatch();
  145. //private bool OnJob1()
  146. //{
  147. // _sw.Restart();
  148. // BufferModule buffer = Modules[ModuleName.Buffer] as BufferModule;
  149. // if (!buffer.CheckToPostMessage(BufferModule.MSG.InTransfer))
  150. // {
  151. // System.Diagnostics.Trace.Assert(false)
  152. // System.Diagnostics.Trace.WriteLine("fail to in transfer");
  153. // }
  154. // if (buffer.IsIdle)
  155. // {
  156. // System.Diagnostics.Trace.Assert(false);
  157. // System.Diagnostics.Trace.WriteLine("!!!==========>IsIdle");
  158. // }
  159. // //System.Diagnostics.Trace.Assert(buffer.IsIdle, $"in {buffer.StringFsmStatus}");
  160. // while (buffer.IsIdle)
  161. // {
  162. // Thread.Sleep(5);
  163. // }
  164. // //buffer.NoteTransferStop(ModuleName.EfemRobot, Hand.Blade1, 0, EnumTransferType.Place);
  165. // //Thread.Sleep(15);
  166. // if (!buffer.CheckToPostMessage(BufferModule.MSG.TransferComplete))
  167. // {
  168. // System.Diagnostics.Trace.Assert(false);
  169. // System.Diagnostics.Trace.WriteLine("fail to complete");
  170. // }
  171. // //if (!buffer.IsIdle)
  172. // //{
  173. // // System.Diagnostics.Trace.WriteLine("not idle");
  174. // //}
  175. // System.Diagnostics.Trace.WriteLine($" === {_sw.ElapsedMilliseconds}");
  176. // while (!buffer.IsIdle)
  177. // {
  178. // Thread.Sleep(5);
  179. // }
  180. // return true;
  181. //}
  182. private void BuildTransitionTable()
  183. {
  184. //Init sequence
  185. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  186. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  187. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  188. Transition(RtState.Error, MSG.ToInit, null, RtState.Init);
  189. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  190. Transition(RtState.Initializing, MSG.ERROR, fError, RtState.Error);
  191. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  192. //Reset
  193. AnyStateTransition(MSG.RESET, fStartReset, RtState.Idle);
  194. AnyStateTransition(MSG.ERROR, fError, RtState.Error);
  195. AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)RtState.Error);
  196. //Auto/manual sequence
  197. Transition(RtState.Idle, MSG.SetAutoMode, fStartAutoTransfer, RtState.AutoIdle);
  198. Transition(RtState.AutoRunning, FSM_MSG.TIMER, fAutoTransfer, RtState.AutoRunning);
  199. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbort, RtState.AutoIdle);
  200. Transition(RtState.AutoRunning, MSG.JobDone, null, RtState.AutoIdle);
  201. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  202. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  203. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  204. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  205. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  206. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  207. Transition(RtState.AutoRunning, MSG.ModuleError, FsmModuleError, RtState.AutoRunning);
  208. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  209. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, null, FSM_MSG.NONE, fExitAutoTransfer);
  210. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  211. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  212. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  213. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  214. Transition(RtState.AutoIdle, MSG.ABORT, FsmAbort, RtState.AutoIdle);
  215. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  216. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  217. //return all wafer
  218. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnAllWafer, RtState.ReturnAllWafer);
  219. Transition(RtState.ReturnAllWafer, FSM_MSG.TIMER, FsmMonitorReturnAllWafer, RtState.Idle);
  220. Transition(RtState.ReturnAllWafer, MSG.ABORT, FsmAbortReturnAllWafer, RtState.Idle);
  221. //Transfer sequence
  222. Transition(RtState.Idle, MSG.MoveWafer, fStartTransfer, RtState.Transfer);
  223. Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
  224. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, fExitTransfer);
  225. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  226. }
  227. void SubscribeDataVariable()
  228. {
  229. DATA.Subscribe("Rt.Status", () => StringFsmStatus);
  230. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit || (FsmState == (int)RtState.AutoIdle));
  231. DATA.Subscribe("System.IsAlarm", () => IsAlarm);
  232. DATA.Subscribe("System.IsBusy", () => IsRunning);
  233. DATA.Subscribe("System.IsAutoRunning", () => IsRunning);
  234. DATA.Subscribe("System.Modules", () => _modules);
  235. }
  236. void SubscribeOperation()
  237. {
  238. OP.Subscribe("Create8InchWafer", InvokeCreate8InchWafer);
  239. OP.Subscribe("Create12InchWafer", InvokeCreate12InchWafer);
  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);
  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. if (args.Length > 8)
  259. {
  260. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3],
  261. (bool)args[4], (int)args[5], (bool)args[6], (int)args[7]);
  262. }
  263. else if (args.Length > 5)
  264. {
  265. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3], (bool)args[4]);
  266. }
  267. return CheckToPostMessage((int)MSG.MoveWafer, source, (int)args[1], destination, (int)args[3]);
  268. });
  269. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  270. {
  271. return CheckToPostMessage((int)MSG.HOME);
  272. });
  273. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  274. {
  275. return CheckToPostMessage((int)MSG.ABORT);
  276. });
  277. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  278. {
  279. return CheckToPostMessage((int)MSG.RESET);
  280. });
  281. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  282. {
  283. return CheckToPostMessage((int)MSG.SetAutoMode);
  284. });
  285. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  286. {
  287. return CheckToPostMessage((int)MSG.SetManualMode);
  288. });
  289. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  290. {
  291. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  292. });
  293. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  294. {
  295. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  296. });
  297. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  298. {
  299. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  300. });
  301. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  302. {
  303. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  304. });
  305. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  306. {
  307. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  308. });
  309. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  310. {
  311. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  312. });
  313. OP.Subscribe("System.ShutDown", InvokeShutDown);
  314. OP.Subscribe("System.MapWafer", InvokeEfemMap);
  315. }
  316. private void Instance_OnAlarmEvent(EventItem obj)
  317. {
  318. }
  319. #region Init
  320. private bool FsmStartHome(object[] objs)
  321. {
  322. _isInited = false;
  323. return _homeAll.Start() == Venus_Core.RState.Running;
  324. }
  325. private bool FsmMonitorHome(object[] objs)
  326. {
  327. RState ret = _homeAll.Monitor();
  328. if (ret == RState.End)
  329. {
  330. _isInited = true;
  331. return true;
  332. }
  333. if (ret == RState.Failed)
  334. {
  335. PostMsg(MSG.ERROR);
  336. }
  337. return false;
  338. }
  339. private bool fError(object[] objs)
  340. {
  341. if (FsmState == (int)RtState.Transfer)
  342. {
  343. }
  344. return true;
  345. }
  346. #endregion
  347. #region AutoTransfer
  348. private bool FsmMonitorAutoIdle(object[] param)
  349. {
  350. RState ret = _auto.Monitor();
  351. if (!_auto.CheckAllJobDone())
  352. {
  353. return false;
  354. }
  355. return ret == RState.End;
  356. }
  357. private bool FsmStartSetManualMode(object[] objs)
  358. {
  359. if (_auto.HasJobRunning)
  360. {
  361. EV.PostWarningLog("System", "Can not change to manual mode, abort running job first");
  362. return false;
  363. }
  364. return true;
  365. }
  366. private bool fStartAutoTransfer(object[] objs)
  367. {
  368. RState ret = _auto.Start(objs);
  369. return ret == RState.Running;
  370. }
  371. private bool fAutoTransfer(object[] objs)
  372. {
  373. RState ret = _auto.Monitor();
  374. if (_auto.CheckAllJobDone())
  375. {
  376. if (!CheckToPostMessage((int)MSG.JobDone))
  377. return false;
  378. }
  379. return ret == RState.End;
  380. }
  381. private bool fExitAutoTransfer(object[] objs)
  382. {
  383. return true;
  384. }
  385. private bool fAbortAutoTransfer(object[] objs)
  386. {
  387. return true;
  388. }
  389. #endregion
  390. #region return all wafer
  391. private bool FsmAbortReturnAllWafer(object[] param)
  392. {
  393. return true;
  394. }
  395. private bool FsmMonitorReturnAllWafer(object[] param)
  396. {
  397. return _returnAll.Monitor() == RState.End;
  398. }
  399. private bool FsmStartReturnAllWafer(object[] param)
  400. {
  401. return _returnAll.Start() == RState.Running;
  402. }
  403. #endregion
  404. #region Transfer
  405. private bool fStartTransfer(object[] objs)
  406. {
  407. RState ret = _manualTransfer.Start(objs);
  408. if (ret == RState.Failed || ret == RState.End)
  409. return false;
  410. return ret == RState.Running;
  411. }
  412. private bool fTransfer(object[] objs)
  413. {
  414. RState ret = _manualTransfer.Monitor();
  415. if (ret == RState.Failed)
  416. {
  417. PostMsg(MSG.ERROR);
  418. return false;
  419. }
  420. return ret == RState.End;
  421. }
  422. private bool fExitTransfer(object[] objs)
  423. {
  424. return true;
  425. }
  426. private bool fAbortTransfer(object[] objs)
  427. {
  428. return true;
  429. }
  430. #endregion
  431. #region reset
  432. private bool fStartReset(object[] objs)
  433. {
  434. EV.ClearAlarmEvent();
  435. //Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
  436. IoProviderManager.Instance.Reset();
  437. foreach (var modulesValue in Modules.Values)
  438. {
  439. modulesValue.Reset();
  440. }
  441. if (FsmState == (int)RtState.Error)
  442. {
  443. if (!_isInited)
  444. {
  445. PostMsg(MSG.ToInit);
  446. return false;
  447. }
  448. return true;
  449. }
  450. return false;
  451. }
  452. #endregion
  453. private bool FsmCreateJob(object[] param)
  454. {
  455. _auto.CreateJob((Dictionary<string, object>)param[0]);
  456. return true;
  457. }
  458. private bool FsmAbortJob(object[] param)
  459. {
  460. _auto.AbortJob((string)param[0]);
  461. return true;
  462. }
  463. private bool FsmStopJob(object[] param)
  464. {
  465. _auto.StopJob((string)param[0]);
  466. //CheckToPostMessage((int)MSG.StopJob);//
  467. return true;
  468. }
  469. private bool FsmResumeJob(object[] param)
  470. {
  471. _auto.ResumeJob((string)param[0]);
  472. return true;
  473. }
  474. private bool FsmPauseJob(object[] param)
  475. {
  476. _auto.PauseJob((string)param[0]);
  477. return true;
  478. }
  479. private bool FsmStartJob(object[] param)
  480. {
  481. return _auto.StartJob((string)param[0]);
  482. }
  483. private bool FsmAbort(object[] param)
  484. {
  485. if (FsmState == (int)RtState.Transfer)
  486. {
  487. // _manualTransfer.Clear();
  488. }
  489. if (FsmState == (int)RtState.AutoRunning)
  490. {
  491. _auto.Clear();
  492. }
  493. if (FsmState == (int)RtState.Initializing)
  494. {
  495. _homeAll.Abort();
  496. }
  497. return true;
  498. }
  499. private bool FsmModuleError(object[] param)
  500. {
  501. _auto.ModuleError((string)param[0]);
  502. return true;
  503. }
  504. private bool FsmMap(object[] param)
  505. {
  506. _auto.Map((string)param[0]);
  507. return true;
  508. }
  509. private bool InvokeReturnWafer(string arg1, object[] args)
  510. {
  511. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  512. int slot = (int)args[1];
  513. if (ModuleHelper.IsLoadPort(target))
  514. {
  515. EV.PostInfoLog("System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  516. return false;
  517. }
  518. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  519. {
  520. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  521. return false;
  522. }
  523. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  524. if (wafer.IsEmpty)
  525. {
  526. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  527. return false;
  528. }
  529. return CheckToPostMessage((int)MSG.MoveWafer,
  530. target, slot,
  531. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  532. false, 0, false, 0);
  533. }
  534. private bool InvokeDeleteWafer(string arg1, object[] args)
  535. {
  536. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  537. int slot = (int)args[1];
  538. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  539. {
  540. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  541. {
  542. WaferManager.Instance.DeleteWafer(chamber, slot);
  543. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  544. }
  545. else
  546. {
  547. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  548. }
  549. }
  550. else
  551. {
  552. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  553. return false;
  554. }
  555. return true;
  556. }
  557. private bool InvokeCreate8InchWafer(string arg1, object[] args)
  558. {
  559. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  560. int slot = (int)args[1];
  561. WaferStatus state = WaferStatus.Normal;
  562. //if (ModuleHelper.IsLoadPort(chamber))
  563. //{
  564. // var lp = Modules[chamber] as LoadPortModule;
  565. // if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
  566. // {
  567. // EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
  568. // return false;
  569. // }
  570. //}
  571. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  572. {
  573. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  574. {
  575. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  576. }
  577. else if (WaferManager.Instance.CreateWafer(chamber, slot, state,WaferSize.WS8) != null)
  578. {
  579. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  580. }
  581. }
  582. else
  583. {
  584. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  585. return false;
  586. }
  587. return true;
  588. }
  589. private bool InvokeCreate12InchWafer(string arg1, object[] args)
  590. {
  591. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  592. int slot = (int)args[1];
  593. WaferStatus state = WaferStatus.Normal;
  594. //if (ModuleHelper.IsLoadPort(chamber))
  595. //{
  596. // var lp = Modules[chamber] as LoadPortModule;
  597. // if (lp.LPDevice.CassetteState != LoadportCassetteState.Normal)
  598. // {
  599. // EV.PostWarningLog("System", $"Can not create wafer at {chamber}.{slot + 1}, Cassette not placed.");
  600. // return false;
  601. // }
  602. //}
  603. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  604. {
  605. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  606. {
  607. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  608. }
  609. else if (WaferManager.Instance.CreateWafer(chamber, slot, state,WaferSize.WS12) != null)
  610. {
  611. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  612. }
  613. }
  614. else
  615. {
  616. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  617. return false;
  618. }
  619. return true;
  620. }
  621. private bool InvokeShutDown(string arg1, object[] arg2)
  622. {
  623. if (IsAlarm || IsIdle || IsInit)
  624. {
  625. EV.PostWarningLog(Module, $"System start shut down");
  626. EV.PostKickoutMessage("ShutDown");
  627. RtApplication.Instance.Terminate();
  628. return true;
  629. }
  630. EV.PostWarningLog(Module, $"System in {StringFsmStatus} mode, can not shut down");
  631. return false;
  632. }
  633. private bool InvokeEfemMap(string arg1, object[] arg2)
  634. {
  635. ModuleName target = ModuleHelper.Converter((string)arg2[0]);
  636. if (!ModuleHelper.IsLoadPort(target))
  637. {
  638. EV.PostWarningLog("System", $"Invalid map target {target}");
  639. return false;
  640. }
  641. for (int i = 0; i < 25; i++)
  642. {
  643. WaferInfo wafer = WaferManager.Instance.GetWafer(target, i);
  644. if (wafer.IsEmpty)
  645. continue;
  646. if (wafer.ProcessState == EnumWaferProcessStatus.Completed ||
  647. wafer.ProcessState == EnumWaferProcessStatus.Failed)
  648. {
  649. EV.PostWarningLog("System", $"{target} wafer is processed, can not map again");
  650. return false;
  651. }
  652. }
  653. if (IsAutoMode)
  654. {
  655. _auto.Map((string)arg2[0]);
  656. return true;
  657. }
  658. //EfemModule efem = Modules[ModuleName.EfemRobot] as EfemModule;
  659. //if (!efem.Map(ModuleHelper.Converter((string) arg2[0]), out string reason))
  660. //{
  661. // EV.PostWarningLog(Module, reason);
  662. //}
  663. return true;
  664. }
  665. private void OnModuleError(string module)
  666. {
  667. if (FsmState == (int)RtState.AutoRunning)
  668. {
  669. ModuleName mod = ModuleHelper.Converter(module);
  670. PostMsg(MSG.ModuleError, module);
  671. }
  672. }
  673. public override void Monitor()
  674. {
  675. base.Monitor();
  676. try
  677. {
  678. }
  679. catch (Exception ex)
  680. {
  681. LOG.WriteExeption(ex);
  682. }
  683. }
  684. }
  685. }