VenusDispatcher.cs 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Diagnostics;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Sorter.Common;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using Aitex.Core.RT.DataCenter;
  12. using Aitex.Core.RT.RecipeCenter;
  13. using Aitex.Core.RT.Fsm;
  14. using MECF.Framework.Common.Jobs;
  15. using MECF.Framework.Common.Routine;
  16. using MECF.Framework.Common.Equipment;
  17. using MECF.Framework.Common.SubstrateTrackings;
  18. using MECF.Framework.Common.Schedulers;
  19. using MECF.Framework.Common.DBCore;
  20. using Venus_Core;
  21. using Venus_RT.Modules.Schedulers;
  22. using Venus_RT.Scheduler;
  23. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  24. namespace Venus_RT.Modules
  25. {
  26. class VCETask : ModuleTask
  27. {
  28. public VCETask(ModuleName mod) : base(mod)
  29. {
  30. }
  31. }
  32. class VenusPMTask : ModuleTask
  33. {
  34. public enum RecipeJobType
  35. {
  36. PreClean,
  37. Process,
  38. PostClean,
  39. WtwClean,
  40. }
  41. public override int TimeToReady
  42. {
  43. get
  44. {
  45. switch (Status)
  46. {
  47. case ModuleStatus.Idle:
  48. case ModuleStatus.IdleClean:
  49. case ModuleStatus.PreJobClean:
  50. case ModuleStatus.PostJobClean:
  51. case ModuleStatus.WTWClean:
  52. case ModuleStatus.Processing:
  53. {
  54. return Scheduler.IsAvailable ? 0 : (Scheduler.TimeToReady + 500) / 1000;
  55. }
  56. }
  57. return int.MaxValue;
  58. }
  59. }
  60. private WaferTask _wafer;
  61. private SchedulerPM _pmScheduler => Scheduler as SchedulerPM;
  62. Queue<KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>> _pendingWaferTasks = new Queue<KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>> ();
  63. KeyValuePair<Guid, Queue<KeyValuePair <RecipeJobType, string>>> _runingWaferTask = new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>> (Guid.Empty, new Queue<KeyValuePair<RecipeJobType, string>>());
  64. public VenusPMTask(ModuleName mod) : base(mod)
  65. { }
  66. public override RState Run()
  67. {
  68. if(_runingWaferTask.Value.Count == 0)
  69. {
  70. if(_pendingWaferTasks.Count > 0)
  71. {
  72. _runingWaferTask = _pendingWaferTasks.Dequeue();
  73. }
  74. else
  75. {
  76. if(Scheduler.IsIdle && Status == ModuleStatus.Idle)
  77. {
  78. if (WaferManager.Instance.CheckNoWafer(Module, 0) && Scheduler.IsOnline)
  79. {
  80. if (_pmScheduler.RunIdleCleanTask()) // Check Idle Clean
  81. {
  82. Status = ModuleStatus.StartIdleClean;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. else
  89. {
  90. if(Scheduler.IsIdle && Status == ModuleStatus.Idle)
  91. {
  92. switch(_runingWaferTask.Value.First().Key)
  93. {
  94. case RecipeJobType.PreClean:
  95. {
  96. if(WaferManager.Instance.CheckNoWafer(Module,0))
  97. {
  98. if (_pmScheduler.RunJobCleanTask(_runingWaferTask.Value.First().Value))
  99. {
  100. Status = ModuleStatus.StartPreJobClean;
  101. }
  102. else
  103. {
  104. LOG.Write(eEvent.WARN_ROUTER, Module, $"Run Prejob clean recipe {_runingWaferTask.Value.First().Value} failed");
  105. TryDequeueRuningTask(Status);
  106. Status = ModuleStatus.Idle;
  107. }
  108. }
  109. }
  110. break;
  111. case RecipeJobType.Process:
  112. {
  113. if (WaferManager.Instance.CheckHasWafer(Module, 0))
  114. {
  115. if(_wafer.waferId == _runingWaferTask.Key)
  116. {
  117. Scheduler.EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.TMRobot, 0, Module, 0));
  118. Status = ModuleStatus.StartProcess;
  119. }
  120. else
  121. {
  122. LOG.Write(eEvent.WARN_ROUTER, Module, $"wafer id dismatch while launch {_wafer.sourceMod}.{_wafer.sourceSlot + 1} process recipe");
  123. }
  124. }
  125. }
  126. break;
  127. case RecipeJobType.PostClean:
  128. {
  129. if (WaferManager.Instance.CheckNoWafer(Module, 0))
  130. {
  131. if (_pmScheduler.RunJobCleanTask(_runingWaferTask.Value.First().Value))
  132. {
  133. Status = ModuleStatus.StartPostJobClean;
  134. }
  135. else
  136. {
  137. LOG.Write(eEvent.WARN_ROUTER, Module, $"Run Postjob clean recipe {_runingWaferTask.Value.First().Value} failed");
  138. TryDequeueRuningTask(Status);
  139. Status = ModuleStatus.Idle;
  140. }
  141. }
  142. }
  143. break;
  144. case RecipeJobType.WtwClean:
  145. {
  146. if (WaferManager.Instance.CheckNoWafer(Module, 0))
  147. {
  148. if (_pmScheduler.RunJobCleanTask(_runingWaferTask.Value.First().Value))
  149. {
  150. Status = ModuleStatus.StartWTWClean;
  151. }
  152. else
  153. {
  154. LOG.Write(eEvent.WARN_ROUTER, Module, $"Run WTW clean recipe {_runingWaferTask.Value.First().Value} failed");
  155. TryDequeueRuningTask(Status);
  156. Status = ModuleStatus.Idle;
  157. }
  158. }
  159. }
  160. break;
  161. }
  162. }
  163. }
  164. if(_runingWaferTask.Value.Count > 0 || Status != ModuleStatus.Idle)
  165. {
  166. if (Scheduler.IsIdle)
  167. {
  168. switch (Status)
  169. {
  170. case ModuleStatus.Processing:
  171. {
  172. var wafer = WaferManager.Instance.GetWafer(Module, 0);
  173. if (Scheduler.IsOnline)
  174. {
  175. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  176. {
  177. _wafer.Return();
  178. TryDequeueRuningTask(Status);
  179. Status = ModuleStatus.Idle;
  180. }
  181. }
  182. else // handle offline exception situation
  183. {
  184. TryDequeueRuningTask(Status);
  185. Status = ModuleStatus.Idle;
  186. }
  187. }
  188. break;
  189. case ModuleStatus.PreJobClean:
  190. case ModuleStatus.PostJobClean:
  191. case ModuleStatus.WTWClean:
  192. {
  193. TryDequeueRuningTask(Status);
  194. Status = ModuleStatus.Idle;
  195. }
  196. break;
  197. case ModuleStatus.IdleClean:
  198. {
  199. Status = ModuleStatus.Idle;
  200. }
  201. break;
  202. case ModuleStatus.StartProcess:
  203. {
  204. if (RouteManager.IsATMMode)
  205. {
  206. Status = ModuleStatus.Processing;
  207. }
  208. }
  209. break;
  210. }
  211. }
  212. else
  213. {
  214. switch (Status)
  215. {
  216. case ModuleStatus.StartProcess:
  217. Status = ModuleStatus.Processing;
  218. break;
  219. case ModuleStatus.StartIdleClean:
  220. Status = ModuleStatus.IdleClean;
  221. break;
  222. case ModuleStatus.StartPreJobClean:
  223. Status = ModuleStatus.PreJobClean;
  224. break;
  225. case ModuleStatus.StartPostJobClean:
  226. Status = ModuleStatus.PostJobClean;
  227. break;
  228. case ModuleStatus.StartWTWClean:
  229. Status = ModuleStatus.WTWClean;
  230. break;
  231. }
  232. }
  233. }
  234. return RState.Running;
  235. }
  236. void TryDequeueRuningTask( ModuleStatus status)
  237. {
  238. bool bMatch = false;
  239. if (_runingWaferTask.Value.Count > 0)
  240. {
  241. switch(status)
  242. {
  243. case ModuleStatus.PreJobClean:
  244. if(_runingWaferTask.Value.First().Key == RecipeJobType.PreClean)
  245. {
  246. _runingWaferTask.Value.Dequeue();
  247. bMatch = true;
  248. }
  249. break;
  250. case ModuleStatus.Processing:
  251. if(_runingWaferTask.Value.First().Key == RecipeJobType.Process)
  252. {
  253. _runingWaferTask.Value.Dequeue();
  254. bMatch = true;
  255. }
  256. break;
  257. case ModuleStatus.PostJobClean:
  258. if(_runingWaferTask.Value.First().Key == RecipeJobType.PostClean)
  259. {
  260. _runingWaferTask.Value.Dequeue();
  261. bMatch = true;
  262. }
  263. break;
  264. case ModuleStatus.WTWClean:
  265. if(_runingWaferTask.Value.First().Key == RecipeJobType.WtwClean)
  266. {
  267. _runingWaferTask.Value.Dequeue();
  268. bMatch = true;
  269. }
  270. break;
  271. case ModuleStatus.WaitPreJobClean:
  272. case ModuleStatus.WaitProcess:
  273. case ModuleStatus.WaitPostJobClean:
  274. case ModuleStatus.WaitWTWClean:
  275. case ModuleStatus.Idle:
  276. _runingWaferTask.Value.Dequeue();
  277. break;
  278. }
  279. }
  280. if(!bMatch)
  281. {
  282. string runingTask = _runingWaferTask.Value.Count > 0 ? _runingWaferTask.Value.First().ToString() : "Empty";
  283. LOG.Write(eEvent.WARN_ROUTER, Module, $"TryDequeueRuningTask() failed, PM Status: {status}, runing task : {runingTask}");
  284. }
  285. if(_runingWaferTask.Value.Count == 0 && _runingWaferTask.Key != Guid.Empty)
  286. {
  287. _runingWaferTask = new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>(Guid.Empty, new Queue<KeyValuePair<RecipeJobType, string>>());
  288. }
  289. }
  290. public override void WaferArrived(WaferTask wafer, int slot)
  291. {
  292. _wafer = wafer;
  293. }
  294. public override void WaferLeaved(WaferTask wafer, int slot)
  295. {
  296. _wafer = null;
  297. }
  298. public void SubscribeWaferTask(WaferTask waferTask)
  299. {
  300. var waferRecipes = new Queue<KeyValuePair<RecipeJobType, string>>();
  301. if (!string.IsNullOrWhiteSpace(waferTask.processRecipe))
  302. {
  303. waferRecipes.Enqueue(new KeyValuePair<RecipeJobType, string>(RecipeJobType.Process, waferTask.processRecipe));
  304. }
  305. if (!string.IsNullOrWhiteSpace(waferTask.wtwCleanRecipe))
  306. {
  307. waferRecipes.Enqueue(new KeyValuePair<RecipeJobType, string>(RecipeJobType.WtwClean, waferTask.wtwCleanRecipe));
  308. }
  309. if(_runingWaferTask.Key == waferTask.waferId || _pendingWaferTasks.ToList().Exists(kv => kv.Key == waferTask.waferId))
  310. {
  311. LOG.Write(eEvent.WARN_ROUTER, Module, $"wafer {waferTask.sourceMod}.{waferTask.sourceSlot + 1} already subscribe job task.");
  312. }
  313. else if (_runingWaferTask.Key == Guid.Empty || _runingWaferTask.Value.Count == 0)
  314. {
  315. _runingWaferTask = new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>(waferTask.waferId, waferRecipes);
  316. }
  317. else
  318. {
  319. _pendingWaferTasks.Enqueue(new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>(waferTask.waferId, waferRecipes));
  320. }
  321. }
  322. public void SubscribeLotCleanTask(ControlJobInfo cj, RecipeJobType cleanType)
  323. {
  324. var lotCleanRecipes = new Queue<KeyValuePair<RecipeJobType, string>>();
  325. if(cleanType == RecipeJobType.PreClean && !string.IsNullOrWhiteSpace(cj.PreJobClean))
  326. {
  327. lotCleanRecipes.Enqueue(new KeyValuePair<RecipeJobType, string>(cleanType, cj.PreJobClean));
  328. }
  329. else if(cleanType == RecipeJobType.PostClean && !string.IsNullOrWhiteSpace (cj.PostJobClean))
  330. {
  331. lotCleanRecipes.Enqueue(new KeyValuePair<RecipeJobType, string>(cleanType, cj.PostJobClean));
  332. }
  333. else
  334. {
  335. return;
  336. }
  337. if ((_runingWaferTask.Key == cj.InnerId && _runingWaferTask.Value.ToList().Exists(pv => pv.Key == cleanType)) || _pendingWaferTasks.ToList().Exists(task => task.Key == cj.InnerId && task.Value.ToList().Exists(pv => pv.Key == cleanType)))
  338. {
  339. LOG.Write(eEvent.WARN_ROUTER, Module, $"Control job {cj.Name} already subscribe {cleanType} task.");
  340. }
  341. else if (_runingWaferTask.Key == Guid.Empty || _runingWaferTask.Value.Count == 0)
  342. {
  343. _runingWaferTask = new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>(cj.InnerId, lotCleanRecipes);
  344. }
  345. else
  346. {
  347. _pendingWaferTasks.Enqueue(new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>(cj.InnerId, lotCleanRecipes));
  348. }
  349. }
  350. public bool ReadyMoveIn(WaferTask wafer)
  351. {
  352. return _runingWaferTask.Key == wafer.waferId && _runingWaferTask.Value.Count > 0 && _runingWaferTask.Value.First().Key == RecipeJobType.Process;
  353. }
  354. public bool IsAllJobCompleted()
  355. {
  356. return Status == ModuleStatus.Idle && (_runingWaferTask.Key == Guid.Empty || _runingWaferTask.Value.Count == 0) && _pendingWaferTasks.Count == 0;
  357. }
  358. public bool IsRecipeJobDone(RecipeJobType job)
  359. {
  360. return (_runingWaferTask.Key == Guid.Empty || !_runingWaferTask.Value.ToList().Exists(kv => kv.Key == job)) && (_pendingWaferTasks.Count == 0 || !_pendingWaferTasks.ToList().Exists(kv => kv.Value.Count > 0 && kv.Value.ToList().Exists(kvv => kvv.Key == job)));
  361. }
  362. public override void ResetTask()
  363. {
  364. base.ResetTask();
  365. _wafer = null;
  366. _pendingWaferTasks.Clear();
  367. _runingWaferTask = new KeyValuePair<Guid, Queue<KeyValuePair<RecipeJobType, string>>>(Guid.Empty, new Queue<KeyValuePair<RecipeJobType, string>>());
  368. }
  369. }
  370. class PreAlignTask : ModuleTask
  371. {
  372. private WaferTask _wafer;
  373. public PreAlignTask(ModuleName aligner) : base(aligner)
  374. {
  375. }
  376. public override RState Run()
  377. {
  378. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerSETMRobot;
  379. if (tmRobot == null || !tmRobot.IsAvailable)
  380. return RState.Running;
  381. switch (Status)
  382. {
  383. case ModuleStatus.WaitAlign:
  384. {
  385. tmRobot.Align(0);
  386. Status = ModuleStatus.Aligning;
  387. }
  388. break;
  389. case ModuleStatus.Aligning:
  390. {
  391. _wafer.IsAligned = true;
  392. Status = ModuleStatus.Idle;
  393. }
  394. break;
  395. }
  396. return RState.Running;
  397. }
  398. public override void WaferArrived(WaferTask wafer, int slot)
  399. {
  400. _wafer = wafer;
  401. Status = ModuleStatus.WaitAlign;
  402. }
  403. public override void WaferLeaved(WaferTask wafer, int slot)
  404. {
  405. _wafer = null;
  406. }
  407. }
  408. class VenusTMRobotTask : ModuleTask
  409. {
  410. public VenusTMRobotTask(ModuleName mod) : base(mod) { }
  411. public override RState Run()
  412. {
  413. return base.Run();
  414. }
  415. }
  416. class VenusDispatcher : ICycle
  417. {
  418. private RState _tmRobotStatus { get { return (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerSETMRobot).RobotStatus; } }
  419. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  420. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  421. private List<WaferTask> _lstWaferTasks = new List<WaferTask>();
  422. private Dictionary<ModuleName, ModuleTask> _dictModuleTask = new Dictionary<ModuleName, ModuleTask>();
  423. private Queue<WaferInfo> _qeReturnWafers = new Queue<WaferInfo>();
  424. private Queue<List<MoveItem>> _tmSchdActions = new Queue<List<MoveItem>>();
  425. private List<MoveItem> _curTmAction = new List<MoveItem>();
  426. private bool _isCycleMode;
  427. private int _cycleSetPoint = 0;
  428. private int _cycledCount = 0;
  429. private int _cycledWafer = 0;
  430. private float _throughput = 0.0f;
  431. private int _tmRobotSingleArmOption = 0;
  432. private Dictionary<ModuleName, int> _lpCycleWafer = new Dictionary<ModuleName, int>();
  433. private Dictionary<ModuleName, int> _lpCycleCount = new Dictionary<ModuleName, int>();
  434. private Dictionary<ModuleName, int> _lpCycleSP = new Dictionary<ModuleName, int>();
  435. private Dictionary<ModuleName, float> _lpThroughput = new Dictionary<ModuleName, float>();
  436. private Stopwatch _cycleWatch = new Stopwatch();
  437. private SchedulerFACallback _faCallback;
  438. private SchedulerDBCallback _dbCallback;
  439. public SequenceLLInOutPath LLInOutPath => SequenceLLInOutPath.DInDOut;
  440. public bool HasJobRunning => _lstControlJobs.Count > 0;
  441. private RState _cycleState = RState.Init;
  442. public RState CycleState => _cycleState;
  443. private Dictionary<string, ControlJobInfo> _loadportControlJobDic = new Dictionary<string, ControlJobInfo>();
  444. public List<string> InUseRecipes = new List<string>();
  445. public VenusDispatcher()
  446. {
  447. _faCallback = new SchedulerFACallback();
  448. _dbCallback = new SchedulerDBCallback();
  449. InitModules();
  450. DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
  451. DATA.Subscribe("Scheduler.PjNameList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.LotName.ToString()).ToList());
  452. DATA.Subscribe("Scheduler.InUsingRecipe", () => InUseRecipes);
  453. foreach (var lp in new List<ModuleName> { ModuleName.LP1, ModuleName.LP2, ModuleName.LP3 })
  454. {
  455. _loadportControlJobDic[lp.ToString()] = null;
  456. DATA.Subscribe($"{lp}.CurrentControlJob", () => _loadportControlJobDic[lp.ToString()], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  457. DATA.Subscribe($"{lp}.CycledCount", () => _lpCycleCount[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  458. DATA.Subscribe($"{lp}.CycledWafer", () => _lpCycleWafer[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  459. DATA.Subscribe($"{lp}.CycleSetPoint", () => _lpCycleSP[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  460. DATA.Subscribe($"{lp}.Throughput", () => _lpThroughput[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  461. }
  462. }
  463. #region public interface
  464. /// <summary>
  465. /// 获取lp当前的ControlJob
  466. /// </summary>
  467. /// <param name="lp"></param>
  468. /// <returns></returns>
  469. public ControlJobInfo GetLoadPortCurrentControlJob(ModuleName lp)
  470. {
  471. if (ModuleHelper.IsLoadPort(lp))
  472. {
  473. return _loadportControlJobDic.ContainsKey(lp.ToString()) ? _loadportControlJobDic[lp.ToString()] : null;
  474. }
  475. else
  476. {
  477. return null;
  478. }
  479. }
  480. public RState Start(params object[] objs)
  481. {
  482. if (WaferManager.Instance.HasDuplicatedWafer)
  483. {
  484. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, "System has dummy wafers, please verify all the wafer position, and delete the invalid wafer");
  485. return RState.Failed;
  486. }
  487. _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
  488. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  489. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  490. _cycledWafer = 0;
  491. _cycledCount = 0;
  492. _throughput = 0;
  493. Clear();
  494. _cycleWatch.Stop();
  495. _lpCycleWafer.Clear();
  496. _lpCycleCount.Clear();
  497. return RState.Running;
  498. }
  499. public bool CreateJob(Dictionary<string, object> param, out string reason)
  500. {
  501. reason = "";
  502. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  503. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  504. string[] slotSequence = (string[])param["SlotSequence"];
  505. string jobId = (string)param["JobId"];
  506. string module = (string)param["Module"];
  507. if (string.IsNullOrEmpty(jobId))
  508. {
  509. jobId = "CJ_Local_" + module;
  510. }
  511. //bool autoStart = (bool)param["AutoStart"];
  512. string lotId = jobId;
  513. if (param.ContainsKey("LotId"))
  514. lotId = (string)param["LotId"];
  515. string preCleanRecipe = param.ContainsKey("PreCleanRecipeName") ? (string)param["PreCleanRecipeName"] : string.Empty;
  516. string postCleanRecipe = param.ContainsKey("PostCleanRecipeName") ? (string)param["PostCleanRecipeName"] : string.Empty;
  517. if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  518. {
  519. reason = $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}";
  520. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  521. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  522. return false;
  523. }
  524. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  525. {
  526. reason = $"{module} should be LoadPort";
  527. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  528. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  529. return false;
  530. }
  531. if (_lstControlJobs.Exists(x => x.Name == jobId))
  532. {
  533. reason = $"{jobId} already created";
  534. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  535. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  536. return false;
  537. }
  538. ControlJobInfo cj = new ControlJobInfo();
  539. cj.Name = jobId;
  540. cj.Module = module;
  541. cj.LotName = lotId;
  542. cj.LotInnerId = Guid.NewGuid();
  543. cj.LotWafers = new List<WaferInfo>();
  544. cj.SetState(EnumControlJobState.WaitingForStart);
  545. cj.JetState = EnumJetCtrlJobState.Quequed;
  546. cj.PreJobClean = preCleanRecipe;
  547. cj.PostJobClean = postCleanRecipe;
  548. cj.SequenceNameList = slotSequence;
  549. cj.CycleNumber = SC.GetValue<int>("System.CycleCount"); // only for temperary debug
  550. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  551. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  552. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  553. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  554. for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
  555. {
  556. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  557. continue;
  558. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  559. indexSequence[groupName] = slotSequence[i];
  560. if (!seqSlot.ContainsKey(groupName))
  561. {
  562. seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  563. }
  564. if (!seqSlotWafers.ContainsKey(groupName))
  565. {
  566. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  567. }
  568. seqSlot[groupName][i] = true;
  569. if (!WaferManager.Instance.CheckHasWafer(module, i))
  570. {
  571. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} not in the carrier");
  572. return false;
  573. }
  574. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  575. {
  576. reason = $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}";
  577. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  578. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  579. return false;
  580. }
  581. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  582. {
  583. reason = $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}";
  584. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  585. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  586. return false;
  587. }
  588. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 start---
  589. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i);
  590. cj.LotWafers.Add(waferInfo);
  591. waferInfo.SequenceName = slotSequence[i];
  592. waferInfo.LotId = lotId;
  593. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 end---
  594. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  595. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  596. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  597. }
  598. if (seqSlotWafers.Count == 0)
  599. {
  600. reason = $"job has not assign wafer";
  601. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  602. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  603. return false;
  604. }
  605. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  606. string[] seqs = seqSlot.Keys.ToArray();
  607. for (int i = 0; i < seqs.Length; i++)
  608. {
  609. ProcessJobInfo pj = new ProcessJobInfo();
  610. pj.Name = jobId + "_" + (i + 1);
  611. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  612. if (pj.Sequence == null)
  613. {
  614. reason = $"invalid sequence[{indexSequence[seqs[i]]}]";
  615. return false;
  616. }
  617. pj.ControlJobName = cj.Name;
  618. pj.LotName = lotId;
  619. pj.SlotWafers = seqSlotWafers[seqs[i]];
  620. pj.SetState(EnumProcessJobState.Queued);
  621. if (!CheckSequencePmReady(pj.Sequence, out reason))
  622. {
  623. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"no valid chamber for the {reason}");
  624. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  625. return false;
  626. }
  627. if (!RouteManager.IsATMMode && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  628. {
  629. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"recipe file not valid in the sequence, {reason}");
  630. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  631. return false;
  632. }
  633. pjs.Add(pj);
  634. }
  635. _dbCallback.LotUpdate(cj);
  636. foreach (var pj in pjs)
  637. {
  638. cj.ProcessJobNameList.Add(pj.Name);
  639. _lstProcessJobs.Add(pj);
  640. }
  641. _lstControlJobs.Add(cj);
  642. //AssociatedPMWithLP(cj);
  643. _loadportControlJobDic[cj.Module] = cj;
  644. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  645. return true;
  646. }
  647. public bool CheckAllJobDone()
  648. {
  649. foreach (var cj in _lstControlJobs)
  650. {
  651. if (cj.State != EnumControlJobState.Completed)
  652. return false;
  653. }
  654. InUseRecipes.Clear();
  655. return true;
  656. }
  657. public bool CheckJobJustDone(out string sJobName)
  658. {
  659. foreach (var cj in _lstControlJobs)
  660. {
  661. if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
  662. {
  663. //LP;WaferSize;Lot;Number;Start;End;
  664. sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
  665. cj.BeenPosted = true;
  666. return true;
  667. }
  668. }
  669. sJobName = "NULL";
  670. return false;
  671. }
  672. public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  673. {
  674. foreach (var pj in _lstProcessJobs)
  675. {
  676. if (pj.ControlJobName == cj.Name)
  677. return pj;
  678. }
  679. return null;
  680. }
  681. public bool AbortJob(string jobName, out string reason)
  682. {
  683. reason = "";
  684. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  685. if (cj == null)
  686. {
  687. reason = $"abort job rejected, not found job with id {jobName}";
  688. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  689. return false;
  690. }
  691. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  692. foreach (var pj in _lstProcessJobs)
  693. {
  694. if (pj.ControlJobName == cj.Name)
  695. {
  696. pj.SetState(EnumProcessJobState.Aborting);
  697. pjAbortList.Add(pj);
  698. int unprocessed = 0;
  699. int aborted = 0;
  700. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  701. foreach (var waferInfo in wafers)
  702. {
  703. waferInfo.ProcessJob = null;
  704. waferInfo.NextSequenceStep = 0;
  705. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  706. unprocessed++;
  707. }
  708. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  709. }
  710. }
  711. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  712. _dbCallback.LotFinished(cj);
  713. foreach (var pj in pjAbortList)
  714. {
  715. _lstProcessJobs.Remove(pj);
  716. }
  717. _lstControlJobs.Remove(cj);
  718. if (_loadportControlJobDic.ContainsKey(cj.Module))
  719. {
  720. _loadportControlJobDic[cj.Module] = null;
  721. }
  722. return true;
  723. }
  724. public bool StopJob(string jobName, out string reason)
  725. {
  726. reason = "";
  727. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  728. if (cj == null)
  729. {
  730. reason = $"stop job rejected, not found job with id {jobName}";
  731. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  732. return false;
  733. }
  734. foreach (var pj in _lstProcessJobs)
  735. {
  736. if (pj.ControlJobName == cj.Name)
  737. {
  738. pj.SetState(EnumProcessJobState.Stopping);
  739. }
  740. }
  741. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  742. _dbCallback.LotFinished(cj);
  743. if (_loadportControlJobDic.ContainsKey(cj.Module))
  744. {
  745. _loadportControlJobDic[cj.Module] = null;
  746. }
  747. return true;
  748. }
  749. public bool ResumeJob(string jobName, out string reason)
  750. {
  751. reason = "";
  752. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  753. if (cj == null)
  754. {
  755. reason = $"resume job rejected, not found job with id {jobName}";
  756. //LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"resume job rejected, not found job with id {jobName}");
  757. return false;
  758. }
  759. if (cj.State == EnumControlJobState.Paused)
  760. {
  761. cj.SetState(EnumControlJobState.Executing);
  762. }
  763. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  764. _cycleState = RState.Running;
  765. return true;
  766. }
  767. public bool PauseJob(string jobName, out string reason)
  768. {
  769. reason = "";
  770. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  771. if (cj == null)
  772. {
  773. reason = $"pause job rejected, not found job with id {jobName}";
  774. //LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"pause job rejected, not found job with id {jobName}");
  775. return false;
  776. }
  777. if (cj.State == EnumControlJobState.Executing)
  778. {
  779. cj.SetState(EnumControlJobState.Paused);
  780. }
  781. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  782. if (!_lstControlJobs.Exists(job => job.State == EnumControlJobState.Executing))
  783. _cycleState = RState.Paused;
  784. return true;
  785. }
  786. public bool StartJob(string jobName, out string reason)
  787. {
  788. reason = "";
  789. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  790. if (cj == null)
  791. {
  792. reason = $"start job rejected, not found job with id {jobName}";
  793. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  794. return false;
  795. }
  796. if (cj.State == EnumControlJobState.WaitingForStart)
  797. {
  798. cj.SetState(EnumControlJobState.Queued);
  799. //PreJobClean(cj);
  800. cj.StartTime = DateTime.Now;
  801. _dbCallback.LotCreated(cj);
  802. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  803. //if (!_blockingWatcher.IsRunning)
  804. // _blockingWatcher.Restart();
  805. //ResetTraceFlag();
  806. }
  807. if (!_cycleWatch.IsRunning)
  808. {
  809. _cycleWatch.Restart();
  810. }
  811. if (!_lpCycleWafer.Keys.Contains(ModuleHelper.Converter(cj.Module)))
  812. {
  813. _lpCycleCount.Add(ModuleHelper.Converter(cj.Module), 0);
  814. _lpCycleWafer.Add(ModuleHelper.Converter(cj.Module), 0);
  815. }
  816. _cycleState = RState.Running;
  817. return true;
  818. }
  819. public RState Monitor()
  820. {
  821. prelude();
  822. RunWaferTask();
  823. RunModuleTasks();
  824. RoutingWafers();
  825. epilogue();
  826. return _cycleState;
  827. }
  828. public void Abort()
  829. {
  830. }
  831. public void Clear()
  832. {
  833. foreach (var module in _dictModuleTask)
  834. {
  835. module.Value.Status = ModuleStatus.Idle;
  836. module.Value.Scheduler.ResetTask();
  837. module.Value.ResetTask();
  838. }
  839. List<string> keys = _loadportControlJobDic.Keys.ToList();
  840. foreach (var key in keys)
  841. {
  842. _loadportControlJobDic[key] = null;
  843. }
  844. _lstWaferTasks.Clear();
  845. _tmSchdActions.Clear();
  846. _curTmAction.Clear();
  847. _lstControlJobs.Clear();
  848. _lstProcessJobs.Clear();
  849. InUseRecipes.Clear();
  850. _cycleState = RState.End;
  851. }
  852. #endregion
  853. #region manual return wafer
  854. // manual return one wafer while system is auto running
  855. public bool ManualReturnWafer(object[] objs)
  856. {
  857. ModuleName SourceModule = (ModuleName)objs[0];
  858. int SourceSlot = (int)objs[1];
  859. if (!_dictModuleTask.Keys.Contains(SourceModule))
  860. {
  861. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Invalid source module {SourceModule} for manual return wafer");
  862. return false;
  863. }
  864. if (WaferManager.Instance.CheckNoWafer(SourceModule, SourceSlot))
  865. {
  866. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Can not return wafer as {SourceModule} {SourceSlot} has no wafer");
  867. return false;
  868. }
  869. if (!_dictModuleTask[SourceModule].Scheduler.IsIdle)
  870. {
  871. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"The module: {SourceModule} is not ready for return wafer");
  872. return false;
  873. }
  874. var wafer = WaferManager.Instance.GetWafer(SourceModule, SourceSlot);
  875. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Manual return wafer: {wafer.WaferOrigin} at {SourceModule} {SourceSlot} while system is auto running");
  876. _qeReturnWafers.Enqueue(wafer);
  877. return true;
  878. }
  879. public RState CheckManualReturnWafer()
  880. {
  881. var pmWaferCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && WaferManager.Instance.CheckHasWafer(mod.Key, 0)).Count();
  882. var tmRobotWaferCount = (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) ? 1 : 0);
  883. if (!_dictModuleTask[ModuleName.TMRobot].Scheduler.IsIdle && (pmWaferCount > 0 || tmRobotWaferCount > 0))
  884. {
  885. LOG.Write(eEvent.ERR_ROUTER, ModuleName.TMRobot, $"The TM Robot is not ready for return wafer.");
  886. return RState.Failed;
  887. }
  888. foreach (var mod in _dictModuleTask)
  889. {
  890. if (ModuleHelper.IsLoadPort(mod.Key))
  891. continue;
  892. if (!ModuleHelper.IsAligner(mod.Key) && !mod.Value.Scheduler.IsIdle)
  893. {
  894. LOG.Write(eEvent.ERR_ROUTER, mod.Key, $"{mod.Key} is not ready for return wafer.");
  895. return RState.Failed;
  896. }
  897. int nSlotNumber = (ModuleHelper.IsTMRobot(mod.Key) ? 2 : 1);
  898. for (int slot = 0; slot < nSlotNumber; slot++)
  899. {
  900. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  901. if (wafer.IsEmpty)
  902. continue;
  903. var destLP = (ModuleName)wafer.OriginStation;
  904. if (!_dictModuleTask[destLP].Scheduler.IsAvailable)
  905. {
  906. LOG.Write(eEvent.ERR_ROUTER, destLP, $"The destination Loadport {destLP} is not ready for return wafer.");
  907. return RState.Failed;
  908. }
  909. if (!ModuleHelper.IsLoadPort(destLP))
  910. {
  911. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"The wafer {wafer.WaferOrigin} cannot be return, please manually drag it.");
  912. return RState.Failed;
  913. }
  914. }
  915. }
  916. Clear();
  917. return RState.Running;
  918. }
  919. public RState ReturnAllWafers()
  920. {
  921. int systemWaferCount = 0;
  922. foreach (var mod in _dictModuleTask)
  923. {
  924. if (ModuleHelper.IsLoadPort(mod.Key))
  925. continue;
  926. int nSlotNumber = ModuleHelper.IsTMRobot(mod.Key) ? 2 : 1;
  927. for (int slot = 0; slot < nSlotNumber; slot++)
  928. {
  929. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  930. if (!wafer.IsEmpty)
  931. systemWaferCount++;
  932. }
  933. }
  934. if (systemWaferCount == 0)
  935. return RState.End;
  936. ReturnInternalWafers();
  937. return RState.Running;
  938. }
  939. #endregion
  940. #region internal implementation
  941. private void InitModules()
  942. {
  943. foreach (var module in ModuleHelper.InstalledModules)
  944. {
  945. if (ModuleHelper.IsInstalled(module))
  946. {
  947. if (ModuleHelper.IsPm(module))
  948. {
  949. _dictModuleTask[module] = new VenusPMTask(module);
  950. }
  951. else if (ModuleHelper.IsTMRobot(module))
  952. {
  953. _dictModuleTask[module] = new VenusTMRobotTask(module);
  954. }
  955. else if (ModuleHelper.IsAligner(module))
  956. {
  957. _dictModuleTask[module] = new PreAlignTask(module);
  958. }
  959. else if (ModuleHelper.IsLoadPort(module))
  960. {
  961. _dictModuleTask[module] = new LoadPortTask(module);
  962. }
  963. }
  964. }
  965. }
  966. private void prelude()
  967. {
  968. bool available = true;
  969. foreach (var mod in _dictModuleTask)
  970. {
  971. available = mod.Value.Scheduler.IsAvailable; // force scheduler update
  972. }
  973. }
  974. private void epilogue()
  975. {
  976. UpdateProcessJobStatus();
  977. UpdateControlJobStatus();
  978. CreateNewWaferTask();
  979. _lstWaferTasks.RemoveAll(item => ModuleHelper.IsLoadPort(item.destMod) && ModuleHelper.IsLoadPort(item.currentMod) && item.pressureStatus == RState.End);
  980. }
  981. private void RunWaferTask()
  982. {
  983. foreach (var task in _lstWaferTasks)
  984. {
  985. task.Run();
  986. }
  987. }
  988. private void RunModuleTasks()
  989. {
  990. foreach (var task in _dictModuleTask)
  991. {
  992. task.Value.Run();
  993. }
  994. }
  995. private void RoutingWafers()
  996. {
  997. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  998. {
  999. RunSchdTMActions();
  1000. return;
  1001. }
  1002. if (_tmRobotStatus != RState.End)
  1003. return;
  1004. if (_tmRobotSingleArmOption != 0)
  1005. {
  1006. RoutingWaferWithSingleArm();
  1007. return;
  1008. }
  1009. var waitInWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)).OrderBy(wt => wt.currentSlot).ToList();
  1010. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  1011. var emptyAndReadyIn20sPMs = _dictModuleTask.Where(pm => ModuleHelper.IsPm(pm.Key) && !_lstWaferTasks.Exists(wt => wt.currentMod == pm.Key) && pm.Value.TimeToReady < 20).OrderBy(pm => pm.Value.TimeToReady).Select(pm => pm.Key).ToList();
  1012. var robotWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod)).ToList();
  1013. var aligner = _dictModuleTask.Where(mod => ModuleHelper.IsAligner(mod.Key)).ToList();
  1014. if(robotWafers.Count == 0)
  1015. {
  1016. if(readyReturnWafers.Count > 0)
  1017. {
  1018. if(readyReturnWafers.Count == 1 || readyReturnWafers[0].destMod != readyReturnWafers[1].destMod)
  1019. {
  1020. // return one wafer
  1021. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnWafers.First().currentMod, 0, ModuleName.TMRobot, (int)Hand.Blade1, Hand.Blade1) });
  1022. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)Hand.Blade1, readyReturnWafers.First().destMod, readyReturnWafers.First().destSlot, Hand.Blade1) });
  1023. }
  1024. else
  1025. {
  1026. // return two wafer
  1027. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnWafers[0].currentMod, 0, ModuleName.TMRobot, (int)Hand.Blade1, Hand.Blade1) });
  1028. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnWafers[1].currentMod, 0, ModuleName.TMRobot, (int)Hand.Blade2, Hand.Blade2) });
  1029. var doublePlaceActions = new List<MoveItem>
  1030. {
  1031. new MoveItem(ModuleName.TMRobot, (int)Hand.Blade1, readyReturnWafers[0].destMod, readyReturnWafers[0].destSlot, Hand.Blade1),
  1032. new MoveItem(ModuleName.TMRobot, (int)Hand.Blade2, readyReturnWafers[1].destMod, readyReturnWafers[1].destSlot, Hand.Blade2)
  1033. };
  1034. _tmSchdActions.Enqueue(doublePlaceActions);
  1035. }
  1036. }
  1037. else if (_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1038. {
  1039. var alignerWafer = _lstWaferTasks.Where(wt => ModuleHelper.IsAligner(wt.currentMod)).First();
  1040. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.TMRobot, (int)Hand.Blade1, Hand.Blade1) });
  1041. if (emptyAndReadyIn20sPMs.Contains(alignerWafer.destMod))
  1042. {
  1043. var pmTask = _dictModuleTask[alignerWafer.destMod] as VenusPMTask;
  1044. if(pmTask.ReadyMoveIn(alignerWafer))
  1045. {
  1046. // move aligner wafer to PM
  1047. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)Hand.Blade1, alignerWafer.destMod, alignerWafer.destSlot, Hand.Blade1) });
  1048. }
  1049. }
  1050. }
  1051. else
  1052. {
  1053. if(emptyAndReadyIn20sPMs.Count >= 2 && waitInWafers.Count >= 2 && waitInWafers[0].currentMod == waitInWafers[1].currentMod)
  1054. {
  1055. var doublePickActions = new List<MoveItem>()
  1056. {
  1057. new MoveItem(waitInWafers[0].currentMod, waitInWafers[0].currentSlot, ModuleName.TMRobot, (int)Hand.Blade1, Hand.Blade1),
  1058. new MoveItem(waitInWafers[1].currentMod, waitInWafers[1].currentSlot, ModuleName.TMRobot, (int)Hand.Blade2, Hand.Blade2)
  1059. };
  1060. _tmSchdActions.Enqueue(doublePickActions);
  1061. if(aligner.Count > 0)
  1062. {
  1063. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)Hand.Blade1, aligner.First().Key, 0, Hand.Blade1) });
  1064. }
  1065. }
  1066. else if(emptyAndReadyIn20sPMs.Count >= 1 && waitInWafers.Count >= 1)
  1067. {
  1068. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafers[0].currentMod, waitInWafers[0].currentSlot, ModuleName.TMRobot, (int)Hand.Blade1, Hand.Blade1) });
  1069. if (aligner.Count > 0)
  1070. {
  1071. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)Hand.Blade1, aligner.First().Key, 0, Hand.Blade1) });
  1072. }
  1073. }
  1074. }
  1075. }
  1076. else if(robotWafers.Count == 1)
  1077. {
  1078. var freeHand = robotWafers.First().currentSlot == 0 ? Hand.Blade2 : Hand.Blade1;
  1079. if (readyReturnWafers.Count >= 1)
  1080. {
  1081. // return one wafer
  1082. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand, freeHand) });
  1083. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHand, readyReturnWafers.First().destMod, readyReturnWafers.First().destSlot, freeHand) });
  1084. }
  1085. else
  1086. {
  1087. if (_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1088. {
  1089. var alignerWafer = _lstWaferTasks.Where(wt => ModuleHelper.IsAligner(wt.currentMod)).First();
  1090. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.TMRobot, (int)freeHand, freeHand) });
  1091. if(!robotWafers.First().IsAligned)
  1092. {
  1093. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, aligner.First().Key, 0, (Hand)robotWafers.First().currentSlot) });
  1094. }
  1095. if (emptyAndReadyIn20sPMs.Contains(alignerWafer.destMod))
  1096. {
  1097. var pmTask = _dictModuleTask[alignerWafer.destMod] as VenusPMTask;
  1098. if (pmTask.ReadyMoveIn(alignerWafer))
  1099. {
  1100. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHand, alignerWafer.destMod, alignerWafer.destSlot, freeHand) });
  1101. }
  1102. }
  1103. }
  1104. else
  1105. {
  1106. if (ModuleHelper.IsPm(robotWafers.First().destMod))
  1107. {
  1108. if (!robotWafers.First().IsAligned)
  1109. {
  1110. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, aligner.First().Key, 0, (Hand)robotWafers.First().currentSlot) });
  1111. }
  1112. else if (emptyAndReadyIn20sPMs.Contains(robotWafers.First().destMod))
  1113. {
  1114. var pmTask = _dictModuleTask[robotWafers.First().destMod] as VenusPMTask;
  1115. if (pmTask.ReadyMoveIn(robotWafers.First()))
  1116. {
  1117. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, robotWafers.First().destMod, robotWafers.First().destSlot, (Hand)(robotWafers.First().currentSlot)) });
  1118. }
  1119. }
  1120. }
  1121. else if (ModuleHelper.IsLoadPort(robotWafers.First().destMod) && _dictModuleTask[robotWafers.First().destMod].Scheduler.IsAvailable)
  1122. {
  1123. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, robotWafers.First().destMod, robotWafers.First().destSlot, (Hand)(robotWafers.First().currentSlot)) });
  1124. }
  1125. }
  1126. }
  1127. }
  1128. else // had better not go here
  1129. {
  1130. foreach(var wafer in robotWafers)
  1131. {
  1132. if (ModuleHelper.IsPm(wafer.destMod))
  1133. {
  1134. if (!wafer.IsAligned)
  1135. {
  1136. if (!_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1137. {
  1138. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, aligner.First().Key, 0, (Hand)wafer.currentSlot) });
  1139. }
  1140. }
  1141. else if (emptyAndReadyIn20sPMs.Contains(wafer.destMod))
  1142. {
  1143. var pmTask = _dictModuleTask[wafer.destMod] as VenusPMTask;
  1144. if (pmTask.ReadyMoveIn(wafer))
  1145. {
  1146. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, wafer.destSlot, (Hand)(wafer.currentSlot)) });
  1147. }
  1148. }
  1149. }
  1150. else if (ModuleHelper.IsLoadPort(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsAvailable)
  1151. {
  1152. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, wafer.destSlot, (Hand)(wafer.currentSlot)) });
  1153. }
  1154. }
  1155. }
  1156. }
  1157. private void RoutingWaferWithSingleArm()
  1158. {
  1159. var waitInWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)).OrderBy(wt => wt.currentSlot).ToList();
  1160. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  1161. var emptyAndReadyIn20sPMs = _dictModuleTask.Where(pm => ModuleHelper.IsPm(pm.Key) && !_lstWaferTasks.Exists(wt => wt.currentMod == pm.Key) && pm.Value.TimeToReady < 20).OrderBy(pm => pm.Value.TimeToReady).Select(pm => pm.Key).ToList();
  1162. var aligner = _dictModuleTask.Where(mod => ModuleHelper.IsAligner(mod.Key)).ToList();
  1163. var validHand = _tmRobotSingleArmOption == 1 ? Hand.Blade1 : Hand.Blade2;
  1164. var robotWafers = _lstWaferTasks.Where(wt => wt.currentMod == ModuleName.TMRobot && wt.currentSlot == (int)validHand).ToList();
  1165. if (robotWafers.Count == 0)
  1166. {
  1167. if (readyReturnWafers.Count > 0)
  1168. {
  1169. // return one wafer
  1170. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnWafers.First().currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  1171. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, readyReturnWafers.First().destMod, readyReturnWafers.First().destSlot, validHand) });
  1172. }
  1173. else
  1174. {
  1175. if(_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1176. {
  1177. var alignerWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsAligner(wt.currentMod));
  1178. if(emptyAndReadyIn20sPMs.Contains(alignerWafer.destMod))
  1179. {
  1180. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  1181. // move aligner wafer to PM
  1182. var pmTask = _dictModuleTask[alignerWafer.destMod] as VenusPMTask;
  1183. if (pmTask.ReadyMoveIn(alignerWafer))
  1184. {
  1185. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, alignerWafer.destMod, alignerWafer.destSlot, validHand) });
  1186. }
  1187. }
  1188. }
  1189. else
  1190. {
  1191. foreach(var wafer in waitInWafers)
  1192. {
  1193. if(emptyAndReadyIn20sPMs.Contains(wafer.destMod))
  1194. {
  1195. // move one wafer from LP to aligner
  1196. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  1197. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, aligner.First().Key, 0, validHand) });
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. else
  1204. {
  1205. var wafer = robotWafers[0];
  1206. if (ModuleHelper.IsPm(wafer.destMod))
  1207. {
  1208. if (!wafer.IsAligned)
  1209. {
  1210. if (!_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1211. {
  1212. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, aligner.First().Key, 0, (Hand)wafer.currentSlot) });
  1213. }
  1214. }
  1215. else if (emptyAndReadyIn20sPMs.Contains(wafer.destMod))
  1216. {
  1217. var pmTask = _dictModuleTask[wafer.destMod] as VenusPMTask;
  1218. if (pmTask.ReadyMoveIn(wafer))
  1219. {
  1220. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, wafer.destSlot, (Hand)(wafer.currentSlot)) });
  1221. }
  1222. }
  1223. }
  1224. else if (ModuleHelper.IsLoadPort(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsAvailable)
  1225. {
  1226. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, wafer.destSlot, (Hand)(wafer.currentSlot)) });
  1227. }
  1228. }
  1229. }
  1230. private void RunSchdTMActions()
  1231. {
  1232. if (_dictModuleTask[ModuleName.TMRobot].IsIdle)
  1233. {
  1234. if (_tmSchdActions.Count > 0)
  1235. {
  1236. if (_curTmAction.Count == 0 || IsMovingActionsDone(_curTmAction))
  1237. {
  1238. var nextActions = _tmSchdActions.First();
  1239. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  1240. return;
  1241. if (ModuleHelper.IsPm(nextActions.First().Module) && !_dictModuleTask[nextActions.First().Module].IsIdle) /// wait PMTask status update to idle
  1242. return;
  1243. _curTmAction = _tmSchdActions.Dequeue();
  1244. foreach (var action in _curTmAction)
  1245. {
  1246. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  1247. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  1248. }
  1249. (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerSETMRobot).SendMoveItems(_curTmAction.ToArray());
  1250. }
  1251. }
  1252. else if (_curTmAction.Count >= 0 && IsMovingActionsDone(_curTmAction)) // all scheduled actions done
  1253. {
  1254. _curTmAction.Clear();
  1255. }
  1256. }
  1257. }
  1258. private bool isReturnActionsDone(List<MoveItem> items)
  1259. {
  1260. foreach (var item in items)
  1261. {
  1262. if (WaferManager.Instance.CheckHasWafer(item.SourceModule, item.SourceSlot) || WaferManager.Instance.CheckNoWafer(item.DestinationModule, item.DestinationSlot))
  1263. return false;
  1264. }
  1265. return true;
  1266. }
  1267. private bool IsMovingActionsDone(List<MoveItem> actions)
  1268. {
  1269. bool CheckWaferExistence(ModuleName mod, int slot)
  1270. {
  1271. return ModuleHelper.IsLoadPort(mod) ? WaferManager.Instance.CheckHasWafer(mod, slot) : _lstWaferTasks.Exists(wt => wt.currentMod == mod && wt.currentSlot == slot);
  1272. }
  1273. if (actions.Count == 1)
  1274. {
  1275. if (CheckWaferExistence(actions.First().SourceModule, actions.First().SourceSlot) ||
  1276. !CheckWaferExistence(actions.First().DestinationModule, actions.First().DestinationSlot))
  1277. return false;
  1278. }
  1279. else
  1280. {
  1281. // initialize all the wafer existance before move
  1282. var slotWafers = new Dictionary<KeyValuePair<ModuleName, int>, bool>();
  1283. foreach (var ac in actions)
  1284. {
  1285. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  1286. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  1287. if (!slotWafers.ContainsKey(scrSlot))
  1288. {
  1289. slotWafers[scrSlot] = true;
  1290. }
  1291. if (!slotWafers.ContainsKey(destSlot))
  1292. {
  1293. slotWafers[destSlot] = false;
  1294. }
  1295. }
  1296. // simulate moved result
  1297. foreach (var ac in actions)
  1298. {
  1299. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  1300. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  1301. if (!slotWafers[scrSlot])
  1302. {
  1303. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[scrSlot]} do not has a wafer");
  1304. }
  1305. else
  1306. {
  1307. slotWafers[scrSlot] = false;
  1308. }
  1309. if (slotWafers[destSlot])
  1310. {
  1311. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[destSlot]} has a wafer");
  1312. }
  1313. else
  1314. {
  1315. slotWafers[destSlot] = true;
  1316. }
  1317. }
  1318. foreach (var slot in slotWafers)
  1319. {
  1320. if (slot.Value != CheckWaferExistence(slot.Key.Key, slot.Key.Value))
  1321. return false;
  1322. }
  1323. }
  1324. return true;
  1325. }
  1326. private void WaferArrived(WaferTask wafer, MoveItem item)
  1327. {
  1328. _dictModuleTask[item.DestinationModule].WaferArrived(wafer, item.DestinationSlot);
  1329. //--2024-03-21 增加了PortJobWaferEnd 上报事件 start--
  1330. if (ModuleHelper.IsLoadPort(item.DestinationModule))
  1331. {
  1332. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.DestinationModule);
  1333. if (currentControlJob != null)
  1334. {
  1335. _faCallback.JobWaferEnd(currentControlJob, item.SourceSlot);
  1336. }
  1337. }
  1338. //--2024-03-21 增加了PortJobWaferEnd 上报事件 end--
  1339. }
  1340. private void WaferLeaved(WaferTask wafer, MoveItem item)
  1341. {
  1342. _dictModuleTask[item.SourceModule].WaferLeaved(wafer, item.DestinationSlot);
  1343. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  1344. if (ModuleHelper.IsLoadPort(item.SourceModule))
  1345. {
  1346. (_dictModuleTask[wafer.destMod] as VenusPMTask).SubscribeWaferTask(wafer);
  1347. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.SourceModule);
  1348. if (currentControlJob != null)
  1349. {
  1350. _faCallback.JobWaferStart(currentControlJob, item.SourceSlot);
  1351. }
  1352. }
  1353. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  1354. }
  1355. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1356. {
  1357. bool allWaferReturn = true;
  1358. foreach (var slot in pj.SlotWafers)
  1359. {
  1360. var wafer = WaferManager.Instance.GetWafer(slot.Item1, slot.Item2);
  1361. if (wafer.IsEmpty || (wafer.ProcessState != EnumWaferProcessStatus.Completed && checkAllProcessed))
  1362. {
  1363. allWaferReturn = false;
  1364. break;
  1365. }
  1366. }
  1367. return allWaferReturn;
  1368. }
  1369. private void ReturnInternalWafers()
  1370. {
  1371. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  1372. {
  1373. RunSchdTMReturnActions();
  1374. return;
  1375. }
  1376. if (_tmRobotStatus != RState.End)
  1377. return;
  1378. for (int i = 0; i < 2; i++)
  1379. {
  1380. if(WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
  1381. {
  1382. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, i);
  1383. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  1384. return;
  1385. }
  1386. }
  1387. foreach(var mod in _dictModuleTask)
  1388. {
  1389. if (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsLoadPort(mod.Key))
  1390. continue;
  1391. if(WaferManager.Instance.CheckHasWafer(mod.Key, 0))
  1392. {
  1393. var wafer = WaferManager.Instance.GetWafer(mod.Key, 0);
  1394. var freeHands = GetTMFreeHand();
  1395. if(freeHands.Count > 0)
  1396. {
  1397. var hand = freeHands[0];
  1398. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(mod.Key, 0, ModuleName.TMRobot, (int)hand, hand) });
  1399. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hand, (ModuleName)wafer.OriginStation, wafer.OriginSlot, hand) });
  1400. return;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. private List<Hand> GetTMFreeHand()
  1406. {
  1407. var lstHands = new List<Hand>();
  1408. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  1409. lstHands.Add(Hand.Blade1);
  1410. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  1411. lstHands.Add(Hand.Blade2);
  1412. return lstHands;
  1413. }
  1414. private void UpdateProcessJobStatus()
  1415. {
  1416. if (_tmRobotStatus == RState.Running)
  1417. return;
  1418. foreach (var pj in _lstProcessJobs)
  1419. {
  1420. if (CheckAllWaferReturned(pj, pj.State != EnumProcessJobState.Stopping))
  1421. {
  1422. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1423. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1424. }
  1425. }
  1426. }
  1427. private void UpdateControlJobStatus()
  1428. {
  1429. if (_lstControlJobs.Count == 0 || _tmRobotStatus == RState.Running)
  1430. return;
  1431. var runningJobs = _lstControlJobs.FindAll(cj => cj.State == EnumControlJobState.Executing);
  1432. var queueJobs = _lstControlJobs.FindAll(cj => cj.State == EnumControlJobState.Queued).OrderBy(cj => cj.StartTime);
  1433. if (runningJobs.Count == 0)
  1434. {
  1435. if (queueJobs.Count() > 0)
  1436. {
  1437. // start the first waiting job
  1438. RunControlJob(queueJobs.First());
  1439. }
  1440. }
  1441. else
  1442. {
  1443. foreach (var runningjob in runningJobs)
  1444. {
  1445. // update the running job
  1446. RunControlJob(runningjob);
  1447. }
  1448. foreach (var queueJob in queueJobs)
  1449. {
  1450. if (!runningJobs.Exists(cj => IsControlJobIntersect(cj, queueJob)))
  1451. {
  1452. // parallelly start the not intersect job
  1453. RunControlJob(queueJob);
  1454. }
  1455. }
  1456. }
  1457. // update system cycle status
  1458. if (_lstControlJobs.All(cj => cj.State == EnumControlJobState.Completed))
  1459. _cycleState = RState.End;
  1460. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1461. foreach (var cj in _lstControlJobs)
  1462. {
  1463. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1464. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  1465. {
  1466. cjRemoveList.Add(cj);
  1467. }
  1468. }
  1469. foreach (var cj in cjRemoveList)
  1470. {
  1471. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1472. foreach (var pj in _lstProcessJobs)
  1473. {
  1474. if (pj.ControlJobName == cj.Name)
  1475. pjRemoveList.Add(pj);
  1476. }
  1477. foreach (var pj in pjRemoveList)
  1478. {
  1479. _lstProcessJobs.Remove(pj);
  1480. }
  1481. _lstControlJobs.Remove(cj);
  1482. }
  1483. }
  1484. private bool RunControlJob(ControlJobInfo cj)
  1485. {
  1486. switch (cj.JetState)
  1487. {
  1488. case EnumJetCtrlJobState.Quequed:
  1489. {
  1490. if (IsCtrlJobNeedPreClean(cj))
  1491. {
  1492. cj.JetState = EnumJetCtrlJobState.PreJobClean;
  1493. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1494. foreach (var pm in PMs)
  1495. {
  1496. var pmTask = _dictModuleTask[pm] as VenusPMTask;
  1497. if (pmTask != null && pmTask.Scheduler.IsOnline)
  1498. {
  1499. pmTask.SubscribeLotCleanTask(cj, VenusPMTask.RecipeJobType.PreClean);
  1500. }
  1501. }
  1502. }
  1503. else
  1504. {
  1505. ActiveControlJob(cj);
  1506. }
  1507. cj.SetState(EnumControlJobState.Executing);
  1508. }
  1509. break;
  1510. case EnumJetCtrlJobState.PreJobClean:
  1511. {
  1512. if (IsPreJobCleanDone(cj))
  1513. {
  1514. ActiveControlJob(cj);
  1515. }
  1516. }
  1517. break;
  1518. case EnumJetCtrlJobState.Processing:
  1519. {
  1520. if (IsCtrlJobNeedPostClean(cj))
  1521. {
  1522. if (IsAllJobWaferProcessedOrProcessing(cj))
  1523. {
  1524. cj.JetState = EnumJetCtrlJobState.PostJobClean;
  1525. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1526. foreach (var pm in PMs)
  1527. {
  1528. var pmTask = _dictModuleTask[pm] as VenusPMTask;
  1529. if (pmTask != null && pmTask.Scheduler.IsOnline)
  1530. {
  1531. pmTask.SubscribeLotCleanTask(cj, VenusPMTask.RecipeJobType.PostClean);
  1532. }
  1533. }
  1534. }
  1535. }
  1536. else
  1537. {
  1538. if (IsAllProcessJobComplete(cj))
  1539. {
  1540. cj.JetState = EnumJetCtrlJobState.Completed;
  1541. }
  1542. }
  1543. }
  1544. break;
  1545. case EnumJetCtrlJobState.PostJobClean:
  1546. {
  1547. if (IsPostJobCleanDone(cj))
  1548. {
  1549. cj.JetState = EnumJetCtrlJobState.Completed;
  1550. }
  1551. }
  1552. break;
  1553. }
  1554. // caculate processed wafer by control job
  1555. var lp = ModuleHelper.Converter(cj.Module);
  1556. int countProcessed = 0;
  1557. foreach (var pjName in cj.ProcessJobNameList)
  1558. {
  1559. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1560. if (pj == null)
  1561. {
  1562. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1563. continue;
  1564. }
  1565. // caculate process wafer by process
  1566. if (_lpCycleCount[lp] < cj.CycleNumber)
  1567. {
  1568. foreach (var pjSlotWafer in pj.SlotWafers)
  1569. {
  1570. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1571. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  1572. countProcessed++;
  1573. }
  1574. }
  1575. }
  1576. int lpCycleWafer = 0;
  1577. if (cj.JetState == EnumJetCtrlJobState.Completed)
  1578. {
  1579. cj.EndTime = DateTime.Now;
  1580. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1581. _dbCallback.LotFinished(cj);
  1582. if (_lpCycleCount[lp] >= cj.CycleNumber)
  1583. (Singleton<TransferModule>.Instance.GetScheduler(lp) as SchedulerLoadPort).NoteJobComplete();
  1584. _lpCycleCount[lp]++;
  1585. lpCycleWafer = _lpCycleCount[lp] * cj.LotWafers.Count;
  1586. _lpThroughput[lp] = (float)(lpCycleWafer / (DateTime.Now - cj.StartTime).TotalHours);
  1587. LOG.Write(eEvent.EV_ROUTER, lp, $"Cycle Count: {_lpCycleCount[lp]}, Total Processed Wafer: {lpCycleWafer}, Throughput: {_lpThroughput[lp]}");
  1588. if (_lpCycleCount[lp] < cj.CycleNumber)
  1589. {
  1590. cj.SetState(EnumControlJobState.Executing);
  1591. cj.JetState = EnumJetCtrlJobState.Quequed;
  1592. cj.LotInnerId = Guid.NewGuid();
  1593. _dbCallback.LotCreated(cj);
  1594. foreach (var pj in _lstProcessJobs)
  1595. {
  1596. if (pj.ControlJobName == cj.Name)
  1597. {
  1598. pj.SetState(EnumProcessJobState.Queued);
  1599. pj.InnerId = Guid.NewGuid();
  1600. foreach (var pjSlotWafer in pj.SlotWafers)
  1601. {
  1602. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1603. wafer.ProcessJob = null;
  1604. wafer.NextSequenceStep = 0;
  1605. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1606. }
  1607. }
  1608. }
  1609. _lstWaferTasks.RemoveAll(wt => wt.currentMod == lp);
  1610. }
  1611. else
  1612. {
  1613. cj.SetState(EnumControlJobState.Completed);
  1614. }
  1615. }
  1616. else
  1617. {
  1618. lpCycleWafer = _lpCycleCount[lp] * cj.LotWafers.Count + countProcessed;
  1619. }
  1620. if (lpCycleWafer != _lpCycleWafer[lp])
  1621. {
  1622. _lpCycleWafer[lp] = lpCycleWafer;
  1623. if (_lpCycleCount[lp] > 0)
  1624. {
  1625. _lpThroughput[lp] = (float)(lpCycleWafer / (DateTime.Now - cj.StartTime).TotalHours);
  1626. }
  1627. }
  1628. return cj.State == EnumControlJobState.Completed;
  1629. }
  1630. private bool IsControlJobIntersect(ControlJobInfo cj1, ControlJobInfo cj2)
  1631. {
  1632. var cj1Pms = GetWaitPreCleanPMsByCtrlJob(cj1);
  1633. var cj2Pms = GetWaitPreCleanPMsByCtrlJob(cj2);
  1634. return cj1Pms.Intersect(cj2Pms).Count() > 0;
  1635. }
  1636. private bool IsCtrlJobNeedPreClean(ControlJobInfo cj)
  1637. {
  1638. return !string.IsNullOrWhiteSpace(cj.PreJobClean);
  1639. }
  1640. private bool IsCtrlJobNeedPostClean(ControlJobInfo cj)
  1641. {
  1642. return !string.IsNullOrWhiteSpace(cj.PostJobClean.Trim());
  1643. }
  1644. private bool IsPreJobCleanDone(ControlJobInfo cj)
  1645. {
  1646. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1647. foreach (var pm in pms)
  1648. {
  1649. var pmTask = _dictModuleTask[pm] as VenusPMTask;
  1650. if (pmTask.Scheduler.IsOnline && !pmTask.IsRecipeJobDone(VenusPMTask.RecipeJobType.PreClean))
  1651. return false;
  1652. }
  1653. return true;
  1654. }
  1655. private bool IsPostJobCleanDone(ControlJobInfo cj)
  1656. {
  1657. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1658. foreach (var pm in pms)
  1659. {
  1660. var pmTask = _dictModuleTask[pm] as VenusPMTask;
  1661. if (pmTask.Scheduler.IsOnline && !pmTask.IsRecipeJobDone(VenusPMTask.RecipeJobType.PostClean))
  1662. return false;
  1663. }
  1664. return true;
  1665. }
  1666. private bool ActiveProcessJob(ProcessJobInfo pj)
  1667. {
  1668. foreach (var pjSlotWafer in pj.SlotWafers)
  1669. {
  1670. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1671. wafer.ProcessJob = pj;
  1672. wafer.NextSequenceStep = 0;
  1673. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1674. }
  1675. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1676. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1677. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1678. pj.SetState(EnumProcessJobState.Processing);
  1679. return true;
  1680. }
  1681. private bool ActiveControlJob(ControlJobInfo cj)
  1682. {
  1683. cj.JetState = EnumJetCtrlJobState.Processing;
  1684. foreach (var pjName in cj.ProcessJobNameList)
  1685. {
  1686. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1687. if (pj == null)
  1688. {
  1689. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1690. continue;
  1691. }
  1692. if (pj.State == EnumProcessJobState.Queued)
  1693. {
  1694. ActiveProcessJob(pj);
  1695. }
  1696. }
  1697. return true;
  1698. }
  1699. private bool IsAllProcessJobComplete(ControlJobInfo cj)
  1700. {
  1701. foreach (var pj in _lstProcessJobs)
  1702. {
  1703. if (pj.ControlJobName == cj.Name && pj.State != EnumProcessJobState.ProcessingComplete)
  1704. {
  1705. return false;
  1706. }
  1707. }
  1708. return true;
  1709. }
  1710. private bool IsAllJobWaferProcessedOrProcessing(ControlJobInfo cj)
  1711. {
  1712. List<ModuleName> allModules = _dictModuleTask.Keys.ToList();
  1713. int original = (int)ModuleHelper.Converter(cj.Module);
  1714. foreach (var mod in allModules)
  1715. {
  1716. if (ModuleHelper.IsLoadPort(mod) && (int)mod != original)
  1717. continue;
  1718. var wafers = WaferManager.Instance.GetWafers(mod);
  1719. foreach (var wafer in wafers)
  1720. {
  1721. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.ControlJobName != cj.Name)
  1722. continue;
  1723. if (wafer.ProcessState != EnumWaferProcessStatus.Completed && wafer.ProcessState != EnumWaferProcessStatus.InProcess)
  1724. return false; ;
  1725. }
  1726. }
  1727. return true;
  1728. }
  1729. private ModuleName GetComingAvailablePM(ControlJobInfo cj)
  1730. {
  1731. var lstInProcessPMs = new List<ModuleName>();
  1732. foreach (var wafer in cj.LotWafers)
  1733. {
  1734. if (!wafer.IsEmpty && wafer.NextSequenceStep == 0 && wafer.ProcessJob != null)
  1735. {
  1736. foreach (var pm in wafer.ProcessJob.Sequence.PMs)
  1737. {
  1738. if (!lstInProcessPMs.Contains(pm) && _dictModuleTask[pm].Scheduler.IsOnline)
  1739. lstInProcessPMs.Add(pm);
  1740. }
  1741. }
  1742. }
  1743. Dictionary<ModuleName, int> pmAssociatedWaferCount = new Dictionary<ModuleName, int>();
  1744. foreach (var mod in _dictModuleTask)
  1745. {
  1746. if (ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline && lstInProcessPMs.Contains(mod.Key))
  1747. {
  1748. pmAssociatedWaferCount[mod.Key] = 0;
  1749. }
  1750. }
  1751. var unprocessedWafer = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.destMod));
  1752. foreach (var wafer in unprocessedWafer)
  1753. {
  1754. if (ModuleHelper.IsPm(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && lstInProcessPMs.Contains(wafer.destMod))
  1755. {
  1756. pmAssociatedWaferCount[wafer.destMod]++;
  1757. }
  1758. }
  1759. var oderedPMCount = pmAssociatedWaferCount.OrderBy(p => p.Value).ToDictionary(p => p.Key, o => o.Value);
  1760. if (oderedPMCount.Count > 0 && oderedPMCount.First().Value < 2)
  1761. return oderedPMCount.First().Key;
  1762. return ModuleName.System;
  1763. }
  1764. private void CreateNewWaferTask()
  1765. {
  1766. var runningJobs = _lstControlJobs.FindAll(cj => cj.JetState == EnumJetCtrlJobState.PreJobClean || cj.JetState == EnumJetCtrlJobState.Processing);
  1767. var onDutyPms = new Dictionary<ModuleName, int>();
  1768. foreach (var job in runningJobs)
  1769. {
  1770. var pms = GetWaitPreCleanPMsByCtrlJob(job);
  1771. foreach (var pm in pms)
  1772. {
  1773. if (_dictModuleTask[pm].Scheduler.IsOnline && !onDutyPms.ContainsKey(pm))
  1774. {
  1775. onDutyPms[pm] = _lstWaferTasks.Where(wt => wt.destMod == pm).Count();
  1776. }
  1777. }
  1778. }
  1779. if (runningJobs.Count == 0 || onDutyPms.Count == 0)
  1780. return;
  1781. var oderedPMs = onDutyPms.OrderBy(kv => kv.Value).OrderBy(kv => _dictModuleTask[kv.Key].TimeToReady);
  1782. if (oderedPMs.First().Value < 1)
  1783. {
  1784. foreach (var runningJob in runningJobs)
  1785. {
  1786. foreach (var wafer in runningJob.LotWafers)
  1787. {
  1788. if (wafer.IsEmpty || wafer.ProcessJob == null)
  1789. continue;
  1790. if (wafer.ProcessJob.Sequence.PMs.Contains(oderedPMs.First().Key) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  1791. {
  1792. CreateWaferTasks(wafer, oderedPMs.First().Key);
  1793. return;
  1794. }
  1795. }
  1796. }
  1797. }
  1798. }
  1799. private void CreateWaferTasks(WaferInfo wafer, ModuleName pm)
  1800. {
  1801. var recipeName = wafer.ProcessJob.Sequence.GetRecipe(pm);
  1802. var recipeContent = RecipeFileManager.Instance.LoadRecipe(pm.ToString(), recipeName, false, RecipeType.Process.ToString());
  1803. Recipe recipe = Recipe.Load(recipeContent);
  1804. int temperature = 0;
  1805. if (int.TryParse(recipe.Header.Temperature, out int temp))
  1806. {
  1807. temperature = temp;
  1808. }
  1809. var waferTask = new WaferTask((ModuleName)wafer.OriginStation,
  1810. wafer.OriginSlot,
  1811. pm,
  1812. 0,
  1813. temperature,
  1814. wafer.InnerId,
  1815. recipeName,
  1816. wafer.ProcessJob.Sequence.WTWCleanRecipe,
  1817. wafer.ProcessJob.Sequence.LLInOutPath,
  1818. wafer.ProcessJob.Sequence.LLDelayTime,
  1819. IsSequenceNeedAlign(wafer.ProcessJob.Sequence)); // post clean
  1820. waferTask.OnWaferArrived += WaferArrived;
  1821. waferTask.OnWaferLeaved += WaferLeaved;
  1822. _lstWaferTasks.Add(waferTask);
  1823. }
  1824. private bool IsSequenceNeedAlign(SequenceInfo sequence)
  1825. {
  1826. // check wether need align
  1827. foreach (var step in sequence.Steps)
  1828. {
  1829. foreach (var mod in step.StepModules)
  1830. {
  1831. if (ModuleHelper.IsAligner(mod))
  1832. return true;
  1833. }
  1834. }
  1835. return false;
  1836. }
  1837. private void RunSchdTMReturnActions()
  1838. {
  1839. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerSETMRobot;
  1840. if (tmRobot == null || !tmRobot.IsAvailable)
  1841. return;
  1842. if (_tmSchdActions.Count > 0)
  1843. {
  1844. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  1845. {
  1846. var nextActions = _tmSchdActions.First();
  1847. var nextModule = nextActions.First().Module;
  1848. if (!_dictModuleTask[nextModule].IsIdle)
  1849. return;
  1850. _curTmAction = _tmSchdActions.Dequeue();
  1851. tmRobot.SendMoveItems(_curTmAction.ToArray());
  1852. }
  1853. }
  1854. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  1855. {
  1856. _curTmAction.Clear();
  1857. }
  1858. }
  1859. #endregion internal implementation
  1860. #region sequence/recipe validation
  1861. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  1862. {
  1863. reason = "";
  1864. foreach (var pm in seq.PMs)
  1865. {
  1866. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  1867. return true;
  1868. }
  1869. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  1870. return false;
  1871. }
  1872. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  1873. {
  1874. for (int i = 0; i < seq.Steps.Count; i++)
  1875. {
  1876. SequenceStepInfo stepInfo = seq.Steps[i];
  1877. foreach (var module in stepInfo.StepModules)
  1878. {
  1879. if (ModuleHelper.IsPm(module))
  1880. {
  1881. string attr = $"{module}Recipe";
  1882. if (stepInfo.StepParameter.ContainsKey(attr)
  1883. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  1884. {
  1885. var recipeName = (string)stepInfo.StepParameter[attr];
  1886. if (!string.IsNullOrWhiteSpace(recipeName))
  1887. {
  1888. var recipeContent =
  1889. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  1890. if (string.IsNullOrWhiteSpace(recipeContent))
  1891. {
  1892. reason = $"Can not find recipe file{recipeName}";
  1893. return false;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. reason = "";
  1901. return true;
  1902. }
  1903. private List<ModuleName> GetWaitPreCleanPMsByCtrlJob(ControlJobInfo cj)
  1904. {
  1905. var pmlist = new List<ModuleName>();
  1906. foreach (var pj in _lstProcessJobs)
  1907. {
  1908. if (pj.ControlJobName == cj.Name)
  1909. {
  1910. foreach (var pm in pj.Sequence.PMs)
  1911. {
  1912. if (!pmlist.Contains(pm))
  1913. pmlist.Add(pm);
  1914. }
  1915. }
  1916. }
  1917. return pmlist;
  1918. }
  1919. #endregion
  1920. }
  1921. }