RouteManager.cs 65 KB

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