RouteManager.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  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. using Venus_RT.Modules.Schedulers;
  31. namespace Venus_RT.Modules
  32. {
  33. class RouteManager : Entity, IEntity, IEquipmentCommand
  34. {
  35. public enum MSG
  36. {
  37. MoveWafer,
  38. ReturnWafer,
  39. HomeUnit,
  40. PauseAuto,
  41. ResumeAuto,
  42. Stop,
  43. StartCycle,
  44. StopCycle,
  45. HOME,
  46. RESET,
  47. ABORT,
  48. ERROR,
  49. SetAutoMode,
  50. SetManualMode,
  51. ResetIdleCleanTime,
  52. ResetIdlePurgeTime,
  53. CreateJob,
  54. PauseJob,
  55. ResumeJob,
  56. StartJob,
  57. StopJob,
  58. AbortJob,
  59. JobDone,
  60. CassetteLeave, //For unload light control off afer job done
  61. Map,
  62. ReturnAllWafer,
  63. TMCycle,
  64. SETMCycle,
  65. StopSECycle,
  66. CreateSEJob,
  67. StartSEJob,
  68. AbortSEJob,
  69. SEMoveWafer,
  70. SEReturnWafer,
  71. SEAbort,
  72. }
  73. public PMEntity PMA { get; private set; }
  74. public PMEntity PMB { get; private set; }
  75. public PMEntity PMC { get; private set; }
  76. public PMEntity PMD { get; private set; }
  77. public TMEntity TM { get; private set; }
  78. public LLEntity LLA { get; private set; }
  79. public LLEntity LLB { get; private set; }
  80. public EfemEntity EFEM { get; private set; }
  81. public VceEntity VCE { get; private set; }
  82. public VceEntity VCEA { get; private set; }
  83. public VceEntity VCEB { get; private set; }
  84. public SETMEntity seTM { get; private set; }
  85. public string Name { get; set; }
  86. public bool IsAutoMode
  87. {
  88. get
  89. {
  90. return fsm.State == (int)RtState.AutoRunning || fsm.State == (int)RtState.AutoIdle;
  91. }
  92. }
  93. public bool IsInit
  94. {
  95. get { return fsm.State == (int)RtState.Init; }
  96. }
  97. public bool IsIdle
  98. {
  99. get { return fsm.State == (int)RtState.Idle || fsm.State == (int)RtState.AutoIdle; }
  100. }
  101. public bool IsAlarm
  102. {
  103. get { return fsm.State == (int)RtState.Error; }
  104. }
  105. public bool IsPaused
  106. {
  107. get { return _AutoCycle.CycleState == RState.Paused; }
  108. }
  109. public bool IsEntityError
  110. {
  111. get
  112. {
  113. return (EFEM?.IsError ?? false)
  114. || (PMA?.IsError ?? false)
  115. || (PMB?.IsError ?? false)
  116. || (PMC?.IsError ?? false)
  117. || (PMD?.IsError ?? false);
  118. }
  119. }
  120. public bool IsRunning
  121. {
  122. get
  123. {
  124. return !IsInit && !IsAlarm && !IsIdle;
  125. }
  126. }
  127. public static bool IsATMMode
  128. {
  129. get
  130. {
  131. if (_isATMMode == -1)
  132. {
  133. _isATMMode = SC.GetValue<bool>("System.IsATMMode") ? 1 : 0;
  134. }
  135. return _isATMMode == 1;
  136. }
  137. }
  138. public SequenceLLInOutPath LLInOutPath => _AutoCycle.LLInOutPath;
  139. private TMCycle _TMCycle;
  140. private ICycle _AutoCycle;
  141. private ManualTransfer _manualTransfer;
  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.CreateJob, args));
  392. OP.Subscribe("System.StartSEJob", (cmd, args) => CheckToPostMessage((int)MSG.StartJob, args));
  393. OP.Subscribe("System.ReturnAllSEWafer", (cmd, args) => CheckToPostMessage((int)MSG.ReturnAllWafer, args));
  394. OP.Subscribe("System.SEAbort", (cmd, args) => CheckToPostMessage((int)MSG.ABORT, 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. LLA?.Initialize();
  562. LLB?.Initialize();
  563. EFEM?.Initialize();
  564. VCE?.Initialize();
  565. VCEA?.Initialize();
  566. VCEB?.Initialize();
  567. if(RtInstance.ConfigType == ConfigType.VenusSE || RtInstance.ConfigType == ConfigType.VenusDE)
  568. {
  569. seTM?.Initialize();
  570. _seTMCycle = new SETMCycle(ModuleName.SETM);
  571. _setransfer = new SEManualTransfer();
  572. _sereturnWafer = new SEReturnWafer(_setransfer);
  573. _AutoCycle = new VenusDispatcher();
  574. }
  575. else
  576. {
  577. TM?.Initialize();
  578. _TMCycle = new TMCycle();
  579. _manualTransfer = new ManualTransfer();
  580. _AutoCycle = new SystemDispatcher();
  581. }
  582. BuildTransitionTable();
  583. return true;
  584. }
  585. private void BuildTransitionTable()
  586. {
  587. //Init sequence
  588. Transition(RtState.Init, MSG.HOME, FsmStartHome, RtState.Initializing);
  589. Transition(RtState.Idle, MSG.HOME, FsmStartHome, RtState.Initializing);
  590. Transition(RtState.Error, MSG.HOME, FsmStartHome, RtState.Initializing);
  591. EnterExitTransition<RtState, FSM_MSG>(RtState.AutoRunning, FsmEnterAutoRunning, FSM_MSG.NONE, FsmExitAutoTransfer);
  592. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, FsmExitTransfer);
  593. EnterExitTransition<RtState, FSM_MSG>(RtState.ReturnWafer, null, FSM_MSG.NONE, FsmExitReturnWafer);
  594. AnyStateTransition(MSG.ERROR, FsmError, RtState.Error);
  595. Transition(RtState.Idle, FSM_MSG.TIMER, FsmMonitor, RtState.Idle);
  596. Transition(RtState.Init, FSM_MSG.TIMER, FsmMonitor, RtState.Init);
  597. Transition(RtState.Initializing, FSM_MSG.TIMER, FsmMonitorHome, RtState.Idle);
  598. Transition(RtState.Initializing, MSG.ERROR, FsmError, RtState.Error);
  599. Transition(RtState.Initializing, MSG.ABORT, FsmAbort, RtState.Init);
  600. // TM Cycle
  601. Transition(RtState.Idle, MSG.TMCycle, FsmStartTMCycle, RtState.TMCycle);
  602. Transition(RtState.TMCycle, FSM_MSG.TIMER, FsmMonitorTMCycle, RtState.Idle);
  603. Transition(RtState.TMCycle, MSG.StopCycle, FsmStopTMCycle, RtState.Idle);
  604. //Auto/manual
  605. Transition(RtState.Idle, MSG.SetAutoMode, FsmStartAutoTransfer, RtState.AutoIdle);
  606. Transition(RtState.AutoRunning, FSM_MSG.TIMER, FsmAutoTransfer, RtState.AutoIdle);
  607. Transition(RtState.AutoRunning, MSG.ABORT, FsmAbortAutoTransfer, RtState.Idle);
  608. //Transition(RtState.AutoRunning, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  609. Transition(RtState.AutoRunning, MSG.JobDone, FsmJobDone, RtState.AutoIdle);
  610. //Transition(RtState.AutoRunning, MSG.CassetteLeave, fCassetteLeave, RtState.AutoRunning); //For unload light control off afer job done
  611. Transition(RtState.AutoRunning, MSG.CreateJob, FsmCreateJob, RtState.AutoRunning);
  612. Transition(RtState.AutoRunning, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  613. Transition(RtState.AutoRunning, MSG.PauseJob, FsmPauseJob, RtState.AutoRunning);
  614. Transition(RtState.AutoRunning, MSG.ResumeJob, FsmResumeJob, RtState.AutoRunning);
  615. Transition(RtState.AutoRunning, MSG.StopJob, FsmStopJob, RtState.AutoRunning);
  616. Transition(RtState.AutoRunning, MSG.AbortJob, FsmAbortJob, RtState.AutoRunning);
  617. Transition(RtState.AutoRunning, MSG.MoveWafer, FsmAutoReturnWafer, RtState.AutoRunning);
  618. Transition(RtState.AutoRunning, MSG.Map, FsmMap, RtState.AutoRunning);
  619. Transition(RtState.AutoRunning, MSG.ResetIdleCleanTime, FsmResetIdleCleanTime, RtState.AutoRunning);
  620. Transition(RtState.AutoRunning, MSG.ResetIdlePurgeTime, FsmResetIdlePurgeTime, RtState.AutoRunning);
  621. Transition(RtState.AutoIdle, FSM_MSG.TIMER, FsmMonitorAutoIdle, RtState.AutoIdle);
  622. Transition(RtState.AutoIdle, MSG.SetManualMode, FsmStartSetManualMode, RtState.Idle);
  623. Transition(RtState.AutoIdle, MSG.CreateJob, FsmCreateJob, RtState.AutoIdle);
  624. Transition(RtState.AutoIdle, MSG.StartJob, FsmStartJob, RtState.AutoRunning);
  625. Transition(RtState.AutoIdle, MSG.PauseJob, FsmPauseJob, RtState.AutoIdle);
  626. Transition(RtState.AutoIdle, MSG.ResumeJob, FsmResumeJob, RtState.AutoIdle);
  627. Transition(RtState.AutoIdle, MSG.StopJob, FsmStopJob, RtState.AutoIdle);
  628. Transition(RtState.AutoIdle, MSG.AbortJob, FsmAbortJob, RtState.AutoIdle);
  629. Transition(RtState.AutoIdle, MSG.Map, FsmMap, RtState.AutoIdle);
  630. //Transfer
  631. Transition(RtState.Idle, MSG.MoveWafer, FsmStartTransfer, RtState.Transfer);
  632. Transition(RtState.Transfer, FSM_MSG.TIMER, FsmMonitorTransfer, RtState.Idle);
  633. Transition(RtState.Transfer, MSG.ABORT, FsmAbort, RtState.Idle);
  634. //Return Wafer
  635. Transition(RtState.Idle, MSG.ReturnAllWafer, FsmStartReturnWafer, RtState.ReturnWafer);
  636. Transition(RtState.ReturnWafer, FSM_MSG.TIMER, FsmMonitorReturnWafer, RtState.Idle);
  637. Transition(RtState.ReturnWafer, MSG.ABORT, FsmAbort, RtState.Idle);
  638. // SETM Cycle
  639. Transition(RtState.Idle, MSG.SETMCycle, FsmStartSETMCycle, RtState.SETMCycle);
  640. Transition(RtState.SETMCycle, FSM_MSG.TIMER, FsmMonitorSETMCycle, RtState.Idle);
  641. Transition(RtState.SETMCycle, MSG.SEAbort, SEAbort, RtState.Idle);
  642. Transition(RtState.SETMCycle, MSG.AbortSEJob, SEAbortJob, RtState.Idle);
  643. // SETM CreateCycle
  644. Transition(RtState.Idle, MSG.CreateSEJob, FsmStartCreateSEJob, RtState.Idle);
  645. // SETM StartCycle
  646. Transition(RtState.Idle, MSG.StartSEJob, FsmStartSEJob, RtState.SERunning);
  647. Transition(RtState.SERunning, FSM_MSG.TIMER, FsmSEJobMonitor, RtState.Idle);
  648. Transition(RtState.SERunning, MSG.SEAbort, SEAbort, RtState.Idle);
  649. Transition(RtState.SERunning, MSG.AbortSEJob, SEAbortJob, RtState.Idle);
  650. Transition(RtState.Idle, MSG.AbortSEJob, SEAbortJob, RtState.Idle);
  651. // SE Transfer
  652. Transition(RtState.Idle, MSG.SEMoveWafer, FsmStartSEMoveWafer, RtState.SETransfer);
  653. Transition(RtState.SETransfer, FSM_MSG.TIMER, FsmMonitorSEMoveWafer, RtState.Idle);
  654. Transition(RtState.SETransfer, MSG.ABORT, SEAbort, RtState.Idle);
  655. // SE ReturnWafer
  656. Transition(RtState.Idle, MSG.SEReturnWafer, FsmStartSEReturnWafer, RtState.SEReturnWafer);
  657. Transition(RtState.SEReturnWafer, FSM_MSG.TIMER, FsmMonitorSEReturnWafer, RtState.Idle);
  658. Transition(RtState.SEReturnWafer, MSG.SEAbort, SEAbort, RtState.Idle);
  659. }
  660. private bool FsmMonitor(object[] objs)
  661. {
  662. _debugRoutine();
  663. return true;
  664. }
  665. private bool FsmStartHome(object[] objs)
  666. {
  667. TM?.Invoke("Home");
  668. EFEM?.Invoke("Home");
  669. seTM?.Invoke("Home");
  670. VCE?.Invoke("Home");
  671. VCEA?.Invoke("Home");
  672. VCEB?.Invoke("Home");
  673. foreach (var mod in ModuleHelper.InstalledModules)
  674. {
  675. if (ModuleHelper.IsPm(mod))
  676. {
  677. if (GetPM(mod).IsInclude)
  678. {
  679. GetPM(mod).Invoke("Home");
  680. }
  681. }
  682. else if (ModuleHelper.IsLoadLock(mod))
  683. {
  684. if (GetLL(mod).IsInclude)
  685. {
  686. GetLL(mod).Invoke("Home");
  687. }
  688. }
  689. }
  690. return true;
  691. }
  692. private bool FsmMonitorHome(object[] objs)
  693. {
  694. ModuleName notReadyModule = ModuleName.System;
  695. foreach (var mod in ModuleHelper.InstalledModules)
  696. {
  697. if ((ModuleHelper.IsPm(mod) && GetPM(mod).IsInclude && !GetPM(mod).IsIdle) ||
  698. (ModuleHelper.IsLoadLock(mod) && GetLL(mod).IsInclude && !GetLL(mod).IsIdle) ||
  699. (ModuleHelper.IsTM(mod) && !GetTM().IsIdle) ||
  700. (ModuleHelper.IsVCE(mod) && !GetVCE(mod).IsIdle) ||
  701. (ModuleHelper.IsEFEM(mod) && !EFEM.IsIdle) ||
  702. (ModuleHelper.isSETM(mod) && !seTM.IsIdle))
  703. {
  704. notReadyModule = mod;
  705. break;
  706. }
  707. }
  708. if (notReadyModule != ModuleName.System)
  709. {
  710. if (fsm.ElapsedTime > 100 * 1000)
  711. {
  712. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"{notReadyModule} home timeout");
  713. PostMsg(MSG.ERROR);
  714. return true;
  715. }
  716. else
  717. return false;
  718. }
  719. return true;
  720. }
  721. private bool FsmEnterAutoRunning(object[] objs)
  722. {
  723. return true;
  724. }
  725. private bool FsmExitAutoTransfer(object[] objs)
  726. {
  727. _AutoCycle.Clear();
  728. return true;
  729. }
  730. private bool FsmExitTransfer(object[] objs)
  731. {
  732. _manualTransfer.Clear();
  733. return true;
  734. }
  735. private bool FsmExitReturnWafer(object[] objs)
  736. {
  737. return true;
  738. }
  739. private bool FsmError(object[] objs)
  740. {
  741. return true;
  742. }
  743. private bool FsmAbort(object[] objs)
  744. {
  745. _manualTransfer?.Clear();
  746. _setransfer?.Abort();
  747. _AutoCycle.Clear();
  748. return true;
  749. }
  750. private bool FsmStartTMCycle(object[] objs)
  751. {
  752. return _TMCycle.Start(objs) == RState.Running;
  753. }
  754. private bool FsmMonitorTMCycle(object[] objs)
  755. {
  756. RState ret = _TMCycle.Monitor();
  757. if (ret == RState.Failed || ret == RState.Timeout)
  758. {
  759. PostMsg(MSG.ERROR);
  760. return false;
  761. }
  762. return ret == RState.End;
  763. }
  764. private bool FsmStopTMCycle(object[] objs)
  765. {
  766. _TMCycle.Abort();
  767. return true;
  768. }
  769. private bool FsmStartAutoTransfer(object[] objs)
  770. {
  771. return _AutoCycle.Start(objs) == RState.Running;
  772. }
  773. private bool FsmAutoTransfer(object[] objs)
  774. {
  775. RState ret = _AutoCycle.Monitor();
  776. if (ret == RState.Failed)
  777. {
  778. if (!CheckToPostMessage((int)MSG.ERROR))
  779. return false;
  780. }
  781. if (_AutoCycle.CheckJobJustDone(out string jobInfo))
  782. {
  783. EV.PostPopDialogMessage(EventLevel.InformationNoDelay, "Job complete", jobInfo);
  784. }
  785. if (_AutoCycle.CheckAllJobDone())
  786. {
  787. if (!CheckToPostMessage((int)MSG.JobDone))
  788. return false;
  789. }
  790. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  791. return ret == RState.End;
  792. }
  793. private bool FsmAbortAutoTransfer(object[] objs)
  794. {
  795. _AutoCycle.Clear();
  796. return true;
  797. }
  798. private bool FsmJobDone(object[] objs)
  799. {
  800. _isWaitUnload = true;
  801. return true;
  802. }
  803. private bool FsmCreateJob(object[] objs)
  804. {
  805. Dictionary<string, object> obj = (Dictionary<string, object>)objs[0];
  806. var moduleName = (ModuleName)Enum.Parse(typeof(ModuleName), obj["Module"].ToString());
  807. if ((Singleton<TransferModule>.Instance.GetScheduler(moduleName) as SchedulerLoadPort).IsLoaded)
  808. {
  809. return _AutoCycle.CreateJob(obj, out var reason);
  810. }
  811. else
  812. {
  813. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{obj["Module"]} is unload,can not create job");
  814. return false;
  815. }
  816. }
  817. private bool FsmStartJob(object[] objs)
  818. {
  819. _AutoCycle.StartJob((string)objs[0], out var reason);
  820. return true;
  821. }
  822. private bool FsmPauseJob(object[] objs)
  823. {
  824. _AutoCycle.PauseJob((string)objs[0], out var reason);
  825. return true;
  826. }
  827. private bool FsmResumeJob(object[] objs)
  828. {
  829. _AutoCycle.ResumeJob((string)objs[0], out var reason);
  830. return true;
  831. }
  832. private bool FsmStopJob(object[] objs)
  833. {
  834. _AutoCycle.StopJob((string)objs[0], out var reason);
  835. return true;
  836. }
  837. private bool FsmAbortJob(object[] objs)
  838. {
  839. _AutoCycle.AbortJob((string)objs[0], out var reason);
  840. return true;
  841. }
  842. private bool FsmStartTransfer(object[] objs)
  843. {
  844. return _manualTransfer.Start(objs) == RState.Running;
  845. }
  846. private bool FsmMonitorTransfer(object[] objs)
  847. {
  848. RState ret = _manualTransfer.Monitor();
  849. if (ret == RState.Failed || ret == RState.Timeout)
  850. {
  851. PostMsg(MSG.ERROR);
  852. return false;
  853. }
  854. return ret == RState.End;
  855. }
  856. private bool FsmStartReturnWafer(object[] objs)
  857. {
  858. //return _returnWafer.Start(objs) == RState.Running;
  859. return _AutoCycle.CheckManualReturnWafer() == RState.Running;
  860. }
  861. private bool FsmMonitorReturnWafer(object[] objs)
  862. {
  863. //RState ret = _returnWafer.Monitor();
  864. RState ret = _AutoCycle.ReturnAllWafers();
  865. if (ret == RState.Failed || ret == RState.Timeout)
  866. {
  867. PostMsg(MSG.ERROR);
  868. return false;
  869. }
  870. return ret == RState.End;
  871. }
  872. private bool FsmMap(object[] objs)
  873. {
  874. return true;
  875. }
  876. private bool FsmResetIdleCleanTime(object[] objs)
  877. {
  878. return true;
  879. }
  880. private bool FsmResetIdlePurgeTime(object[] objs)
  881. {
  882. return true;
  883. }
  884. private bool FsmAutoReturnWafer(object[] objs)
  885. {
  886. return _AutoCycle.ManualReturnWafer(objs);
  887. }
  888. private bool FsmMonitorAutoIdle(object[] objs)
  889. {
  890. RState ret = _AutoCycle.Monitor();
  891. //if (_AutoCycle.CheckAllJobDone())
  892. //{
  893. // if (!CheckToPostMessage((int)MSG.JobDone))
  894. // return false;
  895. //}
  896. //_isWaitUnload = (bool)DATA.Poll("LP1.NotifyJobDone") || (bool)DATA.Poll("LP2.NotifyJobDone");
  897. _debugRoutine();
  898. return ret == RState.End;
  899. }
  900. private bool FsmStartSetManualMode(object[] objs)
  901. {
  902. if (_AutoCycle.HasJobRunning)
  903. {
  904. LOG.Write(eEvent.WARN_ROUTER, "System", "Can not change to manual mode, abort running job first");
  905. return false;
  906. }
  907. return true;
  908. }
  909. private void _debugRoutine()
  910. {
  911. int flag = 0;
  912. // Test Home routine
  913. if (flag == 1)
  914. {
  915. PostMsg(MSG.HOME);
  916. }
  917. else if (flag == 2)
  918. {
  919. PostMsg(MSG.TMCycle);
  920. }
  921. else if (flag == 3)
  922. {
  923. PostMsg(MSG.SetAutoMode);
  924. }
  925. else if (flag == 4)
  926. {
  927. PostMsg(MSG.ReturnAllWafer);
  928. }
  929. else if (flag == 5)
  930. {
  931. PostMsg(MSG.StartJob, "CJ_Local_LP1");
  932. }
  933. }
  934. private bool FsmStartSETMCycle(object[] objs)
  935. {
  936. //return _seTMCycle.Start(objs) == RState.Running;
  937. return _AutoCycle.Start(objs) == RState.Running;
  938. }
  939. private bool FsmMonitorSETMCycle(object[] objs)
  940. {
  941. RState ret = _AutoCycle.Monitor();
  942. if (ret == RState.Failed || ret == RState.Timeout)
  943. {
  944. PostMsg(MSG.ERROR);
  945. return false;
  946. }
  947. return ret == RState.End;
  948. }
  949. private bool FsmStopSETMCycle(object[] objs)
  950. {
  951. _AutoCycle.Abort();
  952. return true;
  953. }
  954. private bool FsmStartCreateSEJob(object[] objs)
  955. {
  956. _AutoCycle.CreateJob((Dictionary<string, object>)objs[0], out string reason);
  957. return true;
  958. }
  959. private bool FsmStartSEJob(object[] objs)
  960. {
  961. //return _seTMCycle.StartJob(objs[0].ToString()) == RState.Running;
  962. return _AutoCycle.StartJob(objs[0].ToString(), out string reason);
  963. }
  964. private bool FsmSEJobMonitor(object[] objs)
  965. {
  966. RState ret = _AutoCycle.Monitor();
  967. return ret == RState.End;
  968. }
  969. private bool FsmStartSEMoveWafer(object[] objs)
  970. {
  971. return _setransfer.Start(objs) == RState.Running;
  972. }
  973. private bool FsmMonitorSEMoveWafer(object[] objs)
  974. {
  975. RState ret = _setransfer.Monitor();
  976. if (ret == RState.Failed || ret == RState.Timeout)
  977. {
  978. PostMsg(MSG.ERROR);
  979. return false;
  980. }
  981. return ret == RState.End;
  982. }
  983. private bool FsmStartSEReturnWafer(object[] objs)
  984. {
  985. return _sereturnWafer.Start(objs) == RState.Running;
  986. }
  987. private bool FsmMonitorSEReturnWafer(object[] objs)
  988. {
  989. RState ret = _sereturnWafer.Monitor();
  990. if (ret == RState.Failed || ret == RState.Timeout)
  991. {
  992. PostMsg(MSG.ERROR);
  993. return false;
  994. }
  995. return ret == RState.End;
  996. }
  997. private bool SEAbortJob(object[] objs)
  998. {
  999. _AutoCycle.AbortJob((string)objs[0], out var reason);
  1000. return true;
  1001. }
  1002. private bool SEAbort(object[] objs)
  1003. {
  1004. //_seTMCycle.Abort();
  1005. _setransfer.Abort();
  1006. _sereturnWafer.Abort();
  1007. seTM.CheckToPostMessage((int)SETMEntity.MSG.Abort);
  1008. return true;
  1009. }
  1010. #region Fa接口
  1011. /// <summary>
  1012. /// 接口指令
  1013. /// </summary>
  1014. /// <param name="command"></param>
  1015. /// <param name="paras"></param>
  1016. /// <param name="reason"></param>
  1017. /// <returns></returns>
  1018. public bool ExcuteCommand(string command, object[] paras, out string reason)
  1019. {
  1020. reason = "";
  1021. switch (command)
  1022. {
  1023. case "PP-SELECT":
  1024. return FaCreateJob(paras, out reason);
  1025. case "StartJob":
  1026. return FaStartJob(paras[0].ToString(), out reason);
  1027. case "StopJob":
  1028. return FaStopJob(paras[0].ToString(), out reason);
  1029. case "AbortJob":
  1030. return FaAbortob(paras[0].ToString(), out reason);
  1031. case "PauseJob":
  1032. return FaPauseJob(paras[0].ToString(), out reason);
  1033. case "ResumeJob":
  1034. return FaResumeJob(paras[0].ToString(), out reason);
  1035. case "Load":
  1036. return FaLoad(paras[0].ToString(), out reason);
  1037. case "Unload":
  1038. return FaUnLoad(paras[0].ToString(), out reason);
  1039. case "ReadID":
  1040. return FaReadId(paras[0].ToString(), out reason);
  1041. }
  1042. return true;
  1043. }
  1044. /// <summary>
  1045. /// Fa创建任务
  1046. /// </summary>
  1047. /// <param name="paras"></param>
  1048. /// <param name="reason"></param>
  1049. /// <returns></returns>
  1050. private bool FaCreateJob(object[] paras, out string reason)
  1051. {
  1052. if (!CheckAuto())
  1053. {
  1054. reason = "System is not in Auto,cannot create job";
  1055. return false;
  1056. }
  1057. else
  1058. {
  1059. Dictionary<string, object> createParams = new Dictionary<string, object>();
  1060. createParams["Module"] = $"LP{paras[0]}";
  1061. createParams["JobId"] = paras[1].ToString();
  1062. createParams["SlotSequence"] = (string[])paras[3];
  1063. createParams["AutoStart"] = true;
  1064. if (paras.Length >= 5)
  1065. {
  1066. createParams["PreCleanRecipeName"] = paras[4].ToString();
  1067. }
  1068. if (paras.Length >= 6)
  1069. {
  1070. createParams["PostCleabRecipeName"] = paras[5].ToString();
  1071. }
  1072. return _AutoCycle.CreateJob(createParams, out reason);
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// Fa启动任务
  1077. /// </summary>
  1078. /// <param name="jobName"></param>
  1079. /// <param name="reason"></param>
  1080. /// <returns></returns>
  1081. private bool FaStartJob(string jobName, out string reason)
  1082. {
  1083. return _AutoCycle.StartJob(jobName, out reason);
  1084. }
  1085. /// <summary>
  1086. /// Fa停止任务
  1087. /// </summary>
  1088. /// <param name="jobName"></param>
  1089. /// <param name="reason"></param>
  1090. /// <returns></returns>
  1091. private bool FaStopJob(string jobName, out string reason)
  1092. {
  1093. return _AutoCycle.StopJob(jobName, out reason);
  1094. }
  1095. /// <summary>
  1096. /// Fa中止任务
  1097. /// </summary>
  1098. /// <param name="jobName"></param>
  1099. /// <param name="reason"></param>
  1100. /// <returns></returns>
  1101. private bool FaAbortob(string jobName, out string reason)
  1102. {
  1103. return _AutoCycle.AbortJob(jobName, out reason);
  1104. }
  1105. /// <summary>
  1106. /// Fa暂停任务
  1107. /// </summary>
  1108. /// <param name="jobName"></param>
  1109. /// <param name="reason"></param>
  1110. /// <returns></returns>
  1111. private bool FaPauseJob(string jobName, out string reason)
  1112. {
  1113. return _AutoCycle.PauseJob(jobName, out reason);
  1114. }
  1115. /// <summary>
  1116. /// Fa恢复任务
  1117. /// </summary>
  1118. /// <param name="jobName"></param>
  1119. /// <param name="reason"></param>
  1120. /// <returns></returns>
  1121. private bool FaResumeJob(string jobName, out string reason)
  1122. {
  1123. return _AutoCycle.ResumeJob(jobName, out reason);
  1124. }
  1125. /// <summary>
  1126. /// Fa Load
  1127. /// </summary>
  1128. /// <param name="lp"></param>
  1129. /// <returns></returns>
  1130. private bool FaLoad(string lp, out string reason)
  1131. {
  1132. reason = "";
  1133. Loadport loadport = FaGetLoadPort(lp, out reason);
  1134. if (loadport != null)
  1135. {
  1136. loadport.Load();
  1137. return true;
  1138. }
  1139. else
  1140. {
  1141. return false;
  1142. }
  1143. }
  1144. /// <summary>
  1145. /// 获取LoadPort对象
  1146. /// </summary>
  1147. /// <param name="lp"></param>
  1148. /// <param name="reason"></param>
  1149. /// <returns></returns>
  1150. private Loadport FaGetLoadPort(string lp, out string reason)
  1151. {
  1152. reason = "";
  1153. if (int.TryParse(lp, out var lpValue))
  1154. {
  1155. LoadPortModule loadPortModule = EFEM.GetLoadportModule(lpValue);
  1156. if (loadPortModule != null)
  1157. {
  1158. if (loadPortModule.LPDevice.HasCassette)
  1159. {
  1160. return loadPortModule.LPDevice;
  1161. }
  1162. else
  1163. {
  1164. reason = $"LP{lpValue} not found carrier, can not load";
  1165. return null;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. reason = $"LP{lp} is null";
  1171. return null;
  1172. }
  1173. }
  1174. else
  1175. {
  1176. reason = $"{lp} is invalid data";
  1177. return null;
  1178. }
  1179. }
  1180. /// <summary>
  1181. /// 读取Id
  1182. /// </summary>
  1183. /// <param name="lp"></param>
  1184. /// <returns></returns>
  1185. private bool FaReadId(string lp, out string reason)
  1186. {
  1187. reason = "";
  1188. Loadport loadport = FaGetLoadPort(lp, out reason);
  1189. if (loadport != null)
  1190. {
  1191. loadport.ReadCarrierID();
  1192. return true;
  1193. }
  1194. else
  1195. {
  1196. return false;
  1197. }
  1198. }
  1199. /// <summary>
  1200. /// Fa Unload
  1201. /// </summary>
  1202. /// <param name="lp"></param>
  1203. /// <returns></returns>
  1204. private bool FaUnLoad(string lp, out string reason)
  1205. {
  1206. reason = "";
  1207. Loadport loadport = FaGetLoadPort(lp, out reason);
  1208. if (loadport != null)
  1209. {
  1210. loadport.Unload();
  1211. return true;
  1212. }
  1213. else
  1214. {
  1215. return false;
  1216. }
  1217. }
  1218. /// <summary>
  1219. /// 获取所有Sequence
  1220. /// </summary>
  1221. /// <returns></returns>
  1222. public string[] GetSequenceList()
  1223. {
  1224. return RecipeFileManager.Instance.GetSequenceNameList().ToArray();
  1225. }
  1226. public string GetSequenceBody(string ppid)
  1227. {
  1228. return RecipeFileManager.Instance.GetSequence(ppid, false);
  1229. }
  1230. public List<string> GetFormatedSequence(string ppid)
  1231. {
  1232. return null;
  1233. }
  1234. public bool deleteSequence(string ppid)
  1235. {
  1236. return true;
  1237. }
  1238. public bool UpdateSequence(string ppid, string body)
  1239. {
  1240. return true;
  1241. }
  1242. public void ShowTerminalMessage(string message)
  1243. {
  1244. }
  1245. public bool CreateProcessJob(string processJobId, string sequenceName, string carrierId, out string reason)
  1246. {
  1247. reason = "";
  1248. return true;
  1249. }
  1250. public void UpdateProcessJobCarrierSlot(string processJobId, string moduleName, List<int> slots)
  1251. {
  1252. }
  1253. public void CreateControlJob(string controlJobId, string carrierId, List<string> processJobs)
  1254. {
  1255. }
  1256. public bool CheckCreateControlJobCondition(List<string> modules, out string reason)
  1257. {
  1258. reason = "";
  1259. return true;
  1260. }
  1261. public bool StartControlJob(string controlJob)
  1262. {
  1263. return true;
  1264. }
  1265. public bool StopControlJob(string controlJob)
  1266. {
  1267. return true;
  1268. }
  1269. public bool AbortControlJob(string controlJob)
  1270. {
  1271. return true;
  1272. }
  1273. public bool PauseControlJob(string controlJob)
  1274. {
  1275. return true;
  1276. }
  1277. public bool ResumeControlJob(string controlJob)
  1278. {
  1279. return true;
  1280. }
  1281. public bool CheckAuto()
  1282. {
  1283. return fsm.State == (int)RtState.AutoIdle;
  1284. }
  1285. public void UpdateControlJobModule(string controlJobId, string moduleName)
  1286. {
  1287. }
  1288. #endregion
  1289. }
  1290. }