AutoTransfer.cs 117 KB

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