RouteManager.cs 56 KB

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