RouteManager.cs 61 KB

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