RouteManager.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.RT.Fsm;
  8. using Aitex.Core.Common;
  9. using Aitex.Core.RT.DataCenter;
  10. using Aitex.Core.RT.Event;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Routine;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.Util;
  15. using MECF.Framework.Common.Jobs;
  16. using MECF.Framework.Common.Equipment;
  17. using MECF.Framework.Common.SubstrateTrackings;
  18. using Venus_Core;
  19. using Venus_RT.Modules.PMs;
  20. using Aitex.Core.RT.Log;
  21. using Venus_RT.Modules.VCE;
  22. using Venus_RT.Devices.PreAligner;
  23. using Venus_RT.Modules.TM.VenusEntity;
  24. using SecsGem.Core.Application;
  25. using Aitex.Core.RT.RecipeCenter;
  26. using System.Reflection;
  27. using Venus_RT.Modules.LPs;
  28. using System.Runtime.InteropServices;
  29. using Venus_RT.Devices.EFEM;
  30. namespace Venus_RT.Modules
  31. {
  32. class RouteManager : Entity, IEntity, IEquipmentCommand
  33. {
  34. public enum MSG
  35. {
  36. MoveWafer,
  37. ReturnWafer,
  38. HomeUnit,
  39. PauseAuto,
  40. ResumeAuto,
  41. Stop,
  42. StartCycle,
  43. StopCycle,
  44. HOME,
  45. RESET,
  46. ABORT,
  47. ERROR,
  48. SetAutoMode,
  49. SetManualMode,
  50. ResetIdleCleanTime,
  51. ResetIdlePurgeTime,
  52. CreateJob,
  53. PauseJob,
  54. ResumeJob,
  55. StartJob,
  56. StopJob,
  57. AbortJob,
  58. JobDone,
  59. CassetteLeave, //For unload light control off afer job done
  60. Map,
  61. ReturnAllWafer,
  62. TMCycle,
  63. SETMCycle,
  64. StopSECycle,
  65. CreateSEJob,
  66. StartSEJob,
  67. AbortSEJob,
  68. SEMoveWafer,
  69. SEReturnWafer,
  70. SEAbort,
  71. }
  72. public PMEntity PMA { get; private set; }
  73. public PMEntity PMB { get; private set; }
  74. public PMEntity PMC { get; private set; }
  75. public PMEntity PMD { get; private set; }
  76. public TMEntity TM { get; private set; }
  77. public LLEntity LLA { get; private set; }
  78. public LLEntity LLB { get; private set; }
  79. public EfemEntity EFEM { get; private set; }
  80. public VceEntity VCE { get; private set; }
  81. public VceEntity VCEA { get; private set; }
  82. public VceEntity VCEB { get; private set; }
  83. public SETMEntity seTM { get; private set; }
  84. public string Name { get; set; }
  85. public bool IsAutoMode
  86. {
  87. get
  88. {
  89. return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle;
  90. }
  91. }
  92. public bool IsInit
  93. {
  94. get { return fsm.State == (int)RtState.Init; }
  95. }
  96. public bool IsIdle
  97. {
  98. get { return fsm.State == (int)RtState.Idle || fsm.State == (int)RtState.AutoIdle; }
  99. }
  100. public bool IsAlarm
  101. {
  102. get { return fsm.State == (int)RtState.Error; }
  103. }
  104. public bool IsPaused
  105. {
  106. get { return _AutoCycle.CycleState == RState.Paused; }
  107. }
  108. public bool IsEntityError
  109. {
  110. get
  111. {
  112. return (EFEM?.IsError ?? false)
  113. || (PMA?.IsError ?? false)
  114. || (PMB?.IsError ?? false)
  115. || (PMC?.IsError ?? false)
  116. || (PMD?.IsError ?? false);
  117. }
  118. }
  119. public bool IsRunning
  120. {
  121. get
  122. {
  123. return !IsInit && !IsAlarm && !IsIdle;
  124. }
  125. }
  126. public static bool IsATMMode
  127. {
  128. get
  129. {
  130. if (_isATMMode == -1)
  131. {
  132. _isATMMode = SC.GetValue<bool>("System.IsATMMode") ? 1 : 0;
  133. }
  134. return _isATMMode == 1;
  135. }
  136. }
  137. public SequenceLLInOutPath LLInOutPath => _AutoCycle.LLInOutPath;
  138. private TMCycle _TMCycle;
  139. private ICycle _AutoCycle;
  140. private ManualTransfer _manualTransfer;
  141. private ReturnAllWafer _returnWafer;
  142. private SETMCycle _seTMCycle;
  143. private SEManualTransfer _setransfer;
  144. private SEReturnWafer _sereturnWafer;
  145. private bool _isWaitUnload;
  146. private static int _isATMMode = -1;
  147. public RouteManager()
  148. {
  149. Name = "System";
  150. if (ModuleHelper.IsInstalled(ModuleName.PMA))
  151. PMA = new PMEntity(ModuleName.PMA);
  152. if (ModuleHelper.IsInstalled(ModuleName.PMB))
  153. PMB = new PMEntity(ModuleName.PMB);
  154. if (ModuleHelper.IsInstalled(ModuleName.PMC))
  155. PMC = new PMEntity(ModuleName.PMC);
  156. if (ModuleHelper.IsInstalled(ModuleName.PMD))
  157. PMD = new PMEntity(ModuleName.PMD);
  158. if (ModuleHelper.IsInstalled(ModuleName.TM))
  159. TM = new TMEntity();
  160. if (ModuleHelper.IsInstalled(ModuleName.LLA))
  161. LLA = new LLEntity(ModuleName.LLA);
  162. if (ModuleHelper.IsInstalled(ModuleName.LLB))
  163. LLB = new LLEntity(ModuleName.LLB);
  164. if (ModuleHelper.IsInstalled(ModuleName.EFEM))
  165. EFEM = new EfemEntity();
  166. if (ModuleHelper.IsInstalled(ModuleName.VCE1))
  167. {
  168. //临时加 后改为配置项
  169. VCE = new VceEntity(ModuleName.VCE1);
  170. }
  171. if (ModuleHelper.IsInstalled(ModuleName.VCEA))
  172. {
  173. //临时加 后改为配置项
  174. VCEA = new VceEntity(ModuleName.VCEA);
  175. }
  176. if (ModuleHelper.IsInstalled(ModuleName.VCEB))
  177. {
  178. //临时加 后改为配置项
  179. VCEB = new VceEntity(ModuleName.VCEB);
  180. }
  181. if (ModuleHelper.IsInstalled(ModuleName.SETM))
  182. {
  183. seTM = new SETMEntity(ModuleName.SETM) ;
  184. }
  185. else if (ModuleHelper.IsInstalled(ModuleName.DETM))
  186. {
  187. seTM = new SETMEntity(ModuleName.DETM);
  188. }
  189. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 200);
  190. SubscribeOperation();
  191. SubscribeDataVariable();
  192. }
  193. public bool Check(int msg, out string reason, params object[] args)
  194. {
  195. if (!fsm.FindTransition(fsm.State, msg))
  196. {
  197. reason = String.Format("{0} is in {1} state,can not do {2}", Name, 0, (MSG)msg);
  198. return false;
  199. }
  200. if (msg == (int)MSG.StartCycle)
  201. {
  202. if (!IsAutoMode)
  203. {
  204. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  205. return false;
  206. }
  207. }
  208. reason = "";
  209. return true;
  210. }
  211. void SubscribeDataVariable()
  212. {
  213. DATA.Subscribe("Rt.Status", () => ((RtState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  214. DATA.Subscribe(ModuleName.System.ToString(), "AlarmEvent", EV.GetAlarmEvent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  215. DATA.Subscribe("System.IsAutoMode", () => IsAutoMode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  216. DATA.Subscribe("System.IsIdle", () => IsIdle || IsInit, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  217. DATA.Subscribe("System.IsAlarm", () => IsAlarm || IsEntityError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  218. DATA.Subscribe("System.IsBusy", () => IsRunning, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  219. DATA.Subscribe("System.IsWaitUnload", () => _isWaitUnload && IsAutoMode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  220. //DATA.Subscribe("System.IsConnectedWithHost", () => Singleton<SecGemApplication>.Instance., SubscriptionAttribute.FLAG.IgnoreSaveDB);
  221. DATA.Subscribe("EquipmentMode", () => IsAutoMode ? 0 : 1, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  222. DATA.Subscribe("EquipmentStatus", () =>
  223. {
  224. //"0 = Uninit
  225. //1 = Idle
  226. //2 = Running
  227. //3 = Error
  228. //4 = Pause
  229. //"
  230. if (IsInit) return 0;
  231. if (IsIdle) return 1;
  232. if (IsAlarm) return 3;
  233. if (IsPaused) return 4;
  234. return 2;
  235. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  236. }
  237. void SubscribeOperation()
  238. {
  239. OP.Subscribe("CreateWafer", InvokeCreateWafer);
  240. OP.Subscribe("DeleteWafer", InvokeDeleteWafer);
  241. OP.Subscribe("System.Home", (cmd, args) => CheckToPostMessage((int)MSG.HOME, args));
  242. OP.Subscribe("TMCycle.Start", (cmd, args) => CheckToPostMessage((int)MSG.TMCycle, args));
  243. OP.Subscribe("TMCycle.Abort", (cmd, args) => CheckToPostMessage((int)MSG.StopCycle, args));
  244. OP.Subscribe("System.StopSECycle", (cmd, args) => CheckToPostMessage((int)MSG.StopSECycle, args));
  245. DATA.Subscribe("SYSTEM.FsmState", () => (((RtState)fsm.State).ToString()));
  246. DATA.Subscribe("TMCycle.CycleIndex", () => (_TMCycle?.CycleIndex));
  247. OP.Subscribe("ReturnWafer", InvokeReturnWafer);
  248. OP.Subscribe("System.ReturnAllWafer", (string cmd, object[] args) =>
  249. {
  250. if (seTM != null && (VCE != null || VCEA !=null || VCEB != null))
  251. return CheckToPostMessage((int)MSG.SEReturnWafer, args);
  252. else
  253. return CheckToPostMessage((int)MSG.ReturnAllWafer, args[0], args[1], args[2], args[3]);
  254. });
  255. OP.Subscribe("System.MoveWafer", (string cmd, object[] args) =>
  256. {
  257. if (!Enum.TryParse((string)args[0], out ModuleName source))
  258. {
  259. EV.PostWarningLog(Name, $"Parameter source {(string)args[0]} not valid");
  260. return false;
  261. }
  262. if (!Enum.TryParse((string)args[2], out ModuleName destination))
  263. {
  264. EV.PostWarningLog(Name, $"Parameter destination {(string)args[1]} not valid");
  265. return false;
  266. }
  267. if (seTM != null && (VCE != null || VCEA != null || VCEB != null))
  268. return CheckToPostMessage((int)MSG.SEMoveWafer,
  269. source, (int)args[1],
  270. destination, (int)args[3],
  271. args[4], args[5],
  272. args[6], args[7], (string)args[8]);
  273. else
  274. return CheckToPostMessage((int)MSG.MoveWafer,
  275. source, (int)args[1],
  276. destination, (int)args[3],
  277. args[4], args[5],
  278. args[6], args[7], (string)args[8]);
  279. });
  280. OP.Subscribe("System.HomeAll", (string cmd, object[] args) =>
  281. {
  282. return CheckToPostMessage((int)MSG.HOME);
  283. });
  284. OP.Subscribe("System.Abort", (string cmd, object[] args) =>
  285. {
  286. return CheckToPostMessage((int)MSG.ABORT);
  287. });
  288. OP.Subscribe("System.Reset", (string cmd, object[] args) =>
  289. {
  290. return CheckToPostMessage((int)MSG.RESET);
  291. });
  292. OP.Subscribe("System.SetAutoMode", (string cmd, object[] args) =>
  293. {
  294. return CheckToPostMessage((int)MSG.SetAutoMode);
  295. });
  296. OP.Subscribe("System.SetManualMode", (string cmd, object[] args) =>
  297. {
  298. return CheckToPostMessage((int)MSG.SetManualMode);
  299. });
  300. OP.Subscribe("System.CreateJob", (string cmd, object[] args) =>
  301. {
  302. return CheckToPostMessage((int)MSG.CreateJob, args[0]);
  303. });
  304. OP.Subscribe("System.StartJob", (string cmd, object[] args) =>
  305. {
  306. return CheckToPostMessage((int)MSG.StartJob, args[0]);
  307. });
  308. OP.Subscribe("System.PauseJob", (string cmd, object[] args) =>
  309. {
  310. return CheckToPostMessage((int)MSG.PauseJob, args[0]);
  311. });
  312. OP.Subscribe("System.ResumeJob", (string cmd, object[] args) =>
  313. {
  314. return CheckToPostMessage((int)MSG.ResumeJob, args[0]);
  315. });
  316. OP.Subscribe("System.StopJob", (string cmd, object[] args) =>
  317. {
  318. return CheckToPostMessage((int)MSG.StopJob, args[0]);
  319. });
  320. OP.Subscribe("System.AbortJob", (string cmd, object[] args) =>
  321. {
  322. return CheckToPostMessage((int)MSG.AbortJob, args[0]);
  323. });
  324. OP.Subscribe("SE.AbortJob", (string cmd, object[] args) =>
  325. {
  326. return CheckToPostMessage((int)MSG.AbortSEJob, args[0]);
  327. });
  328. OP.Subscribe("LP1.Map", (string cmd, object[] args) =>
  329. {
  330. if (IsAutoMode)
  331. {
  332. return CheckToPostMessage((int)MSG.Map, ModuleName.LP1.ToString());
  333. }
  334. return EFEM.InvokeMap(ModuleName.LP1.ToString()) != (int)FSM_MSG.NONE;
  335. });
  336. OP.Subscribe("LP2.Map", (string cmd, object[] args) =>
  337. {
  338. if (IsAutoMode)
  339. {
  340. return CheckToPostMessage((int)MSG.Map, ModuleName.LP2.ToString());
  341. }
  342. return EFEM.InvokeMap(ModuleName.LP2.ToString()) != (int)FSM_MSG.NONE;
  343. });
  344. OP.Subscribe(RtOperation.SetConfig.ToString(), (name, args) =>
  345. {
  346. string sc_key = args[0] as string;
  347. if (!string.IsNullOrWhiteSpace(sc_key) && args.Length > 1)
  348. {
  349. SC.SetItemValue(sc_key, args[1]);
  350. }
  351. return true;
  352. });
  353. OP.Subscribe("System.ResetIdleCleanTime", (string cmd, object[] args) =>
  354. {
  355. return CheckToPostMessage((int)MSG.ResetIdleCleanTime, args[0]);
  356. });
  357. OP.Subscribe("System.ResetIdlePurgeTime", (string cmd, object[] args) =>
  358. {
  359. return CheckToPostMessage((int)MSG.ResetIdlePurgeTime, args[0]);
  360. });
  361. OP.Subscribe("System.SetWaferSize", (string cmd, object[] args) =>
  362. {
  363. string module = (string)args[0];
  364. string size = (string)args[1];
  365. switch (size)
  366. {
  367. case "3":
  368. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  369. break;
  370. case "4":
  371. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  372. break;
  373. case "6":
  374. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  375. break;
  376. default:
  377. EV.PostWarningLog("System", $"wafer size {size} not valid");
  378. break;
  379. }
  380. return true;
  381. });
  382. OP.Subscribe("System.CassetteLeave", (string cmd, object[] args) =>
  383. {
  384. return CheckToPostMessage((int)MSG.CassetteLeave);
  385. });
  386. OP.Subscribe("System.IsModuleInstalled", (string cmd, object[] args) =>
  387. {
  388. return ModuleHelper.IsInstalled((ModuleName)args[0]);
  389. });
  390. OP.Subscribe("System.SETMCycle", (cmd, args) => CheckToPostMessage((int)MSG.SETMCycle, args));
  391. OP.Subscribe("System.CreateSEJob", (cmd, args) => CheckToPostMessage((int)MSG.CreateSEJob, args));
  392. OP.Subscribe("System.StartSEJob", (cmd, args) => CheckToPostMessage((int)MSG.StartSEJob, args));
  393. OP.Subscribe("System.ReturnAllSEWafer", (cmd, args) => CheckToPostMessage((int)MSG.SEReturnWafer, args));
  394. OP.Subscribe("System.SEAbort", (cmd, args) => CheckToPostMessage((int)MSG.SEAbort, args));
  395. }
  396. public bool CheckToPostMessage(int msg, params object[] args)
  397. {
  398. if (!fsm.FindTransition(fsm.State, msg))
  399. {
  400. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"System is in {(RtState)fsm.State} state,can not do {(MSG)msg}");
  401. return false;
  402. }
  403. Running = true;
  404. fsm.PostMsg(msg, args);
  405. return true;
  406. }
  407. public bool InvokeAbort(object[] args)
  408. {
  409. return CheckToPostMessage((int)MSG.ABORT, args);
  410. }
  411. private bool InvokeCreateWafer(string arg1, object[] args)
  412. {
  413. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  414. int slot = (int)args[1];
  415. WaferStatus state = WaferStatus.Normal;
  416. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  417. {
  418. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  419. {
  420. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  421. }
  422. else if (WaferManager.Instance.CreateWafer(chamber, slot, state) != null)
  423. {
  424. LOG.Write(eEvent.EV_WAFER_CREATE, ModuleName.System, chamber.ToString(), (slot + 1).ToString(), state.ToString());
  425. }
  426. }
  427. else
  428. {
  429. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  430. return false;
  431. }
  432. return true;
  433. }
  434. private bool InvokeDeleteWafer(string arg1, object[] args)
  435. {
  436. ModuleName chamber = ModuleHelper.Converter(args[0].ToString());
  437. int slot = (int)args[1];
  438. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  439. {
  440. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  441. {
  442. WaferManager.Instance.DeleteWafer(chamber, slot);
  443. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  444. }
  445. else
  446. {
  447. LOG.Write(eEvent.EV_ROUTER, "System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  448. }
  449. }
  450. else
  451. {
  452. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  453. return false;
  454. }
  455. return true;
  456. }
  457. private bool InvokeReturnWafer(string arg1, object[] args)
  458. {
  459. ModuleName target = ModuleHelper.Converter(args[0].ToString());
  460. int slot = (int)args[1];
  461. if (seTM != null && (VCE != null || VCEA != null || VCEB != null))
  462. {
  463. if (ModuleHelper.IsVCE(target))
  464. {
  465. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at vce {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  466. return false;
  467. }
  468. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  469. if (wafer.IsEmpty)
  470. {
  471. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  472. return false;
  473. }
  474. return CheckToPostMessage((int)MSG.SEMoveWafer,
  475. target, slot,
  476. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  477. false, 0, false, 0, "Blade1");
  478. }
  479. else
  480. {
  481. if (ModuleHelper.IsLoadPort(target))
  482. {
  483. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Wafer already at LoadPort {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  484. return false;
  485. }
  486. if (!WaferManager.Instance.IsWaferSlotLocationValid(target, slot))
  487. {
  488. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("Invalid position,{0},{1}", target.ToString(), slot.ToString()));
  489. return false;
  490. }
  491. WaferInfo wafer = WaferManager.Instance.GetWafer(target, slot);
  492. if (wafer.IsEmpty)
  493. {
  494. LOG.Write(eEvent.WARN_ROUTER, "System", string.Format("No wafer at {0} {1}, return operation is not valid", target.ToString(), slot + 1));
  495. return false;
  496. }
  497. return CheckToPostMessage((int)MSG.MoveWafer,
  498. target, slot,
  499. (ModuleName)wafer.OriginStation, wafer.OriginSlot,
  500. false, 0, false, 0, "Blade1");
  501. }
  502. }
  503. public PMEntity GetPM(ModuleName mod)
  504. {
  505. if (ModuleHelper.IsInstalled(mod))
  506. {
  507. switch (mod)
  508. {
  509. case ModuleName.PMA:
  510. return PMA;
  511. case ModuleName.PMB:
  512. return PMB;
  513. case ModuleName.PMC:
  514. return PMC;
  515. case ModuleName.PMD:
  516. return PMD;
  517. }
  518. }
  519. return null;
  520. }
  521. public LLEntity GetLL(ModuleName mod)
  522. {
  523. if (ModuleHelper.IsInstalled(mod))
  524. {
  525. switch (mod)
  526. {
  527. case ModuleName.LLA:
  528. return LLA;
  529. case ModuleName.LLB:
  530. return LLB;
  531. }
  532. }
  533. return null;
  534. }
  535. public VceEntity GetVCE(ModuleName mod)
  536. {
  537. if (ModuleHelper.IsInstalled(mod))
  538. {
  539. switch (mod)
  540. {
  541. case ModuleName.VCE1:
  542. return VCE;
  543. case ModuleName.VCEA:
  544. return VCEA;
  545. case ModuleName.VCEB:
  546. return VCEB;
  547. }
  548. }
  549. return null;
  550. }
  551. public TMEntity GetTM()
  552. {
  553. return TM;
  554. }
  555. protected override bool Init()
  556. {
  557. PMA?.Initialize();
  558. PMB?.Initialize();
  559. PMC?.Initialize();
  560. PMD?.Initialize();
  561. TM?.Initialize();
  562. LLA?.Initialize();
  563. LLB?.Initialize();
  564. EFEM?.Initialize();
  565. VCE?.Initialize();
  566. VCEA?.Initialize();
  567. VCEB?.Initialize();
  568. seTM?.Initialize();
  569. _TMCycle = new TMCycle();
  570. //_AutoCycle = new AutoCycle();
  571. _AutoCycle = new SystemDispatcher();
  572. _manualTransfer = new ManualTransfer();
  573. _returnWafer = new ReturnAllWafer(_manualTransfer);
  574. _seTMCycle = new SETMCycle(ModuleName.SETM);
  575. _setransfer = new SEManualTransfer();
  576. _sereturnWafer = new SEReturnWafer(_setransfer);
  577. BuildTransitionTable();
  578. return true;
  579. }
  580. private void BuildTransitionTable()
  581. {
  582. //Init sequence
  583. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  584. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  585. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  586. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, FsmEnterAutoRunning, FSM_MSG.NONE, FsmExitAutoTransfer);
  587. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, FsmExitTransfer);
  588. EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
  589. AnyStateTransition(MSG.ERROR, FsmError, RtState.Error);
  590. Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
  591. Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
  592. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  593. Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
  594. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  595. // TM Cycle
  596. Transition(RtState.Idle, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  597. Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  598. Transition(RtState.TMCycle, MSG.StopCycle, FsmStopTMCycle, RtState.Idle);
  599. //Auto/manual
  600. Transition(RtState.Idle, MSG.SetAutoMode, FsmStartAutoTransfer, RtState.AutoIdle);
  601. Transition(RtState.AutoRunning, FSM_MSG.TIMER, FsmAutoTransfer, RtState.AutoIdle);
  602. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbortAutoTransfer, RtState.Idle);
  603. //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  604. Transition(RtState.AutoRunning, MSG.JobDone, FsmJobDone, RtState.AutoIdle);
  605. //Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
  606. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  607. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  608. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  609. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  610. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  611. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  612. Transition(RtState.AutoRunning, MSG.MoveWafer, FsmAutoReturnWafer, RtState.AutoRunning);
  613. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  614. Transition(RtState.AutoRunning, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoRunning);
  615. Transition(RtState.AutoRunning, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoRunning);
  616. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  617. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  618. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  619. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  620. Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
  621. Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
  622. Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
  623. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  624. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  625. //Transfer
  626. Transition(RtState.Idle, MSG.MoveWafer, FsmStartTransfer, RtState.Transfer);
  627. Transition(RtState.Transfer, FSM_MSG.TIMER, FsmMonitorTransfer, RtState.Idle);
  628. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  629. //Return Wafer
  630. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  631. Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
  632. Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
  633. // SETM Cycle
  634. Transition(RtState.Idle, MSG.SETMCycle, FsmStartSETMCycle, RtState.SETMCycle);
  635. Transition(RtState.SETMCycle, FSM_MSG.TIMER, FsmMonitorSETMCycle, RtState.Idle);
  636. Transition(RtState.SETMCycle, MSG.SEAbort, SEAbort, RtState.Idle);
  637. Transition(RtState.SETMCycle, MSG.AbortSEJob, SEAbortJob, RtState.Idle);
  638. // SETM CreateCycle
  639. Transition(RtState.Idle, MSG.CreateSEJob, FsmStartCreateSEJob, RtState.Idle);
  640. // SETM StartCycle
  641. Transition(RtState.Idle, MSG.StartSEJob, FsmStartSEJob, RtState.SERunning);
  642. Transition(RtState.SERunning, FSM_MSG.TIMER, FsmSEJobMonitor, RtState.Idle);
  643. Transition(RtState.SERunning, MSG.SEAbort, SEAbort, RtState.Idle);
  644. Transition(RtState.SERunning, MSG.AbortSEJob, SEAbortJob, RtState.Idle);
  645. Transition(RtState.Idle, MSG.AbortSEJob, SEAbortJob, RtState.Idle);
  646. // SE Transfer
  647. Transition(RtState.Idle, MSG.SEMoveWafer, FsmStartSEMoveWafer, RtState.SETransfer);
  648. Transition(RtState.SETransfer, FSM_MSG.TIMER, FsmMonitorSEMoveWafer, RtState.Idle);
  649. Transition(RtState.SETransfer, MSG.SEAbort, SEAbort, RtState.Idle);
  650. // SE ReturnWafer
  651. Transition(RtState.Idle, MSG.SEReturnWafer, FsmStartSEReturnWafer, RtState.SEReturnWafer);
  652. Transition(RtState.SEReturnWafer, FSM_MSG.TIMER, FsmMonitorSEReturnWafer, RtState.Idle);
  653. Transition(RtState.SEReturnWafer, MSG.SEAbort, SEAbort, RtState.Idle);
  654. }
  655. private bool FsmMonitor(object[] objs)
  656. {
  657. _debugRoutine();
  658. return true;
  659. }
  660. private bool FsmStartHome(object[] objs)
  661. {
  662. TM?.Invoke("Home");
  663. EFEM?.Invoke("Home");
  664. seTM?.Invoke("Home");
  665. VCE?.Invoke("Home");
  666. VCEA?.Invoke("Home");
  667. VCEB?.Invoke("Home");
  668. foreach (var mod in ModuleHelper.InstalledModules)
  669. {
  670. if (ModuleHelper.IsPm(mod))
  671. {
  672. if (GetPM(mod).IsInclude)
  673. {
  674. GetPM(mod).Invoke("Home");
  675. }
  676. }
  677. else if (ModuleHelper.IsLoadLock(mod))
  678. {
  679. if (GetLL(mod).IsInclude)
  680. {
  681. GetLL(mod).Invoke("Home");
  682. }
  683. }
  684. }
  685. return true;
  686. }
  687. private bool FsmMonitorHome(object[] objs)
  688. {
  689. ModuleName notReadyModule = ModuleName.System;
  690. foreach (var mod in ModuleHelper.InstalledModules)
  691. {
  692. if ((ModuleHelper.IsPm(mod) && GetPM(mod).IsInclude && !GetPM(mod).IsIdle) ||
  693. (ModuleHelper.IsLoadLock(mod) && GetLL(mod).IsInclude && !GetLL(mod).IsIdle) ||
  694. (ModuleHelper.IsTM(mod) && !GetTM().IsIdle) ||
  695. (ModuleHelper.IsVCE(mod) && !GetVCE(mod).IsIdle) ||
  696. (ModuleHelper.IsEFEM(mod) && !EFEM.IsIdle) ||
  697. (ModuleHelper.isSETM(mod) && !seTM.IsIdle))
  698. {
  699. notReadyModule = mod;
  700. break;
  701. }
  702. }
  703. if (notReadyModule != ModuleName.System)
  704. {
  705. if (fsm.ElapsedTime > 100 * 1000)
  706. {
  707. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{notReadyModule} home timeout");
  708. PostMsg(MSG.ERROR);
  709. return true;
  710. }
  711. else
  712. return false;
  713. }
  714. return true;
  715. }
  716. private bool FsmEnterAutoRunning(object[] objs)
  717. {
  718. return true;
  719. }
  720. private bool FsmExitAutoTransfer(object[] objs)
  721. {
  722. _AutoCycle.Clear();
  723. return true;
  724. }
  725. private bool FsmExitTransfer(object[] objs)
  726. {
  727. _manualTransfer.Clear();
  728. return true;
  729. }
  730. private bool FsmExitReturnWafer(object[] objs)
  731. {
  732. _returnWafer.Clear();
  733. return true;
  734. }
  735. private bool FsmError(object[] objs)
  736. {
  737. return true;
  738. }
  739. private bool FsmAbort(object[] objs)
  740. {
  741. _manualTransfer.Clear();
  742. _returnWafer.Clear();
  743. _AutoCycle.Clear();
  744. return true;
  745. }
  746. private bool FsmStartTMCycle(object[] objs)
  747. {
  748. return _TMCycle.Start(objs) == RState.Running;
  749. }
  750. private bool FsmMonitorTMCycle(object[] objs)
  751. {
  752. RState ret = _TMCycle.Monitor();
  753. if (ret == RState.Failed || ret == RState.Timeout)
  754. {
  755. PostMsg(MSG.ERROR);
  756. return false;
  757. }
  758. return ret == RState.End;
  759. }
  760. private bool FsmStopTMCycle(object[] objs)
  761. {
  762. _TMCycle.Abort();
  763. return true;
  764. }
  765. private bool FsmStartAutoTransfer(object[] objs)
  766. {
  767. return _AutoCycle.Start(objs) == RState.Running;
  768. }
  769. private bool FsmAutoTransfer(object[] objs)
  770. {
  771. RState ret = _AutoCycle.Monitor();
  772. if (ret == RState.Failed)
  773. {
  774. if (!CheckToPostMessage((int)MSG.ERROR))
  775. return false;
  776. }
  777. if (_AutoCycle.CheckJobJustDone(out string jobInfo))
  778. {
  779. EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  780. }
  781. if (_AutoCycle.CheckAllJobDone())
  782. {
  783. if (!CheckToPostMessage((int)MSG.JobDone))
  784. return false;
  785. }
  786. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  787. return ret == RState.End;
  788. }
  789. private bool FsmAbortAutoTransfer(object[] objs)
  790. {
  791. _AutoCycle.Clear();
  792. return true;
  793. }
  794. private bool FsmJobDone(object[] objs)
  795. {
  796. _isWaitUnload = true;
  797. return true;
  798. }
  799. private bool FsmCreateJob(object[] objs)
  800. {
  801. Dictionary<string, object> obj = (Dictionary<string, object>)objs[0];
  802. var moduleName = (ModuleName)Enum.Parse(typeof(ModuleName), obj["Module"].ToString());
  803. if (EFEM.EfemDevice[moduleName].IsLoaded)
  804. {
  805. return _AutoCycle.CreateJob(obj, out var reason);
  806. }
  807. else
  808. {
  809. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{obj["Module"]} is unload,can not create job");
  810. return false;
  811. }
  812. }
  813. private bool FsmStartJob(object[] objs)
  814. {
  815. _AutoCycle.StartJob((string)objs[0], out var reason);
  816. return true;
  817. }
  818. private bool FsmPauseJob(object[] objs)
  819. {
  820. _AutoCycle.PauseJob((string)objs[0], out var reason);
  821. return true;
  822. }
  823. private bool FsmResumeJob(object[] objs)
  824. {
  825. _AutoCycle.ResumeJob((string)objs[0], out var reason);
  826. return true;
  827. }
  828. private bool FsmStopJob(object[] objs)
  829. {
  830. _AutoCycle.StopJob((string)objs[0], out var reason);
  831. return true;
  832. }
  833. private bool FsmAbortJob(object[] objs)
  834. {
  835. _AutoCycle.AbortJob((string)objs[0], out var reason);
  836. return true;
  837. }
  838. private bool FsmStartTransfer(object[] objs)
  839. {
  840. return _manualTransfer.Start(objs) == RState.Running;
  841. }
  842. private bool FsmMonitorTransfer(object[] objs)
  843. {
  844. RState ret = _manualTransfer.Monitor();
  845. if (ret == RState.Failed || ret == RState.Timeout)
  846. {
  847. PostMsg(MSG.ERROR);
  848. return false;
  849. }
  850. return ret == RState.End;
  851. }
  852. private bool FsmStartReturnWafer(object[] objs)
  853. {
  854. //return _returnWafer.Start(objs) == RState.Running;
  855. return _AutoCycle.CheckManualReturnWafer() == RState.Running;
  856. }
  857. private bool FsmMonitorReturnWafer(object[] objs)
  858. {
  859. //RState ret = _returnWafer.Monitor();
  860. RState ret = _AutoCycle.ReturnAllWafers();
  861. if (ret == RState.Failed || ret == RState.Timeout)
  862. {
  863. PostMsg(MSG.ERROR);
  864. return false;
  865. }
  866. return ret == RState.End;
  867. }
  868. private bool FsmMap(object[] objs)
  869. {
  870. return true;
  871. }
  872. private bool FsmResetIdleCleanTime(object[] objs)
  873. {
  874. return true;
  875. }
  876. private bool FsmResetIdlePurgeTime(object[] objs)
  877. {
  878. return true;
  879. }
  880. private bool FsmAutoReturnWafer(object[] objs)
  881. {
  882. return _AutoCycle.ManualReturnWafer(objs);
  883. }
  884. private bool FsmMonitorAutoIdle(object[] objs)
  885. {
  886. RState ret = _AutoCycle.Monitor();
  887. //if (_AutoCycle.CheckAllJobDone())
  888. //{
  889. // if (!CheckToPostMessage((int)MSG.JobDone))
  890. // return false;
  891. //}
  892. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  893. _debugRoutine();
  894. return ret == RState.End;
  895. }
  896. private bool FsmStartSetManualMode(object[] objs)
  897. {
  898. if (_AutoCycle.HasJobRunning)
  899. {
  900. LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
  901. return false;
  902. }
  903. return true;
  904. }
  905. private void _debugRoutine()
  906. {
  907. int flag = 0;
  908. // Test Home routine
  909. if (flag == 1)
  910. {
  911. PostMsg(MSG.HOME);
  912. }
  913. else if (flag == 2)
  914. {
  915. PostMsg(MSG.TMCycle);
  916. }
  917. else if (flag == 3)
  918. {
  919. PostMsg(MSG.SetAutoMode);
  920. }
  921. else if (flag == 4)
  922. {
  923. PostMsg(MSG.ReturnAllWafer);
  924. }
  925. else if (flag == 5)
  926. {
  927. PostMsg(MSG.StartJob, "CJ_Local_LP1");
  928. }
  929. }
  930. private bool FsmStartSETMCycle(object[] objs)
  931. {
  932. return _seTMCycle.Start(objs) == RState.Running;
  933. }
  934. private bool FsmMonitorSETMCycle(object[] objs)
  935. {
  936. RState ret = _seTMCycle.Monitor();
  937. if (ret == RState.Failed || ret == RState.Timeout)
  938. {
  939. PostMsg(MSG.ERROR);
  940. return false;
  941. }
  942. return ret == RState.End;
  943. }
  944. private bool FsmStopSETMCycle(object[] objs)
  945. {
  946. _seTMCycle.Abort();
  947. return true;
  948. }
  949. private bool FsmStartCreateSEJob(object[] objs)
  950. {
  951. _seTMCycle.CreateJob((Dictionary<string, object>)objs[0]);
  952. return true;
  953. }
  954. private bool FsmStartSEJob(object[] objs)
  955. {
  956. return _seTMCycle.StartJob(objs[0].ToString()) == RState.Running;
  957. }
  958. private bool FsmSEJobMonitor(object[] objs)
  959. {
  960. RState ret = _seTMCycle.Monitor();
  961. return ret == RState.End;
  962. }
  963. private bool FsmStartSEMoveWafer(object[] objs)
  964. {
  965. return _setransfer.Start(objs) == RState.Running;
  966. }
  967. private bool FsmMonitorSEMoveWafer(object[] objs)
  968. {
  969. RState ret = _setransfer.Monitor();
  970. if (ret == RState.Failed || ret == RState.Timeout)
  971. {
  972. PostMsg(MSG.ERROR);
  973. return false;
  974. }
  975. return ret == RState.End;
  976. }
  977. private bool FsmStartSEReturnWafer(object[] objs)
  978. {
  979. return _sereturnWafer.Start(objs) == RState.Running;
  980. }
  981. private bool FsmMonitorSEReturnWafer(object[] objs)
  982. {
  983. RState ret = _sereturnWafer.Monitor();
  984. if (ret == RState.Failed || ret == RState.Timeout)
  985. {
  986. PostMsg(MSG.ERROR);
  987. return false;
  988. }
  989. return ret == RState.End;
  990. }
  991. private bool SEAbortJob(object[] objs)
  992. {
  993. _seTMCycle.AbortJob((string)objs[0], out var reason);
  994. return true;
  995. }
  996. private bool SEAbort(object[] objs)
  997. {
  998. //_seTMCycle.Abort();
  999. _setransfer.Abort();
  1000. _sereturnWafer.Abort();
  1001. seTM.CheckToPostMessage((int)SETMEntity.MSG.Abort);
  1002. return true;
  1003. }
  1004. #region Fa接口
  1005. /// <summary>
  1006. /// 接口指令
  1007. /// </summary>
  1008. /// <param name="command"></param>
  1009. /// <param name="paras"></param>
  1010. /// <param name="reason"></param>
  1011. /// <returns></returns>
  1012. public bool ExcuteCommand(string command, object[] paras, out string reason)
  1013. {
  1014. reason = "";
  1015. switch (command)
  1016. {
  1017. case "PP-SELECT":
  1018. return FaCreateJob(paras, out reason);
  1019. case "StartJob":
  1020. return FaStartJob(paras[0].ToString(), out reason);
  1021. case "StopJob":
  1022. return FaStopJob(paras[0].ToString(), out reason);
  1023. case "AbortJob":
  1024. return FaAbortob(paras[0].ToString(), out reason);
  1025. case "PauseJob":
  1026. return FaPauseJob(paras[0].ToString(), out reason);
  1027. case "ResumeJob":
  1028. return FaResumeJob(paras[0].ToString(), out reason);
  1029. case "Load":
  1030. return FaLoad(paras[0].ToString(), out reason);
  1031. case "Unload":
  1032. return FaUnLoad(paras[0].ToString(), out reason);
  1033. case "ReadID":
  1034. return FaReadId(paras[0].ToString(), out reason);
  1035. }
  1036. return true;
  1037. }
  1038. /// <summary>
  1039. /// Fa创建任务
  1040. /// </summary>
  1041. /// <param name="paras"></param>
  1042. /// <param name="reason"></param>
  1043. /// <returns></returns>
  1044. private bool FaCreateJob(object[] paras, out string reason)
  1045. {
  1046. if (!CheckAuto())
  1047. {
  1048. reason = "System is not in Auto,cannot create job";
  1049. return false;
  1050. }
  1051. else
  1052. {
  1053. Dictionary<string, object> createParams = new Dictionary<string, object>();
  1054. createParams["Module"] = $"LP{paras[0]}";
  1055. createParams["JobId"] = paras[1].ToString();
  1056. createParams["SlotSequence"] = (string[])paras[3];
  1057. createParams["AutoStart"] = true;
  1058. if (paras.Length >= 5)
  1059. {
  1060. createParams["PreCleanRecipeName"] = paras[4].ToString();
  1061. }
  1062. if (paras.Length >= 6)
  1063. {
  1064. createParams["PostCleabRecipeName"] = paras[5].ToString();
  1065. }
  1066. return _AutoCycle.CreateJob(createParams, out reason);
  1067. }
  1068. }
  1069. /// <summary>
  1070. /// Fa启动任务
  1071. /// </summary>
  1072. /// <param name="jobName"></param>
  1073. /// <param name="reason"></param>
  1074. /// <returns></returns>
  1075. private bool FaStartJob(string jobName, out string reason)
  1076. {
  1077. return _AutoCycle.StartJob(jobName, out reason);
  1078. }
  1079. /// <summary>
  1080. /// Fa停止任务
  1081. /// </summary>
  1082. /// <param name="jobName"></param>
  1083. /// <param name="reason"></param>
  1084. /// <returns></returns>
  1085. private bool FaStopJob(string jobName, out string reason)
  1086. {
  1087. return _AutoCycle.StopJob(jobName, out reason);
  1088. }
  1089. /// <summary>
  1090. /// Fa中止任务
  1091. /// </summary>
  1092. /// <param name="jobName"></param>
  1093. /// <param name="reason"></param>
  1094. /// <returns></returns>
  1095. private bool FaAbortob(string jobName, out string reason)
  1096. {
  1097. return _AutoCycle.AbortJob(jobName, out reason);
  1098. }
  1099. /// <summary>
  1100. /// Fa暂停任务
  1101. /// </summary>
  1102. /// <param name="jobName"></param>
  1103. /// <param name="reason"></param>
  1104. /// <returns></returns>
  1105. private bool FaPauseJob(string jobName, out string reason)
  1106. {
  1107. return _AutoCycle.PauseJob(jobName, out reason);
  1108. }
  1109. /// <summary>
  1110. /// Fa恢复任务
  1111. /// </summary>
  1112. /// <param name="jobName"></param>
  1113. /// <param name="reason"></param>
  1114. /// <returns></returns>
  1115. private bool FaResumeJob(string jobName, out string reason)
  1116. {
  1117. return _AutoCycle.ResumeJob(jobName, out reason);
  1118. }
  1119. /// <summary>
  1120. /// Fa Load
  1121. /// </summary>
  1122. /// <param name="lp"></param>
  1123. /// <returns></returns>
  1124. private bool FaLoad(string lp, out string reason)
  1125. {
  1126. reason = "";
  1127. Loadport loadport = FaGetLoadPort(lp, out reason);
  1128. if (loadport != null)
  1129. {
  1130. loadport.Load();
  1131. return true;
  1132. }
  1133. else
  1134. {
  1135. return false;
  1136. }
  1137. }
  1138. /// <summary>
  1139. /// 获取LoadPort对象
  1140. /// </summary>
  1141. /// <param name="lp"></param>
  1142. /// <param name="reason"></param>
  1143. /// <returns></returns>
  1144. private Loadport FaGetLoadPort(string lp, out string reason)
  1145. {
  1146. reason = "";
  1147. if (int.TryParse(lp, out var lpValue))
  1148. {
  1149. LoadPortModule loadPortModule = EFEM.GetLoadportModule(lpValue);
  1150. if (loadPortModule != null)
  1151. {
  1152. if (loadPortModule.LPDevice.HasCassette)
  1153. {
  1154. return loadPortModule.LPDevice;
  1155. }
  1156. else
  1157. {
  1158. reason = $"LP{lpValue} not found carrier, can not load";
  1159. return null;
  1160. }
  1161. }
  1162. else
  1163. {
  1164. reason = $"LP{lp} is null";
  1165. return null;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. reason = $"{lp} is invalid data";
  1171. return null;
  1172. }
  1173. }
  1174. /// <summary>
  1175. /// 读取Id
  1176. /// </summary>
  1177. /// <param name="lp"></param>
  1178. /// <returns></returns>
  1179. private bool FaReadId(string lp, out string reason)
  1180. {
  1181. reason = "";
  1182. Loadport loadport = FaGetLoadPort(lp, out reason);
  1183. if (loadport != null)
  1184. {
  1185. loadport.ReadCarrierID();
  1186. return true;
  1187. }
  1188. else
  1189. {
  1190. return false;
  1191. }
  1192. }
  1193. /// <summary>
  1194. /// Fa Unload
  1195. /// </summary>
  1196. /// <param name="lp"></param>
  1197. /// <returns></returns>
  1198. private bool FaUnLoad(string lp, out string reason)
  1199. {
  1200. reason = "";
  1201. Loadport loadport = FaGetLoadPort(lp, out reason);
  1202. if (loadport != null)
  1203. {
  1204. loadport.Unload();
  1205. return true;
  1206. }
  1207. else
  1208. {
  1209. return false;
  1210. }
  1211. }
  1212. /// <summary>
  1213. /// 获取所有Sequence
  1214. /// </summary>
  1215. /// <returns></returns>
  1216. public string[] GetSequenceList()
  1217. {
  1218. return RecipeFileManager.Instance.GetSequenceNameList().ToArray();
  1219. }
  1220. public string GetSequenceBody(string ppid)
  1221. {
  1222. return RecipeFileManager.Instance.GetSequence(ppid, false);
  1223. }
  1224. public List<string> GetFormatedSequence(string ppid)
  1225. {
  1226. return null;
  1227. }
  1228. public bool deleteSequence(string ppid)
  1229. {
  1230. return true;
  1231. }
  1232. public bool UpdateSequence(string ppid, string body)
  1233. {
  1234. return true;
  1235. }
  1236. public void ShowTerminalMessage(string message)
  1237. {
  1238. }
  1239. public bool CreateProcessJob(string processJobId, string sequenceName, string carrierId, out string reason)
  1240. {
  1241. reason = "";
  1242. return true;
  1243. }
  1244. public void UpdateProcessJobCarrierSlot(string processJobId, string moduleName, List<int> slots)
  1245. {
  1246. }
  1247. public void CreateControlJob(string controlJobId, string carrierId, List<string> processJobs)
  1248. {
  1249. }
  1250. public bool CheckCreateControlJobCondition(List<string> modules, out string reason)
  1251. {
  1252. reason = "";
  1253. return true;
  1254. }
  1255. public bool StartControlJob(string controlJob)
  1256. {
  1257. return true;
  1258. }
  1259. public bool StopControlJob(string controlJob)
  1260. {
  1261. return true;
  1262. }
  1263. public bool AbortControlJob(string controlJob)
  1264. {
  1265. return true;
  1266. }
  1267. public bool PauseControlJob(string controlJob)
  1268. {
  1269. return true;
  1270. }
  1271. public bool ResumeControlJob(string controlJob)
  1272. {
  1273. return true;
  1274. }
  1275. public bool CheckAuto()
  1276. {
  1277. return fsm.State == (int)RtState.AutoIdle;
  1278. }
  1279. public void UpdateControlJobModule(string controlJobId, string moduleName)
  1280. {
  1281. }
  1282. #endregion
  1283. }
  1284. }