AutoCycle.cs 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320
  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 Venus_Unity;
  24. namespace Venus_RT.Modules
  25. {
  26. enum ModulePriority
  27. {
  28. High,
  29. Middle,
  30. Low,
  31. Stop,
  32. }
  33. public enum MovingStatus
  34. {
  35. Idle,
  36. Waiting,
  37. Moving,
  38. Moved,
  39. // PM Status
  40. WaitProcess,
  41. StartProcess,
  42. Processing,
  43. // Align Status
  44. WaitAlign,
  45. StartAlign,
  46. Aligning,
  47. }
  48. class ModuleFlag
  49. {
  50. public ModulePriority Priority { get; set; }
  51. public MovingStatus MovingStatus { get; set; }
  52. public bool InUsed { get; set; }
  53. public ModuleFlag(ModulePriority _priority)
  54. {
  55. Priority = _priority;
  56. MovingStatus = MovingStatus.Idle;
  57. InUsed = true;
  58. }
  59. }
  60. class AutoCycle : IRoutine
  61. {
  62. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  63. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  64. private RState _cycleState = RState.Init;
  65. Dictionary<ModuleName, SchedulerModule> _atmSchedulers = new Dictionary<ModuleName, SchedulerModule>();
  66. Dictionary<ModuleName, ModuleFlag> _atmModules = new Dictionary<ModuleName, ModuleFlag>();
  67. Dictionary<ModuleName, SchedulerModule> _vacSchedulers = new Dictionary<ModuleName, SchedulerModule>();
  68. Dictionary<ModuleName, ModuleFlag> _vacModules = new Dictionary<ModuleName, ModuleFlag>();
  69. SchedulerTMRobot _tmRobot = (SchedulerTMRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot);
  70. SchedulerEfemRobot _efemRobot = (SchedulerEfemRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot);
  71. Dictionary<SlotItem, long> _vacReadyOutSlots = new Dictionary<SlotItem, long>();
  72. Dictionary<SlotItem, long> _vacReadyInSlots = new Dictionary<SlotItem, long>();
  73. Dictionary<SlotItem, long> _atmReadyOutSlots = new Dictionary<SlotItem, long>();
  74. Dictionary<SlotItem, long> _atmReadyInSlots = new Dictionary<SlotItem, long>();
  75. List<int> _LLAInSlot = new List<int> { 0, 1, 2, 3 };
  76. List<int> _LLAOutSlot = new List<int> { 0, 1, 2, 3 };
  77. List<int> _LLBInSlot = new List<int> { 0, 1, 2, 3 };
  78. List<int> _LLBOutSlot = new List<int> { 0, 1, 2, 3 };
  79. int _LLASlotNumber = 4;
  80. int _LLBSlotNumber = 4;
  81. int _efemRobotSingleArmOption = 0;
  82. SequenceLLInOutPath _LLInOutPath = SequenceLLInOutPath.DInDOut;
  83. List<MoveItem> _movingItems = new List<MoveItem>();
  84. List<MoveItem> _efemMovingItems = new List<MoveItem>();
  85. Dictionary<SlotItem, Guid> _vacWaferTargets = new Dictionary<SlotItem, Guid>();
  86. Dictionary<SlotItem, Guid> _atmWaferTargets = new Dictionary<SlotItem, Guid>();
  87. R_TRIG _vacMoveFinishTrig = new R_TRIG();
  88. R_TRIG _atmMoveFinishTrig = new R_TRIG();
  89. private SchedulerFACallback _faCallback;
  90. private SchedulerDBCallback _dbCallback;
  91. private bool _isCycleMode;
  92. private int _cycleSetPoint = 0;
  93. private int _cycledCount = 0;
  94. private int _cycledWafer = 0;
  95. private float _throughput = 0.0f;
  96. private Stopwatch _cycleWatch = new Stopwatch();
  97. public bool HasJobRunning => _lstControlJobs.Count > 0;
  98. #region public interface
  99. public AutoCycle()
  100. {
  101. _faCallback = new SchedulerFACallback();
  102. _dbCallback = new SchedulerDBCallback();
  103. InitModules();
  104. _LLASlotNumber = SC.GetValue<int>("LLA.SlotNumber");
  105. _LLBSlotNumber = SC.GetValue<int>("LLB.SlotNumber");
  106. _LLAInSlot.RemoveAll(item => item >= _LLASlotNumber);
  107. _LLAOutSlot.RemoveAll(item => item >= _LLASlotNumber);
  108. _LLBInSlot.RemoveAll(item => item >= _LLBSlotNumber);
  109. _LLBOutSlot.RemoveAll(item => item >= _LLBSlotNumber);
  110. _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
  111. DATA.Subscribe("Scheduler.CycledCount", () => _cycledCount,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  112. DATA.Subscribe("Scheduler.CycledWafer", () => _cycledWafer, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  113. DATA.Subscribe("Scheduler.CycleSetPoint", () => _cycleSetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  114. DATA.Subscribe("Scheduler.Throughput", () => _throughput, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  115. DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
  116. }
  117. public RState Start(params object[] objs)
  118. {
  119. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  120. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  121. _cycledWafer = 0;
  122. _cycledCount = 0;
  123. _throughput = 0;
  124. _cycleWatch.Stop();
  125. return RState.Running;
  126. }
  127. public RState Monitor()
  128. {
  129. if(_cycleState == RState.Running)
  130. {
  131. prelude();
  132. driveAtmSystem();
  133. driveVacSystem();
  134. epilogue();
  135. }
  136. return _cycleState;
  137. }
  138. public void Abort()
  139. {
  140. }
  141. public void CreateJob(Dictionary<string, object> param)
  142. {
  143. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  144. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  145. string[] slotSequence = (string[])param["SlotSequence"];
  146. string jobId = (string)param["JobId"];
  147. string module = (string)param["Module"];
  148. //bool autoStart = (bool)param["AutoStart"];
  149. string lotId = jobId;
  150. if (param.ContainsKey("LotId"))
  151. lotId = (string)param["LotId"];
  152. if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  153. {
  154. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}");
  155. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  156. return;
  157. }
  158. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  159. {
  160. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{module} should be LoadPort");
  161. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  162. return;
  163. }
  164. if (string.IsNullOrEmpty(jobId))
  165. {
  166. jobId = "CJ_Local_" + module;
  167. }
  168. if (_lstControlJobs.Exists(x => x.Name == jobId))
  169. {
  170. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{jobId} already created");
  171. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  172. return;
  173. }
  174. SchedulerLoadPort lp = _atmSchedulers[ModuleHelper.Converter(module)] as SchedulerLoadPort;
  175. if (!lp.CheckReadyRunJob())
  176. {
  177. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{module} not ready");
  178. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  179. return;
  180. }
  181. ControlJobInfo cj = new ControlJobInfo();
  182. cj.Name = jobId;
  183. cj.Module = module;
  184. cj.LotName = lotId;
  185. cj.LotInnerId = Guid.NewGuid();
  186. cj.LotWafers = new List<WaferInfo>();
  187. cj.SetState(EnumControlJobState.WaitingForStart);
  188. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  189. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  190. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  191. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  192. for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
  193. {
  194. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  195. continue;
  196. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  197. indexSequence[groupName] = slotSequence[i];
  198. if (!seqSlot.ContainsKey(groupName))
  199. {
  200. seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  201. }
  202. if (!seqSlotWafers.ContainsKey(groupName))
  203. {
  204. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  205. }
  206. seqSlot[groupName][i] = true;
  207. if (!WaferManager.Instance.CheckHasWafer(module, i))
  208. {
  209. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} not in the carrier");
  210. return;
  211. }
  212. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  213. {
  214. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}");
  215. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  216. return;
  217. }
  218. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  219. {
  220. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}");
  221. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  222. return;
  223. }
  224. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  225. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
  226. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  227. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  228. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  229. }
  230. if (seqSlotWafers.Count == 0)
  231. {
  232. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job has not assign wafer");
  233. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  234. return;
  235. }
  236. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  237. string[] seqs = seqSlot.Keys.ToArray();
  238. for (int i = 0; i < seqs.Length; i++)
  239. {
  240. ProcessJobInfo pj = new ProcessJobInfo();
  241. pj.Name = jobId + "_" + (i + 1);
  242. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  243. pj.ControlJobName = cj.Name;
  244. pj.LotName = lotId;
  245. pj.SlotWafers = seqSlotWafers[seqs[i]];
  246. pj.SetState(EnumProcessJobState.Queued);
  247. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  248. {
  249. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"no valid chamber for the {reason}");
  250. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  251. return;
  252. }
  253. if (!RouteManager.IsATMMode && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  254. {
  255. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"recipe file not valid in the sequence, {reason}");
  256. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  257. return;
  258. }
  259. pjs.Add(pj);
  260. }
  261. _dbCallback.LotUpdate(cj);
  262. foreach (var pj in pjs)
  263. {
  264. cj.ProcessJobNameList.Add(pj.Name);
  265. _lstProcessJobs.Add(pj);
  266. }
  267. _lstControlJobs.Add(cj);
  268. //AssociatedPMWithLP(cj);
  269. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  270. }
  271. public bool CheckAllJobDone()
  272. {
  273. foreach (var cj in _lstControlJobs)
  274. {
  275. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  276. return false;
  277. }
  278. return true;
  279. }
  280. public bool CheckJobJustDone(out string sJobName)
  281. {
  282. foreach (var cj in _lstControlJobs)
  283. {
  284. if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
  285. {
  286. //LP;WaferSize;Lot;Number;Start;End;
  287. sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
  288. cj.BeenPosted = true;
  289. return true;
  290. }
  291. }
  292. sJobName = "NULL";
  293. return false;
  294. }
  295. public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  296. {
  297. foreach (var pj in _lstProcessJobs)
  298. {
  299. if (pj.ControlJobName == cj.Name)
  300. return pj;
  301. }
  302. return null;
  303. }
  304. public void AbortJob(string jobName)
  305. {
  306. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  307. if (cj == null)
  308. {
  309. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"abort job rejected, not found job with id {jobName}");
  310. return;
  311. }
  312. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  313. foreach (var pj in _lstProcessJobs)
  314. {
  315. if (pj.ControlJobName == cj.Name)
  316. {
  317. pj.SetState(EnumProcessJobState.Aborting);
  318. pjAbortList.Add(pj);
  319. int unprocessed = 0;
  320. int aborted = 0;
  321. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  322. foreach (var waferInfo in wafers)
  323. {
  324. waferInfo.ProcessJob = null;
  325. waferInfo.NextSequenceStep = 0;
  326. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  327. unprocessed++;
  328. }
  329. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  330. }
  331. }
  332. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  333. _dbCallback.LotFinished(cj);
  334. foreach (var pj in pjAbortList)
  335. {
  336. _lstProcessJobs.Remove(pj);
  337. }
  338. _lstControlJobs.Remove(cj);
  339. }
  340. public void StopJob(string jobName)
  341. {
  342. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  343. if (cj == null)
  344. {
  345. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"stop job rejected, not found job with id {jobName}");
  346. return;
  347. }
  348. foreach (var pj in _lstProcessJobs)
  349. {
  350. if (pj.ControlJobName == cj.Name)
  351. {
  352. pj.SetState(EnumProcessJobState.Stopping);
  353. }
  354. }
  355. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  356. _dbCallback.LotFinished(cj);
  357. }
  358. public void ResumeJob(string jobName)
  359. {
  360. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  361. if (cj == null)
  362. {
  363. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"resume job rejected, not found job with id {jobName}");
  364. return;
  365. }
  366. if (cj.State == EnumControlJobState.Paused)
  367. {
  368. cj.SetState(EnumControlJobState.Executing);
  369. }
  370. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  371. }
  372. public void PauseJob(string jobName)
  373. {
  374. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  375. if (cj == null)
  376. {
  377. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"pause job rejected, not found job with id {jobName}");
  378. return;
  379. }
  380. if (cj.State == EnumControlJobState.Executing)
  381. {
  382. cj.SetState(EnumControlJobState.Paused);
  383. }
  384. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  385. }
  386. public void StartJob(string jobName)
  387. {
  388. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  389. if (cj == null)
  390. {
  391. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"start job rejected, not found job with id {jobName}");
  392. return;
  393. }
  394. if (cj.State == EnumControlJobState.WaitingForStart)
  395. {
  396. cj.SetState(EnumControlJobState.Executing);
  397. //PreJobClean(cj);
  398. (_atmSchedulers[ModuleHelper.Converter(cj.Module)] as SchedulerLoadPort).NoteJobStart();
  399. cj.StartTime = DateTime.Now;
  400. _dbCallback.LotCreated(cj);
  401. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  402. //if (!_blockingWatcher.IsRunning)
  403. // _blockingWatcher.Restart();
  404. //ResetTraceFlag();
  405. }
  406. if(!_cycleWatch.IsRunning)
  407. {
  408. _cycleWatch.Restart();
  409. }
  410. _cycleState = RState.Running;
  411. }
  412. public void Clear()
  413. {
  414. _vacWaferTargets.Clear();
  415. _atmWaferTargets.Clear();
  416. _movingItems.Clear();
  417. _efemMovingItems.Clear();
  418. _vacMoveFinishTrig.RST = true;
  419. _atmMoveFinishTrig.RST = true;
  420. _efemRobot.ResetTask();
  421. _tmRobot.ResetTask();
  422. foreach (var module in _vacSchedulers)
  423. {
  424. module.Value.ResetTask();
  425. _vacModules[module.Key].MovingStatus = MovingStatus.Idle;
  426. }
  427. foreach (var module in _atmSchedulers)
  428. {
  429. module.Value.ResetTask();
  430. _atmModules[module.Key].MovingStatus = MovingStatus.Idle;
  431. }
  432. _lstControlJobs.Clear();
  433. _lstProcessJobs.Clear();
  434. _cycleState = RState.End;
  435. }
  436. #endregion
  437. private void InitModules()
  438. {
  439. foreach(var module in new ModuleName[]{ ModuleName.LP1, ModuleName.LP2, ModuleName.LP3,
  440. ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2})
  441. {
  442. if(ModuleHelper.IsInstalled(module))
  443. {
  444. if(ModuleHelper.IsLoadPort(module))
  445. {
  446. _atmSchedulers[module] = Singleton<TransferModule>.Instance.GetScheduler(module);
  447. _atmModules[module] = new ModuleFlag(ModulePriority.Middle);
  448. }
  449. else if(ModuleHelper.IsAligner(module) || ModuleHelper.IsCooling(module))
  450. {
  451. _atmSchedulers[module] = Singleton<TransferModule>.Instance.GetScheduler(module);
  452. _atmModules[module] = new ModuleFlag(ModulePriority.Middle);
  453. }
  454. }
  455. }
  456. foreach (var module in new ModuleName[] { ModuleName.PMA, ModuleName.PMB, ModuleName.PMC,
  457. ModuleName.PMD, ModuleName.PME, ModuleName.PMF})
  458. {
  459. if (ModuleHelper.IsInstalled(module))
  460. {
  461. _vacSchedulers[module] = Singleton<TransferModule>.Instance.GetScheduler(module);
  462. _vacModules[module] = new ModuleFlag(ModulePriority.Middle);
  463. }
  464. }
  465. foreach (var module in new ModuleName[] { ModuleName.LLA, ModuleName.LLB })
  466. {
  467. if (ModuleHelper.IsInstalled(module))
  468. {
  469. var llScheduler = Singleton<TransferModule>.Instance.GetScheduler(module);
  470. _vacSchedulers[module] = llScheduler;
  471. _vacModules[module] = new ModuleFlag(ModulePriority.Middle);
  472. _atmSchedulers[module] = llScheduler;
  473. _atmModules[module] = new ModuleFlag(ModulePriority.Middle);
  474. }
  475. }
  476. }
  477. private void prelude()
  478. {
  479. }
  480. private void epilogue()
  481. {
  482. CheckWaferArrived();
  483. ProcessPMTask();
  484. ProcessAlignerTask();
  485. UpdateProcessJobStatus();
  486. UpdateControlJobStatus();
  487. StartNewJob();
  488. UpdateLLInOutPathProperty();
  489. }
  490. private void driveVacSystem()
  491. {
  492. PumpingTMRobotTask();
  493. ProcessTMRobotTask();
  494. RuningTMRobotTask();
  495. }
  496. #region Vacuum System
  497. private void PumpingTMRobotTask()
  498. {
  499. if (!_tmRobot.IsAvailable)
  500. return;
  501. foreach(var mod in _vacSchedulers)
  502. {
  503. if (mod.Value.IsAvailable && _vacModules[mod.Key].MovingStatus == MovingStatus.Idle)
  504. {
  505. if(ModuleHelper.IsLoadLock(mod.Key))
  506. {
  507. var inSlots = mod.Key == ModuleName.LLA ? _LLAInSlot : _LLBInSlot;
  508. foreach(var slot in inSlots)
  509. {
  510. if (IsLoadLockReservedByEFEM(mod.Key))
  511. continue;
  512. if(WaferManager.Instance.CheckHasWafer(mod.Key, slot) && IsVacWaferReadyOut(mod.Key, slot))
  513. {
  514. _vacReadyOutSlots.Add(new SlotItem(mod.Key, slot), mod.Value.WaferArrivedTicks(slot));
  515. }
  516. }
  517. var outSlots = mod.Key == ModuleName.LLA ? _LLAOutSlot : _LLBOutSlot;
  518. foreach(var slot in outSlots)
  519. {
  520. if (IsLoadLockReservedByEFEM(mod.Key))
  521. continue;
  522. if (WaferManager.Instance.CheckNoWafer(mod.Key, slot))
  523. {
  524. _vacReadyInSlots.Add(new SlotItem(mod.Key, slot), mod.Value.WaferArrivedTicks(slot));
  525. }
  526. }
  527. }
  528. else
  529. {
  530. if(WaferManager.Instance.CheckHasWafer(mod.Key, 0) && IsVacWaferReadyOut(mod.Key, 0)) // processed?
  531. {
  532. _vacReadyOutSlots.Add(new SlotItem(mod.Key, 0), mod.Value.WaferArrivedTicks(0));
  533. }
  534. else if(WaferManager.Instance.CheckNoWafer(mod.Key, 0))
  535. {
  536. _vacReadyInSlots.Add(new SlotItem(mod.Key, 0), mod.Value.WaferArrivedTicks(0));
  537. }
  538. }
  539. }
  540. }
  541. _vacReadyOutSlots = _vacReadyOutSlots.OrderByDescending(item => item.Value).ToDictionary(k => k.Key, v => v.Value);
  542. }
  543. bool SearchWaferDestination(SlotItem outSlot, out SlotItem destSlot)
  544. {
  545. destSlot = new SlotItem(ModuleName.System, -1);
  546. var wafer = WaferManager.Instance.GetWafer(outSlot.Module, outSlot.Slot);
  547. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  548. return false;
  549. foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  550. {
  551. var validSlots = GetModuleValidSlots(next_module);
  552. foreach (var nSlot in validSlots)
  553. {
  554. if (_movingItems.Exists(mItem => mItem.DestinationModule == next_module && mItem.DestinationSlot == nSlot))
  555. continue;
  556. foreach(var inItem in _vacReadyInSlots)
  557. {
  558. if(inItem.Key.Module == next_module && inItem.Key.Slot == nSlot && _vacModules[next_module].MovingStatus != MovingStatus.Moving)
  559. {
  560. destSlot.Module = next_module;
  561. destSlot.Slot = nSlot;
  562. return true;
  563. }
  564. }
  565. }
  566. }
  567. return false;
  568. }
  569. bool SearchCanReplaceSlot(SlotItem llSlot, out SlotItem replaceSlot, out SlotItem destSlot)
  570. {
  571. replaceSlot = new SlotItem(ModuleName.System, -1);
  572. destSlot = new SlotItem(ModuleName.System, -1);
  573. var wafer = WaferManager.Instance.GetWafer(llSlot.Module, llSlot.Slot);
  574. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  575. return false;
  576. foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  577. {
  578. if (!ModuleHelper.IsPm(next_module) || WaferManager.Instance.CheckNoWafer(next_module, 0))
  579. continue;
  580. if (SearchWaferDestination(new SlotItem(next_module, 0), out destSlot))
  581. {
  582. replaceSlot.Module = next_module;
  583. replaceSlot.Slot = 0;
  584. return true;
  585. }
  586. }
  587. return false;
  588. }
  589. List<int> GetModuleValidSlots(ModuleName mod)
  590. {
  591. var validSlot = new List<int>();
  592. if(ModuleHelper.IsLoadLock(mod))
  593. {
  594. if(!IsLoadLockReservedByEFEM(mod))
  595. {
  596. var inSlots = mod == ModuleName.LLA ? _LLAInSlot : _LLBInSlot;
  597. foreach (var slot in inSlots)
  598. {
  599. if (WaferManager.Instance.CheckNoWafer(mod, slot) && !_movingItems.Exists(item => item.DestinationModule == mod && item.DestinationSlot == slot))
  600. validSlot.Add(slot);
  601. if (WaferManager.Instance.CheckHasWafer(mod, slot) && _movingItems.Exists(item => item.SourceModule == mod && item.SourceSlot == slot))
  602. validSlot.Add(slot);
  603. }
  604. }
  605. }
  606. else if(ModuleHelper.IsPm(mod))
  607. {
  608. if (WaferManager.Instance.CheckNoWafer(mod, 0) && !_movingItems.Exists(item => item.DestinationModule == mod))
  609. validSlot.Add(0);
  610. if (WaferManager.Instance.CheckHasWafer(mod, 0) && _movingItems.Exists(item => item.SourceModule == mod))
  611. validSlot.Add(0);
  612. }
  613. return validSlot.Distinct().ToList();
  614. }
  615. private int GetModuleSlotCount(ModuleName mod)
  616. {
  617. int nSlotCount = 1;
  618. if(ModuleHelper.IsLoadLock(mod))
  619. {
  620. nSlotCount = mod == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  621. }
  622. else if(ModuleHelper.IsLoadPort(mod))
  623. {
  624. nSlotCount = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
  625. }
  626. else if(ModuleHelper.IsTMRobot(mod) || ModuleHelper.IsEFEMRobot(mod))
  627. {
  628. nSlotCount = 2;
  629. }
  630. return nSlotCount;
  631. }
  632. List<MoveItem> SearchWaitInSlots(ModuleName inModule)
  633. {
  634. List<MoveItem> inSlots = new List<MoveItem>();
  635. var validSlots = GetModuleValidSlots(inModule);
  636. foreach(var slot in _vacReadyOutSlots)
  637. {
  638. if (slot.Key.Module == inModule || _vacModules[slot.Key.Module].MovingStatus != MovingStatus.Idle)
  639. continue;
  640. if (IsLoadLockReservedByEFEM(slot.Key.Module))
  641. continue;
  642. var wafer = WaferManager.Instance.GetWafer(slot.Key.Module, slot.Key.Slot);
  643. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  644. continue;
  645. foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  646. {
  647. if(next_module == inModule && validSlots.Count > 0 && !_movingItems.Exists(item => item.SourceModule == slot.Key.Module && item.SourceSlot == slot.Key.Slot))
  648. {
  649. if(!inSlots.Exists(item => item.SourceModule == slot.Key.Module && item.SourceSlot == slot.Key.Slot))
  650. {
  651. inSlots.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, inModule, validSlots.First(), Hand.None));
  652. }
  653. validSlots.RemoveAt(0);
  654. }
  655. }
  656. }
  657. return inSlots;
  658. }
  659. private void UpdateItemMovingStatus(MoveItem moveItem, MovingStatus status = MovingStatus.Moving)
  660. {
  661. if(!ModuleHelper.IsTMRobot(moveItem.DestinationModule))
  662. {
  663. _vacModules[moveItem.DestinationModule].MovingStatus = status;
  664. }
  665. if(!ModuleHelper.IsTMRobot(moveItem.SourceModule))
  666. {
  667. _vacModules[moveItem.SourceModule].MovingStatus = status;
  668. }
  669. }
  670. private void UpdateModuleMovingStatus(ModuleName module, MovingStatus status = MovingStatus.Moving)
  671. {
  672. if (!ModuleHelper.IsTMRobot(module))
  673. {
  674. _vacModules[module].MovingStatus = status;
  675. }
  676. }
  677. private void ProcessTMRobotTask()
  678. {
  679. if(_tmRobot.IsAvailable)
  680. {
  681. if(WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
  682. {
  683. for(int i = 0; i < 2; i++)
  684. {
  685. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
  686. {
  687. if (SearchWaferDestination(new SlotItem(ModuleName.TMRobot, i), out SlotItem destSlot))
  688. {
  689. _movingItems.Add(new MoveItem(ModuleName.TMRobot, i, destSlot.Module, destSlot.Slot, (Hand)i));
  690. UpdateModuleMovingStatus(destSlot.Module);
  691. }
  692. }
  693. }
  694. return;
  695. }
  696. foreach (var slot in _vacReadyOutSlots)
  697. {
  698. if (_vacModules[slot.Key.Module].MovingStatus != MovingStatus.Idle)
  699. continue;
  700. if (ModuleHelper.IsLoadLock(slot.Key.Module))
  701. {
  702. if (IsLoadLockReservedByEFEM(slot.Key.Module))
  703. continue;
  704. var llStatus = GetLLProcessStatusCount(slot.Key.Module);
  705. if(SearchWaferDestination(slot.Key, out SlotItem destSlot))
  706. {
  707. _movingItems.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, destSlot.Module, destSlot.Slot, Hand.None));
  708. UpdateModuleMovingStatus(slot.Key.Module);
  709. UpdateModuleMovingStatus(destSlot.Module);
  710. if(llStatus.Item2 > 1)
  711. {
  712. // check whether match double pick pattern
  713. foreach (var item in _vacReadyOutSlots)
  714. {
  715. if (item.Key.Module == slot.Key.Module && item.Key.Slot != slot.Key.Slot)
  716. {
  717. if (SearchWaferDestination(item.Key, out SlotItem destSlot_2))
  718. {
  719. _movingItems.Add(new MoveItem(item.Key.Module, item.Key.Slot, destSlot_2.Module, destSlot_2.Slot, Hand.None));
  720. UpdateModuleMovingStatus(destSlot_2.Module);
  721. break;
  722. }
  723. }
  724. }
  725. if(_movingItems.Count == 1)
  726. {
  727. foreach (var item in _vacReadyOutSlots)
  728. {
  729. if (item.Key.Module == slot.Key.Module && item.Key.Slot != slot.Key.Slot)
  730. {
  731. if(SearchCanReplaceSlot(item.Key, out SlotItem replaceSlot, out SlotItem destSlot_2))
  732. {
  733. _movingItems.Add(new MoveItem(item.Key.Module, item.Key.Slot, replaceSlot.Module, replaceSlot.Slot, Hand.None));
  734. _movingItems.Add(new MoveItem(replaceSlot.Module, replaceSlot.Slot, destSlot_2.Module, destSlot_2.Slot, Hand.None));
  735. UpdateModuleMovingStatus(replaceSlot.Module);
  736. UpdateModuleMovingStatus(destSlot.Module);
  737. return;
  738. }
  739. }
  740. }
  741. }
  742. }
  743. // check whether match swap pattern
  744. int inCount = 0;
  745. var in_slots = SearchWaitInSlots(slot.Key.Module);
  746. foreach(var in_slot in in_slots)
  747. {
  748. if(_vacModules[in_slot.DestinationModule].MovingStatus == MovingStatus.Idle && inCount < 2)
  749. {
  750. _movingItems.Add(in_slot);
  751. UpdateItemMovingStatus(in_slot);
  752. inCount++;
  753. }
  754. }
  755. return;
  756. }
  757. }
  758. else // PM
  759. {
  760. if(SearchWaferDestination(slot.Key, out SlotItem destSlot))
  761. {
  762. _movingItems.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, destSlot.Module, destSlot.Slot, Hand.None));
  763. UpdateModuleMovingStatus(slot.Key.Module);
  764. UpdateModuleMovingStatus(destSlot.Module);
  765. // check whether match swap pattern
  766. int swapCount = 0;
  767. var in_slots = SearchWaitInSlots(slot.Key.Module);
  768. foreach(var swap_slot in in_slots)
  769. {
  770. if(_vacModules[swap_slot.SourceModule].MovingStatus == MovingStatus.Idle && swapCount < 1)
  771. {
  772. _movingItems.Add(swap_slot);
  773. UpdateItemMovingStatus(swap_slot);
  774. swapCount++;
  775. }
  776. }
  777. if(swapCount == 0)
  778. {
  779. // check whether match double move pattern
  780. int inCount = 0;
  781. var same_dest = SearchWaitInSlots(destSlot.Module);
  782. foreach(var in_slot in same_dest)
  783. {
  784. if(_vacModules[in_slot.SourceModule].MovingStatus == MovingStatus.Idle && inCount < 1)
  785. {
  786. _movingItems.Add(in_slot);
  787. UpdateItemMovingStatus(in_slot);
  788. inCount++;
  789. }
  790. }
  791. }
  792. return;
  793. }
  794. }
  795. }
  796. _vacReadyOutSlots.Clear();
  797. _vacReadyInSlots.Clear();
  798. }
  799. }
  800. private void RuningTMRobotTask()
  801. {
  802. if(_tmRobot.IsAvailable)
  803. {
  804. if(_tmRobot.PostMoveItems(_movingItems.ToArray()))
  805. {
  806. foreach(var item in _movingItems)
  807. {
  808. var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
  809. if (wafer.IsEmpty)
  810. {
  811. // post alarm
  812. _cycleState = RState.Failed;
  813. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run TM moving task as Get {item.SourceModule}{item.SourceModule} Wafer Info failed");
  814. return;
  815. }
  816. var slot = new SlotItem(item.DestinationModule, item.DestinationSlot);
  817. _vacWaferTargets[slot] = wafer.InnerId;
  818. }
  819. }
  820. }
  821. }
  822. private void ProcessPMTask()
  823. {
  824. foreach(var mod in _vacModules)
  825. {
  826. if(ModuleHelper.IsPm(mod.Key))
  827. {
  828. if(_vacSchedulers[mod.Key].IsAvailable)
  829. {
  830. switch (mod.Value.MovingStatus)
  831. {
  832. case MovingStatus.WaitProcess:
  833. {
  834. _vacSchedulers[mod.Key].EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.TMRobot, 0, mod.Key, 0));
  835. mod.Value.MovingStatus = MovingStatus.StartProcess;
  836. }
  837. break;
  838. case MovingStatus.Processing:
  839. mod.Value.MovingStatus = MovingStatus.Idle;
  840. break;
  841. }
  842. }
  843. else
  844. {
  845. switch(mod.Value.MovingStatus)
  846. {
  847. case MovingStatus.StartProcess:
  848. mod.Value.MovingStatus = MovingStatus.Processing;
  849. break;
  850. }
  851. }
  852. }
  853. }
  854. }
  855. private Hand GetTMRobotFreeHand()
  856. {
  857. var blade1HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0);
  858. var blade2HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1);
  859. if (blade1HasWafer && blade2HasWafer)
  860. return Hand.None;
  861. else if (!blade1HasWafer && !blade2HasWafer)
  862. return Hand.Both;
  863. else if (blade1HasWafer)
  864. return Hand.Blade2;
  865. else
  866. return Hand.Blade1;
  867. }
  868. private bool IsVacWaferReadyOut(ModuleName mod, int slot)
  869. {
  870. var wafer = WaferManager.Instance.GetWafer(mod, slot);
  871. if (wafer.IsEmpty)
  872. return false;
  873. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  874. return false;
  875. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  876. {
  877. // should not go here
  878. //LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Wafer:{wafer.WaferOrigin} NextSequenceStep {wafer.NextSequenceStep} exceeds {wafer.ProcessJob.Sequence.Name} max steps number");
  879. return false;
  880. }
  881. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod))
  882. return false;
  883. foreach(var module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  884. {
  885. if (ModuleHelper.IsLoadLock(module) || ModuleHelper.IsPm(module))
  886. return true;
  887. }
  888. return false;
  889. }
  890. #endregion Vacuum System
  891. #region Atm System
  892. private void driveAtmSystem()
  893. {
  894. PumpingEFEMRobotTask();
  895. RuningEFEMRobotTask();
  896. }
  897. private void PumpingEFEMRobotTask()
  898. {
  899. if (!_efemRobot.IsAvailable)
  900. return;
  901. foreach(var scheduler in _atmSchedulers)
  902. {
  903. if (!scheduler.Value.IsAvailable)
  904. continue;
  905. if(ModuleHelper.IsAligner(scheduler.Key))
  906. {
  907. if(_atmModules[scheduler.Key].MovingStatus != MovingStatus.Idle)
  908. {
  909. ProcessAlignerTask();
  910. if (_atmModules[scheduler.Key].MovingStatus != MovingStatus.Idle)
  911. return;
  912. }
  913. if (ProcessAlignerEFEMRobotTask(scheduler.Key))
  914. return;
  915. }
  916. else if (ModuleHelper.IsLoadLock(scheduler.Key))
  917. {
  918. if (ProcessLLEFEMRobotTask(scheduler.Key))
  919. return;
  920. }
  921. else if (ModuleHelper.IsCooling(scheduler.Key))
  922. {
  923. if (ProcessCoolingEFEMRobotTask(scheduler.Key))
  924. return;
  925. }
  926. else if (ModuleHelper.IsLoadPort(scheduler.Key))
  927. {
  928. if (ProcessLPEFEMRobotTask(scheduler.Key))
  929. return;
  930. }
  931. else
  932. {
  933. // should not go here
  934. LOG.Write(eEvent.ERR_ROUTER, $"Wrong Module: {scheduler.Key} in ATM System");
  935. }
  936. }
  937. }
  938. List<int> GetEfemRobotWaferReadyInHands(ModuleName mod)
  939. {
  940. var slots = new List<int>();
  941. for(int i = 0; i < 2; i++)
  942. {
  943. if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != i + 1)
  944. continue;
  945. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  946. if (wafer.IsEmpty)
  947. continue;
  948. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  949. continue;
  950. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  951. {
  952. // should not go here
  953. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Wafer:{wafer.WaferOrigin} NextSequenceStep {wafer.NextSequenceStep} exceeds {wafer.ProcessJob.Sequence.Name} max steps number");
  954. continue;
  955. }
  956. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod))
  957. {
  958. slots.Add(i);
  959. }
  960. }
  961. return slots;
  962. }
  963. bool IsAtmWaferReadyOut(ModuleName mod, int slot)
  964. {
  965. var wafer = WaferManager.Instance.GetWafer(mod, slot);
  966. if (wafer.IsEmpty)
  967. return false;
  968. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  969. return false;
  970. if (wafer.NextSequenceStep == wafer.ProcessJob.Sequence.Steps.Count)
  971. {
  972. // need return
  973. return true;
  974. }
  975. else if(wafer.NextSequenceStep > wafer.ProcessJob.Sequence.Steps.Count)
  976. {
  977. // should not go here
  978. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Wafer:{wafer.WaferOrigin} NextSequenceStep {wafer.NextSequenceStep} exceeds {wafer.ProcessJob.Sequence.Name} max steps number");
  979. return false;
  980. }
  981. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod))
  982. return false;
  983. if(ModuleHelper.IsLoadLock(mod))
  984. {
  985. foreach (var module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  986. {
  987. if (ModuleHelper.IsPm(module))
  988. return false;
  989. }
  990. }
  991. return true;
  992. }
  993. private bool ProcessLLEFEMRobotTask(ModuleName ll)
  994. {
  995. if (_vacModules[ll].MovingStatus != MovingStatus.Idle || IsLoadLockReservedByTM(ll))
  996. return false;
  997. var robotSlots = GetEfemRobotWaferReadyInHands(ll);
  998. var inSlots = ll == ModuleName.LLA ? _LLAInSlot : _LLBInSlot;
  999. foreach(var slot in inSlots)
  1000. {
  1001. if(robotSlots.Count >= 1)
  1002. {
  1003. if(WaferManager.Instance.CheckNoWafer(ll, slot))
  1004. {
  1005. _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, robotSlots.First(), ll, slot, (Hand)robotSlots.First()));
  1006. robotSlots.RemoveAt(0);
  1007. }
  1008. }
  1009. }
  1010. var slotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  1011. Dictionary<int, long> slot_delays = new Dictionary<int, long>();
  1012. for (int i = 0; i < slotNumber; i++)
  1013. {
  1014. if(IsAtmWaferReadyOut(ll, i))
  1015. {
  1016. slot_delays[i] = _atmSchedulers[ll].WaferArrivedTicks(i);
  1017. }
  1018. }
  1019. slot_delays = slot_delays.OrderByDescending(item => item.Value).ToDictionary(k => k.Key, v => v.Value);
  1020. if(slot_delays.Count > 0)
  1021. {
  1022. var robotHand = GetEFEMRobotFreeHand();
  1023. if (robotHand != Hand.None)
  1024. {
  1025. _efemMovingItems.Add(new MoveItem(ll, slot_delays.ElementAt(0).Key, ModuleName.EfemRobot, (int)robotHand, robotHand));
  1026. }
  1027. if(slot_delays.Count > 1)
  1028. {
  1029. var secondHand = GetEFEMRobotFreeHand();
  1030. if(secondHand != Hand.None)
  1031. {
  1032. _efemMovingItems.Add(new MoveItem(ll, slot_delays.ElementAt(1).Key, ModuleName.EfemRobot, (int)secondHand, secondHand));
  1033. }
  1034. }
  1035. }
  1036. return _efemMovingItems.Count > 0;
  1037. }
  1038. private Tuple<int, int> GetPMWaferExistence()
  1039. {
  1040. int exist = 0;
  1041. int empty = 0;
  1042. foreach (var module in _vacModules)
  1043. {
  1044. if (ModuleHelper.IsPm(module.Key) && _vacSchedulers[module.Key].IsOnline && module.Value.InUsed)
  1045. {
  1046. if (WaferManager.Instance.CheckHasWafer(module.Key, 0))
  1047. exist++;
  1048. else
  1049. empty++;
  1050. }
  1051. }
  1052. return new Tuple<int, int>(exist, empty);
  1053. }
  1054. private int GetTMRobotWaferCount()
  1055. {
  1056. return (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) ? 1 : 0);
  1057. }
  1058. private int GetEfemRoborWaferCount()
  1059. {
  1060. return (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) ? 1 : 0);
  1061. }
  1062. private bool IsLoadLockReservedByEFEM(ModuleName ll)
  1063. {
  1064. List<ModuleName> unfinished = new List<ModuleName>();
  1065. foreach (var item in _atmWaferTargets)
  1066. {
  1067. var moving = _efemMovingItems.Find(m_item => m_item.DestinationModule == item.Key.Module && m_item.DestinationSlot == item.Key.Slot);
  1068. if (!unfinished.Contains(moving.SourceModule))
  1069. unfinished.Add(moving.SourceModule);
  1070. if (!unfinished.Contains(moving.DestinationModule))
  1071. unfinished.Add(moving.DestinationModule);
  1072. }
  1073. return unfinished.Contains(ll);
  1074. }
  1075. private bool IsLoadLockReservedByTM(ModuleName ll)
  1076. {
  1077. List<ModuleName> unfinished = new List<ModuleName>();
  1078. foreach (var item in _vacWaferTargets)
  1079. {
  1080. var moving = _movingItems.Find(m_item => m_item.DestinationModule == item.Key.Module && m_item.DestinationSlot == item.Key.Slot);
  1081. if (!unfinished.Contains(moving.SourceModule))
  1082. unfinished.Add(moving.SourceModule);
  1083. if (!unfinished.Contains(moving.DestinationModule))
  1084. unfinished.Add(moving.DestinationModule);
  1085. }
  1086. return unfinished.Contains(ll);
  1087. }
  1088. private Tuple<int, int> GetLLProcessStatusCount(ModuleName ll)
  1089. {
  1090. int processedCount = 0;
  1091. int unprocessCount = 0;
  1092. int slotCount = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  1093. if(ModuleHelper.IsLoadLock(ll))
  1094. {
  1095. for(int i = 0; i < slotCount;i++)
  1096. {
  1097. if(WaferManager.Instance.CheckHasWafer(ll, i))
  1098. {
  1099. if(CheckWaferNeedProcessAndPMAvailable(ll, i))
  1100. unprocessCount++;
  1101. else
  1102. processedCount++;
  1103. }
  1104. }
  1105. }
  1106. return new Tuple<int, int>(processedCount, unprocessCount);
  1107. }
  1108. private int GetAtmInerWaferCount()
  1109. {
  1110. int nCount = 0;
  1111. foreach(var atmModule in _atmModules)
  1112. {
  1113. if (!ModuleHelper.IsEFEMRobot(atmModule.Key) && !ModuleHelper.IsLoadPort(atmModule.Key) && WaferManager.Instance.CheckHasWafer(atmModule.Key, 0))
  1114. nCount++;
  1115. }
  1116. return nCount;
  1117. }
  1118. private int CanPushInWaferNumber()
  1119. {
  1120. if (_tmRobot.RobotStatus == RState.Running)
  1121. return 0;
  1122. var llaWaferStatus = GetLLProcessStatusCount(ModuleName.LLA);
  1123. var llbWaferStatus = GetLLProcessStatusCount(ModuleName.LLB);
  1124. var pmWaferStatus = GetPMWaferExistence();
  1125. if(_LLInOutPath == SequenceLLInOutPath.AInBOut)
  1126. {
  1127. return llbWaferStatus.Item1 == _LLBSlotNumber ? 0 :
  1128. _LLASlotNumber + pmWaferStatus.Item2 - llaWaferStatus.Item1 - llaWaferStatus.Item2
  1129. - GetTMRobotWaferCount() - GetAtmInerWaferCount() - GetEfemRoborWaferCount();
  1130. }
  1131. else if(_LLInOutPath == SequenceLLInOutPath.BInAOut)
  1132. {
  1133. return llaWaferStatus.Item1 == _LLASlotNumber ? 0 :
  1134. _LLBSlotNumber + pmWaferStatus.Item2 - llbWaferStatus.Item1 - llbWaferStatus.Item2
  1135. - GetTMRobotWaferCount() - GetAtmInerWaferCount() - GetEfemRoborWaferCount();
  1136. }
  1137. else if(_LLInOutPath == SequenceLLInOutPath.AInAOut || (_LLInOutPath == SequenceLLInOutPath.DInDOut && _vacSchedulers[ModuleName.LLA].IsOnline && !_vacSchedulers[ModuleName.LLB].IsOnline))
  1138. {
  1139. return llaWaferStatus.Item1 > 0 ? 0 :
  1140. _LLASlotNumber / 2 + pmWaferStatus.Item2 - llaWaferStatus.Item2
  1141. - GetTMRobotWaferCount() - GetEfemRoborWaferCount() - GetAtmInerWaferCount();
  1142. }
  1143. else if (_LLInOutPath == SequenceLLInOutPath.BInBOut || (_LLInOutPath == SequenceLLInOutPath.DInDOut && !_vacSchedulers[ModuleName.LLA].IsOnline && _vacSchedulers[ModuleName.LLB].IsOnline))
  1144. {
  1145. return llbWaferStatus.Item1 > 0 ? 0 :
  1146. _LLBSlotNumber / 2 + pmWaferStatus.Item2 - llbWaferStatus.Item2
  1147. -GetTMRobotWaferCount() - GetEfemRoborWaferCount() - GetAtmInerWaferCount();
  1148. }
  1149. else if(_LLInOutPath == SequenceLLInOutPath.DInDOut && _vacSchedulers[ModuleName.LLA].IsOnline && _vacSchedulers[ModuleName.LLB].IsOnline)
  1150. {
  1151. return llaWaferStatus.Item1 + llbWaferStatus.Item1 > 1 ? 0 :
  1152. (_LLASlotNumber + _LLBSlotNumber) / 2 + pmWaferStatus.Item2
  1153. - llaWaferStatus.Item1 - llaWaferStatus.Item2 - llbWaferStatus.Item1 - llbWaferStatus.Item2
  1154. - GetTMRobotWaferCount() - GetEfemRoborWaferCount() - GetAtmInerWaferCount();
  1155. }
  1156. else
  1157. {
  1158. _cycleState = RState.Failed;
  1159. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, "Both LLA/LLB offline, stop runing.");
  1160. return 0;
  1161. }
  1162. }
  1163. private bool IsForwardPathBlocking(ModuleName mod, int slot)
  1164. {
  1165. var wafer = WaferManager.Instance.GetWafer(mod, slot);
  1166. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1167. return false;
  1168. foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  1169. {
  1170. var SlotNumber = GetModuleSlotCount(next_module);
  1171. for(int i = 0; i < SlotNumber; i++)
  1172. {
  1173. if (WaferManager.Instance.CheckNoWafer(next_module, i))
  1174. return false;
  1175. }
  1176. }
  1177. return true;
  1178. }
  1179. private bool ProcessLPEFEMRobotTask(ModuleName lp)
  1180. {
  1181. // check return
  1182. for(int i = 0; i < 2; i++)
  1183. {
  1184. if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != i + 1)
  1185. continue;
  1186. if(WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i))
  1187. {
  1188. var returnWafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  1189. if (returnWafer.IsEmpty)
  1190. continue;
  1191. if (returnWafer.ProcessJob == null || returnWafer.ProcessJob.Sequence == null)
  1192. continue;
  1193. if (returnWafer.NextSequenceStep >= returnWafer.ProcessJob.Sequence.Steps.Count && lp == (ModuleName)returnWafer.OriginStation) // need return
  1194. {
  1195. _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, i, lp, returnWafer.OriginSlot, (Hand)i));
  1196. }
  1197. }
  1198. }
  1199. var canPushInWafers = CanPushInWaferNumber();
  1200. if(_efemMovingItems.Count == 0 && canPushInWafers > 0)
  1201. {
  1202. var outSlots = GetNextWaferInJobQueue(lp);
  1203. var hand = GetEFEMRobotFreeHand();
  1204. if (hand != Hand.None && outSlots.Count > 0 && !IsForwardPathBlocking(lp, outSlots[0]))
  1205. {
  1206. _efemMovingItems.Add(new MoveItem(lp, outSlots[0], ModuleName.EfemRobot, (int)hand, hand));
  1207. }
  1208. if(canPushInWafers > 1)
  1209. {
  1210. hand = GetEFEMRobotFreeHand();
  1211. if (hand != Hand.None && outSlots.Count > 1 && !IsForwardPathBlocking(lp, outSlots[1]))
  1212. {
  1213. _efemMovingItems.Add(new MoveItem(lp, outSlots[1], ModuleName.EfemRobot, (int)hand, hand));
  1214. }
  1215. }
  1216. }
  1217. return _efemMovingItems.Count > 0;
  1218. }
  1219. private List<int> GetNextWaferInJobQueue(ModuleName lp)
  1220. {
  1221. var inSlots = new List<int>();
  1222. foreach (var cj in _lstControlJobs)
  1223. {
  1224. if (lp != ModuleName.System && (cj.Module != lp.ToString()))
  1225. continue;
  1226. if (cj.State == EnumControlJobState.Executing)
  1227. {
  1228. foreach (var pj in _lstProcessJobs)
  1229. {
  1230. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  1231. {
  1232. foreach (var pjSlotWafer in pj.SlotWafers)
  1233. {
  1234. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  1235. {
  1236. var wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1237. if(!wafer.IsEmpty && wafer.NextSequenceStep == 0)
  1238. {
  1239. inSlots.Add(pjSlotWafer.Item2);
  1240. if (inSlots.Count >= 2)
  1241. return inSlots;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }
  1249. return inSlots;
  1250. }
  1251. private bool ProcessAlignerEFEMRobotTask(ModuleName aligner)
  1252. {
  1253. if(WaferManager.Instance.CheckHasWafer(aligner, 0) && IsAtmWaferReadyOut(aligner, 0) && _atmModules[aligner].MovingStatus == MovingStatus.Idle)
  1254. {
  1255. var hand = GetEFEMRobotFreeHand();
  1256. if(hand != Hand.None)
  1257. {
  1258. _efemMovingItems.Add(new MoveItem(aligner, 0, ModuleName.EfemRobot, (int)hand, hand));
  1259. }
  1260. //// check with whether another robot arm wafer wait go to aligner
  1261. //var robotSlots = GetEfemRobotWaferReadyInHands(aligner);
  1262. //if (robotSlots.Count > 0)
  1263. //{
  1264. // _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, robotSlots.First(), aligner, 0, (Hand)robotSlots.First()));
  1265. //}
  1266. }
  1267. else if(WaferManager.Instance.CheckNoWafer(aligner, 0))
  1268. {
  1269. var robotSlots = GetEfemRobotWaferReadyInHands(aligner);
  1270. if(robotSlots.Count > 0)
  1271. {
  1272. _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, robotSlots.First(), aligner, 0, (Hand)robotSlots.First()));
  1273. }
  1274. }
  1275. return _efemMovingItems.Count > 0;
  1276. }
  1277. private bool ProcessCoolingEFEMRobotTask(ModuleName cooling)
  1278. {
  1279. if (WaferManager.Instance.CheckHasWafer(cooling, 0) && IsAtmWaferReadyOut(cooling, 0))
  1280. {
  1281. var hand = GetEFEMRobotFreeHand();
  1282. if (hand != Hand.None)
  1283. {
  1284. _efemMovingItems.Add(new MoveItem(cooling, 0, ModuleName.EfemRobot, (int)hand, hand));
  1285. }
  1286. }
  1287. else
  1288. {
  1289. var robotSlots = GetEfemRobotWaferReadyInHands(cooling);
  1290. if (robotSlots.Count > 0)
  1291. {
  1292. _efemMovingItems.Add(new MoveItem(cooling, 0, ModuleName.EfemRobot, robotSlots.First(), (Hand)robotSlots.First()));
  1293. }
  1294. }
  1295. return _efemMovingItems.Count > 0;
  1296. }
  1297. private void RuningEFEMRobotTask()
  1298. {
  1299. if (_efemRobot.IsAvailable && _efemMovingItems.Count > 0)
  1300. {
  1301. if (_efemRobot.PostMoveItems(_efemMovingItems.ToArray()))
  1302. {
  1303. foreach (var item in _efemMovingItems)
  1304. {
  1305. var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
  1306. if (wafer.IsEmpty)
  1307. {
  1308. // post alarm
  1309. _cycleState = RState.Failed;
  1310. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run EFEM moving task as Get {item.SourceModule}{item.SourceModule} Wafer Info failed");
  1311. return;
  1312. }
  1313. var slot = new SlotItem(item.DestinationModule, item.DestinationSlot);
  1314. _atmWaferTargets[slot] = wafer.InnerId;
  1315. if(ModuleHelper.IsLoadLock(item.Module))
  1316. {
  1317. _vacModules[item.Module].MovingStatus = MovingStatus.Moving;
  1318. }
  1319. }
  1320. }
  1321. }
  1322. }
  1323. private Hand GetEFEMRobotFreeHand()
  1324. {
  1325. for(int i = 0; i < 2; i++)
  1326. {
  1327. if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != i + 1)
  1328. continue;
  1329. if ((WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, i) &&
  1330. !_efemMovingItems.Exists(item => item.DestinationModule == ModuleName.EfemRobot && item.DestinationSlot == i)) ||
  1331. (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i) &&
  1332. _efemMovingItems.Exists(item => item.SourceModule == ModuleName.EfemRobot && item.SourceSlot == i) &&
  1333. !_efemMovingItems.Exists(item => item.DestinationModule == ModuleName.EfemRobot && item.DestinationSlot == i)))
  1334. return (Hand)i;
  1335. }
  1336. return Hand.None;
  1337. }
  1338. private void ProcessAlignerTask()
  1339. {
  1340. foreach(var align in _atmModules)
  1341. {
  1342. if(ModuleHelper.IsAligner(align.Key))
  1343. {
  1344. switch(align.Value.MovingStatus)
  1345. {
  1346. case MovingStatus.WaitAlign:
  1347. if(_efemRobot.IsAvailable)
  1348. {
  1349. WaferInfo wafer = WaferManager.Instance.GetWafer(align.Key, 0);
  1350. if(!wafer.IsEmpty)
  1351. {
  1352. string attr = "AlignAngle";
  1353. string angle = string.Empty;
  1354. int step = wafer.NextSequenceStep;
  1355. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(align.Key))
  1356. {
  1357. step = wafer.NextSequenceStep - 1;
  1358. }
  1359. if (wafer.ProcessJob.Sequence.Steps[step].StepParameter.ContainsKey(attr))
  1360. {
  1361. angle = (string)wafer.ProcessJob.Sequence.Steps[step].StepParameter[attr];
  1362. if (_efemRobot.Align(float.Parse(angle)))
  1363. {
  1364. align.Value.MovingStatus = MovingStatus.StartAlign;
  1365. return;
  1366. }
  1367. }
  1368. }
  1369. align.Value.MovingStatus = MovingStatus.Idle;
  1370. }
  1371. break;
  1372. case MovingStatus.StartAlign:
  1373. if(!_efemRobot.IsAvailable)
  1374. {
  1375. align.Value.MovingStatus = MovingStatus.Aligning;
  1376. }
  1377. break;
  1378. case MovingStatus.Aligning:
  1379. {
  1380. if(_efemRobot.IsAvailable)
  1381. {
  1382. align.Value.MovingStatus = MovingStatus.Idle;
  1383. }
  1384. }
  1385. break;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. #endregion Atm System
  1391. #region Sequence validation
  1392. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  1393. {
  1394. pmUsed = new List<ModuleName>();
  1395. reason = "";
  1396. bool pmIsReady = true;
  1397. for (int i = 0; i < seq.Steps.Count; i++)
  1398. {
  1399. SequenceStepInfo stepInfo = seq.Steps[i];
  1400. bool hasPm = false;
  1401. foreach (var module in stepInfo.StepModules)
  1402. {
  1403. if (!ModuleHelper.IsPm(module))
  1404. {
  1405. hasPm = true;
  1406. break;
  1407. }
  1408. if (ModuleHelper.IsInstalled(module) && (pmOccupied == null || !pmOccupied.Contains(module)))
  1409. {
  1410. hasPm = true;
  1411. }
  1412. if (!pmUsed.Contains(module))
  1413. pmUsed.Add(module);
  1414. }
  1415. if (pmIsReady && !hasPm)
  1416. {
  1417. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1418. pmIsReady = false;
  1419. }
  1420. }
  1421. return pmIsReady;
  1422. }
  1423. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  1424. {
  1425. for (int i = 0; i < seq.Steps.Count; i++)
  1426. {
  1427. SequenceStepInfo stepInfo = seq.Steps[i];
  1428. foreach (var module in stepInfo.StepModules)
  1429. {
  1430. if (ModuleHelper.IsPm(module))
  1431. {
  1432. string attr = $"{module}Recipe";
  1433. if (stepInfo.StepParameter.ContainsKey(attr)
  1434. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1435. {
  1436. var recipeName = (string)stepInfo.StepParameter[attr];
  1437. if (!string.IsNullOrEmpty(recipeName))
  1438. {
  1439. var recipeContent =
  1440. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false);
  1441. if (string.IsNullOrEmpty(recipeContent))
  1442. {
  1443. reason = $"Can not find recipe file{recipeName}";
  1444. return false;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. reason = "";
  1452. return true;
  1453. }
  1454. private bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  1455. {
  1456. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1457. if (wafer.IsEmpty)
  1458. return false;
  1459. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1460. return false;
  1461. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1462. return false;
  1463. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  1464. {
  1465. var hasPmAvailable = false;
  1466. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  1467. {
  1468. if (!ModuleHelper.IsPm(stepModule))
  1469. break;
  1470. if (!_vacSchedulers.Keys.Contains(stepModule))
  1471. continue;
  1472. var pm = _vacSchedulers[stepModule] as SchedulerPM;
  1473. if (pm != null)
  1474. {
  1475. if (_vacModules[stepModule].InUsed)
  1476. {
  1477. hasPmAvailable = true;
  1478. break;
  1479. }
  1480. }
  1481. }
  1482. if (!hasPmAvailable)
  1483. continue;
  1484. if (processIn == ModuleName.System)
  1485. return true;
  1486. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  1487. .Contains(processIn))
  1488. return true;
  1489. }
  1490. return false;
  1491. }
  1492. private List<ModuleName> GetPmUsedInRunningPj()
  1493. {
  1494. var pmUsed = new List<ModuleName>();
  1495. foreach (var cj in _lstControlJobs)
  1496. {
  1497. if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
  1498. continue;
  1499. foreach (var pj in _lstProcessJobs)
  1500. {
  1501. if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
  1502. {
  1503. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  1504. {
  1505. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  1506. foreach (var module in stepInfo.StepModules)
  1507. {
  1508. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  1509. pmUsed.Add(module);
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. return pmUsed;
  1516. }
  1517. private List<SchedulerPM> GetPmNeeded(ControlJobInfo cj)
  1518. {
  1519. List<SchedulerPM> result = new List<SchedulerPM>();
  1520. foreach (var pj in _lstProcessJobs)
  1521. {
  1522. if (pj.ControlJobName != cj.Name)
  1523. continue;
  1524. var seq = pj.Sequence;
  1525. for (int i = 0; i < seq.Steps.Count; i++)
  1526. {
  1527. SequenceStepInfo stepInfo = seq.Steps[i];
  1528. foreach (var module in stepInfo.StepModules)
  1529. {
  1530. if (ModuleHelper.IsPm(module) && _vacSchedulers.ContainsKey(module))
  1531. {
  1532. var pm = _vacSchedulers[module] as SchedulerPM;
  1533. if (pm != null && !result.Contains(pm))
  1534. {
  1535. result.Add(pm);
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. return result;
  1542. }
  1543. private void UpateSequenceStep(List<MoveItem> items)
  1544. {
  1545. foreach(var item in items)
  1546. {
  1547. if(!ModuleHelper.IsTMRobot(item.DestinationModule) && !ModuleHelper.IsEFEMRobot(item.DestinationModule))
  1548. {
  1549. var wafer = WaferManager.Instance.GetWafer(item.DestinationModule, item.DestinationSlot);
  1550. if(!wafer.IsEmpty && wafer.ProcessJob != null)
  1551. {
  1552. if (wafer.NextSequenceStep < wafer.ProcessJob.Sequence.Steps.Count && wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(item.DestinationModule))
  1553. wafer.NextSequenceStep++;
  1554. }
  1555. else
  1556. {
  1557. // should not go here
  1558. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"UpateSequenceStep() failed, location: {item.DestinationModule}:{item.DestinationSlot + 1}, NextSequenceStep: {wafer.NextSequenceStep}");
  1559. }
  1560. }
  1561. }
  1562. }
  1563. private void CheckWaferArrived()
  1564. {
  1565. if (_cycleState != RState.Running)
  1566. return;
  1567. foreach (var mod in _vacSchedulers.Append(new KeyValuePair<ModuleName, SchedulerModule>(ModuleName.TMRobot, _tmRobot)))
  1568. {
  1569. var tars = _vacWaferTargets.Where(item => item.Key.Module == mod.Key).ToArray();
  1570. foreach (var tar in tars)
  1571. {
  1572. var wafer = WaferManager.Instance.GetWafer(tar.Key.Module, tar.Key.Slot);
  1573. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1574. continue;
  1575. if (wafer.InnerId == tar.Value && _tmRobot.RobotStatus != RState.Running)
  1576. {
  1577. // wafer arrive
  1578. _vacWaferTargets.Remove(tar.Key);
  1579. if (!ModuleHelper.IsTMRobot(tar.Key.Module))
  1580. _vacSchedulers[tar.Key.Module].WaferArrived(tar.Key.Slot);
  1581. //LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"wafer {wafer.WaferOrigin}: {wafer.InnerId} arrived {tar.Key.Module}{tar.Key.Slot + 1}");
  1582. if (ModuleHelper.IsPm(tar.Key.Module))
  1583. {
  1584. _vacModules[tar.Key.Module].MovingStatus = MovingStatus.WaitProcess;
  1585. }
  1586. if(!ModuleHelper.IsTMRobot(tar.Key.Module))
  1587. wafer.NextSequenceStep++;
  1588. }
  1589. }
  1590. if(ModuleHelper.IsLoadLock(mod.Key))
  1591. {
  1592. if(!IsLoadLockReservedByTM(mod.Key) && mod.Value.IsAvailable)
  1593. {
  1594. _vacModules[mod.Key].MovingStatus = MovingStatus.Idle;
  1595. }
  1596. }
  1597. }
  1598. _vacMoveFinishTrig.CLK = _vacWaferTargets.Count == 0 && _tmRobot.RobotStatus != RState.Running;
  1599. if (_vacMoveFinishTrig.Q)
  1600. {
  1601. foreach (var item in _movingItems)
  1602. {
  1603. if (_vacModules[item.DestinationModule].MovingStatus == MovingStatus.Moving)
  1604. {
  1605. _vacModules[item.DestinationModule].MovingStatus = MovingStatus.Idle;
  1606. }
  1607. if (_vacModules[item.SourceModule].MovingStatus == MovingStatus.Moving)
  1608. {
  1609. _vacModules[item.SourceModule].MovingStatus = MovingStatus.Idle;
  1610. }
  1611. }
  1612. //UpateSequenceStep(_movingItems);
  1613. _movingItems.Clear();
  1614. }
  1615. foreach (var mod in _atmSchedulers.Append(new KeyValuePair<ModuleName, SchedulerModule>(ModuleName.EfemRobot, _efemRobot)))
  1616. {
  1617. var tars = _atmWaferTargets.Where(item => item.Key.Module == mod.Key).ToArray();
  1618. foreach (var tar in tars)
  1619. {
  1620. var wafer = WaferManager.Instance.GetWafer(tar.Key.Module, tar.Key.Slot);
  1621. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1622. continue;
  1623. if (wafer.InnerId == tar.Value && _efemRobot.RobotStatus != RState.Running)
  1624. {
  1625. //LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"wafer {wafer.WaferOrigin}: {wafer.InnerId} arrived {tar.Key.Module}{tar.Key.Slot + 1}");
  1626. // wafer arrive
  1627. if (!ModuleHelper.IsLoadPort(tar.Key.Module) && !ModuleHelper.IsEFEMRobot(tar.Key.Module))
  1628. _atmSchedulers[tar.Key.Module].WaferArrived(tar.Key.Slot);
  1629. _atmWaferTargets.Remove(tar.Key);
  1630. if (ModuleHelper.IsAligner(tar.Key.Module))
  1631. {
  1632. _atmModules[tar.Key.Module].MovingStatus = MovingStatus.WaitAlign;
  1633. }
  1634. if (!ModuleHelper.IsEFEMRobot(tar.Key.Module))
  1635. wafer.NextSequenceStep++;
  1636. }
  1637. }
  1638. if (ModuleHelper.IsLoadLock(mod.Key))
  1639. {
  1640. if (!IsLoadLockReservedByEFEM(mod.Key) && mod.Value.IsAvailable)
  1641. {
  1642. _vacModules[mod.Key].MovingStatus = MovingStatus.Idle;
  1643. }
  1644. }
  1645. }
  1646. _atmMoveFinishTrig.CLK = _atmWaferTargets.Count == 0 && _efemRobot.RobotStatus != RState.Running;
  1647. if (_atmMoveFinishTrig.Q)
  1648. {
  1649. foreach (var item in _efemMovingItems)
  1650. {
  1651. if (ModuleHelper.IsLoadLock(item.Module))
  1652. {
  1653. _vacModules[item.Module].MovingStatus = MovingStatus.Idle;
  1654. }
  1655. }
  1656. //UpateSequenceStep(_efemMovingItems);
  1657. _efemMovingItems.Clear();
  1658. }
  1659. }
  1660. private void PreJobClean(ControlJobInfo cj)
  1661. {
  1662. if (cj.IsPreJobCleanDone)
  1663. return;
  1664. cj.IsPreJobCleanDone = true;
  1665. List<SchedulerPM> pms = GetPmNeeded(cj);
  1666. foreach (var pm in pms)
  1667. {
  1668. pm.PreJobClean();
  1669. }
  1670. }
  1671. private bool ActiveProcessJob(ProcessJobInfo pj)
  1672. {
  1673. foreach (var pjSlotWafer in pj.SlotWafers)
  1674. {
  1675. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1676. wafer.ProcessJob = pj;
  1677. wafer.NextSequenceStep = 0;
  1678. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1679. }
  1680. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1681. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1682. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1683. pj.SetState(EnumProcessJobState.Processing);
  1684. PreJobClean(cj);
  1685. return true;
  1686. }
  1687. private void StartNewJob()
  1688. {
  1689. ControlJobInfo cjActived = null;
  1690. List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
  1691. foreach (var cj in _lstControlJobs)
  1692. {
  1693. if (cj.State != EnumControlJobState.Executing)
  1694. continue;
  1695. cjActived = cj;
  1696. foreach (var pjName in cjActived.ProcessJobNameList)
  1697. {
  1698. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1699. if (pj == null)
  1700. {
  1701. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cjActived.Name}");
  1702. continue;
  1703. }
  1704. if (pj.State == EnumProcessJobState.Queued)
  1705. {
  1706. if (CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason))
  1707. {
  1708. ActiveProcessJob(pj);
  1709. foreach (var moduleName in pmUsed)
  1710. {
  1711. if (!pmOccupied.Contains(moduleName))
  1712. pmOccupied.Add(moduleName);
  1713. }
  1714. }
  1715. break;
  1716. }
  1717. }
  1718. }
  1719. }
  1720. private static bool IsWaferNeedGotoModule(WaferInfo wafer, ModuleName module)
  1721. {
  1722. if (wafer.IsEmpty)
  1723. return false;
  1724. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1725. return false;
  1726. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1727. return false;
  1728. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  1729. {
  1730. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  1731. .Contains(module))
  1732. return true;
  1733. }
  1734. return false;
  1735. }
  1736. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1737. {
  1738. bool allWaferReturn = true;
  1739. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1740. {
  1741. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1742. if (wafer.IsEmpty)
  1743. continue;
  1744. foreach(var mod in _vacModules)
  1745. {
  1746. if(ModuleHelper.IsPm(mod.Key))
  1747. {
  1748. if (checkAllProcessed && IsWaferNeedGotoModule(wafer, mod.Key))
  1749. {
  1750. mod.Value.InUsed = true;
  1751. allWaferReturn = false;
  1752. }
  1753. }
  1754. }
  1755. }
  1756. return allWaferReturn;
  1757. }
  1758. private void UpdateProcessJobStatus()
  1759. {
  1760. if (_efemRobot.RobotStatus == RState.Running)
  1761. return;
  1762. foreach(var mod in _vacModules)
  1763. {
  1764. if (ModuleHelper.IsPm(mod.Key))
  1765. {
  1766. mod.Value.InUsed = false;
  1767. }
  1768. }
  1769. foreach (var pj in _lstProcessJobs)
  1770. {
  1771. if (pj.State == EnumProcessJobState.Processing)
  1772. {
  1773. if (CheckAllWaferReturned(pj, true))
  1774. {
  1775. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1776. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1777. }
  1778. }
  1779. else if (pj.State == EnumProcessJobState.Stopping)
  1780. {
  1781. if (CheckAllWaferReturned(pj, false))
  1782. {
  1783. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1784. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1785. }
  1786. }
  1787. }
  1788. }
  1789. private void CompleteJobClean(ControlJobInfo cj)
  1790. {
  1791. List<SchedulerPM> pms = GetPmNeeded(cj);
  1792. foreach (var pm in pms)
  1793. {
  1794. pm.CompleteJobClean();
  1795. }
  1796. }
  1797. private void UpdateControlJobStatus()
  1798. {
  1799. if (_lstControlJobs.Count == 0)
  1800. return;
  1801. if (_efemRobot.RobotStatus == RState.Running)
  1802. return;
  1803. bool allControlJobComplete = true;
  1804. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1805. foreach (var cj in _lstControlJobs)
  1806. {
  1807. if (!Singleton<TransferModule>.Instance.GetScheduler(ModuleHelper.Converter(cj.Module)).IsAvailable)
  1808. {
  1809. allControlJobComplete = false;
  1810. continue;
  1811. }
  1812. if (cj.State == EnumControlJobState.Executing)
  1813. {
  1814. bool allPjCompleted = true;
  1815. foreach (var pjName in cj.ProcessJobNameList)
  1816. {
  1817. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1818. if (pj == null)
  1819. {
  1820. LOG.Write( eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1821. continue;
  1822. }
  1823. if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
  1824. {
  1825. allPjCompleted = false;
  1826. break;
  1827. }
  1828. if (allPjCompleted)
  1829. {
  1830. pj.SlotWafers.ForEach(p => {
  1831. if (ModuleHelper.IsLoadPort(p.Item1))
  1832. {
  1833. allPjCompleted = allPjCompleted && WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(p.Item1.ToString()), p.Item2);
  1834. }
  1835. });
  1836. }
  1837. }
  1838. if (allPjCompleted)
  1839. {
  1840. cj.SetState(EnumControlJobState.Completed);
  1841. cj.EndTime = DateTime.Now;
  1842. if (!(_isCycleMode && _cycledCount + 1 < _cycleSetPoint))
  1843. {
  1844. CompleteJobClean(cj);
  1845. }
  1846. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1847. _dbCallback.LotFinished(cj);
  1848. if (!(_isCycleMode && _cycledCount < _cycleSetPoint))
  1849. (Singleton<TransferModule>.Instance.GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
  1850. }
  1851. }
  1852. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1853. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  1854. {
  1855. cjRemoveList.Add(cj);
  1856. }
  1857. allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
  1858. }
  1859. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1860. {
  1861. int countPerCycle = 0;
  1862. int countProcessed = 0;
  1863. foreach (var pj in _lstProcessJobs)
  1864. {
  1865. foreach (var pjSlotWafer in pj.SlotWafers)
  1866. {
  1867. countPerCycle++;
  1868. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1869. if (!wafer.IsEmpty && !IsWaferNeedGotoModule(wafer, ModuleName.PMA) && !IsWaferNeedGotoModule(wafer, ModuleName.PMB) && !IsWaferNeedGotoModule(wafer, ModuleName.PMC) && !IsWaferNeedGotoModule(wafer, ModuleName.PMD))
  1870. countProcessed++;
  1871. }
  1872. }
  1873. int totalCycleWafer = _cycledCount * countPerCycle + countProcessed;
  1874. if(_cycledWafer != totalCycleWafer)
  1875. {
  1876. _cycledWafer = totalCycleWafer;
  1877. if(_cycledWafer >= 25)
  1878. {
  1879. _throughput = (float)(_cycledWafer / _cycleWatch.Elapsed.TotalHours);
  1880. }
  1881. else
  1882. {
  1883. _throughput = 0;
  1884. }
  1885. }
  1886. if (allControlJobComplete)
  1887. {
  1888. _cycledCount++;
  1889. if (_cycledCount < _cycleSetPoint)
  1890. {
  1891. foreach (var cj in _lstControlJobs)
  1892. {
  1893. cj.SetState(EnumControlJobState.Executing);
  1894. cj.LotInnerId = Guid.NewGuid();
  1895. _dbCallback.LotCreated(cj);
  1896. }
  1897. foreach (var pj in _lstProcessJobs)
  1898. {
  1899. pj.SetState(EnumProcessJobState.Queued);
  1900. pj.InnerId = Guid.NewGuid();
  1901. foreach (var pjSlotWafer in pj.SlotWafers)
  1902. {
  1903. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1904. wafer.ProcessJob = null;
  1905. wafer.NextSequenceStep = 0;
  1906. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1907. }
  1908. }
  1909. }
  1910. else
  1911. _cycleState = RState.End;
  1912. }
  1913. }
  1914. foreach (var cj in cjRemoveList)
  1915. {
  1916. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1917. foreach (var pj in _lstProcessJobs)
  1918. {
  1919. if (pj.ControlJobName == cj.Name)
  1920. pjRemoveList.Add(pj);
  1921. }
  1922. foreach (var pj in pjRemoveList)
  1923. {
  1924. _lstProcessJobs.Remove(pj);
  1925. }
  1926. _lstControlJobs.Remove(cj);
  1927. }
  1928. }
  1929. private void UpdateLLInOutPathProperty()
  1930. {
  1931. if (_lstControlJobs.Count == 0)
  1932. return;
  1933. List<SequenceLLInOutPath> inOutPaths = new List<SequenceLLInOutPath>();
  1934. foreach (var cj in _lstControlJobs)
  1935. {
  1936. if (cj.State == EnumControlJobState.Executing)
  1937. {
  1938. bool allPjCompleted = true;
  1939. foreach (var pjName in cj.ProcessJobNameList)
  1940. {
  1941. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1942. if (pj == null || pj.State != EnumProcessJobState.Processing)
  1943. continue;
  1944. if (!inOutPaths.Exists(item => item == pj.Sequence.LLInOutPath))
  1945. inOutPaths.Add(pj.Sequence.LLInOutPath);
  1946. }
  1947. }
  1948. }
  1949. if (inOutPaths.Count == 1)
  1950. {
  1951. _LLInOutPath = inOutPaths[0];
  1952. }
  1953. }
  1954. private static WaferInfo GetCloneWafer(ModuleName mod, int slot)
  1955. {
  1956. var Wafer = WaferManager.Instance.GetWafer(mod, slot);
  1957. if (Wafer.IsEmpty || Wafer.ProcessJob == null || Wafer.ProcessJob.Sequence == null)
  1958. return Wafer;
  1959. var cloneWafer = SerializeHelper.DeepCopyJson(Wafer);
  1960. if (Wafer.IsEmpty || Wafer.ProcessJob == null || Wafer.ProcessJob.Sequence == null)
  1961. return Wafer;
  1962. return cloneWafer;
  1963. }
  1964. #endregion
  1965. }
  1966. }