AutoTransfer.cs 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.RecipeCenter;
  7. using Aitex.Core.RT.Routine;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using Aitex.Sorter.Common;
  11. using MECF.Framework.Common.DBCore;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.Jobs;
  14. using MECF.Framework.Common.Schedulers;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Xml;
  21. using VirgoRT.Modules.Schedulers;
  22. using VirgoRT.Scheduler;
  23. namespace VirgoRT.Modules
  24. {
  25. public partial class AutoTransfer : TransferModule
  26. {
  27. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  28. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  29. //private Object _locker = new Object();
  30. private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
  31. private List<SchedulerAligner> _lstAligners = new List<SchedulerAligner>();
  32. private List<SchedulerAligner> _lstCoolings = new List<SchedulerAligner>();
  33. private List<SchedulerLoadPort> _lstLps = new List<SchedulerLoadPort>();
  34. private const string LogSource = "Scheduler";
  35. private bool _isCycleMode;
  36. private int _lp1cycleSetPoint = 0;
  37. private int _lp2cycleSetPoint = 0;
  38. //private int _cycledCount = 0;
  39. //private int _cycledWafer = 0;
  40. private int _lp1cycledWafer = 0;
  41. private int _lp2cycledWafer = 0;
  42. private int _lp1cycledCount = 0;
  43. private int _lp2cycledCount = 0;
  44. private bool _isRunningInParallelMode;
  45. private bool _isFixAlignerAndCooling; // 如果不同的尺寸,就固定住4寸和6寸,用不同的aligner,cooling,PM,避免来回
  46. private Dictionary<ModuleName, ModuleName> _mapLpPm = new Dictionary<ModuleName, ModuleName>();
  47. private Dictionary<ModuleName, ModuleName> _mapLpAligner = new Dictionary<ModuleName, ModuleName>();
  48. private Dictionary<ModuleName, ModuleName> _mapLpCooling = new Dictionary<ModuleName, ModuleName>();
  49. private List<ModuleName> _mapTarget = new List<ModuleName>();
  50. public bool HasJobRunning
  51. {
  52. get { return _lstControlJobs.Count > 0; }
  53. }
  54. private SchedulerFACallback _faCallback;
  55. private SchedulerDBCallback _dbCallback;
  56. public AutoTransfer()
  57. {
  58. _faCallback = new SchedulerFACallback();
  59. _dbCallback = new SchedulerDBCallback();
  60. if (SC.GetValue<bool>("System.PMAIsInstalled"))
  61. _lstPms.Add(_pma);
  62. if (SC.GetValue<bool>("System.PMBIsInstalled"))
  63. _lstPms.Add(_pmb);
  64. _lstAligners.AddRange(new[] { _aligner1, _aligner2 });
  65. _lstCoolings.AddRange(new[] { _cooling1, _cooling2 });
  66. _lstLps.AddRange(new[] { _lp1, _lp2 });
  67. //DATA.Subscribe("Scheduler.CycledCount", () => _cycledCount);
  68. //DATA.Subscribe("Scheduler.CycledWafer", () => _cycledWafer);
  69. DATA.Subscribe("Scheduler.LP1CycledWafer", () => _lp1cycledWafer);
  70. DATA.Subscribe("Scheduler.LP2CycledWafer", () => _lp2cycledWafer);
  71. DATA.Subscribe("Scheduler.LP1CycledCount", () => _lp1cycledCount);
  72. DATA.Subscribe("Scheduler.LP2CycledCount", () => _lp2cycledCount);
  73. DATA.Subscribe("Scheduler.LP1CycleSetPoint", () => _lp1cycleSetPoint);
  74. DATA.Subscribe("Scheduler.LP2CycleSetPoint", () => _lp2cycleSetPoint);
  75. DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
  76. foreach (var lp in _lstLps)
  77. {
  78. DATA.Subscribe($"{lp.Module}.LocalJobName", () =>
  79. {
  80. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Module.ToString());
  81. if (cj != null)
  82. return cj.Name;
  83. return "";
  84. });
  85. DATA.Subscribe($"{lp.Module}.JobLotName", () =>
  86. {
  87. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Module.ToString());
  88. if (cj != null)
  89. return cj.LotName;
  90. return "";
  91. });
  92. DATA.Subscribe($"{lp.Module}.LocalJobStatus", () =>
  93. {
  94. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Module.ToString());
  95. if (cj != null)
  96. return cj.State.ToString();
  97. return "";
  98. });
  99. DATA.Subscribe($"{lp.Module}.CurrentRecipeList", () =>
  100. {
  101. var local = lp;
  102. List<string> result = Enumerable.Repeat("", 25).ToList();
  103. for (int i = 0; i < _lstProcessJobs.Count; i++)
  104. {
  105. foreach (var wafers in _lstProcessJobs[i].SlotWafers)
  106. {
  107. if (wafers.Item1 == local.Module)
  108. {
  109. result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
  110. }
  111. }
  112. }
  113. return result;
  114. });
  115. }
  116. }
  117. public void Clear()
  118. {
  119. _efemRobot.ResetTask();
  120. foreach (var pm in _lstPms)
  121. {
  122. pm.ResetTask();
  123. }
  124. foreach (var buffer in _lstAligners)
  125. {
  126. buffer.ResetTask();
  127. }
  128. foreach (var buffer in _lstCoolings)
  129. {
  130. buffer.ResetTask();
  131. }
  132. foreach (var lp in _lstLps)
  133. {
  134. lp.ResetTask();
  135. }
  136. _lstControlJobs.Clear();
  137. _lstProcessJobs.Clear();
  138. _mapLpAligner.Clear();
  139. _mapLpCooling.Clear();
  140. _mapLpPm.Clear();
  141. _isFixAlignerAndCooling = false;
  142. _isRunningInParallelMode = false;
  143. _mapTarget.Clear();
  144. }
  145. #region Job Management
  146. public void CreateJob(Dictionary<string, object> param)
  147. {
  148. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  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 != 25)
  157. {
  158. EV.PostWarningLog(LogSource, $"slot sequence parameter not valid, length is {slotSequence.Length}, should be 25");
  159. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  160. return;
  161. }
  162. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  163. {
  164. EV.PostWarningLog(LogSource, $"{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. EV.PostWarningLog(LogSource, $"{jobId} already created");
  175. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  176. return;
  177. }
  178. SchedulerLoadPort lp = GetModule(module) as SchedulerLoadPort;
  179. if (!lp.CheckReadyRunJob())
  180. {
  181. EV.PostWarningLog(LogSource, $"{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 < 25; 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[25];
  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. EV.PostWarningLog(LogSource, $"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. EV.PostWarningLog(LogSource, $"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. EV.PostWarningLog(LogSource, $"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. var smallWafer = SC.GetValue<int>($"System.SmallWafer");
  229. //特殊场景,3寸片第一片不能取放
  230. if (i == 0 && (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size == WaferSize.WS3) && (int)smallWafer == 3)
  231. {
  232. EV.PostWarningLog(LogSource, $"job wafer: {module} 3 inch slot {i + 1} is not supported.");
  233. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  234. return;
  235. }
  236. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  237. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
  238. WaferManager.Instance.UpdateWaferLotId(ModuleHelper.Converter(module), i, lotId);
  239. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  240. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  241. }
  242. if (seqSlotWafers.Count == 0)
  243. {
  244. EV.PostWarningLog(LogSource, $"job has not assign wafer");
  245. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  246. return;
  247. }
  248. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  249. string[] seqs = seqSlot.Keys.ToArray();
  250. for (int i = 0; i < seqs.Length; i++)
  251. {
  252. ProcessJobInfo pj = new ProcessJobInfo();
  253. pj.Name = jobId + "_" + (i + 1);
  254. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  255. pj.ControlJobName = cj.Name;
  256. pj.LotName = lotId;
  257. pj.SlotWafers = seqSlotWafers[seqs[i]];
  258. pj.SetState(EnumProcessJobState.Queued);
  259. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  260. {
  261. EV.PostWarningLog(LogSource, $"no valid chamber for the {reason}");
  262. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  263. return;
  264. }
  265. if (SC.GetValue<bool>("System.WaferThickness.EnableThickness"))
  266. {
  267. // sequence must have thickness type
  268. if (string.IsNullOrEmpty(pj.Sequence.ThicknessType))
  269. {
  270. EV.PostWarningLog(LogSource, $"not set valid thickness type in {pj.Sequence.Name}");
  271. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  272. return;
  273. }
  274. if (!lp.CheckOrSetThickness(pj.Sequence.ThicknessType, out string reason1))
  275. {
  276. EV.PostWarningLog(LogSource, $"not set valid thickness type in {pj.Sequence.Name}, {reason1}");
  277. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  278. return;
  279. }
  280. }
  281. if (!CheckSequenceOrderOk(pj.Sequence, out reason))
  282. {
  283. EV.PostWarningLog(LogSource, $"sequence path not valid, {reason}");
  284. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  285. return;
  286. }
  287. if (!SC.GetValue<bool>("System.IsATMMode") && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  288. {
  289. EV.PostWarningLog(LogSource, $"recipe file not valid in the sequence, {reason}");
  290. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  291. return;
  292. }
  293. if (!SetSequenceTemperatureInfo(pj.Sequence, out reason))
  294. {
  295. EV.PostWarningLog(LogSource, $"sequence recipe temperature not valid, {reason}");
  296. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  297. return;
  298. }
  299. pjs.Add(pj);
  300. }
  301. _dbCallback.LotUpdate(cj);
  302. foreach (var pj in pjs)
  303. {
  304. cj.ProcessJobNameList.Add(pj.Name);
  305. _lstProcessJobs.Add(pj);
  306. }
  307. _lstControlJobs.Add(cj);
  308. UpdateParallelMode();
  309. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  310. if (cj.Module == ModuleName.LP1.ToString())
  311. {
  312. _lp1cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  313. _lp1cycledWafer = 0;
  314. _lp1cycledCount = 0;
  315. }else if (cj.Module == ModuleName.LP2.ToString())
  316. {
  317. _lp2cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  318. _lp2cycledWafer = 0;
  319. _lp2cycledCount = 0;
  320. }
  321. }
  322. internal ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  323. {
  324. foreach (var pj in _lstProcessJobs)
  325. {
  326. if (pj.ControlJobName == cj.Name)
  327. return pj;
  328. }
  329. return null;
  330. }
  331. internal void StopJob(string jobName)
  332. {
  333. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  334. if (cj == null)
  335. {
  336. EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
  337. return;
  338. }
  339. foreach (var pj in _lstProcessJobs)
  340. {
  341. if (pj.ControlJobName == cj.Name)
  342. {
  343. pj.SetState(EnumProcessJobState.Stopping);
  344. }
  345. }
  346. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  347. _dbCallback.LotFinished(cj);
  348. }
  349. internal void AbortJob(string jobName)
  350. {
  351. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  352. if (cj == null)
  353. {
  354. EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
  355. return;
  356. }
  357. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  358. foreach (var pj in _lstProcessJobs)
  359. {
  360. if (pj.ControlJobName == cj.Name)
  361. {
  362. pj.SetState(EnumProcessJobState.Aborting);
  363. pjAbortList.Add(pj);
  364. int unprocessed = 0;
  365. int aborted = 0;
  366. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  367. foreach (var waferInfo in wafers)
  368. {
  369. waferInfo.ProcessJob = null;
  370. waferInfo.NextSequenceStep = 0;
  371. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  372. unprocessed++;
  373. }
  374. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  375. }
  376. }
  377. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  378. _dbCallback.LotFinished(cj);
  379. foreach (var pj in pjAbortList)
  380. {
  381. _lstProcessJobs.Remove(pj);
  382. }
  383. _lstControlJobs.Remove(cj);
  384. }
  385. public void ResumeJob(string jobName)
  386. {
  387. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  388. if (cj == null)
  389. {
  390. EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
  391. return;
  392. }
  393. if (cj.State == EnumControlJobState.Paused)
  394. {
  395. cj.SetState(EnumControlJobState.Executing);
  396. }
  397. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  398. }
  399. internal void StartJob(string jobName)
  400. {
  401. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  402. if (cj == null)
  403. {
  404. EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
  405. return;
  406. }
  407. if (cj.State == EnumControlJobState.WaitingForStart)
  408. {
  409. cj.SetState(EnumControlJobState.Executing);
  410. //PreJobClean(cj);
  411. (GetModule(cj.Module) as SchedulerLoadPort).NoteJobStart();
  412. cj.StartTime = DateTime.Now;
  413. _dbCallback.LotCreated(cj);
  414. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  415. }
  416. }
  417. internal void PauseJob(string jobName)
  418. {
  419. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  420. if (cj == null)
  421. {
  422. EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
  423. return;
  424. }
  425. if (cj.State == EnumControlJobState.Executing)
  426. {
  427. cj.SetState(EnumControlJobState.Paused);
  428. }
  429. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  430. }
  431. internal void Map(string moduleName)
  432. {
  433. ModuleName target = ModuleHelper.Converter(moduleName);
  434. if (!ModuleHelper.IsLoadPort(target))
  435. {
  436. EV.PostWarningLog(LogSource, $"Invalid map target {target}");
  437. return;
  438. }
  439. if (!_mapTarget.Contains(target))
  440. {
  441. _mapTarget.Add(target);
  442. }
  443. }
  444. #endregion Job Management
  445. public Result Start(params object[] objs)
  446. {
  447. //_isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  448. //_cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  449. //_cycledWafer = 0;
  450. //_cycledCount = 0;
  451. //_lp1cycledWafer = 0;
  452. //_lp2cycledWafer = 0;
  453. bool hasPmOnline = false;
  454. foreach (var schedulerPm in _lstPms)
  455. {
  456. if (schedulerPm.IsAvailable)
  457. {
  458. schedulerPm.SetPMAuto();
  459. hasPmOnline = true;
  460. continue;
  461. }
  462. }
  463. if (!hasPmOnline)
  464. {
  465. EV.PostWarningLog("Scheduler", "can not change to auto mode, at least one process chamber be online");
  466. return Result.FAIL;
  467. }
  468. return Result.RUN;
  469. }
  470. public Result Monitor()
  471. {
  472. MonitorEfemRobotMapTask();
  473. ControlJobInfo cjActive = _lstControlJobs.Find(x => x.State == EnumControlJobState.Executing);
  474. if (cjActive != null)
  475. {
  476. MonitorModuleTasks();
  477. }
  478. MonitorJobTasks();
  479. MonitorCleanTasks();
  480. return Result.RUN;
  481. }
  482. #region Job task
  483. public Result MonitorJobTasks()
  484. {
  485. UpdateParallelMode();
  486. UpdateProcessJobStatus();
  487. UpdateControlJobStatus();
  488. StartNewJob();
  489. return Result.RUN;
  490. }
  491. private void UpdateParallelMode()
  492. {
  493. bool enableParallel = SC.GetValue<bool>("Scheduler.IsRunInParallelMode");
  494. bool bothLpHasJob = true;
  495. _isRunningInParallelMode = enableParallel;
  496. Dictionary<ModuleName, Dictionary<ModuleName, float>> lpNeededPmTemperature = new Dictionary<ModuleName, Dictionary<ModuleName, float>>();
  497. foreach (var lp in _lstLps)
  498. {
  499. var cj = _lstControlJobs.Find(x => x.Module == lp.Module.ToString());
  500. bothLpHasJob = bothLpHasJob && (cj != null);
  501. if (cj != null)
  502. {
  503. lpNeededPmTemperature[lp.Module] = new Dictionary<ModuleName, float>();
  504. var pj = _lstProcessJobs.FirstOrDefault(x => x.ControlJobName == cj.Name);
  505. if (pj != null)
  506. {
  507. var seq = pj.Sequence;
  508. for (int i = 0; i < seq.Steps.Count; i++)
  509. {
  510. SequenceStepInfo stepInfo = seq.Steps[i];
  511. foreach (var module in stepInfo.StepModules)
  512. {
  513. if (ModuleHelper.IsPm(module) && !lpNeededPmTemperature[lp.Module].ContainsKey(module))
  514. {
  515. lpNeededPmTemperature[lp.Module][module] = (float)seq.Steps[i]
  516. .StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
  517. }
  518. }
  519. }
  520. }
  521. }
  522. }
  523. bool needSamePm = false;
  524. ModuleName pmSource = ModuleName.System;
  525. foreach (var pmNeeded in lpNeededPmTemperature)
  526. {
  527. if (pmNeeded.Value.Count == 1)
  528. {
  529. var source = pmNeeded.Value.Keys.First();
  530. if (source != pmSource)
  531. {
  532. pmSource = source;
  533. }
  534. else
  535. {
  536. needSamePm = true;
  537. break;
  538. }
  539. }
  540. else if (pmNeeded.Value.Count > 1)
  541. {
  542. needSamePm = true;
  543. }
  544. }
  545. var needFixPosition = enableParallel && bothLpHasJob && !needSamePm;
  546. _isRunningInParallelMode = needFixPosition;
  547. if (needFixPosition != _isFixAlignerAndCooling)
  548. {
  549. _isFixAlignerAndCooling = needFixPosition;
  550. if (needFixPosition)
  551. {
  552. //aligner固定不做逻辑
  553. _mapLpAligner[ModuleName.LP1] = ModuleName.Aligner1;
  554. _mapLpAligner[ModuleName.LP2] = ModuleName.Aligner2;
  555. _mapLpCooling[ModuleName.LP1] = ModuleName.Cooling1;
  556. _mapLpCooling[ModuleName.LP2] = ModuleName.Cooling2;
  557. bool assigned = false;
  558. foreach (var pmNeeded in lpNeededPmTemperature)
  559. {
  560. if (pmNeeded.Value.Count == 1)
  561. {
  562. _mapLpPm[pmNeeded.Key] = pmNeeded.Value.Keys.First();
  563. var anotherLp = pmNeeded.Key == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1;
  564. var anotherPm = _mapLpPm[pmNeeded.Key] == ModuleName.PMA ? ModuleName.PMB : ModuleName.PMA;
  565. _mapLpPm[anotherLp] = anotherPm;
  566. assigned = true;
  567. break;
  568. }
  569. }
  570. if (!assigned)
  571. {
  572. _mapLpPm[ModuleName.LP1] = ModuleName.PMA;
  573. _mapLpPm[ModuleName.LP2] = ModuleName.PMB;
  574. float pmaTemp = ((SchedulerPM)GetModule(ModuleName.PMA.ToString())).Temperature;
  575. float pmbTemp = ((SchedulerPM)GetModule(ModuleName.PMB.ToString())).Temperature;
  576. float tempCurrent = Math.Abs(lpNeededPmTemperature[ModuleName.LP1][ModuleName.PMA] - pmaTemp)
  577. + Math.Abs(lpNeededPmTemperature[ModuleName.LP2][ModuleName.PMB] - pmbTemp);
  578. float tempAnother = Math.Abs(lpNeededPmTemperature[ModuleName.LP1][ModuleName.PMB] - pmbTemp)
  579. + Math.Abs(lpNeededPmTemperature[ModuleName.LP2][ModuleName.PMA] - pmaTemp);
  580. if (tempAnother < tempCurrent)
  581. {
  582. _mapLpPm[ModuleName.LP1] = ModuleName.PMB;
  583. _mapLpPm[ModuleName.LP2] = ModuleName.PMA;
  584. }
  585. }
  586. }
  587. }
  588. }
  589. private void UpdateProcessJobStatus()
  590. {
  591. foreach (var pj in _lstProcessJobs)
  592. {
  593. if (pj.State == EnumProcessJobState.Processing)
  594. {
  595. if (CheckAllWaferReturned(pj, true))
  596. {
  597. pj.SetState(EnumProcessJobState.ProcessingComplete);
  598. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  599. }
  600. }
  601. else if (pj.State == EnumProcessJobState.Stopping)
  602. {
  603. if (CheckAllWaferReturned(pj, false))
  604. {
  605. pj.SetState(EnumProcessJobState.ProcessingComplete);
  606. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  607. }
  608. }
  609. }
  610. }
  611. private void UpdateControlJobStatus()
  612. {
  613. if (_lstControlJobs.Count == 0)
  614. return;
  615. bool lp1ControlJobComplete = true;
  616. bool lp2ControlJobComplete = true;
  617. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  618. foreach (var cj in _lstControlJobs)
  619. {
  620. if (!GetModule(cj.Module).IsAvailable)
  621. {
  622. if (cj.Module == ModuleName.LP1.ToString())
  623. lp1ControlJobComplete = false;
  624. else
  625. {
  626. lp2ControlJobComplete = false;
  627. }
  628. continue;
  629. }
  630. if (cj.State == EnumControlJobState.Executing)
  631. {
  632. bool allPjCompleted = true;
  633. foreach (var pjName in cj.ProcessJobNameList)
  634. {
  635. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  636. if (pj == null)
  637. {
  638. LOG.Error($"Not find pj named {pjName} in {cj.Name}");
  639. continue;
  640. }
  641. if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
  642. {
  643. allPjCompleted = false;
  644. break;
  645. }
  646. }
  647. if (allPjCompleted)
  648. {
  649. cj.SetState(EnumControlJobState.Completed);
  650. cj.EndTime = DateTime.Now;
  651. int cycledCount = cj.Module == ModuleName.LP1.ToString() ? _lp1cycledCount : _lp2cycledCount;
  652. int cycleSetPoint = cj.Module == ModuleName.LP1.ToString() ? _lp1cycleSetPoint : _lp2cycleSetPoint;
  653. if (!(_isCycleMode && cycledCount + 1 < cycleSetPoint))
  654. {
  655. CompleteJobClean(cj);
  656. }
  657. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  658. _dbCallback.LotFinished(cj);
  659. if (!(_isCycleMode && cycledCount < cycleSetPoint))
  660. (GetModule(cj.Module) as SchedulerLoadPort).NoteJobComplete();
  661. }
  662. }
  663. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  664. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  665. {
  666. cjRemoveList.Add(cj);
  667. }
  668. if (cj.Module == ModuleName.LP1.ToString())
  669. {
  670. lp1ControlJobComplete = lp1ControlJobComplete && cj.State == EnumControlJobState.Completed;
  671. }
  672. else
  673. {
  674. lp2ControlJobComplete = lp2ControlJobComplete && cj.State == EnumControlJobState.Completed;
  675. }
  676. }
  677. if (_isCycleMode && ((_lp1cycledCount < _lp1cycleSetPoint) || (_lp2cycledCount < _lp2cycleSetPoint)))
  678. {
  679. //int countPerCycle = 0;
  680. int lp1countPerCycle = 0;
  681. int lp2countPerCycle = 0;
  682. //int countProcessed = 0;
  683. int lp1countProcessed = 0;
  684. int lp2countProcessed = 0;
  685. foreach (var pj in _lstProcessJobs)
  686. {
  687. var cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  688. if (cj.Module == ModuleName.LP1.ToString())
  689. {
  690. foreach (var pjSlotWafer in pj.SlotWafers)
  691. {
  692. lp1countPerCycle++;
  693. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  694. if (!wafer.IsEmpty)
  695. {
  696. if (!(wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null))
  697. {
  698. if (!CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  699. {
  700. lp1countProcessed++;
  701. }
  702. }
  703. }
  704. //if (!wafer.IsEmpty && !CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  705. // lp1countProcessed++;
  706. }
  707. }else if (cj.Module == ModuleName.LP2.ToString())
  708. {
  709. foreach (var pjSlotWafer in pj.SlotWafers)
  710. {
  711. lp2countPerCycle++;
  712. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  713. if (!wafer.IsEmpty)
  714. {
  715. if (!(wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null))
  716. {
  717. if (!CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  718. {
  719. lp2countProcessed++;
  720. }
  721. }
  722. }
  723. //if (!wafer.IsEmpty && !CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  724. // lp2countProcessed++;
  725. }
  726. }
  727. //foreach (var pjSlotWafer in pj.SlotWafers)
  728. //{
  729. // countPerCycle++;
  730. // WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  731. // if (!wafer.IsEmpty && !CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  732. // countProcessed++;
  733. //}
  734. }
  735. //_cycledWafer = _cycledCount * countPerCycle + countProcessed;
  736. if (_lp1cycledCount < _lp1cycleSetPoint)
  737. _lp1cycledWafer = _lp1cycledCount * lp1countPerCycle + lp1countProcessed;
  738. if (_lp2cycledCount < _lp2cycleSetPoint)
  739. _lp2cycledWafer = _lp2cycledCount * lp2countPerCycle + lp2countProcessed;
  740. if (lp1ControlJobComplete && (_lp1cycledCount < _lp1cycleSetPoint))
  741. {
  742. _lp1cycledCount++;
  743. if (_lp1cycledCount < _lp1cycleSetPoint)
  744. {
  745. foreach (var cj in _lstControlJobs)
  746. {
  747. if (cj.Module != ModuleName.LP1.ToString())
  748. continue;
  749. cj.SetState(EnumControlJobState.Executing);
  750. cj.LotInnerId = Guid.NewGuid();
  751. //PreJobClean(cj);
  752. _dbCallback.LotCreated(cj);
  753. foreach (var pj in _lstProcessJobs)
  754. {
  755. if (pj.ControlJobName != cj.Name)
  756. continue;
  757. pj.SetState(EnumProcessJobState.Queued);
  758. pj.InnerId = Guid.NewGuid();
  759. foreach (var pjSlotWafer in pj.SlotWafers)
  760. {
  761. WaferInfo wafer =
  762. WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  763. wafer.ProcessJob = null;
  764. wafer.NextSequenceStep = 0;
  765. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  766. }
  767. }
  768. }
  769. }
  770. }
  771. if (lp2ControlJobComplete && (_lp2cycledCount < _lp2cycleSetPoint))
  772. {
  773. _lp2cycledCount++;
  774. if (_lp2cycledCount < _lp2cycleSetPoint)
  775. {
  776. foreach (var cj in _lstControlJobs)
  777. {
  778. if (cj.Module != ModuleName.LP2.ToString())
  779. continue;
  780. cj.SetState(EnumControlJobState.Executing);
  781. cj.LotInnerId = Guid.NewGuid();
  782. //PreJobClean(cj);
  783. _dbCallback.LotCreated(cj);
  784. foreach (var pj in _lstProcessJobs)
  785. {
  786. if (pj.ControlJobName != cj.Name)
  787. continue;
  788. pj.SetState(EnumProcessJobState.Queued);
  789. pj.InnerId = Guid.NewGuid();
  790. foreach (var pjSlotWafer in pj.SlotWafers)
  791. {
  792. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  793. wafer.ProcessJob = null;
  794. wafer.NextSequenceStep = 0;
  795. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  796. }
  797. }
  798. }
  799. }
  800. }
  801. }
  802. foreach (var cj in cjRemoveList)
  803. {
  804. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  805. foreach (var pj in _lstProcessJobs)
  806. {
  807. if (pj.ControlJobName == cj.Name)
  808. pjRemoveList.Add(pj);
  809. }
  810. foreach (var pj in pjRemoveList)
  811. {
  812. _lstProcessJobs.Remove(pj);
  813. }
  814. _lstControlJobs.Remove(cj);
  815. }
  816. if (cjRemoveList.Count > 0)
  817. {
  818. UpdateParallelMode();
  819. }
  820. }
  821. public bool CheckJobJustDone(out string sJobName)
  822. {
  823. foreach (var cj in _lstControlJobs)
  824. {
  825. if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
  826. {
  827. //LP;WaferSize;Lot;Number;Start;End;
  828. sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
  829. cj.BeenPosted = true;
  830. return true;
  831. }
  832. }
  833. //string strInfo = $"{cj.Module} has finished: \r\n\r\nProcessed wafer number: {cj.LotWafers.Count} \r\nStart time: {cj.BeginTime} \r\nEnd time: {cj.EndTime} \r\nDuration: {(cj.EndTime - cj.BeginTime).TotalSeconds:F0} sec";
  834. sJobName = "NULL";
  835. return false;
  836. }
  837. public bool CheckAllJobDone()
  838. {
  839. foreach (var cj in _lstControlJobs)
  840. {
  841. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  842. return false;
  843. }
  844. return true;
  845. }
  846. private void StartNewJob()
  847. {
  848. ControlJobInfo cjActived = null;
  849. List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
  850. foreach (var cj in _lstControlJobs)
  851. {
  852. if (cj.State != EnumControlJobState.Executing)
  853. continue;
  854. cjActived = cj;
  855. foreach (var pjName in cjActived.ProcessJobNameList)
  856. {
  857. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  858. if (pj == null)
  859. {
  860. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  861. continue;
  862. }
  863. if (pj.State == EnumProcessJobState.Queued)
  864. {
  865. if (CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason))
  866. {
  867. ActiveProcessJob(pj);
  868. foreach (var moduleName in pmUsed)
  869. {
  870. if (!pmOccupied.Contains(moduleName))
  871. pmOccupied.Add(moduleName);
  872. }
  873. }
  874. break;
  875. }
  876. }
  877. if (!_isRunningInParallelMode)
  878. break;
  879. }
  880. }
  881. private bool ActiveProcessJob(ProcessJobInfo pj)
  882. {
  883. foreach (var pjSlotWafer in pj.SlotWafers)
  884. {
  885. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  886. wafer.ProcessJob = pj;
  887. wafer.NextSequenceStep = 0;
  888. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  889. }
  890. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  891. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  892. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  893. pj.SetState(EnumProcessJobState.Processing);
  894. PreJobClean(cj);
  895. return true;
  896. }
  897. #endregion Job task
  898. #region Module task
  899. public Result MonitorModuleTasks()
  900. {
  901. MonitorPMTask();
  902. MonitorEfemRobotTask();
  903. MonitorAlignerTask();
  904. MonitorCoolingTask();
  905. MonitorInterlockTask();
  906. return Result.RUN;
  907. }
  908. private void MonitorInterlockTask()
  909. {
  910. foreach (var cj in _lstControlJobs)
  911. {
  912. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused ||
  913. cj.State == EnumControlJobState.WaitingForStart)
  914. {
  915. var lp = GetModule(cj.Module);
  916. if (!(lp as SchedulerLoadPort).CheckPlaced())
  917. {
  918. EV.PostAlarmLog("System", "Cassette removed while job not finished.");
  919. Singleton<RouteManager>.Instance.PostMsg(RouteManager.MSG.ERROR);
  920. }
  921. }
  922. }
  923. }
  924. private void MonitorAlignerTask()
  925. {
  926. foreach (var schedulerBuffer in _lstAligners)
  927. {
  928. if (!schedulerBuffer.IsAvailable
  929. || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
  930. )
  931. continue;
  932. if (CheckWaferNextStepIsAlign(schedulerBuffer.Module, 0))
  933. {
  934. WaferInfo wafer = WaferManager.Instance.GetWafers(schedulerBuffer.Module)[0];
  935. var job = wafer.ProcessJob;
  936. GetWaferSequenceAlignTime(schedulerBuffer.Module, 0, out float time);
  937. if (schedulerBuffer.Align(time))
  938. {
  939. wafer.NextSequenceStep++;
  940. }
  941. }
  942. }
  943. }
  944. private void MonitorCoolingTask()
  945. {
  946. foreach (var schedulerBuffer in _lstCoolings)
  947. {
  948. if (!schedulerBuffer.IsAvailable
  949. || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
  950. )
  951. continue;
  952. if (CheckWaferNextStepIsCooling(schedulerBuffer.Module, 0))
  953. {
  954. WaferInfo wafer = WaferManager.Instance.GetWafers(schedulerBuffer.Module)[0];
  955. var job = wafer.ProcessJob;
  956. GetWaferSequenceAlignTime(schedulerBuffer.Module, 0, out float time);
  957. if (schedulerBuffer.Cooling((int)time))
  958. {
  959. wafer.NextSequenceStep++;
  960. }
  961. }
  962. }
  963. }
  964. private void MonitorEfemRobotTask()
  965. {
  966. if (!_efemRobot.IsAvailable)
  967. return;
  968. //efem robot is idle, release all the target
  969. foreach (var pm in _lstPms)
  970. {
  971. if (pm.IsWaitTransfer(ModuleName.EfemRobot))
  972. {
  973. pm.PostTransfer(ModuleName.EfemRobot);
  974. }
  975. }
  976. foreach (var buffer in _lstCoolings)
  977. {
  978. if (buffer.IsWaitTransfer(ModuleName.EfemRobot))
  979. {
  980. buffer.PostTransfer(ModuleName.EfemRobot);
  981. }
  982. }
  983. foreach (var buffer in _lstAligners)
  984. {
  985. if (buffer.IsWaitTransfer(ModuleName.EfemRobot))
  986. {
  987. buffer.PostTransfer(ModuleName.EfemRobot);
  988. }
  989. }
  990. foreach (var lp in _lstLps)
  991. {
  992. if (lp.IsWaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick))
  993. {
  994. lp.PostTransfer(ModuleName.EfemRobot);
  995. }
  996. if (lp.IsWaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place))
  997. {
  998. lp.PostTransfer(ModuleName.EfemRobot);
  999. ProcessJobInfo pj = WaferManager.Instance.GetWafer(lp.Module, lp.InTransferSlot)
  1000. .ProcessJob;
  1001. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1002. _faCallback.JobWaferEnd(cj, pj, lp.Module.ToString(), lp.InTransferSlot);
  1003. }
  1004. }
  1005. bool blade0HasWaferAndNeedCooling = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  1006. CheckWaferNeedCooling(ModuleName.EfemRobot, 0);
  1007. bool blade1HasWaferAndNeedCooling = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  1008. CheckWaferNeedCooling(ModuleName.EfemRobot, 1);
  1009. if (blade0HasWaferAndNeedCooling || blade1HasWaferAndNeedCooling)
  1010. {
  1011. MonitorEfemRobotCoolingTask();
  1012. if (!_efemRobot.IsAvailable)
  1013. return;
  1014. }
  1015. bool blade0HasWaferAndComplete = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0)
  1016. && !CheckWaferNeedProcess(ModuleName.EfemRobot, 0)
  1017. && !CheckWaferNeedCooling(ModuleName.EfemRobot, 0);
  1018. bool blade1HasWaferAndComplete = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1)
  1019. && !CheckWaferNeedProcess(ModuleName.EfemRobot, 1)
  1020. && !CheckWaferNeedCooling(ModuleName.EfemRobot, 1);
  1021. if (blade0HasWaferAndComplete || blade1HasWaferAndComplete || ModuleHelper.IsLoadPort(_efemRobot.PreviousTarget))
  1022. {
  1023. MonitorEfemRobotLoadPortTask();
  1024. if (!_efemRobot.IsAvailable)
  1025. return;
  1026. }
  1027. //bool blade0HasWaferAndNeedAligner = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  1028. // CheckWaferNeedAlign(ModuleName.EfemRobot, 0);
  1029. //bool blade1HasWaferAndNeedAligner = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  1030. // CheckWaferNeedAlign(ModuleName.EfemRobot, 1);
  1031. //if (blade0HasWaferAndNeedAligner || blade1HasWaferAndNeedAligner)
  1032. //{
  1033. // MonitorEfemRobotAlignerTask();
  1034. // if (!_efemRobot.IsAvailable)
  1035. // return;
  1036. //}
  1037. MonitorEfemRobotAlignerTask();
  1038. if (!_efemRobot.IsAvailable)
  1039. return;
  1040. MonitorEfemRobotPMTask();
  1041. if (!_efemRobot.IsAvailable)
  1042. return;
  1043. MonitorEfemRobotLoadPortTask();
  1044. if (!_efemRobot.IsAvailable)
  1045. return;
  1046. MonitorEfemRobotCoolingTask();
  1047. if (!_efemRobot.IsAvailable)
  1048. return;
  1049. MonitorEfemRobotGotoTask();
  1050. if (!_efemRobot.IsAvailable)
  1051. return;
  1052. }
  1053. private void MonitorEfemRobotMapTask()
  1054. {
  1055. if (!_efemRobot.IsAvailable)
  1056. return;
  1057. if (_mapTarget.Count > 0)
  1058. {
  1059. ModuleName first = _mapTarget[0];
  1060. //避免重复map,job信息被清除
  1061. foreach (var cj in _lstControlJobs)
  1062. {
  1063. if (cj.Module != first.ToString())
  1064. continue;
  1065. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1066. {
  1067. EV.PostWarningLog("System", $"{first} is running, can not map again");
  1068. _mapTarget.Remove(first);
  1069. }
  1070. }
  1071. SchedulerLoadPort lp = GetModule(first.ToString()) as SchedulerLoadPort;
  1072. if (lp != null && lp.IsAvailable)
  1073. {
  1074. _efemRobot.Map(first);
  1075. _mapTarget.Remove(first);
  1076. }
  1077. }
  1078. }
  1079. private void MonitorEfemRobotPMTask()
  1080. {
  1081. if (!_efemRobot.IsAvailable)
  1082. return;
  1083. //swap PM
  1084. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ^ WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  1085. {
  1086. Hand pickBlade = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ? Hand.Blade1 : Hand.Blade2;
  1087. Hand placeBlade = pickBlade == Hand.Blade1 ? Hand.Blade2 : Hand.Blade1;
  1088. SchedulerPM swapPm = null;
  1089. foreach (var pm in _lstPms)
  1090. {
  1091. if (!pm.IsAvailable || !WaferManager.Instance.CheckHasWafer(pm.Module, 0)
  1092. || CheckWaferNeedProcess(pm.Module, 0, pm.Module)
  1093. || !pm.IsReadyForPick(ModuleName.EfemRobot, 0, pickBlade)
  1094. || !CheckVacuumWaferHasAvailableTarget(pm.Module, 0)
  1095. || !CheckWaferNextProcessIn(ModuleName.EfemRobot, (int)placeBlade, pm.Module))
  1096. continue;
  1097. if (swapPm == null || (pm.WaferArriveTicks[0] < swapPm.WaferArriveTicks[0]))
  1098. {
  1099. swapPm = pm;
  1100. }
  1101. }
  1102. if (swapPm != null)
  1103. {
  1104. if (_efemRobot.PickAndPlace(swapPm.Module, 0, 0, pickBlade, placeBlade))
  1105. {
  1106. swapPm.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1107. return;
  1108. }
  1109. }
  1110. }
  1111. //place to pm
  1112. bool blade0HasWaferAndNeedProcess = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0)
  1113. && CheckWaferNeedProcess(ModuleName.EfemRobot, 0);
  1114. bool blade1HasWaferAndNeedProcess = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1)
  1115. && CheckWaferNeedProcess(ModuleName.EfemRobot, 1);
  1116. if (blade0HasWaferAndNeedProcess || blade1HasWaferAndNeedProcess)
  1117. {
  1118. List<Hand> orderedBlade = new List<Hand>();
  1119. if (blade0HasWaferAndNeedProcess && blade1HasWaferAndNeedProcess)
  1120. {
  1121. int result = CompareWaferPriority(ModuleName.EfemRobot, 0, ModuleName.EfemRobot, 1);
  1122. if (result < 0 || (result == 0 && _efemRobot.WaferArriveTicks[1] < _efemRobot.WaferArriveTicks[0]))
  1123. {
  1124. orderedBlade.AddRange(new List<Hand>() { Hand.Blade2, Hand.Blade1 });
  1125. }
  1126. else
  1127. {
  1128. orderedBlade.AddRange(new List<Hand>() { Hand.Blade1, Hand.Blade2 });
  1129. }
  1130. }
  1131. else
  1132. {
  1133. orderedBlade.Add(blade0HasWaferAndNeedProcess ? Hand.Blade1 : Hand.Blade2);
  1134. }
  1135. foreach (Hand placeBlade in orderedBlade)
  1136. {
  1137. foreach (var pm in _lstPms)
  1138. {
  1139. if (!pm.IsAvailable
  1140. || !WaferManager.Instance.CheckNoWafer(pm.Module, 0)
  1141. || !CheckWaferNextProcessIn(ModuleName.EfemRobot, (int)placeBlade, pm.Module))
  1142. continue;
  1143. if (_isFixAlignerAndCooling && GetWaferCountOutofLP(ModuleName.LP1) <= 1 && GetWaferCountOutofLP(ModuleName.LP2) <= 1)
  1144. {
  1145. int origin = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)placeBlade).OriginStation;
  1146. if (origin == (int)ModuleName.LP1 && _mapLpPm[ModuleName.LP1] != pm.Module)
  1147. continue;
  1148. if (origin == (int)ModuleName.LP2 && _mapLpPm[ModuleName.LP2] != pm.Module)
  1149. continue;
  1150. }
  1151. if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, placeBlade))
  1152. continue;
  1153. if (_efemRobot.Place(pm.Module, 0, placeBlade))
  1154. {
  1155. pm.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  1156. return;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. if (!_efemRobot.IsAvailable)
  1162. return;
  1163. //pick from pm
  1164. bool blade1Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  1165. bool blade2Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  1166. if (blade1Empty || blade2Empty)
  1167. {
  1168. ModuleName pickPm = ModuleName.System;
  1169. int preOriginSlot = int.MaxValue;
  1170. string pmPj = string.Empty;
  1171. int preWaferCountInCooling = 0;
  1172. foreach (var schedulerPm in _lstPms)
  1173. {
  1174. if (!schedulerPm.IsAvailable
  1175. || WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0)
  1176. || CheckWaferNeedProcess(schedulerPm.Module, 0, schedulerPm.Module))
  1177. continue;
  1178. WaferInfo wafer = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  1179. bool pickAllowed = CheckVacuumWaferHasAvailableTarget(schedulerPm.Module, 0);
  1180. if (!pickAllowed)
  1181. continue;
  1182. if ((pickPm == ModuleName.System)
  1183. || (wafer.OriginSlot < preOriginSlot && pmPj == wafer.ProcessJob.Name)
  1184. || (GetCoolingWaferCount(wafer.ProcessJob.Name) < preWaferCountInCooling))
  1185. {
  1186. preOriginSlot = wafer.OriginSlot;
  1187. pickPm = schedulerPm.Module;
  1188. pmPj = wafer.ProcessJob.Name;
  1189. preWaferCountInCooling = GetCoolingWaferCount(pmPj);
  1190. continue;
  1191. }
  1192. }
  1193. if (pickPm != ModuleName.System)
  1194. {
  1195. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  1196. if (blade1Empty && blade2Empty)
  1197. {
  1198. if (_efemRobot.WaferArriveTicks[1] < _efemRobot.WaferArriveTicks[0])
  1199. pickBlade = Hand.Blade2;
  1200. }
  1201. SchedulerModule pm = GetModule(pickPm.ToString());
  1202. if (pm.IsReadyForPick(ModuleName.EfemRobot, 0, pickBlade))
  1203. {
  1204. if (_efemRobot.Pick(pm.Module, 0, pickBlade))
  1205. {
  1206. pm.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1207. return;
  1208. }
  1209. }
  1210. }
  1211. }
  1212. }
  1213. private void MonitorEfemRobotLoadPortTask()
  1214. {
  1215. if (!_efemRobot.IsAvailable)
  1216. return;
  1217. //pick
  1218. int maxOutWafer = 6;//cooling*2 + Aligner*2+PM*2
  1219. bool blade1Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  1220. bool blade2Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  1221. bool bothAlignerEmpty = true;
  1222. foreach (var schedulerAligner in _lstAligners)
  1223. {
  1224. if (WaferManager.Instance.CheckHasWafer(schedulerAligner.Module, 0))
  1225. {
  1226. bothAlignerEmpty = false;
  1227. break;
  1228. }
  1229. }
  1230. bool bothBladeEmpty = blade1Empty && blade2Empty;
  1231. if (GetWaferCountOutofLP(ModuleName.System) < maxOutWafer
  1232. && GetWaferCountInJobQueue(ModuleName.System) > 0
  1233. && (bothBladeEmpty || (bothAlignerEmpty && (blade1Empty || blade2Empty))))
  1234. {
  1235. SlotItem position = GetNextWaferInJobQueue(ModuleName.System);
  1236. if (position != null
  1237. && CheckWaferHasAvailableTarget(position.Module, position.Slot)
  1238. && CheckWaferPmTemperatureIsOk(position.Module, position.Slot))
  1239. {
  1240. SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(position.Module.ToString());
  1241. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  1242. if (lp.IsReadyForPick(ModuleName.EfemRobot, position.Slot, pickBlade))
  1243. {
  1244. if (_efemRobot.Pick(position.Module, position.Slot, pickBlade))
  1245. {
  1246. lp.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, position.Slot);
  1247. ProcessJobInfo pj = WaferManager.Instance.GetWafer(position.Module, position.Slot)
  1248. .ProcessJob;
  1249. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1250. _faCallback.JobWaferStart(cj, pj, position.Module.ToString(), position.Slot);
  1251. return;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. if (!_efemRobot.IsAvailable)
  1257. return;
  1258. //place
  1259. bool blade0HasWaferAndProcessed = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0)
  1260. && !CheckWaferNeedProcess(ModuleName.EfemRobot, 0)
  1261. && !CheckWaferNeedCooling(ModuleName.EfemRobot, 0);
  1262. bool blade1HasWaferAndProcessed = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1)
  1263. && !CheckWaferNeedProcess(ModuleName.EfemRobot, 1)
  1264. && !CheckWaferNeedCooling(ModuleName.EfemRobot, 1);
  1265. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  1266. {
  1267. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  1268. if (blade0HasWaferAndProcessed && blade1HasWaferAndProcessed)
  1269. {
  1270. if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
  1271. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
  1272. {
  1273. placeBlade = Hand.Blade2;
  1274. }
  1275. }
  1276. SlotItem destination = GetWaferReturnLoadPort(_efemRobot.Module, (int)placeBlade);
  1277. if (destination != null && ModuleHelper.IsLoadPort(destination.Module))
  1278. {
  1279. SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(destination.Module.ToString());
  1280. if (lp.IsReadyForPlace(ModuleName.EfemRobot, destination.Slot, placeBlade))
  1281. {
  1282. if (_efemRobot.Place(destination.Module, destination.Slot, (Hand)placeBlade))
  1283. {
  1284. lp.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, destination.Slot);
  1285. //_cycledTotalWafer++;
  1286. //if (SC.ContainsItem("System.TotalCycledWafer"))
  1287. // SC.SetItemValue("System.TotalCycledWafer", _cycledTotalWafer);
  1288. return;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. private void MonitorEfemRobotAlignerTask()
  1295. {
  1296. if (!_efemRobot.IsAvailable)
  1297. return;
  1298. //swap Aligner
  1299. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ^ WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  1300. {
  1301. Hand pickBlade = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ? Hand.Blade1 : Hand.Blade2;
  1302. Hand placeBlade = pickBlade == Hand.Blade1 ? Hand.Blade2 : Hand.Blade1;
  1303. SchedulerAligner swapAligner = null;
  1304. foreach (var aligner in _lstAligners)
  1305. {
  1306. if (!aligner.IsAvailable || !WaferManager.Instance.CheckHasWafer(aligner.Module, 0)
  1307. || !aligner.IsReadyForPick(ModuleName.EfemRobot, 0, pickBlade)
  1308. || CheckWaferNeedAlign(aligner.Module, 0)
  1309. || !CheckWaferNeedAlign(ModuleName.EfemRobot, (int)placeBlade))
  1310. continue;
  1311. if (swapAligner == null || (aligner.WaferArriveTicks[0] < swapAligner.WaferArriveTicks[0]))
  1312. {
  1313. swapAligner = aligner;
  1314. }
  1315. }
  1316. if (swapAligner != null)
  1317. {
  1318. if (_efemRobot.PickAndPlace(swapAligner.Module, 0, 0, pickBlade, placeBlade))
  1319. {
  1320. swapAligner.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1321. return;
  1322. }
  1323. }
  1324. }
  1325. //place to aligner
  1326. bool blade0HasWaferAndNeedAligner = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  1327. CheckWaferNeedAlign(ModuleName.EfemRobot, 0);
  1328. bool blade1HasWaferAndNeedAligner = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  1329. CheckWaferNeedAlign(ModuleName.EfemRobot, 1);
  1330. if (blade0HasWaferAndNeedAligner || blade1HasWaferAndNeedAligner)
  1331. {
  1332. foreach (var buffer in _lstAligners)
  1333. {
  1334. if (!buffer.IsAvailable || !WaferManager.Instance.CheckNoWafer(buffer.Module, 0))
  1335. continue;
  1336. List<Hand> orderedBlade = new List<Hand>();
  1337. if (blade0HasWaferAndNeedAligner && blade1HasWaferAndNeedAligner)
  1338. {
  1339. int result = CompareWaferPriority(ModuleName.EfemRobot, 0, ModuleName.EfemRobot, 1);
  1340. if (result < 0 || (result == 0 && _efemRobot.WaferArriveTicks[1] < _efemRobot.WaferArriveTicks[0]))
  1341. {
  1342. orderedBlade.AddRange(new List<Hand>() { Hand.Blade2, Hand.Blade1 });
  1343. }
  1344. else
  1345. {
  1346. orderedBlade.AddRange(new List<Hand>() { Hand.Blade1, Hand.Blade2 });
  1347. }
  1348. }
  1349. else
  1350. {
  1351. orderedBlade.Add(blade0HasWaferAndNeedAligner ? Hand.Blade1 : Hand.Blade2);
  1352. }
  1353. foreach (Hand placeBlade in orderedBlade)
  1354. {
  1355. if (_isFixAlignerAndCooling && GetWaferCountOutofLP(ModuleName.LP1) <= 1 && GetWaferCountOutofLP(ModuleName.LP2) <= 1)
  1356. {
  1357. int origin = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)placeBlade).OriginStation;
  1358. if (origin == (int)ModuleName.LP1 && _mapLpAligner[ModuleName.LP1] != buffer.Module)
  1359. continue;
  1360. if (origin == (int)ModuleName.LP2 && _mapLpAligner[ModuleName.LP2] != buffer.Module)
  1361. continue;
  1362. }
  1363. if (!buffer.IsReadyForPlace(ModuleName.EfemRobot, 0, placeBlade))
  1364. continue;
  1365. if (_efemRobot.Place(buffer.Module, 0, placeBlade))
  1366. {
  1367. buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  1368. return;
  1369. }
  1370. }
  1371. }
  1372. }
  1373. if (!_efemRobot.IsAvailable)
  1374. return;
  1375. //pick from aligner
  1376. bool blade1Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  1377. bool blade2Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  1378. if (blade1Empty || blade2Empty)
  1379. {
  1380. ModuleName pickAligner = ModuleName.System;
  1381. int preOriginSlot = int.MaxValue;
  1382. string prePj = string.Empty;
  1383. int preWaferCountInCooling = 0;
  1384. foreach (var schedulerAligner in _lstAligners)
  1385. {
  1386. if (!schedulerAligner.IsAvailable
  1387. || WaferManager.Instance.CheckNoWafer(schedulerAligner.Module, 0)
  1388. || CheckWaferNeedAlign(schedulerAligner.Module, 0))
  1389. continue;
  1390. WaferInfo wafer = WaferManager.Instance.GetWafer(schedulerAligner.Module, 0);
  1391. bool pickAllowed = CheckBufferWaferHasAvailableTarget(schedulerAligner.Module, 0)
  1392. || (blade1Empty && blade2Empty);
  1393. if (!pickAllowed)
  1394. {
  1395. continue;
  1396. }
  1397. if ((pickAligner == ModuleName.System)
  1398. || (wafer.OriginSlot < preOriginSlot && prePj == wafer.ProcessJob.Name)
  1399. || (GetCoolingWaferCount(wafer.ProcessJob.Name) < preWaferCountInCooling))
  1400. {
  1401. preOriginSlot = wafer.OriginSlot;
  1402. pickAligner = schedulerAligner.Module;
  1403. prePj = wafer.ProcessJob.Name;
  1404. preWaferCountInCooling = GetCoolingWaferCount(prePj);
  1405. continue;
  1406. }
  1407. }
  1408. if (pickAligner != ModuleName.System)
  1409. {
  1410. SchedulerModule buffer = GetModule(pickAligner.ToString());
  1411. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  1412. if (!CheckWaferNeedProcess(ModuleName.EfemRobot, 0) &&
  1413. !CheckWaferNeedProcess(ModuleName.EfemRobot, 1))
  1414. {
  1415. if (buffer.IsReadyForPick(ModuleName.EfemRobot, 0, pickBlade))
  1416. {
  1417. if (_efemRobot.Pick(buffer.Module, 0, pickBlade))
  1418. {
  1419. buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1420. return;
  1421. }
  1422. }
  1423. }
  1424. }
  1425. }
  1426. }
  1427. private void MonitorEfemRobotCoolingTask()
  1428. {
  1429. if (!_efemRobot.IsAvailable)
  1430. return;
  1431. //swap Cooling
  1432. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ^ WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1))
  1433. {
  1434. Hand pickBlade = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) ? Hand.Blade1 : Hand.Blade2;
  1435. Hand placeBlade = pickBlade == Hand.Blade1 ? Hand.Blade2 : Hand.Blade1;
  1436. SchedulerAligner swapCooling = null;
  1437. foreach (var cooling in _lstCoolings)
  1438. {
  1439. if (!cooling.IsAvailable || !WaferManager.Instance.CheckHasWafer(cooling.Module, 0)
  1440. || !cooling.IsReadyForPick(ModuleName.EfemRobot, 0, pickBlade)
  1441. || !CheckWaferNeedCooling(ModuleName.EfemRobot, (int)placeBlade))
  1442. continue;
  1443. if (swapCooling == null || (cooling.WaferArriveTicks[0] < swapCooling.WaferArriveTicks[0]))
  1444. {
  1445. swapCooling = cooling;
  1446. }
  1447. }
  1448. if (swapCooling != null)
  1449. {
  1450. if (_efemRobot.PickAndPlace(swapCooling.Module, 0, 0, pickBlade, placeBlade))
  1451. {
  1452. swapCooling.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1453. return;
  1454. }
  1455. }
  1456. }
  1457. if (!_efemRobot.IsAvailable)
  1458. return;
  1459. //place to cooling
  1460. bool blade0HasWaferAndNeedCooling = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  1461. CheckWaferNeedCooling(ModuleName.EfemRobot, 0);
  1462. bool blade1HasWaferAndNeedCooling = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  1463. CheckWaferNeedCooling(ModuleName.EfemRobot, 1);
  1464. if (blade0HasWaferAndNeedCooling || blade1HasWaferAndNeedCooling)
  1465. {
  1466. foreach (var buffer in _lstCoolings)
  1467. {
  1468. if (!buffer.IsAvailable || !WaferManager.Instance.CheckNoWafer(buffer.Module, 0))
  1469. continue;
  1470. List<Hand> orderedBlade = new List<Hand>();
  1471. if (blade0HasWaferAndNeedCooling && blade1HasWaferAndNeedCooling)
  1472. {
  1473. int result = CompareWaferPriority(ModuleName.EfemRobot, 0, ModuleName.EfemRobot, 1);
  1474. if (result < 0 || (result == 0 && _efemRobot.WaferArriveTicks[1] < _efemRobot.WaferArriveTicks[0]))
  1475. {
  1476. orderedBlade.AddRange(new List<Hand>() { Hand.Blade2, Hand.Blade1 });
  1477. }
  1478. else
  1479. {
  1480. orderedBlade.AddRange(new List<Hand>() { Hand.Blade1, Hand.Blade2 });
  1481. }
  1482. }
  1483. else
  1484. {
  1485. orderedBlade.Add(blade0HasWaferAndNeedCooling ? Hand.Blade1 : Hand.Blade2);
  1486. }
  1487. foreach (Hand placeBlade in orderedBlade)
  1488. {
  1489. if (_isFixAlignerAndCooling && GetWaferCountOutofLP(ModuleName.LP1) <= 1 && GetWaferCountOutofLP(ModuleName.LP2) <= 1)
  1490. {
  1491. int origin = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)placeBlade).OriginStation;
  1492. if (origin == (int)ModuleName.LP1 && _mapLpCooling[ModuleName.LP1] != buffer.Module)
  1493. continue;
  1494. if (origin == (int)ModuleName.LP2 && _mapLpCooling[ModuleName.LP2] != buffer.Module)
  1495. continue;
  1496. }
  1497. if (!buffer.IsReadyForPlace(ModuleName.EfemRobot, 0, placeBlade))
  1498. continue;
  1499. if (_efemRobot.Place(buffer.Module, 0, placeBlade))
  1500. {
  1501. buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  1502. return;
  1503. }
  1504. }
  1505. }
  1506. }
  1507. if (!_efemRobot.IsAvailable)
  1508. return;
  1509. //pick from cooling
  1510. bool blade1Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  1511. bool blade2Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  1512. if (blade1Empty || blade2Empty)
  1513. {
  1514. ModuleName pickBuffer = ModuleName.System;
  1515. int preOriginSlot = int.MaxValue;
  1516. string prePj = string.Empty;
  1517. int preWaferCountInPm = 0;
  1518. foreach (var schedulerBuffer in _lstCoolings)
  1519. {
  1520. if (!schedulerBuffer.IsAvailable
  1521. || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
  1522. || CheckWaferNeedCooling(schedulerBuffer.Module, 0))
  1523. continue;
  1524. WaferInfo wafer = WaferManager.Instance.GetWafer(schedulerBuffer.Module, 0);
  1525. bool pickAllowed = CheckWaferHasAvailableTarget(schedulerBuffer.Module, 0);
  1526. if (!pickAllowed)
  1527. continue;
  1528. if ((pickBuffer == ModuleName.System)
  1529. || (wafer.OriginSlot < preOriginSlot && prePj == wafer.ProcessJob.Name)
  1530. || (GetProcessingWaferCount(wafer.ProcessJob.Name) < preWaferCountInPm))
  1531. {
  1532. preOriginSlot = wafer.OriginSlot;
  1533. pickBuffer = schedulerBuffer.Module;
  1534. prePj = wafer.ProcessJob.Name;
  1535. preWaferCountInPm = GetProcessingWaferCount(prePj);
  1536. continue;
  1537. }
  1538. }
  1539. if (pickBuffer != ModuleName.System)
  1540. {
  1541. SchedulerModule buffer = GetModule(pickBuffer.ToString());
  1542. Hand pickBlade = blade1Empty ? Hand.Blade1 : Hand.Blade2;
  1543. if (buffer.IsReadyForPick(ModuleName.EfemRobot, 0, pickBlade))
  1544. {
  1545. if (_efemRobot.Pick(buffer.Module, 0, pickBlade))
  1546. {
  1547. buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1548. return;
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. private void MonitorEfemRobotGotoTask()
  1555. {
  1556. if (!_efemRobot.IsAvailable)
  1557. return;
  1558. SchedulerPM gotoPm = null;
  1559. int gotoSlot = Int32.MaxValue;
  1560. int gotoModule = -1;
  1561. foreach (var pm in _lstPms)
  1562. {
  1563. WaferInfo wafer = WaferManager.Instance.GetWafer(pm.Module, 0);
  1564. if (wafer.IsEmpty)
  1565. continue;
  1566. if (gotoPm == null)
  1567. {
  1568. gotoPm = pm;
  1569. gotoModule = wafer.OriginStation;
  1570. gotoSlot = wafer.OriginSlot;
  1571. continue;
  1572. }
  1573. if (wafer.OriginSlot < gotoSlot && gotoModule == wafer.OriginStation)
  1574. {
  1575. gotoSlot = wafer.OriginSlot;
  1576. gotoPm = pm;
  1577. }
  1578. }
  1579. if (gotoPm != null)
  1580. {
  1581. if (_efemRobot.PreviousTarget == gotoPm.Module)
  1582. return;
  1583. if (_efemRobot.Goto(gotoPm.Module, 0))
  1584. {
  1585. return;
  1586. }
  1587. }
  1588. }
  1589. private void MonitorPMTask()
  1590. {
  1591. bool robotWaferAssigned = false;
  1592. bool aligner1WaferAssigned = false;
  1593. bool aligner2WaferAssigned = false;
  1594. foreach (var pm in _lstPms)
  1595. {
  1596. if (!pm.IsAvailable)
  1597. continue;
  1598. if (WaferManager.Instance.CheckHasWafer(pm.Module, 0))
  1599. {
  1600. if (CheckWaferNeedProcess(pm.Module, 0, pm.Module))
  1601. {
  1602. WaferInfo wafer = WaferManager.Instance.GetWafer(pm.Module, 0);
  1603. var recipeName = pm.Module == ModuleName.PMA
  1604. ? wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["PMARecipe"]
  1605. : wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["PMBRecipe"];
  1606. if (pm.Process((string)recipeName, false, true, wafer))
  1607. {
  1608. WaferManager.Instance.GetWafer(pm.Module, 0).NextSequenceStep++;
  1609. continue;
  1610. }
  1611. }
  1612. else
  1613. {
  1614. if (!pm.IsReadyForPick(ModuleName.EfemRobot, 0, Hand.Blade1))
  1615. {
  1616. pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  1617. }
  1618. }
  1619. }
  1620. else //no wafer
  1621. {
  1622. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)
  1623. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1)
  1624. && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner1, 0)
  1625. && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner2, 0))
  1626. {
  1627. ModuleName source = ModuleName.System;
  1628. if (_isFixAlignerAndCooling)
  1629. {
  1630. foreach (var moduleName in _mapLpPm)
  1631. {
  1632. if (moduleName.Value == pm.Module)
  1633. source = moduleName.Key;
  1634. }
  1635. }
  1636. SlotItem item = GetNextWaferInJobQueue(source);
  1637. if (item != null && CheckWaferNeedProcess(item.Module, item.Slot, pm.Module))
  1638. {
  1639. if (GetWaferTemperatureSetInRecipe(item.Module, item.Slot, pm.Module, out float temp) && !pm.IsTemperatureReady(temp))
  1640. {
  1641. pm.Preheating(temp);
  1642. continue;
  1643. }
  1644. }
  1645. }
  1646. if (!pm.IsAvailable)
  1647. continue;
  1648. if (!robotWaferAssigned
  1649. && CheckWaferNeedProcess(ModuleName.EfemRobot, 0, pm.Module)
  1650. && CheckWaferNextProcessIn(ModuleName.EfemRobot, 0, pm.Module))
  1651. {
  1652. robotWaferAssigned = true;
  1653. GetWaferTemperatureSetInRecipe(ModuleName.EfemRobot, 0, pm.Module, out float temp);
  1654. bool alreadyPrepare = false;
  1655. foreach (var schedulerPm in _lstPms)
  1656. {
  1657. if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
  1658. || (!_efemRobot.IsAvailable)
  1659. || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(pm.Module, 0) && pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1)))
  1660. alreadyPrepare = true;
  1661. }
  1662. if (!alreadyPrepare)
  1663. {
  1664. if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1) || !pm.IsTemperatureReady(temp))
  1665. {
  1666. pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).Size);
  1667. }
  1668. }
  1669. }
  1670. if (!pm.IsAvailable)
  1671. continue;
  1672. if (!robotWaferAssigned
  1673. && CheckWaferNeedProcess(ModuleName.EfemRobot, 1, pm.Module)
  1674. && CheckWaferNextProcessIn(ModuleName.EfemRobot, 1, pm.Module))
  1675. {
  1676. robotWaferAssigned = true;
  1677. GetWaferTemperatureSetInRecipe(ModuleName.EfemRobot, 1, pm.Module, out float temp);
  1678. bool alreadyPrepare = false;
  1679. foreach (var schedulerPm in _lstPms)
  1680. {
  1681. if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
  1682. || (!_efemRobot.IsAvailable)
  1683. || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(pm.Module, 0) && pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade2)))
  1684. alreadyPrepare = true;
  1685. }
  1686. if (!alreadyPrepare)
  1687. {
  1688. if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade2) ||
  1689. !pm.IsTemperatureReady(temp))
  1690. {
  1691. pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade2,
  1692. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).Size);
  1693. }
  1694. }
  1695. }
  1696. if (!pm.IsAvailable)
  1697. continue;
  1698. //并行模式下,避免提前预判aligner的wafer位置
  1699. if (_isRunningInParallelMode)
  1700. continue;
  1701. if (!aligner1WaferAssigned && CheckWaferNeedProcess(ModuleName.Aligner1, 0, pm.Module))
  1702. {
  1703. aligner1WaferAssigned = true;
  1704. GetWaferTemperatureSetInRecipe(ModuleName.Aligner1, 0, pm.Module, out float temp);
  1705. bool alreadyPrepare = false;
  1706. foreach (var schedulerPm in _lstPms)
  1707. {
  1708. if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
  1709. || (!_efemRobot.IsAvailable)
  1710. || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(pm.Module, 0) && pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1)))
  1711. alreadyPrepare = true;
  1712. }
  1713. if (!alreadyPrepare)
  1714. {
  1715. if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1) ||
  1716. !pm.IsTemperatureReady(temp))
  1717. {
  1718. pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade1,
  1719. WaferManager.Instance.GetWafer(ModuleName.Aligner1, 0).Size);
  1720. }
  1721. }
  1722. }
  1723. if (!pm.IsAvailable)
  1724. continue;
  1725. if (!aligner2WaferAssigned && CheckWaferNeedProcess(ModuleName.Aligner2, 0, pm.Module))
  1726. {
  1727. aligner2WaferAssigned = true;
  1728. GetWaferTemperatureSetInRecipe(ModuleName.Aligner2, 0, pm.Module, out float temp);
  1729. bool alreadyPrepare = false;
  1730. foreach (var schedulerPm in _lstPms)
  1731. {
  1732. if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
  1733. || (!_efemRobot.IsAvailable)
  1734. || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(pm.Module, 0) && pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1)))
  1735. alreadyPrepare = true;
  1736. }
  1737. if (!alreadyPrepare)
  1738. {
  1739. if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1) ||
  1740. !pm.IsTemperatureReady(temp))
  1741. {
  1742. pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade1,
  1743. WaferManager.Instance.GetWafer(ModuleName.Aligner2, 0).Size);
  1744. }
  1745. }
  1746. }
  1747. if (!pm.IsAvailable)
  1748. continue;
  1749. }
  1750. }
  1751. }
  1752. #endregion Module task
  1753. #region Logic Check
  1754. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  1755. {
  1756. pmUsed = new List<ModuleName>();
  1757. reason = "";
  1758. bool pmIsReady = true;
  1759. for (int i = 0; i < seq.Steps.Count; i++)
  1760. {
  1761. SequenceStepInfo stepInfo = seq.Steps[i];
  1762. bool hasPm = false;
  1763. foreach (var module in stepInfo.StepModules)
  1764. {
  1765. if (!ModuleHelper.IsPm(module))
  1766. {
  1767. hasPm = true;
  1768. break;
  1769. }
  1770. PM pm = DEVICE.GetDevice<PM>(module.ToString());
  1771. if (pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(module)))
  1772. {
  1773. hasPm = true;
  1774. }
  1775. if (!pmUsed.Contains(module))
  1776. pmUsed.Add(module);
  1777. }
  1778. if (pmIsReady && !hasPm)
  1779. {
  1780. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1781. pmIsReady = false;
  1782. }
  1783. }
  1784. return pmIsReady;
  1785. }
  1786. private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
  1787. {
  1788. reason = "";
  1789. bool foundPm = false;
  1790. bool isAlignerAfterPm = false;
  1791. for (int i = 0; i < seq.Steps.Count; i++)
  1792. {
  1793. SequenceStepInfo stepInfo = seq.Steps[i];
  1794. foreach (var module in stepInfo.StepModules)
  1795. {
  1796. if (ModuleHelper.IsPm(module))
  1797. {
  1798. foundPm = true;
  1799. }
  1800. if (ModuleHelper.IsAligner(module) && foundPm)
  1801. {
  1802. isAlignerAfterPm = true;
  1803. }
  1804. }
  1805. }
  1806. if (!foundPm)
  1807. {
  1808. reason = $"not found PM in the sequence file;";
  1809. }
  1810. if (isAlignerAfterPm)
  1811. {
  1812. reason += "Aligner after PM not support";
  1813. }
  1814. return true;
  1815. }
  1816. protected int GetUnprocessedWaferCount()
  1817. {
  1818. int count = 0;
  1819. foreach (ProcessJobInfo pj in _lstProcessJobs)
  1820. {
  1821. if (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused)
  1822. count += GetUnprocessedWaferCount(pj);
  1823. }
  1824. return count;
  1825. }
  1826. protected int GetUnprocessedWaferCount(ProcessJobInfo pj)
  1827. {
  1828. int count = 0;
  1829. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1830. {
  1831. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1832. if (wafer.IsEmpty)
  1833. continue;
  1834. if (CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
  1835. count++;
  1836. }
  1837. return count;
  1838. }
  1839. protected bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1840. {
  1841. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1842. {
  1843. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1844. if (wafer.IsEmpty)
  1845. return false;
  1846. if (checkAllProcessed && CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
  1847. return false;
  1848. }
  1849. return true;
  1850. }
  1851. private bool CheckWaferNextStepIsAlign(ModuleName module, int slot)
  1852. {
  1853. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  1854. return false;
  1855. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  1856. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1857. return false;
  1858. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1859. return false;
  1860. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1)
  1861. || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2))
  1862. return true;
  1863. return false;
  1864. }
  1865. private bool CheckWaferNextStepIsCooling(ModuleName module, int slot)
  1866. {
  1867. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  1868. return false;
  1869. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  1870. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1871. return false;
  1872. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1873. return false;
  1874. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1)
  1875. || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
  1876. return true;
  1877. return false;
  1878. }
  1879. private bool GetWaferTemperatureSetInRecipe(ModuleName waferModule, int waferSlot, ModuleName pmModule, out float temp)
  1880. {
  1881. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1882. var seq = wafer.ProcessJob.Sequence;
  1883. for (int i = 0; i < seq.Steps.Count; i++)
  1884. {
  1885. SequenceStepInfo stepInfo = seq.Steps[i];
  1886. foreach (var module in stepInfo.StepModules)
  1887. {
  1888. if (module == pmModule)
  1889. {
  1890. temp = (float)seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
  1891. return true;
  1892. }
  1893. }
  1894. }
  1895. temp = 0;
  1896. LOG.Error($"Can not find wafer {waferModule} {waferSlot + 1} temperature set in recipe");
  1897. return false;
  1898. }
  1899. private bool CheckWaferPmTemperatureIsOk(ModuleName waferModule, int waferSlot)
  1900. {
  1901. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1902. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1903. return false;
  1904. var seq = wafer.ProcessJob.Sequence;
  1905. for (int i = 0; i < seq.Steps.Count; i++)
  1906. {
  1907. SequenceStepInfo stepInfo = seq.Steps[i];
  1908. bool stepOk = false;
  1909. foreach (var module in stepInfo.StepModules)
  1910. {
  1911. if (ModuleHelper.IsPm(module))
  1912. {
  1913. float tempNeeded = (float)seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
  1914. if ((GetModule(module.ToString()) as SchedulerPM).IsTemperatureReady(tempNeeded))
  1915. {
  1916. stepOk = true;
  1917. break;
  1918. }
  1919. }
  1920. else
  1921. {
  1922. stepOk = true;
  1923. }
  1924. }
  1925. if (!stepOk)
  1926. return false;
  1927. }
  1928. return true;
  1929. }
  1930. private bool CheckWaferNeedAlign(ModuleName waferModule, int waferSlot)
  1931. {
  1932. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1933. if (wafer.IsEmpty)
  1934. return false;
  1935. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1936. return false;
  1937. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1938. return false;
  1939. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
  1940. .Contains(ModuleName.Aligner1) && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
  1941. .Contains(ModuleName.Aligner2))
  1942. return false;
  1943. return true;
  1944. }
  1945. private bool CheckWaferNeedCooling(ModuleName waferModule, int waferSlot)
  1946. {
  1947. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1948. if (wafer.IsEmpty)
  1949. return false;
  1950. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1951. return false;
  1952. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1953. return false;
  1954. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
  1955. .Contains(ModuleName.Cooling1) && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
  1956. .Contains(ModuleName.Cooling2))
  1957. return false;
  1958. return true;
  1959. }
  1960. private bool CheckWaferNextProcessIn(ModuleName waferModule, int waferSlot, ModuleName chamber)
  1961. {
  1962. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1963. if (wafer.IsEmpty ||
  1964. wafer.ProcessJob == null ||
  1965. wafer.ProcessJob.Sequence == null ||
  1966. wafer.ProcessJob.Sequence.Steps == null ||
  1967. wafer.ProcessJob.Sequence.Steps.Count <= wafer.NextSequenceStep ||
  1968. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep] == null ||
  1969. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  1970. {
  1971. return false;
  1972. }
  1973. if (_isFixAlignerAndCooling && _mapLpPm[(ModuleName)wafer.OriginStation] != chamber)
  1974. return false;
  1975. return wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(chamber);
  1976. }
  1977. public bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  1978. {
  1979. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  1980. if (wafer.IsEmpty)
  1981. return false;
  1982. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1983. return false;
  1984. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1985. return false;
  1986. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  1987. {
  1988. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  1989. .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
  1990. .Contains(ModuleName.PMB))
  1991. {
  1992. var hasPmAvailable = false;
  1993. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  1994. {
  1995. var pm = GetModule(stepModule.ToString()) as SchedulerPM;
  1996. if (pm != null)
  1997. {
  1998. if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
  1999. {
  2000. hasPmAvailable = true;
  2001. break;
  2002. }
  2003. }
  2004. }
  2005. if (!hasPmAvailable)
  2006. return false;
  2007. if (processIn == ModuleName.System)
  2008. return true;
  2009. if (_isFixAlignerAndCooling && _mapLpPm[(ModuleName)wafer.OriginStation] != processIn)
  2010. return false;
  2011. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  2012. .Contains(processIn))
  2013. return true;
  2014. }
  2015. }
  2016. return false;
  2017. }
  2018. public bool CheckWaferNeedProcess(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  2019. {
  2020. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  2021. if (wafer.IsEmpty)
  2022. return false;
  2023. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  2024. return false;
  2025. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  2026. return false;
  2027. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  2028. {
  2029. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  2030. .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
  2031. .Contains(ModuleName.PMB))
  2032. {
  2033. if (processIn == ModuleName.System)
  2034. return true;
  2035. if (_isFixAlignerAndCooling && _mapLpPm[(ModuleName)wafer.OriginStation] != processIn)
  2036. return false;
  2037. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  2038. .Contains(processIn))
  2039. return true;
  2040. }
  2041. }
  2042. return false;
  2043. }
  2044. private bool CheckVacuumWaferHasAvailableTarget(ModuleName waferModule, int waferSlot)
  2045. {
  2046. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  2047. //System.Diagnostics.Trace.Assert(!wafer.IsEmpty);
  2048. //if (CheckWaferNeedProcess(waferModule, waferSlot))
  2049. //{
  2050. // // Check for an empty PM
  2051. // foreach (var pm in _lstPms)
  2052. // {
  2053. // if (WaferManager.Instance.CheckNoWafer(pm.Module, 0))
  2054. // {
  2055. // if (pm.IsAvailable == false)
  2056. // continue;
  2057. // if (!CheckWaferNextProcessIn(waferModule, waferSlot, pm.Module))
  2058. // continue;
  2059. // return true;
  2060. // }
  2061. // }
  2062. //}
  2063. //else
  2064. {
  2065. // No more processing needed, check for a outbound BUFFER slot
  2066. foreach (var buffer in _lstCoolings)
  2067. {
  2068. if (!buffer.IsAvailable)
  2069. continue;
  2070. if (WaferManager.Instance.CheckNoWafer(buffer.Module, 0))
  2071. {
  2072. return true;
  2073. }
  2074. }
  2075. }
  2076. return false;
  2077. }
  2078. private bool CheckWaferHasAvailableTarget(ModuleName waferModule, int waferSlot)
  2079. {
  2080. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  2081. if (wafer.IsEmpty)
  2082. return false;
  2083. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  2084. return false;
  2085. //sequence done, return LP
  2086. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  2087. return true;
  2088. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  2089. {
  2090. if (WaferManager.Instance.CheckNoWafer(stepModule, 0))
  2091. return true;
  2092. }
  2093. return false;
  2094. }
  2095. private bool CheckBufferWaferHasAvailableTarget(ModuleName waferModule, int waferSlot)
  2096. {
  2097. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  2098. //System.Diagnostics.Trace.Assert(!wafer.IsEmpty);
  2099. if (!CheckWaferNeedProcess(waferModule, waferSlot))
  2100. return true;
  2101. // Check for an empty PM
  2102. foreach (var pm in _lstPms)
  2103. {
  2104. if (WaferManager.Instance.CheckNoWafer(pm.Module, 0))
  2105. {
  2106. if (pm.IsAvailable == false)
  2107. continue;
  2108. if (!CheckWaferNextProcessIn(waferModule, waferSlot, pm.Module))
  2109. continue;
  2110. return true;
  2111. }
  2112. }
  2113. return false;
  2114. }
  2115. private bool SetSequenceTemperatureInfo(SequenceInfo seq, out string reason)
  2116. {
  2117. for (int i = 0; i < seq.Steps.Count; i++)
  2118. {
  2119. SequenceStepInfo stepInfo = seq.Steps[i];
  2120. foreach (var module in stepInfo.StepModules)
  2121. {
  2122. if (ModuleHelper.IsPm(module))
  2123. {
  2124. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  2125. if (stepInfo.StepParameter.ContainsKey(attr)
  2126. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  2127. {
  2128. var recipeName = (string)stepInfo.StepParameter[attr];
  2129. if (!string.IsNullOrEmpty(recipeName))
  2130. {
  2131. var recipeContent =
  2132. RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
  2133. if (string.IsNullOrEmpty(recipeContent))
  2134. {
  2135. reason = $"Can not find recipe file{recipeName}";
  2136. return false;
  2137. }
  2138. try
  2139. {
  2140. XmlDocument xml = new XmlDocument();
  2141. xml.LoadXml(recipeContent);
  2142. var substrateTemp = xml.DocumentElement.HasAttribute("SubstrateTemp") ? xml.DocumentElement.Attributes["SubstrateTemp"].Value : "";
  2143. if (!float.TryParse(substrateTemp, out float temp))
  2144. {
  2145. reason = $"Invalid substrate temperature in recipe head {recipeName}";
  2146. return false;
  2147. }
  2148. seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"] = temp;
  2149. }
  2150. catch (Exception ex)
  2151. {
  2152. LOG.Write(ex);
  2153. reason = $"recipe not valid, {recipeName}";
  2154. return false;
  2155. }
  2156. }
  2157. }
  2158. }
  2159. }
  2160. }
  2161. reason = "";
  2162. return true;
  2163. }
  2164. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  2165. {
  2166. for (int i = 0; i < seq.Steps.Count; i++)
  2167. {
  2168. SequenceStepInfo stepInfo = seq.Steps[i];
  2169. foreach (var module in stepInfo.StepModules)
  2170. {
  2171. if (ModuleHelper.IsPm(module))
  2172. {
  2173. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  2174. if (stepInfo.StepParameter.ContainsKey(attr)
  2175. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  2176. {
  2177. var recipeName = (string)stepInfo.StepParameter[attr];
  2178. if (!string.IsNullOrEmpty(recipeName))
  2179. {
  2180. var recipeContent =
  2181. RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
  2182. if (string.IsNullOrEmpty(recipeContent))
  2183. {
  2184. reason = $"Can not find recipe file{recipeName}";
  2185. return false;
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. }
  2192. reason = "";
  2193. return true;
  2194. }
  2195. private bool GetWaferSequenceAlignTime(ModuleName module, int slot, out float time)
  2196. {
  2197. time = 0;
  2198. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  2199. return false;
  2200. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  2201. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  2202. return false;
  2203. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  2204. return false;
  2205. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1)
  2206. && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2)
  2207. && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1)
  2208. && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
  2209. return false;
  2210. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter.ContainsKey("CoolingTime"))
  2211. return false;
  2212. if (!float.TryParse((string)wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["CoolingTime"],
  2213. out time))
  2214. return false;
  2215. return true;
  2216. }
  2217. private int GetWaferCountOutofLP(ModuleName lp)
  2218. {
  2219. int count = 0;
  2220. var lstPosition = new List<ModuleName>()
  2221. {
  2222. ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2, ModuleName.PMA, ModuleName.PMB,
  2223. };
  2224. foreach (var moduleName in lstPosition)
  2225. {
  2226. if (ModuleHelper.IsPm(moduleName) && !GetModule(moduleName.ToString()).IsOnline)
  2227. continue;
  2228. if (WaferManager.Instance.CheckHasWafer(moduleName, 0))
  2229. {
  2230. if (lp == ModuleName.System ||
  2231. WaferManager.Instance.GetWafer(moduleName, 0).OriginStation == (int)lp)
  2232. count++;
  2233. }
  2234. }
  2235. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  2236. {
  2237. if (lp == ModuleName.System ||
  2238. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginStation == (int)lp)
  2239. count++;
  2240. }
  2241. return count;
  2242. }
  2243. private SlotItem GetWaferReturnLoadPort(ModuleName module, int slot)
  2244. {
  2245. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  2246. if (!wafer.IsEmpty)
  2247. {
  2248. return new SlotItem((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  2249. }
  2250. return null;
  2251. }
  2252. private int GetWaferCountInJobQueue(ModuleName sourceLp)
  2253. {
  2254. int count = 0;
  2255. foreach (var lp in _lstLps)
  2256. {
  2257. for (int i = 0; i < 25; i++)
  2258. {
  2259. if (CheckWaferNeedProcess(lp.Module, i) && (sourceLp == ModuleName.System || sourceLp == lp.Module))
  2260. count++;
  2261. }
  2262. }
  2263. return count;
  2264. }
  2265. /// <summary>
  2266. /// 获取下一个Wafer。根据某个LP,或者任意LP
  2267. /// </summary>
  2268. /// <param name="lpModule">如果是System,表示查询的时候根据任意LoadPort</param>
  2269. /// <returns></returns>
  2270. private SlotItem GetNextWaferInJobQueue(ModuleName lpModule)
  2271. {
  2272. if (!_isRunningInParallelMode)
  2273. {
  2274. foreach (var cj in _lstControlJobs)
  2275. {
  2276. if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
  2277. continue;
  2278. if (cj.State == EnumControlJobState.Executing)
  2279. {
  2280. foreach (var pj in _lstProcessJobs)
  2281. {
  2282. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  2283. {
  2284. foreach (var pjSlotWafer in pj.SlotWafers)
  2285. {
  2286. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  2287. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. return null;
  2294. }
  2295. //parallel mode
  2296. Dictionary<string, SlotItem> pjWafer = new Dictionary<string, SlotItem>();
  2297. Dictionary<string, List<ModuleName>> pmUsed = new Dictionary<string, List<ModuleName>>();
  2298. foreach (var cj in _lstControlJobs)
  2299. {
  2300. if (cj.State != EnumControlJobState.Executing)
  2301. continue;
  2302. foreach (var pj in _lstProcessJobs)
  2303. {
  2304. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  2305. {
  2306. foreach (var pjSlotWafer in pj.SlotWafers)
  2307. {
  2308. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  2309. {
  2310. pjWafer[pj.Name] = new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  2311. break;
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. if (pjWafer.Count == 0)
  2318. return null;
  2319. if (pjWafer.Count == 1)
  2320. return pjWafer.Values.First();
  2321. string preferPj = pjWafer.Keys.First();
  2322. int runningWaferCount = GetWaitingProcessWaferCount(preferPj);
  2323. foreach (var slotItem in pjWafer)
  2324. {
  2325. if (slotItem.Key == preferPj)
  2326. continue;
  2327. int count = GetWaitingProcessWaferCount(slotItem.Key);
  2328. if (count < runningWaferCount)
  2329. {
  2330. preferPj = slotItem.Key;
  2331. runningWaferCount = count;
  2332. }
  2333. }
  2334. return pjWafer[preferPj];
  2335. }
  2336. private int GetWaitingProcessWaferCount(string pjName)
  2337. {
  2338. List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
  2339. {
  2340. Tuple.Create(ModuleName.EfemRobot, 0),
  2341. Tuple.Create(ModuleName.EfemRobot, 1),
  2342. Tuple.Create(ModuleName.Aligner1, 0),
  2343. Tuple.Create(ModuleName.Aligner2, 0),
  2344. Tuple.Create(ModuleName.PMA, 0),
  2345. Tuple.Create(ModuleName.PMB, 0),
  2346. };
  2347. int count = 0;
  2348. foreach (var tuple in location)
  2349. {
  2350. if (ModuleHelper.IsPm(tuple.Item1) && !GetModule(tuple.Item1.ToString()).IsOnline)
  2351. continue;
  2352. WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
  2353. if (wafer.IsEmpty)
  2354. continue;
  2355. if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
  2356. count++;
  2357. }
  2358. return count;
  2359. }
  2360. private int GetCoolingWaferCount(string pjName)
  2361. {
  2362. List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
  2363. {
  2364. Tuple.Create(ModuleName.Cooling1, 0),
  2365. Tuple.Create(ModuleName.Cooling2, 0),
  2366. };
  2367. int count = 0;
  2368. foreach (var tuple in location)
  2369. {
  2370. WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
  2371. if (wafer.IsEmpty)
  2372. continue;
  2373. if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
  2374. count++;
  2375. }
  2376. return count;
  2377. }
  2378. private int GetProcessingWaferCount(string pjName)
  2379. {
  2380. List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
  2381. {
  2382. Tuple.Create(ModuleName.PMA, 0),
  2383. Tuple.Create(ModuleName.PMB, 0),
  2384. };
  2385. int count = 0;
  2386. foreach (var tuple in location)
  2387. {
  2388. if (ModuleHelper.IsPm(tuple.Item1) && !GetModule(tuple.Item1.ToString()).IsOnline)
  2389. continue;
  2390. WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
  2391. if (wafer.IsEmpty)
  2392. continue;
  2393. if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
  2394. count++;
  2395. }
  2396. return count;
  2397. }
  2398. private List<ModuleName> GetPmUsedInRunningPj()
  2399. {
  2400. var pmUsed = new List<ModuleName>();
  2401. foreach (var cj in _lstControlJobs)
  2402. {
  2403. if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
  2404. continue;
  2405. foreach (var pj in _lstProcessJobs)
  2406. {
  2407. if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
  2408. {
  2409. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  2410. {
  2411. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  2412. foreach (var module in stepInfo.StepModules)
  2413. {
  2414. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  2415. pmUsed.Add(module);
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. return pmUsed;
  2422. }
  2423. private int CompareWaferPriority(ModuleName module1, int slot1, ModuleName module2, int slot2)
  2424. {
  2425. if (module1 == ModuleName.System || module2 == ModuleName.System)
  2426. return 0;
  2427. WaferInfo wafer1 = WaferManager.Instance.GetWafer(module1, slot1);
  2428. WaferInfo wafer2 = WaferManager.Instance.GetWafer(module2, slot2);
  2429. if (wafer1.IsEmpty || wafer2.IsEmpty)
  2430. return 0;
  2431. if (wafer1.Size != wafer2.Size)
  2432. return 0;
  2433. //same process job && same load port
  2434. if (_lstProcessJobs.Exists(x => x.SlotWafers.Exists(y => y.Item1 == (ModuleName)wafer1.OriginStation && y.Item2 == wafer1.OriginSlot)
  2435. && x.SlotWafers.Exists((y =>
  2436. y.Item1 == (ModuleName)wafer2.OriginStation && y.Item2 == wafer2.OriginSlot)))
  2437. && (wafer1.OriginStation == wafer2.OriginStation))
  2438. {
  2439. //lower number slot has high priority
  2440. return wafer2.OriginSlot - wafer1.OriginSlot;
  2441. }
  2442. return 0;
  2443. }
  2444. private List<SchedulerPM> GetPmNeeded(ControlJobInfo cj)
  2445. {
  2446. List<SchedulerPM> result = new List<SchedulerPM>();
  2447. foreach (var pj in _lstProcessJobs)
  2448. {
  2449. if (pj.ControlJobName != cj.Name)
  2450. continue;
  2451. var seq = pj.Sequence;
  2452. for (int i = 0; i < seq.Steps.Count; i++)
  2453. {
  2454. SequenceStepInfo stepInfo = seq.Steps[i];
  2455. foreach (var module in stepInfo.StepModules)
  2456. {
  2457. if (ModuleHelper.IsPm(module))
  2458. {
  2459. var pm = _lstPms.Find(x => x.Module == module);
  2460. if (pm != null && !result.Contains(pm))
  2461. {
  2462. result.Add(pm);
  2463. }
  2464. }
  2465. }
  2466. }
  2467. }
  2468. return result;
  2469. }
  2470. public bool CheckRecipeUsedInJob(string pathName)
  2471. {
  2472. foreach (var pj in _lstProcessJobs)
  2473. {
  2474. var seq = pj.Sequence;
  2475. for (int i = 0; i < seq.Steps.Count; i++)
  2476. {
  2477. SequenceStepInfo stepInfo = seq.Steps[i];
  2478. foreach (var module in stepInfo.StepModules)
  2479. {
  2480. if (ModuleHelper.IsPm(module))
  2481. {
  2482. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  2483. if (stepInfo.StepParameter.ContainsKey(attr)
  2484. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  2485. {
  2486. var recipeName = (string)stepInfo.StepParameter[attr];
  2487. if (!string.IsNullOrEmpty(recipeName))
  2488. {
  2489. if (pathName.EndsWith(recipeName + ".rcp"))
  2490. return true;
  2491. }
  2492. }
  2493. }
  2494. }
  2495. }
  2496. }
  2497. return false;
  2498. }
  2499. public bool CheckSequenceUsedInJob(string pathName)
  2500. {
  2501. foreach (var pj in _lstProcessJobs)
  2502. {
  2503. if (pathName.EndsWith(pj.Sequence.Name + ".seq"))
  2504. return true;
  2505. }
  2506. return false;
  2507. }
  2508. #endregion Logic Check
  2509. }
  2510. }