AutoCycle.cs 92 KB

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