RouteManager.cs 49 KB

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