12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.DBCore;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Jobs;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Xml;
- using Aitex.Core.Util;
- using VirgoRT.Modules.Schedulers;
- using VirgoRT.Scheduler;
- namespace VirgoRT.Modules
- {
- public partial class AutoTransfer : TransferModule
- {
- private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
- private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
- //private Object _locker = new Object();
- private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
- private List<SchedulerAligner> _lstAligners = new List<SchedulerAligner>();
- private List<SchedulerAligner> _lstCoolings = new List<SchedulerAligner>();
- private List<SchedulerLoadPort> _lstLps = new List<SchedulerLoadPort>();
- private const string LogSource = "Scheduler";
- private bool _isCycleMode;
- private int _cycleSetPoint = 0;
- private int _cycledCount = 0;
- private int _cycledWafer = 0;
- private bool _isRunningInParallelMode;
- private bool _isFixAlignerAndCooling; // 如果不同的尺寸,就固定住4寸和6寸,用不同的aligner,cooling,PM,避免来回
- private Dictionary<ModuleName, ModuleName> _mapLpPm = new Dictionary<ModuleName, ModuleName>();
- private Dictionary<ModuleName, ModuleName> _mapLpAligner = new Dictionary<ModuleName, ModuleName>();
- private Dictionary<ModuleName, ModuleName> _mapLpCooling = new Dictionary<ModuleName, ModuleName>();
- private List<ModuleName> _mapTarget = new List<ModuleName>();
- public bool HasJobRunning
- {
- get { return _lstControlJobs.Count > 0; }
- }
- private SchedulerFACallback _faCallback;
- private SchedulerDBCallback _dbCallback;
- public AutoTransfer()
- {
- _faCallback = new SchedulerFACallback();
- _dbCallback = new SchedulerDBCallback();
- if (SC.GetValue<bool>("System.PMAIsInstalled"))
- _lstPms.Add(_pma);
- if (SC.GetValue<bool>("System.PMBIsInstalled"))
- _lstPms.Add(_pmb);
- _lstAligners.AddRange(new[] { _aligner1, _aligner2 });
- _lstCoolings.AddRange(new[] { _cooling1, _cooling2 });
- _lstLps.AddRange(new[] { _lp1, _lp2 });
- DATA.Subscribe("Scheduler.CycledCount", () => _cycledCount);
- DATA.Subscribe("Scheduler.CycledWafer", () => _cycledWafer);
- DATA.Subscribe("Scheduler.CycleSetPoint", () => _cycleSetPoint);
- DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
- //DATA.Subscribe("LP1.LocalJobName", () =>
- //{
- // if (_lstControlJobs.Exists(x => x.Name == "CJ_Local_LP1"))
- // return "CJ_Local_LP1";
- // return "";
- //});
- //DATA.Subscribe("LP1.LocalJobStatus", () =>
- //{
- // var jb = _lstControlJobs.Find(x => x.Name == "CJ_Local_LP1");
- // if (jb != null)
- // return jb.State.ToString();
- // return "";
- //});
- //DATA.Subscribe("LP2.LocalJobName", () =>
- //{
- // if (_lstControlJobs.Exists(x => x.Name == "CJ_Local_LP2"))
- // return "CJ_Local_LP2";
- // return "";
- //});
- //DATA.Subscribe("LP2.LocalJobStatus", () =>
- //{
- // var jb = _lstControlJobs.Find(x => x.Name == "CJ_Local_LP2");
- // if (jb != null)
- // return jb.State.ToString();
- // return "";
- //});
- foreach (var lp in _lstLps)
- {
- DATA.Subscribe($"{lp.Module}.LocalJobName", () =>
- {
- var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Module.ToString());
- if (cj != null)
- return cj.Name;
- return "";
- });
- DATA.Subscribe($"{lp.Module}.JobLotName", () =>
- {
- var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Module.ToString());
- if (cj != null)
- return cj.LotName;
- return "";
- });
- DATA.Subscribe($"{lp.Module}.LocalJobStatus", () =>
- {
- var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Module.ToString());
- if (cj != null)
- return cj.State.ToString();
- return "";
- });
- DATA.Subscribe($"{lp.Module}.CurrentRecipeList", () =>
- {
- var local = lp;
- List<string> result = Enumerable.Repeat("", 25).ToList();
- for (int i = 0; i < _lstProcessJobs.Count; i++)
- {
- foreach (var wafers in _lstProcessJobs[i].SlotWafers)
- {
- if (wafers.Item1 == local.Module)
- {
- result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
- }
- }
- }
- return result;
- });
- }
- }
- public void Clear()
- {
- _efemRobot.ResetTask();
- foreach (var pm in _lstPms)
- {
- pm.ResetTask();
- }
- foreach (var buffer in _lstAligners)
- {
- buffer.ResetTask();
- }
- foreach (var buffer in _lstCoolings)
- {
- buffer.ResetTask();
- }
- foreach (var lp in _lstLps)
- {
- lp.ResetTask();
- }
- _lstControlJobs.Clear();
- _lstProcessJobs.Clear();
- _mapLpAligner.Clear();
- _mapLpCooling.Clear();
- _mapLpPm.Clear();
- _isFixAlignerAndCooling = false;
- _isRunningInParallelMode = false;
- _mapTarget.Clear();
- }
- #region Job Management
- public void CreateJob(Dictionary<string, object> param)
- {
- _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
- _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
- string[] slotSequence = (string[])param["SlotSequence"];
- string jobId = (string)param["JobId"];
- string module = (string)param["Module"];
- bool autoStart = (bool)param["AutoStart"];
- string lotId = jobId;
- if (param.ContainsKey("LotId"))
- lotId = (string)param["LotId"];
- if (slotSequence.Length != 25)
- {
- EV.PostWarningLog(LogSource, $"slot sequence parameter not valid, length is {slotSequence.Length}, should be 25");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
- {
- EV.PostWarningLog(LogSource, $"{module} should be LoadPort");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (string.IsNullOrEmpty(jobId))
- {
- jobId = "CJ_Local_" + module;
- }
- if (_lstControlJobs.Exists(x => x.Name == jobId))
- {
- EV.PostWarningLog(LogSource, $"{jobId} already created");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- SchedulerLoadPort lp = GetModule(module) as SchedulerLoadPort;
- if (!lp.CheckReadyRunJob())
- {
- EV.PostWarningLog(LogSource, $"{module} not ready");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- ControlJobInfo cj = new ControlJobInfo();
- cj.Name = jobId;
- cj.Module = module;
- cj.LotName = lotId;
- cj.LotInnerId = Guid.NewGuid();
- cj.LotWafers = new List<WaferInfo>();
- cj.SetState(EnumControlJobState.WaitingForStart);
- Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
- Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
- Dictionary<string, string> indexSequence = new Dictionary<string, string>();
- bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
- for (int i = 0; i < 25; i++)
- {
- if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
- continue;
- string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
- indexSequence[groupName] = slotSequence[i];
- if (!seqSlot.ContainsKey(groupName))
- {
- seqSlot[groupName] = new bool[25];
- }
- if (!seqSlotWafers.ContainsKey(groupName))
- {
- seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
- }
- seqSlot[groupName][i] = true;
- if (!WaferManager.Instance.CheckHasWafer(module, i))
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} not in the carrier");
- //return;
- }
- if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- var smallWafer = SC.GetValue<int>($"System.SmallWafer");
- //特殊场景,3寸片第一片不能取放
- if (i == 0 && (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size == WaferSize.WS3) && (int)smallWafer == 3)
- {
- EV.PostWarningLog(LogSource, $"job wafer: {module} 3 inch slot {i + 1} is not supported.");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
- WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
- WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).NextSequenceStep = 0;
- WaferManager.Instance.UpdateWaferLotId(ModuleHelper.Converter(module), i, lotId);
-
- seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
- cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
- }
- if (seqSlotWafers.Count == 0)
- {
- EV.PostWarningLog(LogSource, $"job has not assign wafer");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
- string[] seqs = seqSlot.Keys.ToArray();
- for (int i = 0; i < seqs.Length; i++)
- {
- ProcessJobInfo pj = new ProcessJobInfo();
- pj.Name = jobId + "_" + (i + 1);
- pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
- pj.ControlJobName = cj.Name;
- pj.LotName = lotId;
- pj.SlotWafers = seqSlotWafers[seqs[i]];
- pj.SetState(EnumProcessJobState.Queued);
- if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
- {
- EV.PostWarningLog(LogSource, $"no valid chamber for the {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!CheckSequenceOrderOk(pj.Sequence, out reason))
- {
- EV.PostWarningLog(LogSource, $"sequence path not valid, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!SC.GetValue<bool>("System.IsATMMode") && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
- {
- EV.PostWarningLog(LogSource, $"recipe file not valid in the sequence, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- if (!SetSequenceTemperatureInfo(pj.Sequence, out reason))
- {
- EV.PostWarningLog(LogSource, $"sequence recipe temperature not valid, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return;
- }
- pjs.Add(pj);
- }
- _dbCallback.LotUpdate(cj);
- foreach (var pj in pjs)
- {
- cj.ProcessJobNameList.Add(pj.Name);
- _lstProcessJobs.Add(pj);
- }
- _lstControlJobs.Add(cj);
- UpdateParallelMode();
- _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
- }
- internal ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- return pj;
- }
- return null;
- }
- internal void StopJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
- return;
- }
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- {
- pj.SetState(EnumProcessJobState.Stopping);
- }
- }
- _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- }
- internal void AbortJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
- return;
- }
- List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- {
- pj.SetState(EnumProcessJobState.Aborting);
- pjAbortList.Add(pj);
- int unprocessed = 0;
- int aborted = 0;
- WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
- foreach (var waferInfo in wafers)
- {
- waferInfo.ProcessJob = null;
- waferInfo.NextSequenceStep = 0;
- if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
- unprocessed++;
- }
- JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
- }
- }
- _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- foreach (var pj in pjAbortList)
- {
- _lstProcessJobs.Remove(pj);
- }
- _lstControlJobs.Remove(cj);
- }
- public void ResumeJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
- return;
- }
- if (cj.State == EnumControlJobState.Paused)
- {
- cj.SetState(EnumControlJobState.Executing);
- }
- _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
- }
- internal void StartJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
- return;
- }
- if (cj.State == EnumControlJobState.WaitingForStart)
- {
- cj.SetState(EnumControlJobState.Executing);
- //PreJobClean(cj);
- (GetModule(cj.Module) as SchedulerLoadPort).NoteJobStart();
- cj.StartTime = DateTime.Now;
- _dbCallback.LotCreated(cj);
- _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
- }
- }
- internal void PauseJob(string jobName)
- {
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
- return;
- }
- if (cj.State == EnumControlJobState.Executing)
- {
- cj.SetState(EnumControlJobState.Paused);
- }
- _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
- }
- internal void Map(string moduleName)
- {
- ModuleName target = ModuleHelper.Converter(moduleName);
- if (!ModuleHelper.IsLoadPort(target))
- {
- EV.PostWarningLog(LogSource, $"Invalid map target {target}");
- return;
- }
- if (!_mapTarget.Contains(target))
- {
- _mapTarget.Add(target);
- }
- }
- #endregion Job Management
- public Result Start(params object[] objs)
- {
- _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
- _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
- _cycledWafer = 0;
- _cycledCount = 0;
- bool hasPmOnline = false;
- foreach (var schedulerPm in _lstPms)
- {
- if (schedulerPm.IsAvailable)
- {
- schedulerPm.SetPMAuto();
- hasPmOnline = true;
- continue;
- }
- }
- if (!hasPmOnline)
- {
- EV.PostWarningLog("Scheduler", "can not change to auto mode, at least one process chamber be online");
- return Result.FAIL;
- }
- return Result.RUN;
- }
- public Result Monitor()
- {
- MonitorEfemRobotMapTask();
- ControlJobInfo cjActive = _lstControlJobs.Find(x => x.State == EnumControlJobState.Executing);
- if (cjActive != null)
- {
- MonitorModuleTasks();
- }
- MonitorJobTasks();
- MonitorCleanTasks();
- return Result.RUN;
- }
- #region Job task
- public Result MonitorJobTasks()
- {
- UpdateParallelMode();
- UpdateProcessJobStatus();
- UpdateControlJobStatus();
- StartNewJob();
- return Result.RUN;
- }
- private void UpdateParallelMode()
- {
- bool enableParallel = SC.GetValue<bool>("Scheduler.IsRunInParallelMode");
- bool bothLpHasJob = true;
- _isRunningInParallelMode = enableParallel;
- Dictionary<ModuleName, Dictionary<ModuleName, float>> lpNeededPmTemperature = new Dictionary<ModuleName, Dictionary<ModuleName, float>>();
- foreach (var lp in _lstLps)
- {
- var cj = _lstControlJobs.Find(x => x.Module == lp.Module.ToString());
- bothLpHasJob = bothLpHasJob && (cj != null);
- if (cj != null)
- {
- lpNeededPmTemperature[lp.Module] = new Dictionary<ModuleName, float>();
- var pj = _lstProcessJobs.FirstOrDefault(x => x.ControlJobName == cj.Name);
- if (pj != null)
- {
- var seq = pj.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module) && !lpNeededPmTemperature[lp.Module].ContainsKey(module))
- {
- lpNeededPmTemperature[lp.Module][module] = (float)seq.Steps[i]
- .StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
- }
- }
- }
- }
- }
- }
- bool needSamePm = false;
- ModuleName pmSource = ModuleName.System;
- foreach (var pmNeeded in lpNeededPmTemperature)
- {
- if (pmNeeded.Value.Count == 1)
- {
- var source = pmNeeded.Value.Keys.First();
- if (source != pmSource)
- {
- pmSource = source;
- }
- else
- {
- needSamePm = true;
- break;
- }
- }
- else if(pmNeeded.Value.Count > 1)
- {
- needSamePm = true;
- }
- }
- var needFixPosition = enableParallel && bothLpHasJob && !needSamePm;
- _isRunningInParallelMode = needFixPosition;
- if (needFixPosition != _isFixAlignerAndCooling)
- {
- _isFixAlignerAndCooling = needFixPosition;
- if (needFixPosition)
- {
- //aligner固定不做逻辑
- _mapLpAligner[ModuleName.LP1] = ModuleName.Aligner1;
- _mapLpAligner[ModuleName.LP2] = ModuleName.Aligner2;
- _mapLpCooling[ModuleName.LP1] = ModuleName.Cooling1;
- _mapLpCooling[ModuleName.LP2] = ModuleName.Cooling2;
- bool assigned = false;
- foreach (var pmNeeded in lpNeededPmTemperature)
- {
- if (pmNeeded.Value.Count == 1)
- {
- _mapLpPm[pmNeeded.Key] = pmNeeded.Value.Keys.First();
- var anotherLp = pmNeeded.Key == ModuleName.LP1 ? ModuleName.LP2 : ModuleName.LP1;
- var anotherPm = _mapLpPm[pmNeeded.Key] == ModuleName.PMA ? ModuleName.PMB : ModuleName.PMA;
- _mapLpPm[anotherLp] = anotherPm;
- assigned = true;
- break;
- }
- }
- if (!assigned)
- {
- _mapLpPm[ModuleName.LP1] = ModuleName.PMA;
- _mapLpPm[ModuleName.LP2] = ModuleName.PMB;
- float pmaTemp = ((SchedulerPM)GetModule(ModuleName.PMA.ToString())).Temperature;
- float pmbTemp = ((SchedulerPM)GetModule(ModuleName.PMB.ToString())).Temperature;
- float tempCurrent = Math.Abs(lpNeededPmTemperature[ModuleName.LP1][ModuleName.PMA] - pmaTemp)
- + Math.Abs(lpNeededPmTemperature[ModuleName.LP2][ModuleName.PMB] - pmbTemp);
- float tempAnother = Math.Abs(lpNeededPmTemperature[ModuleName.LP1][ModuleName.PMB] - pmbTemp)
- + Math.Abs(lpNeededPmTemperature[ModuleName.LP2][ModuleName.PMA] - pmaTemp);
- if (tempAnother < tempCurrent)
- {
- _mapLpPm[ModuleName.LP1] = ModuleName.PMB;
- _mapLpPm[ModuleName.LP2] = ModuleName.PMA;
- }
- }
- }
- }
- }
- private void UpdateProcessJobStatus()
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.State == EnumProcessJobState.Processing)
- {
- if (CheckAllWaferReturned(pj, true))
- {
- pj.SetState(EnumProcessJobState.ProcessingComplete);
- JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
- }
- }
- else if (pj.State == EnumProcessJobState.Stopping)
- {
- if (CheckAllWaferReturned(pj, false))
- {
- pj.SetState(EnumProcessJobState.ProcessingComplete);
- JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
- }
- }
- }
- }
- private void UpdateControlJobStatus()
- {
- if (_lstControlJobs.Count == 0)
- return;
- bool allControlJobComplete = true;
- List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
- foreach (var cj in _lstControlJobs)
- {
- if (!GetModule(cj.Module).IsAvailable)
- {
- allControlJobComplete = false;
- continue;
- }
- if (cj.State == EnumControlJobState.Executing)
- {
- bool allPjCompleted = true;
- foreach (var pjName in cj.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Error($"Not find pj named {pjName} in {cj.Name}");
- continue;
- }
- if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
- {
- allPjCompleted = false;
- break;
- }
- }
- if (allPjCompleted)
- {
- cj.SetState(EnumControlJobState.Completed);
- cj.EndTime = DateTime.Now;
- if( !(_isCycleMode && _cycledCount+1 < _cycleSetPoint))
- {
- CompleteJobClean(cj);
- }
- _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- if (!(_isCycleMode && _cycledCount < _cycleSetPoint))
- (GetModule(cj.Module) as SchedulerLoadPort).NoteJobComplete();
- }
- }
- LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
- if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
- {
- cjRemoveList.Add(cj);
- }
- allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
- }
- if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
- {
- int countPerCycle = 0;
- int countProcessed = 0;
- foreach (var pj in _lstProcessJobs)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- countPerCycle++;
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- if (!wafer.IsEmpty && !CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
- countProcessed++;
- }
- }
- _cycledWafer = _cycledCount * countPerCycle + countProcessed;
- if (allControlJobComplete)
- {
- _cycledCount++;
- _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
- if (!_isCycleMode)
- _cycleSetPoint = 0;
- if (_cycledCount < _cycleSetPoint)
- {
- foreach (var cj in _lstControlJobs)
- {
- cj.SetState(EnumControlJobState.Executing);
- //循环模式,不做PreJob Clean
- //PreJobClean(cj);
- cj.LotInnerId = Guid.NewGuid();
- //PreJobClean(cj);
- _dbCallback.LotCreated(cj);
- }
- foreach (var pj in _lstProcessJobs)
- {
- pj.SetState(EnumProcessJobState.Queued);
- pj.InnerId = Guid.NewGuid();
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- wafer.ProcessJob = null;
- wafer.NextSequenceStep = 0;
- wafer.ProcessState = EnumWaferProcessStatus.Idle;
- }
- }
- }
- }
- }
- foreach (var cj in cjRemoveList)
- {
- List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- pjRemoveList.Add(pj);
- }
- foreach (var pj in pjRemoveList)
- {
- _lstProcessJobs.Remove(pj);
- }
- _lstControlJobs.Remove(cj);
- }
- if (cjRemoveList.Count > 0)
- {
- UpdateParallelMode();
- }
- }
- public bool CheckJobJustDone(out string sJobName)
- {
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
- {
- //LP;WaferSize;Lot;Number;Start;End;
- sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
- cj.BeenPosted = true;
- return true;
- }
- }
- //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";
- sJobName = "NULL";
- return false;
- }
- public bool CheckAllJobDone()
- {
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
- return false;
- }
- return true;
- }
- private void StartNewJob()
- {
- ControlJobInfo cjActived = null;
- List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State != EnumControlJobState.Executing)
- continue;
- cjActived = cj;
- foreach (var pjName in cjActived.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
- continue;
- }
- if (pj.State == EnumProcessJobState.Queued)
- {
- if (CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason))
- {
- ActiveProcessJob(pj);
- foreach (var moduleName in pmUsed)
- {
- if (!pmOccupied.Contains(moduleName))
- pmOccupied.Add(moduleName);
- }
- }
- break;
- }
- }
- if (!_isRunningInParallelMode)
- break;
- }
- }
- private bool ActiveProcessJob(ProcessJobInfo pj)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- wafer.ProcessJob = pj;
- wafer.NextSequenceStep = 0;
- WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
- }
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
- CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
- JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
- pj.SetState(EnumProcessJobState.Processing);
- PreJobClean(cj);
- return true;
- }
- #endregion Job task
- #region Module task
- public Result MonitorModuleTasks()
- {
- MonitorPMTask();
- MonitorEfemRobotTask();
- MonitorAlignerTask();
- MonitorCoolingTask();
- MonitorInterlockTask();
- return Result.RUN;
- }
- private void MonitorInterlockTask()
- {
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused ||
- cj.State == EnumControlJobState.WaitingForStart)
- {
- var lp = GetModule(cj.Module);
- if (!(lp as SchedulerLoadPort).CheckPlaced())
- {
- EV.PostAlarmLog("System", "Cassette removed while job not finished.");
- Singleton<RouteManager>.Instance.PostMsg(RouteManager.MSG.ERROR);
- }
- }
- }
- }
- private void MonitorAlignerTask()
- {
- foreach (var schedulerBuffer in _lstAligners)
- {
- if (!schedulerBuffer.IsAvailable
- || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
- )
- continue;
- if (CheckWaferNextStepIsAlign(schedulerBuffer.Module, 0))
- {
- WaferInfo wafer = WaferManager.Instance.GetWafers(schedulerBuffer.Module)[0];
- var job = wafer.ProcessJob;
- GetWaferSequenceAlignTime(schedulerBuffer.Module, 0, out float time);
- if (schedulerBuffer.Align(time))
- {
- wafer.NextSequenceStep++;
- }
- }
- }
- }
- private void MonitorCoolingTask()
- {
- foreach (var schedulerBuffer in _lstCoolings)
- {
- if (!schedulerBuffer.IsAvailable
- || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
- )
- continue;
- if (CheckWaferNextStepIsCooling(schedulerBuffer.Module, 0))
- {
- WaferInfo wafer = WaferManager.Instance.GetWafers(schedulerBuffer.Module)[0];
- var job = wafer.ProcessJob;
- GetWaferSequenceAlignTime(schedulerBuffer.Module, 0, out float time);
- if (schedulerBuffer.Cooling((int)time))
- {
- wafer.NextSequenceStep++;
- }
- }
- }
- }
- private void MonitorEfemRobotTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- //efem robot is idle, release all the target
- foreach (var pm in _lstPms)
- {
- if (pm.IsWaitTransfer(ModuleName.EfemRobot))
- {
- pm.PostTransfer(ModuleName.EfemRobot);
- }
- }
- foreach (var buffer in _lstCoolings)
- {
- if (buffer.IsWaitTransfer(ModuleName.EfemRobot))
- {
- buffer.PostTransfer(ModuleName.EfemRobot);
- }
- }
- foreach (var buffer in _lstAligners)
- {
- if (buffer.IsWaitTransfer(ModuleName.EfemRobot))
- {
- buffer.PostTransfer(ModuleName.EfemRobot);
- }
- }
- foreach (var lp in _lstLps)
- {
- if (lp.IsWaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick))
- {
- lp.PostTransfer(ModuleName.EfemRobot);
- }
- if (lp.IsWaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place))
- {
- lp.PostTransfer(ModuleName.EfemRobot);
- ProcessJobInfo pj = WaferManager.Instance.GetWafer(lp.Module, lp.InTransferSlot)
- .ProcessJob;
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
- _faCallback.JobWaferEnd(cj, pj, lp.Module.ToString(), lp.InTransferSlot);
- }
- }
- MonitorEfemRobotAlignerTask();
- if (!_efemRobot.IsAvailable)
- return;
- MonitorEfemRobotLoadPortTask();
- if (!_efemRobot.IsAvailable)
- return;
- MonitorEfemRobotPMTask();
- if (!_efemRobot.IsAvailable)
- return;
- MonitorEfemRobotCoolingTask();
- if (!_efemRobot.IsAvailable)
- return;
- }
- private void MonitorEfemRobotMapTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- if (_mapTarget.Count > 0)
- {
- ModuleName first = _mapTarget[0];
- //避免重复map,job信息被清除
- foreach (var cj in _lstControlJobs)
- {
- if (cj.Module != first.ToString())
- continue;
- if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
- {
- EV.PostWarningLog("System", $"{first} is running, can not map again");
- _mapTarget.Remove(first);
- return;
- }
- }
- SchedulerLoadPort lp = GetModule(first.ToString()) as SchedulerLoadPort;
- if (lp != null && lp.IsAvailable)
- {
- _efemRobot.Map(first);
- _mapTarget.Remove(first);
- }
- }
- }
- private void MonitorEfemRobotPMTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- //place to pm
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && !CheckWaferNeedAlign(ModuleName.EfemRobot, 0))
- {
- foreach (var pm in _lstPms)
- {
- if (!pm.IsAvailable
- || !WaferManager.Instance.CheckNoWafer(pm.Module, 0)
- || !CheckWaferNeedProcess(ModuleName.EfemRobot, 0, pm.Module))
- continue;
- if (_isFixAlignerAndCooling && GetWaferCountOutofLP(ModuleName.LP1) <= 1 && GetWaferCountOutofLP(ModuleName.LP2) <= 1)
- {
- int origin = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginStation;
- if (origin == (int)ModuleName.LP1 && _mapLpPm[ModuleName.LP1] != pm.Module)
- continue;
- if (origin == (int)ModuleName.LP2 && _mapLpPm[ModuleName.LP2] != pm.Module)
- continue;
- }
- if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1))
- continue;
- if (_efemRobot.Place(pm.Module, 0, Hand.Blade1))
- {
- pm.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
- return;
- }
- }
- }
- if (!_efemRobot.IsAvailable)
- return;
- //pick from pm
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
- {
- ModuleName pickPm = ModuleName.System;
- int preOriginSlot = int.MaxValue;
- string pmPj = string.Empty;
- int preWaferCountInCooling = 0;
- foreach (var schedulerPm in _lstPms)
- {
- if (!schedulerPm.IsAvailable
- || WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0)
- || CheckWaferNeedProcess(schedulerPm.Module, 0, schedulerPm.Module))
- continue;
- WaferInfo wafer = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
- bool pickAllowed = CheckVacuumWaferHasAvailableTarget(schedulerPm.Module, 0);
- if (!pickAllowed)
- continue;
- if ((pickPm == ModuleName.System)
- || (wafer.OriginSlot < preOriginSlot && pmPj == wafer.ProcessJob.Name)
- || (GetCoolingWaferCount(wafer.ProcessJob.Name) < preWaferCountInCooling))
- {
- preOriginSlot = wafer.OriginSlot;
- pickPm = schedulerPm.Module;
- pmPj = wafer.ProcessJob.Name;
- preWaferCountInCooling = GetCoolingWaferCount(pmPj);
- continue;
- }
- }
- if (pickPm != ModuleName.System)
- {
- SchedulerModule pm = GetModule(pickPm.ToString());
- if (pm.IsReadyForPick(ModuleName.EfemRobot, 0, Hand.Blade1))
- {
- if (_efemRobot.Pick(pm.Module, 0, Hand.Blade1))
- {
- pm.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
- return;
- }
- }
- }
- }
- }
- private void MonitorEfemRobotLoadPortTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- //pick
- if (GetWaferCountOutofLP(ModuleName.System) < GetMaxOutWafer() && GetWaferCountInJobQueue(ModuleName.System) > 0 &&
- WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
- {
- SlotItem position = GetNextWaferInJobQueue(ModuleName.System);
- if (position != null && CheckWaferHasAvailableTarget(position.Module, position.Slot) && CheckWaferPmTemperatureIsOk(position.Module, position.Slot))
- {
- SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(position.Module.ToString());
- if (lp.IsReadyForPick(ModuleName.EfemRobot, position.Slot, Hand.Blade1))
- {
- if (_efemRobot.Pick(position.Module, position.Slot, Hand.Blade1))
- {
- lp.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, position.Slot);
- ProcessJobInfo pj = WaferManager.Instance.GetWafer(position.Module, position.Slot)
- .ProcessJob;
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
- _faCallback.JobWaferStart(cj, pj, position.Module.ToString(), position.Slot);
- return;
- }
- }
- }
- }
- if (!_efemRobot.IsAvailable)
- return;
- //place
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && !CheckWaferNeedProcess(ModuleName.EfemRobot, 0)
- && !CheckWaferNeedCooling(ModuleName.EfemRobot, 0))
- {
- SlotItem destination = GetWaferReturnLoadPort(_efemRobot.Module, 0);
- if (destination != null)
- {
- SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(destination.Module.ToString());
- if (lp.IsReadyForPlace(ModuleName.EfemRobot, destination.Slot, Hand.Blade1))
- {
- if (_efemRobot.Place(destination.Module, destination.Slot, Hand.Blade1))
- {
- lp.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, destination.Slot);
- return;
- }
- }
- }
- }
- }
- private void MonitorEfemRobotAlignerTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- //place
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
- CheckWaferNeedAlign(ModuleName.EfemRobot, 0))
- {
- foreach (var buffer in _lstAligners)
- {
- if (!buffer.IsAvailable || !WaferManager.Instance.CheckNoWafer(buffer.Module, 0))
- continue;
- if (_isFixAlignerAndCooling && GetWaferCountOutofLP(ModuleName.LP1) <= 1 && GetWaferCountOutofLP(ModuleName.LP2) <= 1)
- {
- int origin = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginStation;
- if (origin == (int)ModuleName.LP1 && _mapLpAligner[ModuleName.LP1] != buffer.Module)
- continue;
- if (origin == (int)ModuleName.LP2 && _mapLpAligner[ModuleName.LP2] != buffer.Module)
- continue;
- }
- if (!buffer.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1))
- continue;
- if (_efemRobot.Place(buffer.Module, 0, Hand.Blade1))
- {
- buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
- return;
- }
- }
- }
- if (!_efemRobot.IsAvailable)
- return;
- //pick from aligner
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
- {
- ModuleName pickBuffer = ModuleName.System;
- int preOriginSlot = int.MaxValue;
- string prePj = string.Empty;
- int preWaferCountInCooling = 0;
- foreach (var schedulerBuffer in _lstAligners)
- {
- if (!schedulerBuffer.IsAvailable
- || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
- || CheckWaferNeedAlign(schedulerBuffer.Module, 0))
- continue;
- WaferInfo wafer = WaferManager.Instance.GetWafer(schedulerBuffer.Module, 0);
- bool pickAllowed = CheckBufferWaferHasAvailableTarget(schedulerBuffer.Module, 0);
- if (!pickAllowed)
- continue;
- if ((pickBuffer == ModuleName.System)
- || (wafer.OriginSlot < preOriginSlot && prePj == wafer.ProcessJob.Name)
- || (GetCoolingWaferCount(wafer.ProcessJob.Name) < preWaferCountInCooling))
- {
- preOriginSlot = wafer.OriginSlot;
- pickBuffer = schedulerBuffer.Module;
- prePj = wafer.ProcessJob.Name;
- preWaferCountInCooling = GetCoolingWaferCount(prePj);
- continue;
- }
- }
- if (pickBuffer != ModuleName.System)
- {
- SchedulerModule buffer = GetModule(pickBuffer.ToString());
- if (buffer.IsReadyForPick(ModuleName.EfemRobot, 0, Hand.Blade1))
- {
- if (_efemRobot.Pick(buffer.Module, 0, Hand.Blade1))
- {
- buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
- return;
- }
- }
- }
- }
- }
- private void MonitorEfemRobotCoolingTask()
- {
- if (!_efemRobot.IsAvailable)
- return;
- //place to buffer
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
- CheckWaferNeedCooling(ModuleName.EfemRobot, 0))
- {
- foreach (var buffer in _lstCoolings)
- {
- if (!buffer.IsAvailable || !WaferManager.Instance.CheckNoWafer(buffer.Module, 0))
- continue;
- if (_isFixAlignerAndCooling && GetWaferCountOutofLP(ModuleName.LP1) <= 1 && GetWaferCountOutofLP(ModuleName.LP2) <= 1)
- {
- int origin = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginStation;
- if (origin == (int)ModuleName.LP1 && _mapLpCooling[ModuleName.LP1] != buffer.Module)
- continue;
- if (origin == (int)ModuleName.LP2 && _mapLpCooling[ModuleName.LP2] != buffer.Module)
- continue;
- }
- if (!buffer.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1))
- continue;
- if (_efemRobot.Place(buffer.Module, 0, Hand.Blade1))
- {
- buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
- return;
- }
- }
- }
- if (!_efemRobot.IsAvailable)
- return;
- //pick from cooling
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0))
- {
- ModuleName pickBuffer = ModuleName.System;
- int preOriginSlot = int.MaxValue;
- string prePj = string.Empty;
- int preWaferCountInPm = 0;
- foreach (var schedulerBuffer in _lstCoolings)
- {
- if (!schedulerBuffer.IsAvailable
- || WaferManager.Instance.CheckNoWafer(schedulerBuffer.Module, 0)
- || CheckWaferNeedCooling(schedulerBuffer.Module, 0))
- continue;
- WaferInfo wafer = WaferManager.Instance.GetWafer(schedulerBuffer.Module, 0);
- bool pickAllowed = CheckWaferHasAvailableTarget(schedulerBuffer.Module, 0);
- if (!pickAllowed)
- continue;
- if ((pickBuffer == ModuleName.System)
- || (wafer.OriginSlot < preOriginSlot && prePj == wafer.ProcessJob.Name)
- || (GetProcessingWaferCount(wafer.ProcessJob.Name) < preWaferCountInPm))
- {
- preOriginSlot = wafer.OriginSlot;
- pickBuffer = schedulerBuffer.Module;
- prePj = wafer.ProcessJob.Name;
- preWaferCountInPm = GetProcessingWaferCount(prePj);
- continue;
- }
- }
- if (pickBuffer != ModuleName.System)
- {
- SchedulerModule buffer = GetModule(pickBuffer.ToString());
- if (buffer.IsReadyForPick(ModuleName.EfemRobot, 0, Hand.Blade1))
- {
- if (_efemRobot.Pick(buffer.Module, 0, Hand.Blade1))
- {
- buffer.WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
- return;
- }
- }
- }
- }
- }
- private void MonitorPMTask()
- {
- bool robotWaferAssigned = false;
- bool aligner1WaferAssigned = false;
- bool aligner2WaferAssigned = false;
- foreach (var pm in _lstPms)
- {
- if (!pm.IsAvailable)
- continue;
- if (WaferManager.Instance.CheckHasWafer(pm.Module, 0))
- {
- if (CheckWaferNeedProcess(pm.Module, 0, pm.Module))
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pm.Module, 0);
- var recipeName = pm.Module == ModuleName.PMA
- ? wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["PMARecipe"]
- : wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["PMBRecipe"];
- if (pm.Process((string)recipeName, false, true, wafer))
- {
- WaferManager.Instance.GetWafer(pm.Module, 0).NextSequenceStep++;
- continue;
- }
- }
- else
- {
- if (!pm.IsReadyForPick(ModuleName.EfemRobot, 0, Hand.Blade1))
- {
- pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
- }
- }
- }
- else //no wafer
- {
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner1, 0)
- && WaferManager.Instance.CheckNoWafer(ModuleName.Aligner2, 0))
- {
- ModuleName source = ModuleName.System;
- if (_isFixAlignerAndCooling)
- {
- foreach (var moduleName in _mapLpPm)
- {
- if (moduleName.Value == pm.Module)
- source = moduleName.Key;
- }
- }
- SlotItem item = GetNextWaferInJobQueue(source);
- if (item != null && CheckWaferNeedProcess(item.Module, item.Slot, pm.Module))
- {
- if (GetWaferTemperatureSetInRecipe(item.Module, item.Slot, pm.Module, out float temp) && !pm.IsTemperatureReady(temp))
- {
- pm.Preheating(temp);
- continue;
- }
- }
- }
- if (!pm.IsAvailable)
- continue;
- if (!robotWaferAssigned && CheckWaferNeedProcess(ModuleName.EfemRobot, 0, pm.Module) && CheckWaferNextProcessIn(ModuleName.EfemRobot, 0, pm.Module))
- {
- robotWaferAssigned = true;
- GetWaferTemperatureSetInRecipe(ModuleName.EfemRobot, 0, pm.Module, out float temp);
- bool alreadyPrepare = false;
- foreach (var schedulerPm in _lstPms)
- {
- if (!CheckWaferNeedProcess(ModuleName.EfemRobot, 0, schedulerPm.Module) || !CheckWaferNextProcessIn(ModuleName.EfemRobot, 0, schedulerPm.Module))
- continue;
- if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
- || (!_efemRobot.IsAvailable)
- || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0) && schedulerPm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1)))
- alreadyPrepare = true;
- }
- if (!alreadyPrepare)
- {
- if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).Size) || !pm.IsTemperatureReady(temp))
- {
- pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).Size);
- }
- }
- }
- if (!pm.IsAvailable)
- continue;
- if (!aligner1WaferAssigned && CheckWaferNeedProcess(ModuleName.Aligner1, 0, pm.Module))
- {
- aligner1WaferAssigned = true;
- GetWaferTemperatureSetInRecipe(ModuleName.Aligner1, 0, pm.Module, out float temp);
- bool alreadyPrepare = false;
- foreach (var schedulerPm in _lstPms)
- {
- if (!CheckWaferNeedProcess(ModuleName.Aligner1, 0, schedulerPm.Module) || !CheckWaferNextProcessIn(ModuleName.Aligner1, 0, schedulerPm.Module))
- continue;
- if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
- || (!_efemRobot.IsAvailable)
- || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0) && schedulerPm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1)))
- alreadyPrepare = true;
- }
- if (!alreadyPrepare)
- {
- if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.Aligner1, 0).Size) || !pm.IsTemperatureReady(temp))
- {
- pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.Aligner1, 0).Size);
- }
- }
- }
- if (!pm.IsAvailable)
- continue;
- if (!aligner2WaferAssigned && CheckWaferNeedProcess(ModuleName.Aligner2, 0, pm.Module))
- {
- aligner2WaferAssigned = true;
- GetWaferTemperatureSetInRecipe(ModuleName.Aligner2, 0, pm.Module, out float temp);
- bool alreadyPrepare = false;
- foreach (var schedulerPm in _lstPms)
- {
- if (!CheckWaferNeedProcess(ModuleName.Aligner2, 0, schedulerPm.Module) || !CheckWaferNextProcessIn(ModuleName.Aligner2, 0, schedulerPm.Module))
- continue;
- if (schedulerPm.IsPrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0)
- || (!_efemRobot.IsAvailable)
- || (schedulerPm.IsAvailable && WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0) && schedulerPm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1)))
- alreadyPrepare = true;
- }
- if (!alreadyPrepare)
- {
- if (!pm.IsReadyForPlace(ModuleName.EfemRobot, 0, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.Aligner2, 0).Size) || !pm.IsTemperatureReady(temp))
- {
- pm.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0, temp, Hand.Blade1, WaferManager.Instance.GetWafer(ModuleName.Aligner2, 0).Size);
- }
- }
- }
- if (!pm.IsAvailable)
- continue;
- }
- }
- }
- #endregion Module task
- #region Logic Check
- private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
- {
- pmUsed = new List<ModuleName>();
- reason = "";
- bool pmIsReady = true;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- bool hasPm = false;
- foreach (var module in stepInfo.StepModules)
- {
- if (!ModuleHelper.IsPm(module))
- {
- hasPm = true;
- break;
- }
- PM pm = DEVICE.GetDevice<PM>(module.ToString());
- if (pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(module)))
- {
- hasPm = true;
- }
- if (!pmUsed.Contains(module))
- pmUsed.Add(module);
- }
- if (pmIsReady && !hasPm)
- {
- reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
- pmIsReady = false;
- }
- }
- return pmIsReady;
- }
- private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
- {
- reason = "";
- bool foundPm = false;
- bool isAlignerAfterPm = false;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- foundPm = true;
- }
- if (ModuleHelper.IsAligner(module) && foundPm)
- {
- isAlignerAfterPm = true;
- }
- }
- }
- if (!foundPm)
- {
- reason = $"not found PM in the sequence file;";
- }
- if (isAlignerAfterPm)
- {
- reason += "Aligner after PM not support";
- }
- return true;
- }
- protected int GetUnprocessedWaferCount()
- {
- int count = 0;
- foreach (ProcessJobInfo pj in _lstProcessJobs)
- {
- if (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused)
- count += GetUnprocessedWaferCount(pj);
- }
- return count;
- }
- protected int GetUnprocessedWaferCount(ProcessJobInfo pj)
- {
- int count = 0;
- for (int i = 0; i < pj.SlotWafers.Count; ++i)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
- if (wafer.IsEmpty)
- continue;
- if (CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
- count++;
- }
- return count;
- }
- protected bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
- {
- for (int i = 0; i < pj.SlotWafers.Count; ++i)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
- if (wafer.IsEmpty)
- return false;
- if (checkAllProcessed && CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
- return false;
- }
- return true;
- }
- private bool CheckWaferNextStepIsAlign(ModuleName module, int slot)
- {
- if (!WaferManager.Instance.CheckHasWafer(module, slot))
- return false;
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1)
- || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2))
- return true;
- return false;
- }
- private bool CheckWaferNextStepIsCooling(ModuleName module, int slot)
- {
- if (!WaferManager.Instance.CheckHasWafer(module, slot))
- return false;
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1)
- || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
- return true;
- return false;
- }
- private bool GetWaferTemperatureSetInRecipe(ModuleName waferModule, int waferSlot, ModuleName pmModule, out float temp)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- var seq = wafer.ProcessJob.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (module == pmModule)
- {
- temp = (float)seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
- return true;
- }
- }
- }
- temp = 0;
- LOG.Error($"Can not find wafer {waferModule} {waferSlot + 1} temperature set in recipe");
- return false;
- }
- private bool CheckWaferPmTemperatureIsOk(ModuleName waferModule, int waferSlot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- var seq = wafer.ProcessJob.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- bool stepOk = false;
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- float tempNeeded = (float)seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
- if ((GetModule(module.ToString()) as SchedulerPM).IsTemperatureReady(tempNeeded))
- {
- stepOk = true;
- break;
- }
- }
- else
- {
- stepOk = true;
- }
- }
- if (!stepOk)
- return false;
- }
- return true;
- }
- private bool CheckWaferNeedAlign(ModuleName waferModule, int waferSlot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
- .Contains(ModuleName.Aligner1) && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
- .Contains(ModuleName.Aligner2))
- return false;
- return true;
- }
- private bool CheckWaferNeedCooling(ModuleName waferModule, int waferSlot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
- .Contains(ModuleName.Cooling1) && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
- .Contains(ModuleName.Cooling2))
- return false;
- return true;
- }
- private bool CheckWaferNextProcessIn(ModuleName waferModule, int waferSlot, ModuleName chamber)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty ||
- wafer.ProcessJob == null ||
- wafer.ProcessJob.Sequence == null ||
- wafer.ProcessJob.Sequence.Steps == null ||
- wafer.ProcessJob.Sequence.Steps.Count <= wafer.NextSequenceStep ||
- wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep] == null ||
- wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
- {
- return false;
- }
- if (_isFixAlignerAndCooling && _mapLpPm[(ModuleName)wafer.OriginStation] != chamber)
- return false;
- return wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(chamber);
- }
- public bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
- {
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(ModuleName.PMB))
- {
- var hasPmAvailable = false;
- foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
- {
- var pm = GetModule(stepModule.ToString()) as SchedulerPM;
- if (pm != null)
- {
- if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
- {
- hasPmAvailable = true;
- break;
- }
- }
- }
- if (!hasPmAvailable)
- return false;
- if (processIn == ModuleName.System)
- return true;
- if (_isFixAlignerAndCooling && _mapLpPm[(ModuleName)wafer.OriginStation] != processIn)
- return false;
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(processIn))
- return true;
- }
- }
- return false;
- }
- public bool CheckWaferNeedProcess(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
- {
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(ModuleName.PMB))
- {
- if (processIn == ModuleName.System)
- return true;
- if (_isFixAlignerAndCooling && _mapLpPm[(ModuleName)wafer.OriginStation] != processIn)
- return false;
- if (wafer.ProcessJob.Sequence.Steps[i].StepModules
- .Contains(processIn))
- return true;
- }
- }
- return false;
- }
- private bool CheckVacuumWaferHasAvailableTarget(ModuleName waferModule, int waferSlot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- //System.Diagnostics.Trace.Assert(!wafer.IsEmpty);
- //if (CheckWaferNeedProcess(waferModule, waferSlot))
- //{
- // // Check for an empty PM
- // foreach (var pm in _lstPms)
- // {
- // if (WaferManager.Instance.CheckNoWafer(pm.Module, 0))
- // {
- // if (pm.IsAvailable == false)
- // continue;
- // if (!CheckWaferNextProcessIn(waferModule, waferSlot, pm.Module))
- // continue;
- // return true;
- // }
- // }
- //}
- //else
- {
- // No more processing needed, check for a outbound BUFFER slot
- foreach (var buffer in _lstCoolings)
- {
- if (!buffer.IsAvailable)
- continue;
- if (WaferManager.Instance.CheckNoWafer(buffer.Module, 0))
- {
- return true;
- }
- }
- }
- return false;
- }
- private bool CheckWaferHasAvailableTarget(ModuleName waferModule, int waferSlot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- //sequence done, return LP
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return true;
- foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- if (WaferManager.Instance.CheckNoWafer(stepModule, 0))
- return true;
- }
- return false;
- }
- private bool CheckBufferWaferHasAvailableTarget(ModuleName waferModule, int waferSlot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
- //System.Diagnostics.Trace.Assert(!wafer.IsEmpty);
- if (!CheckWaferNeedProcess(waferModule, waferSlot))
- return true;
- // Check for an empty PM
- foreach (var pm in _lstPms)
- {
- if (WaferManager.Instance.CheckNoWafer(pm.Module, 0))
- {
- if (pm.IsAvailable == false)
- continue;
- if (!CheckWaferNextProcessIn(waferModule, waferSlot, pm.Module))
- continue;
- return true;
- }
- }
- return false;
- }
- private bool SetSequenceTemperatureInfo(SequenceInfo seq, out string reason)
- {
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
- if (stepInfo.StepParameter.ContainsKey(attr)
- && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
- {
- var recipeName = (string)stepInfo.StepParameter[attr];
- if (!string.IsNullOrEmpty(recipeName))
- {
- var recipeContent =
- RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
- if (string.IsNullOrEmpty(recipeContent))
- {
- reason = $"Can not find recipe file{recipeName}";
- return false;
- }
- try
- {
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(recipeContent);
- var substrateTemp = xml.DocumentElement.HasAttribute("SubstrateTemp") ? xml.DocumentElement.Attributes["SubstrateTemp"].Value : "";
- if (!float.TryParse(substrateTemp, out float temp))
- {
- reason = $"Invalid substrate temperature in recipe head {recipeName}";
- return false;
- }
- seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"] = temp;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- reason = $"recipe not valid, {recipeName}";
- return false;
- }
- }
- }
- }
- }
- }
- reason = "";
- return true;
- }
- private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
- {
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
- if (stepInfo.StepParameter.ContainsKey(attr)
- && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
- {
- var recipeName = (string)stepInfo.StepParameter[attr];
- if (!string.IsNullOrEmpty(recipeName))
- {
- var recipeContent =
- RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
- if (string.IsNullOrEmpty(recipeContent))
- {
- reason = $"Can not find recipe file{recipeName}";
- return false;
- }
- }
- }
- }
- }
- }
- reason = "";
- return true;
- }
- private bool GetWaferSequenceAlignTime(ModuleName module, int slot, out float time)
- {
- time = 0;
- if (!WaferManager.Instance.CheckHasWafer(module, slot))
- return false;
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1)
- && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2)
- && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1)
- && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
- return false;
- if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter.ContainsKey("CoolingTime"))
- return false;
- if (!float.TryParse((string)wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["CoolingTime"],
- out time))
- return false;
- return true;
- }
- private int GetWaferCountOutofLP(ModuleName lp)
- {
- int count = 0;
- var lstPosition = new List<ModuleName>()
- {
- ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2, ModuleName.PMA, ModuleName.PMB,
- };
- foreach (var moduleName in lstPosition)
- {
- if (ModuleHelper.IsPm(moduleName) && !GetModule(moduleName.ToString()).IsOnline)
- continue;
- if (WaferManager.Instance.CheckHasWafer(moduleName, 0))
- {
- if (lp == ModuleName.System ||
- WaferManager.Instance.GetWafer(moduleName, 0).OriginStation == (int)lp)
- count++;
- }
- }
- return count;
- }
- private SlotItem GetWaferReturnLoadPort(ModuleName module, int slot)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
- if (!wafer.IsEmpty)
- {
- return new SlotItem((ModuleName)wafer.OriginStation, wafer.OriginSlot);
- }
- return null;
- }
- private int GetWaferCountInJobQueue(ModuleName sourceLp)
- {
- int count = 0;
- foreach (var lp in _lstLps)
- {
- for (int i = 0; i < 25; i++)
- {
- if (CheckWaferNeedProcess(lp.Module, i) && (sourceLp == ModuleName.System || sourceLp == lp.Module))
- count++;
- }
- }
- return count;
- }
- /// <summary>
- /// 获取下一个Wafer。根据某个LP,或者任意LP
- /// </summary>
- /// <param name="lpModule">如果是System,表示查询的时候根据任意LoadPort</param>
- /// <returns></returns>
- private SlotItem GetNextWaferInJobQueue(ModuleName lpModule)
- {
- if (!_isRunningInParallelMode)
- {
- foreach (var cj in _lstControlJobs)
- {
- if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
- continue;
- if (cj.State == EnumControlJobState.Executing)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
- return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
- }
- }
- }
- }
- }
- return null;
- }
- //parallel mode
- Dictionary<string, SlotItem> pjWafer = new Dictionary<string, SlotItem>();
- Dictionary<string, List<ModuleName>> pmUsed = new Dictionary<string, List<ModuleName>>();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State != EnumControlJobState.Executing)
- continue;
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
- {
- pjWafer[pj.Name] = new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
- break;
- }
- }
- }
- }
- }
- if (pjWafer.Count == 0)
- return null;
- if (pjWafer.Count == 1)
- return pjWafer.Values.First();
- string preferPj = pjWafer.Keys.First();
- int runningWaferCount = GetWaitingProcessWaferCount(preferPj);
- foreach (var slotItem in pjWafer)
- {
- if (slotItem.Key == preferPj)
- continue;
- int count = GetWaitingProcessWaferCount(slotItem.Key);
- if (count < runningWaferCount)
- {
- preferPj = slotItem.Key;
- runningWaferCount = count;
- }
- }
- return pjWafer[preferPj];
- }
- private int GetWaitingProcessWaferCount(string pjName)
- {
- List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
- {
- Tuple.Create(ModuleName.EfemRobot, 0),
- Tuple.Create(ModuleName.Aligner1, 0),
- Tuple.Create(ModuleName.Aligner2, 0),
- Tuple.Create(ModuleName.PMA, 0),
- Tuple.Create(ModuleName.PMB, 0),
- };
- int count = 0;
- foreach (var tuple in location)
- {
- if (ModuleHelper.IsPm(tuple.Item1) && !GetModule(tuple.Item1.ToString()).IsOnline)
- continue;
- WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
- if (wafer.IsEmpty)
- continue;
- if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
- count++;
- }
- return count;
- }
- private int GetCoolingWaferCount(string pjName)
- {
- List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
- {
- Tuple.Create(ModuleName.Cooling1, 0),
- Tuple.Create(ModuleName.Cooling2, 0),
- };
- int count = 0;
- foreach (var tuple in location)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
- if (wafer.IsEmpty)
- continue;
- if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
- count++;
- }
- return count;
- }
- private int GetProcessingWaferCount(string pjName)
- {
- List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
- {
- Tuple.Create(ModuleName.PMA, 0),
- Tuple.Create(ModuleName.PMB, 0),
- };
- int count = 0;
- foreach (var tuple in location)
- {
- if (ModuleHelper.IsPm(tuple.Item1) && !GetModule(tuple.Item1.ToString()).IsOnline)
- continue;
- WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
- if (wafer.IsEmpty)
- continue;
- if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
- count++;
- }
- return count;
- }
- private int GetMaxOutWafer()
- {
- return 6;
- }
- private List<ModuleName> GetPmUsedInRunningPj()
- {
- var pmUsed = new List<ModuleName>();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
- continue;
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
- {
- for (int i = 0; i < pj.Sequence.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
- pmUsed.Add(module);
- }
- }
- }
- }
- }
- return pmUsed;
- }
- private List<SchedulerPM> GetPmNeeded(ControlJobInfo cj)
- {
- List<SchedulerPM> result = new List<SchedulerPM>();
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName != cj.Name)
- continue;
- var seq = pj.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- var pm = _lstPms.Find(x => x.Module == module);
- if (pm != null && !result.Contains(pm))
- {
- result.Add(pm);
- }
- }
- }
- }
- }
- return result;
- }
- private List<SchedulerPM> GetPmNeeded(ProcessJobInfo pj)
- {
- List<SchedulerPM> result = new List<SchedulerPM>();
- var seq = pj.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- var pm = _lstPms.Find(x => x.Module == module);
- if (pm != null && !result.Contains(pm))
- {
- result.Add(pm);
- }
- }
- }
- }
- return result;
- }
- public bool CheckRecipeUsedInJob(string pathName)
- {
- foreach (var pj in _lstProcessJobs)
- {
- var seq = pj.Sequence;
- for (int i = 0; i < seq.Steps.Count; i++)
- {
- SequenceStepInfo stepInfo = seq.Steps[i];
- foreach (var module in stepInfo.StepModules)
- {
- if (ModuleHelper.IsPm(module))
- {
- string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
- if (stepInfo.StepParameter.ContainsKey(attr)
- && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
- {
- var recipeName = (string)stepInfo.StepParameter[attr];
- if (!string.IsNullOrEmpty(recipeName))
- {
- if (pathName.EndsWith(recipeName+".rcp"))
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
- public bool CheckSequenceUsedInJob(string pathName)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pathName.EndsWith(pj.Sequence.Name+".seq"))
- return true;
- }
- return false;
- }
- #endregion Logic Check
- }
- }
|