12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Diagnostics;
- using Aitex.Core.Common;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Sorter.Common;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.Fsm;
- using MECF.Framework.Common.Jobs;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.Common.DBCore;
- using Venus_Core;
- using Venus_RT.Modules.Schedulers;
- using Venus_RT.Scheduler;
- using Venus_Unity;
- namespace Venus_RT.Modules
- {
- enum ModulePriority
- {
- High,
- Middle,
- Low,
- Stop,
- }
- public enum MovingStatus
- {
- Idle,
- Waiting,
- Moving,
- // PM Status
- WaitProcess,
- StartProcess,
- Processing,
- StartIdleClean,
- IdleClean,
- WaitPreJobClean,
- StartPreJobClean,
- PreJobClean,
- WaitPostJobClean,
- StartPostJobClean,
- PostJobClean,
- WaitWTWClean,
- StartWTWClean,
- WTWClean,
- // Align Status
- WaitAlign,
- StartAlign,
- Aligning,
- }
- class ModuleFlag
- {
- public ModulePriority Priority { get; set; }
- public MovingStatus MovingStatus { get; set; }
- public bool InUsed { get; set; }
- public ModuleFlag(ModulePriority _priority)
- {
- Priority = _priority;
- MovingStatus = MovingStatus.Idle;
- InUsed = true;
- }
- }
- class AutoCycle : ICycle
- {
- private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
- private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
- private RState _cycleState = RState.Init;
- Dictionary<ModuleName, SchedulerModule> _atmSchedulers = new Dictionary<ModuleName, SchedulerModule>();
- Dictionary<ModuleName, ModuleFlag> _atmModules = new Dictionary<ModuleName, ModuleFlag>();
- Dictionary<ModuleName, SchedulerModule> _vacSchedulers = new Dictionary<ModuleName, SchedulerModule>();
- Dictionary<ModuleName, ModuleFlag> _vacModules = new Dictionary<ModuleName, ModuleFlag>();
- SchedulerTMRobot _tmRobot = (SchedulerTMRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot);
- SchedulerEfemRobot _efemRobot = (SchedulerEfemRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot);
- Dictionary<SlotItem, long> _vacReadyOutSlots = new Dictionary<SlotItem, long>();
- Dictionary<SlotItem, long> _vacReadyInSlots = new Dictionary<SlotItem, long>();
- Dictionary<SlotItem, long> _atmReadyOutSlots = new Dictionary<SlotItem, long>();
- Dictionary<SlotItem, long> _atmReadyInSlots = new Dictionary<SlotItem, long>();
- List<int> _LLAInSlot = new List<int> { 0, 1, 2, 3 };
- List<int> _LLAOutSlot = new List<int> { 0, 1, 2, 3 };
- List<int> _LLBInSlot = new List<int> { 0, 1, 2, 3 };
- List<int> _LLBOutSlot = new List<int> { 0, 1, 2, 3 };
- int _LLASlotNumber = 4;
- int _LLBSlotNumber = 4;
- int _efemRobotSingleArmOption = 0;
- List<MoveItem> _movingItems = new List<MoveItem>();
- List<MoveItem> _efemMovingItems = new List<MoveItem>();
- Dictionary<SlotItem, Guid> _vacWaferTargets = new Dictionary<SlotItem, Guid>();
- Dictionary<SlotItem, Guid> _atmWaferTargets = new Dictionary<SlotItem, Guid>();
- R_TRIG _vacMoveFinishTrig = new R_TRIG();
- R_TRIG _atmMoveFinishTrig = new R_TRIG();
- private SchedulerFACallback _faCallback;
- private SchedulerDBCallback _dbCallback;
- private bool _isCycleMode;
- private int _cycleSetPoint = 0;
- private int _cycledCount = 0;
- private int _cycledWafer = 0;
- private float _throughput = 0.0f;
- private Dictionary<ModuleName, int> _lpCycleWafer = new Dictionary<ModuleName, int>();
- private Dictionary<ModuleName, int> _lpCycleCount = new Dictionary<ModuleName, int>();
- private Stopwatch _cycleWatch = new Stopwatch();
- private List<ModuleName> _waitPreCleanPMs = new List<ModuleName>();
- private List<ModuleName> _waitPostCleanPMs = new List<ModuleName>();
- private Dictionary<ModuleName, string> _waitWTWCleanPMs = new Dictionary<ModuleName, string>();
- private List<Guid> _lstReturnWafers = new List<Guid>();
- SequenceLLInOutPath _LLInOutPath = SequenceLLInOutPath.DInDOut;
- public SequenceLLInOutPath LLInOutPath { get { return _LLInOutPath; } }
- public bool HasJobRunning => _lstControlJobs.Count > 0;
- public RState CycleState => _cycleState;
- private Dictionary<string, ControlJobInfo> _loadportControlJobDic = new Dictionary<string, ControlJobInfo>();
- #region public interface
- public AutoCycle()
- {
- _faCallback = new SchedulerFACallback();
- _dbCallback = new SchedulerDBCallback();
- InitModules();
- _LLASlotNumber = SC.GetValue<int>("LLA.SlotNumber");
- _LLBSlotNumber = SC.GetValue<int>("LLB.SlotNumber");
- _LLAInSlot.RemoveAll(item => item >= _LLASlotNumber);
- _LLAOutSlot.RemoveAll(item => item >= _LLASlotNumber);
- _LLBInSlot.RemoveAll(item => item >= _LLBSlotNumber);
- _LLBOutSlot.RemoveAll(item => item >= _LLBSlotNumber);
- _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
- DATA.Subscribe("Scheduler.CycledCount", () => _cycledCount, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("Scheduler.CycledWafer", () => _cycledWafer, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("Scheduler.CycleSetPoint", () => _cycleSetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("Scheduler.Throughput", () => _throughput, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
- DATA.Subscribe("Scheduler.PjNameList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.LotName.ToString()).ToList());
- for(int i=1;i<=3;i++)
- {
- _loadportControlJobDic[$"LP{i}"] = null;
- string lp = $"LP{i}";
- DATA.Subscribe($"{lp}.CurrentControlJob", () => _loadportControlJobDic[lp],SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- }
- public RState Start(params object[] objs)
- {
- _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
- _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
- _cycledWafer = 0;
- _cycledCount = 0;
- _throughput = 0;
- _cycleWatch.Stop();
- _lpCycleWafer.Clear();
- _lpCycleCount.Clear();
- return RState.Running;
- }
- public RState Monitor()
- {
- if (_cycleState == RState.Running)
- {
- prelude();
- driveAtmSystem();
- driveVacSystem();
- epilogue();
- }
- return _cycleState;
- }
- public void Abort()
- {
- }
- public bool CreateJob(Dictionary<string, object> param,out string reason)
- {
- reason = "";
- _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"];
- if (string.IsNullOrEmpty(jobId))
- {
- jobId = "CJ_Local_" + module;
- }
- string lotId = jobId;
- if (param.ContainsKey("LotId"))
- lotId = (string)param["LotId"];
- string preCleanRecipe = param.ContainsKey("PreCleanRecipeName") ? (string)param["PreCleanRecipeName"] : string.Empty;
- string postCleanRecipe = param.ContainsKey("PostCleanRecipeName") ? (string)param["PostCleanRecipeName"] : string.Empty;
- if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
- {
- reason = $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
- {
- reason = $"{module} should be LoadPort";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- if (_lstControlJobs.Exists(x => x.Name == jobId))
- {
- reason = $"{jobId} already created";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System,reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- SchedulerLoadPort lp = _atmSchedulers[ModuleHelper.Converter(module)] as SchedulerLoadPort;
- if (!lp.CheckReadyRunJob())
- {
- reason = $"{module} not ready";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- 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);
- cj.JetState = EnumJetCtrlJobState.Created;
- cj.PreJobClean = preCleanRecipe;
- cj.PostJobClean = postCleanRecipe;
- cj.SequenceNameList = slotSequence;
- cj.CarrierID = "";
- 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 < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); 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[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
- }
- if (!seqSlotWafers.ContainsKey(groupName))
- {
- seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
- }
- seqSlot[groupName][i] = true;
- if (!WaferManager.Instance.CheckHasWafer(module, i))
- {
- reason = $"job wafer: {module} slot {i + 1} not in the carrier";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- return false;
- }
- if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
- {
- reason = $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
- {
- reason = $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
- WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
- seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
- cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
- LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
- }
- if (seqSlotWafers.Count == 0)
- {
- reason = $"job has not assign wafer";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- 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]]);
- if(pj.Sequence==null)
- {
- reason = $"invalid sequence[{indexSequence[seqs[i]]}]";
- return false;
- }
- pj.ControlJobName = cj.Name;
- pj.LotName = lotId;
- pj.SlotWafers = seqSlotWafers[seqs[i]];
- pj.SetState(EnumProcessJobState.Queued);
- if (!CheckSequencePmReady(pj.Sequence, null, out _, out reason))
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"no valid chamber for the {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- if (!RouteManager.IsATMMode && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"recipe file not valid in the sequence, {reason}");
- _faCallback.JobCreateFailed(module, lotId, jobId, "");
- return false;
- }
- pjs.Add(pj);
- }
- _dbCallback.LotUpdate(cj);
- foreach (var pj in pjs)
- {
- cj.ProcessJobNameList.Add(pj.Name);
- _lstProcessJobs.Add(pj);
- }
- _lstControlJobs.Add(cj);
- //AssociatedPMWithLP(cj);
- _loadportControlJobDic[cj.Module] = cj;
- _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
- return true;
- }
- public bool CheckAllJobDone()
- {
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
- return false;
- }
- return true;
- }
- 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;
- }
- }
- sJobName = "NULL";
- return false;
- }
- public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
- {
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- return pj;
- }
- return null;
- }
- public bool AbortJob(string jobName,out string reason)
- {
- reason = "";
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- reason=$"abort job rejected, not found job with id {jobName}";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- return false;
- }
- 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);
- if (_loadportControlJobDic.ContainsKey(cj.Module))
- {
- _loadportControlJobDic[cj.Module] = null;
- }
- return true;
- }
- public bool StopJob(string jobName,out string reason)
- {
- reason = "";
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- reason = $"stop job rejected, not found job with id {jobName}";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System,reason);
- return false;
- }
- foreach (var pj in _lstProcessJobs)
- {
- if (pj.ControlJobName == cj.Name)
- {
- pj.SetState(EnumProcessJobState.Stopping);
- }
- }
- _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
-
- return true;
- }
- public bool ResumeJob(string jobName,out string reason)
- {
- reason = "";
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- reason = $"resume job rejected, not found job with id {jobName}";
- //LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"resume job rejected, not found job with id {jobName}");
- return false;
- }
- if (cj.State == EnumControlJobState.Paused)
- {
- cj.SetState(EnumControlJobState.Executing);
- }
- _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
- _cycleState = RState.Running;
- return true;
- }
- public bool PauseJob(string jobName,out string reason)
- {
- reason = "";
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- reason = $"pause job rejected, not found job with id {jobName}";
- //LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"pause job rejected, not found job with id {jobName}");
- return false;
- }
- if (cj.State == EnumControlJobState.Executing)
- {
- cj.SetState(EnumControlJobState.Paused);
- }
- _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
- if (!_lstControlJobs.Exists(job => job.State == EnumControlJobState.Executing))
- _cycleState = RState.Paused;
- return true;
- }
- public bool StartJob(string jobName,out string reason)
- {
- reason = "";
- ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
- if (cj == null)
- {
- reason = $"start job rejected, not found job with id {jobName}";
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
- return false;
- }
- if (cj.State == EnumControlJobState.WaitingForStart)
- {
- cj.SetState(EnumControlJobState.Executing);
- //PreJobClean(cj);
- cj.JetState = EnumJetCtrlJobState.Quequed;
- (_atmSchedulers[ModuleHelper.Converter(cj.Module)] as SchedulerLoadPort).NoteJobStart();
- cj.StartTime = DateTime.Now;
- _dbCallback.LotCreated(cj);
- _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
- //if (!_blockingWatcher.IsRunning)
- // _blockingWatcher.Restart();
- //ResetTraceFlag();
- }
- if (!_cycleWatch.IsRunning)
- {
- _cycleWatch.Restart();
- }
- if (!_lpCycleWafer.Keys.Contains(ModuleHelper.Converter(cj.Module)))
- {
- _lpCycleCount.Add(ModuleHelper.Converter(cj.Module), 0);
- _lpCycleWafer.Add(ModuleHelper.Converter(cj.Module), 0);
- }
- _cycleState = RState.Running;
- return true;
- }
- public void Clear()
- {
- _vacWaferTargets.Clear();
- _atmWaferTargets.Clear();
- _movingItems.Clear();
- _efemMovingItems.Clear();
- _waitPreCleanPMs.Clear();
- _waitPostCleanPMs.Clear();
- _waitWTWCleanPMs.Clear();
- _vacMoveFinishTrig.RST = true;
- _atmMoveFinishTrig.RST = true;
- _efemRobot.ResetTask();
- _tmRobot.ResetTask();
- foreach (var module in _vacSchedulers)
- {
- module.Value.ResetTask();
- _vacModules[module.Key].MovingStatus = MovingStatus.Idle;
- }
- foreach (var module in _atmSchedulers)
- {
- module.Value.ResetTask();
- _atmModules[module.Key].MovingStatus = MovingStatus.Idle;
- }
- _lstControlJobs.Clear();
- List<string> keys = _loadportControlJobDic.Keys.ToList();
- foreach(var key in keys)
- {
- _loadportControlJobDic[key] = null;
- }
- _lstProcessJobs.Clear();
- _cycleState = RState.End;
- }
- public bool ManualReturnWafer(object[] objs)
- {
- ModuleName SourceModule = (ModuleName)objs[0];
- int SourceSlot = (int)objs[1];
- if (!_vacSchedulers.Keys.Contains(SourceModule) && !_atmSchedulers.Keys.Contains(SourceModule))
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Invalid source module {SourceModule} for manual return wafer");
- return false;
- }
- if (WaferManager.Instance.CheckNoWafer(SourceModule, SourceSlot))
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Can not return wafer as {SourceModule} {SourceSlot} has no wafer");
- return false;
- }
- if (!_vacSchedulers.Keys.Contains(SourceModule) || !_vacSchedulers[SourceModule].IsIdle)
- {
- LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"The module: {SourceModule} is not ready for return wafer");
- return false;
- }
- var wafer = WaferManager.Instance.GetWafer(SourceModule, SourceSlot);
- LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Manual return wafer: {wafer.WaferOrigin} at {SourceModule} {SourceSlot} while system is auto running");
- _lstReturnWafers.Add(wafer.InnerId);
- return true;
- }
- #endregion
- private void InitModules()
- {
- foreach (var module in new ModuleName[]{ ModuleName.LP1, ModuleName.LP2, ModuleName.LP3,
- ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2})
- {
- if (ModuleHelper.IsInstalled(module))
- {
- if (ModuleHelper.IsLoadPort(module))
- {
- _atmSchedulers[module] = Singleton<TransferModule>.Instance.GetScheduler(module);
- _atmModules[module] = new ModuleFlag(ModulePriority.Middle);
- }
- else if (ModuleHelper.IsAligner(module) || ModuleHelper.IsCooling(module))
- {
- _atmSchedulers[module] = Singleton<TransferModule>.Instance.GetScheduler(module);
- _atmModules[module] = new ModuleFlag(ModulePriority.Middle);
- }
- }
- }
- foreach (var module in new ModuleName[] { ModuleName.PMA, ModuleName.PMB, ModuleName.PMC,
- ModuleName.PMD, ModuleName.PME, ModuleName.PMF})
- {
- if (ModuleHelper.IsInstalled(module))
- {
- _vacSchedulers[module] = Singleton<TransferModule>.Instance.GetScheduler(module);
- _vacModules[module] = new ModuleFlag(ModulePriority.Middle);
- }
- }
- foreach (var module in new ModuleName[] { ModuleName.LLA, ModuleName.LLB })
- {
- if (ModuleHelper.IsInstalled(module))
- {
- var llScheduler = Singleton<TransferModule>.Instance.GetScheduler(module);
- _vacSchedulers[module] = llScheduler;
- _vacModules[module] = new ModuleFlag(ModulePriority.Middle);
- _atmSchedulers[module] = llScheduler;
- _atmModules[module] = new ModuleFlag(ModulePriority.Middle);
- }
- }
- }
- private void prelude()
- {
- }
- private void epilogue()
- {
- CheckWaferArrived();
- ProcessPMTask();
- ProcessAlignerTask();
- UpdateProcessJobStatus();
- UpdateControlJobStatus();
- //DispatchCtrlJobs();
- UpdateLLInOutPathProperty();
- }
- private void driveVacSystem()
- {
- if (_tmRobot.IsAvailable && _movingItems.Count == 0 && _tmRobot.RobotStatus != RState.Running)
- {
- RoutingInnerPart();
- RuningTMRobotTask();
- }
- }
- #region Vacuum System
- private void PumpingTMRobotTask()
- {
- if (!_tmRobot.IsAvailable || _tmRobot.RobotStatus == RState.Running)
- return;
- foreach (var mod in _vacSchedulers)
- {
- if (mod.Value.IsAvailable && _vacModules[mod.Key].MovingStatus == MovingStatus.Idle)
- {
- if (ModuleHelper.IsLoadLock(mod.Key))
- {
- var inSlots = mod.Key == ModuleName.LLA ? _LLAInSlot : _LLBInSlot;
- foreach (var slot in inSlots)
- {
- if (IsLoadLockReservedByEFEM(mod.Key))
- continue;
- if (WaferManager.Instance.CheckHasWafer(mod.Key, slot) && IsVacWaferReadyOut(mod.Key, slot))
- {
- _vacReadyOutSlots.Add(new SlotItem(mod.Key, slot), mod.Value.WaferArrivedTicks(slot));
- }
- }
- var outSlots = mod.Key == ModuleName.LLA ? _LLAOutSlot : _LLBOutSlot;
- foreach (var slot in outSlots)
- {
- if (IsLoadLockReservedByEFEM(mod.Key))
- continue;
- if (WaferManager.Instance.CheckNoWafer(mod.Key, slot))
- {
- _vacReadyInSlots.Add(new SlotItem(mod.Key, slot), mod.Value.WaferArrivedTicks(slot));
- }
- }
- }
- else
- {
- if (WaferManager.Instance.CheckHasWafer(mod.Key, 0) && IsVacWaferReadyOut(mod.Key, 0)) // processed?
- {
- _vacReadyOutSlots.Add(new SlotItem(mod.Key, 0), mod.Value.WaferArrivedTicks(0));
- }
- else if (WaferManager.Instance.CheckNoWafer(mod.Key, 0))
- {
- _vacReadyInSlots.Add(new SlotItem(mod.Key, 0), mod.Value.WaferArrivedTicks(0));
- }
- }
- }
- }
- _vacReadyOutSlots = _vacReadyOutSlots.OrderByDescending(item => item.Value).ToDictionary(k => k.Key, v => v.Value);
- }
- bool SearchWaferDestination(SlotItem outSlot, out SlotItem destSlot)
- {
- destSlot = new SlotItem(ModuleName.System, -1);
- var wafer = WaferManager.Instance.GetWafer(outSlot.Module, outSlot.Slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- var validSlots = GetModuleValidSlots(next_module);
- foreach (var nSlot in validSlots)
- {
- if (_movingItems.Exists(mItem => mItem.DestinationModule == next_module && mItem.DestinationSlot == nSlot))
- continue;
- foreach (var inItem in _vacReadyInSlots)
- {
- if (inItem.Key.Module == next_module && inItem.Key.Slot == nSlot && _vacModules[next_module].MovingStatus == MovingStatus.Idle && _vacSchedulers[next_module].IsAvailable)
- {
- destSlot.Module = next_module;
- destSlot.Slot = nSlot;
- return true;
- }
- }
- }
- }
- return false;
- }
- bool SearchCanReplaceSlot(SlotItem llSlot, out SlotItem replaceSlot, out SlotItem destSlot)
- {
- replaceSlot = new SlotItem(ModuleName.System, -1);
- destSlot = new SlotItem(ModuleName.System, -1);
- var wafer = WaferManager.Instance.GetWafer(llSlot.Module, llSlot.Slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- if (!ModuleHelper.IsPm(next_module) || WaferManager.Instance.CheckNoWafer(next_module, 0))
- continue;
- if (SearchWaferDestination(new SlotItem(next_module, 0), out destSlot))
- {
- replaceSlot.Module = next_module;
- replaceSlot.Slot = 0;
- return true;
- }
- }
- return false;
- }
- Queue<int> GetModuleValidSlots(ModuleName mod)
- {
- var validSlot = new Queue<int>();
- if (ModuleHelper.IsLoadLock(mod))
- {
- if (!IsLoadLockReservedByEFEM(mod))
- {
- var inSlots = mod == ModuleName.LLA ? _LLAInSlot : _LLBInSlot;
- foreach (var slot in inSlots)
- {
- if (WaferManager.Instance.CheckNoWafer(mod, slot) && !_movingItems.Exists(item => item.DestinationModule == mod && item.DestinationSlot == slot))
- validSlot.Enqueue(slot);
- if (WaferManager.Instance.CheckHasWafer(mod, slot) && _movingItems.Exists(item => item.SourceModule == mod && item.SourceSlot == slot))
- validSlot.Enqueue(slot);
- }
- }
- }
- else if (ModuleHelper.IsPm(mod))
- {
- if (WaferManager.Instance.CheckNoWafer(mod, 0) && !_movingItems.Exists(item => item.DestinationModule == mod))
- validSlot.Enqueue(0);
- if (WaferManager.Instance.CheckHasWafer(mod, 0) && _movingItems.Exists(item => item.SourceModule == mod))
- validSlot.Enqueue(0);
- }
- return validSlot;
- }
- private int GetModuleSlotCount(ModuleName mod)
- {
- int nSlotCount = 1;
- if (ModuleHelper.IsLoadLock(mod))
- {
- nSlotCount = mod == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- }
- else if (ModuleHelper.IsLoadPort(mod))
- {
- nSlotCount = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
- }
- else if (ModuleHelper.IsTMRobot(mod) || ModuleHelper.IsEFEMRobot(mod))
- {
- nSlotCount = 2;
- }
- return nSlotCount;
- }
- List<MoveItem> SearchWaitInSlots(ModuleName inModule)
- {
- List<MoveItem> inSlots = new List<MoveItem>();
- var validSlots = GetModuleValidSlots(inModule);
- foreach (var slot in _vacReadyOutSlots)
- {
- if (slot.Key.Module == inModule || _vacModules[slot.Key.Module].MovingStatus != MovingStatus.Idle)
- continue;
- if (IsLoadLockReservedByEFEM(slot.Key.Module))
- continue;
- var wafer = WaferManager.Instance.GetWafer(slot.Key.Module, slot.Key.Slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- continue;
- foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- if (next_module == inModule && validSlots.Count > 0 && !_movingItems.Exists(item => item.SourceModule == slot.Key.Module && item.SourceSlot == slot.Key.Slot))
- {
- if (!inSlots.Exists(item => item.SourceModule == slot.Key.Module && item.SourceSlot == slot.Key.Slot))
- {
- inSlots.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, inModule, validSlots.Dequeue(), Hand.None));
- }
- }
- }
- }
- return inSlots;
- }
- private void UpdateItemMovingStatus(MoveItem moveItem, MovingStatus status = MovingStatus.Moving)
- {
- if (!ModuleHelper.IsTMRobot(moveItem.DestinationModule))
- {
- _vacModules[moveItem.DestinationModule].MovingStatus = status;
- }
- if (!ModuleHelper.IsTMRobot(moveItem.SourceModule))
- {
- _vacModules[moveItem.SourceModule].MovingStatus = status;
- }
- }
- private void UpdateModuleMovingStatus(ModuleName module, MovingStatus status = MovingStatus.Moving)
- {
- if (!ModuleHelper.IsTMRobot(module))
- {
- _vacModules[module].MovingStatus = status;
- }
- }
- private void ProcessTMRobotTask()
- {
- if (_tmRobot.IsAvailable && _tmRobot.RobotStatus != RState.Running)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
- {
- for (int i = 0; i < 2; i++)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
- {
- if (SearchWaferDestination(new SlotItem(ModuleName.TMRobot, i), out SlotItem destSlot))
- {
- _movingItems.Add(new MoveItem(ModuleName.TMRobot, i, destSlot.Module, destSlot.Slot, (Hand)i));
- UpdateModuleMovingStatus(destSlot.Module);
- }
- }
- }
- return;
- }
- foreach (var slot in _vacReadyOutSlots)
- {
- if (_vacModules[slot.Key.Module].MovingStatus != MovingStatus.Idle)
- continue;
- if (ModuleHelper.IsLoadLock(slot.Key.Module))
- {
- if (IsLoadLockReservedByEFEM(slot.Key.Module))
- continue;
- var llStatus = GetLLProcessStatusCount(slot.Key.Module);
- if (SearchWaferDestination(slot.Key, out SlotItem destSlot))
- {
- _movingItems.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, destSlot.Module, destSlot.Slot, Hand.None));
- UpdateModuleMovingStatus(slot.Key.Module);
- UpdateModuleMovingStatus(destSlot.Module);
- if (llStatus.Item2 > 1)
- {
- // check whether match double pick pattern
- foreach (var item in _vacReadyOutSlots)
- {
- if (item.Key.Module == slot.Key.Module && item.Key.Slot != slot.Key.Slot)
- {
- if (SearchWaferDestination(item.Key, out SlotItem destSlot_2))
- {
- _movingItems.Add(new MoveItem(item.Key.Module, item.Key.Slot, destSlot_2.Module, destSlot_2.Slot, Hand.None));
- UpdateModuleMovingStatus(destSlot_2.Module);
- break;
- }
- }
- }
- if (_movingItems.Count == 1)
- {
- foreach (var item in _vacReadyOutSlots)
- {
- if (item.Key.Module == slot.Key.Module && item.Key.Slot != slot.Key.Slot)
- {
- if (SearchCanReplaceSlot(item.Key, out SlotItem replaceSlot, out SlotItem destSlot_2))
- {
- _movingItems.Add(new MoveItem(item.Key.Module, item.Key.Slot, replaceSlot.Module, replaceSlot.Slot, Hand.None));
- _movingItems.Add(new MoveItem(replaceSlot.Module, replaceSlot.Slot, destSlot_2.Module, destSlot_2.Slot, Hand.None));
- UpdateModuleMovingStatus(replaceSlot.Module);
- UpdateModuleMovingStatus(destSlot.Module);
- return;
- }
- }
- }
- }
- }
- // check whether match swap pattern
- int inCount = 0;
- var in_slots = SearchWaitInSlots(slot.Key.Module);
- foreach (var in_slot in in_slots)
- {
- if (_vacModules[in_slot.DestinationModule].MovingStatus == MovingStatus.Idle && inCount < 2)
- {
- _movingItems.Add(in_slot);
- UpdateItemMovingStatus(in_slot);
- inCount++;
- }
- }
- return;
- }
- }
- else // PM
- {
- if (SearchWaferDestination(slot.Key, out SlotItem destSlot))
- {
- _movingItems.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, destSlot.Module, destSlot.Slot, Hand.None));
- UpdateModuleMovingStatus(slot.Key.Module);
- UpdateModuleMovingStatus(destSlot.Module);
- // check whether match double move pattern
- int inCount = 0;
- var same_dest = SearchWaitInSlots(destSlot.Module);
- foreach (var in_slot in same_dest)
- {
- if (_vacModules[in_slot.SourceModule].MovingStatus == MovingStatus.Idle && inCount < 1)
- {
- _movingItems.Add(in_slot);
- UpdateItemMovingStatus(in_slot);
- inCount++;
- }
- }
- // check whether match swap pattern
- if (inCount == 0 && !IsPMWaferNeedWTWClean(slot.Key.Module, out string wtwClean))
- {
- int swapCount = 0;
- var in_slots = SearchWaitInSlots(slot.Key.Module);
- foreach (var swap_slot in in_slots)
- {
- if (_vacModules[swap_slot.SourceModule].MovingStatus == MovingStatus.Idle && swapCount < 1)
- {
- _movingItems.Add(swap_slot);
- UpdateItemMovingStatus(swap_slot);
- swapCount++;
- }
- }
- }
- return;
- }
- }
- }
- _vacReadyOutSlots.Clear();
- _vacReadyInSlots.Clear();
- }
- }
- bool PushTMRobotWafers()
- {
- if (_tmRobot.IsAvailable && _tmRobot.RobotStatus != RState.Running)
- {
- for (int i = 0; i < 2; i++)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i) && IsWaferCtrlJobRuning(ModuleName.TMRobot, i))
- {
- if (SearchWaferDestination(new SlotItem(ModuleName.TMRobot, i), out SlotItem destSlot))
- {
- _movingItems.Add(new MoveItem(ModuleName.TMRobot, i, destSlot.Module, destSlot.Slot, (Hand)i));
- UpdateModuleMovingStatus(destSlot.Module);
- }
- }
- }
- }
- return _movingItems.Count > 0;
- }
- bool PushPmWafers()
- {
- if (_tmRobot.IsAvailable && _tmRobot.RobotStatus != RState.Running)
- {
- foreach (var slot in _vacReadyOutSlots)
- {
- if (_vacModules[slot.Key.Module].MovingStatus != MovingStatus.Idle)
- continue;
- if (ModuleHelper.IsPm(slot.Key.Module))
- {
- if (SearchWaferDestination(slot.Key, out SlotItem destSlot))
- {
- _movingItems.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, destSlot.Module, destSlot.Slot, Hand.None));
- UpdateModuleMovingStatus(slot.Key.Module);
- UpdateModuleMovingStatus(destSlot.Module);
- // check whether match double move pattern
- int inCount = 0;
- var same_dest = SearchWaitInSlots(destSlot.Module);
- foreach (var in_slot in same_dest)
- {
- if (_vacModules[in_slot.SourceModule].MovingStatus == MovingStatus.Idle && inCount < 1)
- {
- _movingItems.Add(in_slot);
- UpdateItemMovingStatus(in_slot);
- inCount++;
- }
- }
- // check whether match swap pattern
- if (inCount == 0 && !IsPMWaferNeedWTWClean(slot.Key.Module, out string wtwClean))
- {
- int swapCount = 0;
- var in_slots = SearchWaitInSlots(slot.Key.Module);
- foreach (var swap_slot in in_slots)
- {
- if (_vacModules[swap_slot.SourceModule].MovingStatus == MovingStatus.Idle && swapCount < 1)
- {
- _movingItems.Add(swap_slot);
- UpdateItemMovingStatus(swap_slot);
- swapCount++;
- }
- }
- }
- }
- }
- }
- }
- return _movingItems.Count > 0;
- }
- private bool PushLoadlockWafers()
- {
- if (_tmRobot.IsAvailable && _tmRobot.RobotStatus != RState.Running)
- {
- foreach (var slot in _vacReadyOutSlots)
- {
- if (_vacModules[slot.Key.Module].MovingStatus != MovingStatus.Idle)
- continue;
- if (ModuleHelper.IsLoadLock(slot.Key.Module))
- {
- if (IsLoadLockReservedByEFEM(slot.Key.Module))
- continue;
- var llStatus = GetLLProcessStatusCount(slot.Key.Module);
- if (SearchWaferDestination(slot.Key, out SlotItem destSlot))
- {
- _movingItems.Add(new MoveItem(slot.Key.Module, slot.Key.Slot, destSlot.Module, destSlot.Slot, Hand.None));
- UpdateModuleMovingStatus(slot.Key.Module);
- UpdateModuleMovingStatus(destSlot.Module);
- if (llStatus.Item2 > 1)
- {
- // check whether match double pick pattern
- foreach (var item in _vacReadyOutSlots)
- {
- if (item.Key.Module == slot.Key.Module && item.Key.Slot != slot.Key.Slot)
- {
- if (SearchWaferDestination(item.Key, out SlotItem destSlot_2))
- {
- _movingItems.Add(new MoveItem(item.Key.Module, item.Key.Slot, destSlot_2.Module, destSlot_2.Slot, Hand.None));
- UpdateModuleMovingStatus(destSlot_2.Module);
- break;
- }
- }
- }
- if (_movingItems.Count == 1)
- {
- foreach (var item in _vacReadyOutSlots)
- {
- if (item.Key.Module == slot.Key.Module && item.Key.Slot != slot.Key.Slot)
- {
- if (SearchCanReplaceSlot(item.Key, out SlotItem replaceSlot, out SlotItem destSlot_2))
- {
- _movingItems.Add(new MoveItem(item.Key.Module, item.Key.Slot, replaceSlot.Module, replaceSlot.Slot, Hand.None));
- _movingItems.Add(new MoveItem(replaceSlot.Module, replaceSlot.Slot, destSlot_2.Module, destSlot_2.Slot, Hand.None));
- UpdateModuleMovingStatus(replaceSlot.Module);
- UpdateModuleMovingStatus(destSlot.Module);
- return true;
- }
- }
- }
- }
- }
- // check whether match swap pattern
- int inCount = 0;
- var in_slots = SearchWaitInSlots(slot.Key.Module);
- foreach (var in_slot in in_slots)
- {
- if (_vacModules[in_slot.DestinationModule].MovingStatus == MovingStatus.Idle && inCount < 2)
- {
- _movingItems.Add(in_slot);
- UpdateItemMovingStatus(in_slot);
- inCount++;
- }
- }
- return true;
- }
- }
- }
- }
- return _movingItems.Count > 0;
- }
- private bool SearchOutLLSlot(ModuleName pm, ModuleName ll, out SlotItem outSlot)
- {
- outSlot = new SlotItem(ModuleName.System, -1);
- var wafer = WaferManager.Instance.GetWafer(pm, 0);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ll))
- {
- var slotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- for (int slot = 0; slot < slotNumber; slot++)
- {
- if ((WaferManager.Instance.CheckNoWafer(ll, slot) && !_movingItems.Exists(item => item.DestinationModule == ll && item.DestinationSlot == slot)) ||
- (WaferManager.Instance.CheckHasWafer(ll, slot) && _movingItems.Exists(item => item.SourceModule == ll && item.SourceSlot == slot)))
- {
- outSlot.Module = ll;
- outSlot.Slot = slot;
- return true;
- }
- }
- }
- return false;
- }
- private bool SearchValidInPM(ModuleName ll, int slot, out SlotItem inSlot)
- {
- inSlot = new SlotItem(ModuleName.System, -1);
- var wafer = WaferManager.Instance.GetWafer(ll, slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- foreach (var mod in _vacModules)
- {
- if (ModuleHelper.IsPm(mod.Key) && _vacSchedulers[mod.Key].IsAvailable && _vacModules[mod.Key].MovingStatus == MovingStatus.Idle)
- {
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod.Key))
- {
- if ((WaferManager.Instance.CheckNoWafer(mod.Key, 0) && !_movingItems.Exists(item => item.DestinationModule == mod.Key)) ||
- (WaferManager.Instance.CheckHasWafer(mod.Key, 0) && _movingItems.Exists(item => item.SourceModule == mod.Key) && !_movingItems.Exists(item => item.DestinationModule == mod.Key) && !IsPMWaferNeedWTWClean(mod.Key, out string wtwClean)))
- {
- inSlot.Module = mod.Key;
- inSlot.Slot = 0;
- return true;
- }
- }
- }
- }
- return false;
- }
- private bool ForwardPMsWaferToLL(ModuleName ll)
- {
- int outWaferCount = 0;
- foreach (var module in _vacModules)
- {
- if (outWaferCount >= 2)
- break;
- if (ModuleHelper.IsPm(module.Key) && _vacSchedulers[module.Key].IsAvailable && _vacModules[module.Key].MovingStatus == MovingStatus.Idle)
- {
- if (IsWaferCtrlJobRuning(module.Key, 0))
- {
- if (SearchOutLLSlot(module.Key, ll, out SlotItem outSlot))
- {
- outWaferCount++;
- _movingItems.Add(new MoveItem(module.Key, 0, outSlot.Module, outSlot.Slot, Hand.None));
- }
- }
- }
- }
- return _movingItems.Count > 0;
- }
- private bool ForwardLLWaferToPMs(ModuleName ll)
- {
- int inWaferCount = 0;
- var slots = (_vacSchedulers[ll] as SchedulerLoadLock).GetOrderedOutSlot();
- foreach (var slot in slots)
- {
- if (slot >= (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber))
- continue;
- if (inWaferCount >= 2)
- break;
- if (IsWaferCtrlJobRuning(ll, slot) && SearchValidInPM(ll, slot, out SlotItem inSlot))
- {
- inWaferCount++;
- _movingItems.Add(new MoveItem(ll, slot, inSlot.Module, inSlot.Slot, Hand.None));
- }
- }
- return _movingItems.Count > 0;
- }
- private bool ExchangeLLWafersWithPMs(ModuleName ll)
- {
- ForwardPMsWaferToLL(ll);
- ForwardLLWaferToPMs(ll);
- return _movingItems.Count > 0;
- }
- private bool ProcessVacManaulReturnWafers()
- {
- if (_lstReturnWafers.Count == 0)
- return false;
- Queue<SlotItem> returnSlots = new Queue<SlotItem>();
- for (int i = 0; i < 2; i++)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, i))
- {
- var wafer_id = WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).InnerId;
- if (_lstReturnWafers.FindIndex(item => item == wafer_id) != -1)
- {
- returnSlots.Enqueue(new SlotItem(ModuleName.TMRobot, i));
- }
- }
- }
- foreach (var mod in _vacModules)
- {
- if (ModuleHelper.IsPm(mod.Key) && WaferManager.Instance.CheckHasWafer(mod.Key, 0) && _vacSchedulers[mod.Key].IsIdle)
- {
- var wafer_id = WaferManager.Instance.GetWafer(mod.Key, 0).InnerId;
- if (_lstReturnWafers.FindIndex(item => item == wafer_id) != -1)
- {
- returnSlots.Enqueue(new SlotItem(mod.Key, 0));
- }
- }
- }
- if (returnSlots.Count == 0)
- return false;
- var llaSlotStatus = GetLLProcessStatusCount(ModuleName.LLA);
- var llbSlotStatus = GetLLProcessStatusCount(ModuleName.LLB);
- ModuleName destLL = ModuleName.System;
- if (IsLoadReadyForTM(ModuleName.LLA) && llaSlotStatus.empty > 0 && (!IsLoadReadyForTM(ModuleName.LLB) || (!_vacSchedulers[ModuleName.LLB].IsVac && llaSlotStatus.empty == llbSlotStatus.empty) || llaSlotStatus.empty > llbSlotStatus.empty))
- {
- destLL = ModuleName.LLA;
- }
- else if (IsLoadReadyForTM(ModuleName.LLB) && llbSlotStatus.empty > 0)
- {
- destLL = ModuleName.LLB;
- }
- if (destLL != ModuleName.System)
- {
- int slotNumber = destLL == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- for (int i = 0; i < slotNumber; i++)
- {
- if (WaferManager.Instance.CheckNoWafer(destLL, i))
- {
- if (_movingItems.Count >= 2 || returnSlots.Count == 0)
- break;
- var source = returnSlots.Dequeue();
- _movingItems.Add(new MoveItem(source.Module, source.Slot, destLL, i, Hand.None));
- }
- }
- }
- return _movingItems.Count > 0;
- }
- private void RoutingInnerPart()
- {
- if (ProcessVacManaulReturnWafers())
- return;
- if (PushTMRobotWafers())
- return;
- var pmSlotStaus = GetPMValidSlotsStatus();
- if (pmSlotStaus.Processed + pmSlotStaus.Empty == 0)
- return;
- var llaSlotStatus = GetLLProcessStatusCount(ModuleName.LLA);
- var llbSlotStatus = GetLLProcessStatusCount(ModuleName.LLB);
- if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
- {
- ModuleName InModule = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
- ModuleName OutModule = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
- int InNumber = Math.Min(InModule == ModuleName.LLA ? llaSlotStatus.unprocessed : llbSlotStatus.unprocessed, pmSlotStaus.Empty);
- int OutNumber = Math.Min(OutModule == ModuleName.LLA ? llaSlotStatus.empty : llbSlotStatus.empty, pmSlotStaus.Processed);
- if (InNumber + OutNumber == 0)
- return;
- if (IsLoadReadyForTM(InModule) && (!IsLoadReadyForTM(OutModule) || (!_vacSchedulers[OutModule].IsVac && InNumber == OutNumber) || InNumber > OutNumber))
- {
- // move in wafer
- ForwardLLWaferToPMs(InModule);
- }
- else if (IsLoadReadyForTM(OutModule) && OutNumber > 0)
- {
- // move out wafer
- ForwardPMsWaferToLL(OutModule);
- }
- }
- else if (LLInOutPath == SequenceLLInOutPath.AInAOut || LLInOutPath == SequenceLLInOutPath.BInBOut)
- {
- ModuleName loadlock = LLInOutPath == SequenceLLInOutPath.AInAOut ? ModuleName.LLA : ModuleName.LLB;
- if (IsLoadReadyForTM(loadlock))
- {
- // switch wafer
- ExchangeLLWafersWithPMs(loadlock);
- }
- }
- else // DInDOut or mix pattern
- {
- int llaOutNumber = Math.Min(Math.Min(pmSlotStaus.Processed, 2), llaSlotStatus.empty);
- int llaInNumber = Math.Min(Math.Min(llaSlotStatus.unprocessed, 2), pmSlotStaus.Empty + llaOutNumber);
- int llaExchangeNumber = llaOutNumber + llaInNumber;
- int llbOutNumber = Math.Min(Math.Min(pmSlotStaus.Processed, 2), llbSlotStatus.empty);
- int llbInNumber = Math.Min(Math.Min(llbSlotStatus.unprocessed, 2), pmSlotStaus.Empty + llbOutNumber);
- int llbExchangeNumber = llbOutNumber + llbInNumber;
- if (IsLoadReadyForTM(ModuleName.LLA) && ((!_vacSchedulers[ModuleName.LLB].IsVac && llaExchangeNumber == llbExchangeNumber) ||
- (llaExchangeNumber > llbExchangeNumber) ||
- (!IsLoadReadyForTM(ModuleName.LLB) && llaExchangeNumber > 0)))
- {
- ExchangeLLWafersWithPMs(ModuleName.LLA);
- }
- else if (IsLoadReadyForTM(ModuleName.LLB) && llbExchangeNumber > 0)
- {
- ExchangeLLWafersWithPMs(ModuleName.LLB);
- }
- }
- }
- private void RuningTMRobotTask()
- {
- if (_movingItems.Count > 0)
- {
- if (_tmRobot.PostMoveItems(_movingItems.ToArray()))
- {
- foreach (var item in _movingItems)
- {
- var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
- if (wafer.IsEmpty)
- {
- // post alarm
- _cycleState = RState.Failed;
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run TM moving task as Get {item.SourceModule}{item.SourceSlot} Wafer Info failed");
- return;
- }
- var slot = new SlotItem(item.DestinationModule, item.DestinationSlot);
- _vacWaferTargets[slot] = wafer.InnerId;
- }
- }
- }
- }
- private void ProcessPMTask()
- {
- foreach (var mod in _vacModules)
- {
- if (ModuleHelper.IsPm(mod.Key))
- {
- if (_vacSchedulers[mod.Key].IsAvailable)
- {
- switch (mod.Value.MovingStatus)
- {
- case MovingStatus.WaitProcess:
- {
- _vacSchedulers[mod.Key].EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.TMRobot, 0, mod.Key, 0));
- mod.Value.MovingStatus = MovingStatus.StartProcess;
- }
- break;
- case MovingStatus.Processing:
- {
- if (IsPMWaferNeedWTWClean(mod.Key, out string WTWCleanRecipe))
- {
- _waitWTWCleanPMs.Add(mod.Key, WTWCleanRecipe);
- }
- mod.Value.MovingStatus = MovingStatus.Idle;
- }
- break;
- case MovingStatus.IdleClean:
- case MovingStatus.PreJobClean:
- case MovingStatus.PostJobClean:
- case MovingStatus.WTWClean:
- mod.Value.MovingStatus = MovingStatus.Idle;
- break;
- case MovingStatus.Idle:
- {
- var pmScheduler = _vacSchedulers[mod.Key] as SchedulerPM;
- if (IsPMKeepEmpty(mod.Key))
- {
- if (_waitWTWCleanPMs.ContainsKey(mod.Key))
- {
- mod.Value.MovingStatus = MovingStatus.WaitWTWClean;
- }
- else if (_waitPreCleanPMs.Contains(mod.Key))
- {
- mod.Value.MovingStatus = MovingStatus.WaitPreJobClean;
- }
- else if (_waitPostCleanPMs.Contains(mod.Key))
- {
- mod.Value.MovingStatus = MovingStatus.WaitPostJobClean;
- }
- else if (pmScheduler.RunIdleCleanTask()) // Check Idle Clean
- {
- mod.Value.MovingStatus = MovingStatus.StartIdleClean;
- }
- }
- }
- break;
- case MovingStatus.WaitPreJobClean:
- {
- mod.Value.MovingStatus = MovingStatus.Idle;
- var pmScheduler = _vacSchedulers[mod.Key] as SchedulerPM;
- if (IsPMKeepEmpty(mod.Key))
- {
- if (IsPreJobCleanPending(mod.Key, out string preCleanRecipe))
- {
- if (pmScheduler.RunJobCleanTask(preCleanRecipe))
- {
- mod.Value.MovingStatus = MovingStatus.StartPreJobClean;
- }
- _waitPreCleanPMs.Remove(mod.Key);
- }
- }
- }
- break;
- case MovingStatus.WaitPostJobClean:
- {
- mod.Value.MovingStatus = MovingStatus.Idle;
- var pmScheduler = _vacSchedulers[mod.Key] as SchedulerPM;
- if (IsPMKeepEmpty(mod.Key))
- {
- if (IsPostJobCleanPending(mod.Key, out string postCleanRecipe))
- {
- if (pmScheduler.RunJobCleanTask(postCleanRecipe))
- {
- mod.Value.MovingStatus = MovingStatus.StartPostJobClean;
- }
- _waitPostCleanPMs.Remove(mod.Key);
- }
- }
- }
- break;
- case MovingStatus.WaitWTWClean:
- {
- mod.Value.MovingStatus = MovingStatus.Idle;
- var pmScheduler = _vacSchedulers[mod.Key] as SchedulerPM;
- if (IsPMKeepEmpty(mod.Key) && _waitWTWCleanPMs.ContainsKey(mod.Key))
- {
- string WTWCleanRecipe = _waitWTWCleanPMs[mod.Key].Trim();
- if (WTWCleanRecipe.Length > 0)
- {
- if (pmScheduler.RunJobCleanTask(WTWCleanRecipe))
- {
- mod.Value.MovingStatus = MovingStatus.StartWTWClean;
- }
- _waitWTWCleanPMs.Remove(mod.Key);
- }
- }
- }
- break;
- }
- }
- else
- {
- switch (mod.Value.MovingStatus)
- {
- case MovingStatus.StartProcess:
- mod.Value.MovingStatus = MovingStatus.Processing;
- break;
- case MovingStatus.StartIdleClean:
- mod.Value.MovingStatus = MovingStatus.IdleClean;
- break;
- case MovingStatus.StartPreJobClean:
- mod.Value.MovingStatus = MovingStatus.PreJobClean;
- break;
- case MovingStatus.StartPostJobClean:
- mod.Value.MovingStatus = MovingStatus.PostJobClean;
- break;
- case MovingStatus.StartWTWClean:
- mod.Value.MovingStatus = MovingStatus.WTWClean;
- break;
- }
- }
- }
- }
- }
- private Hand GetTMRobotFreeHand()
- {
- var blade1HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0);
- var blade2HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1);
- if (blade1HasWafer && blade2HasWafer)
- return Hand.None;
- else if (!blade1HasWafer && !blade2HasWafer)
- return Hand.Both;
- else if (blade1HasWafer)
- return Hand.Blade2;
- else
- return Hand.Blade1;
- }
- private bool IsVacWaferReadyOut(ModuleName mod, int slot)
- {
- var wafer = WaferManager.Instance.GetWafer(mod, slot);
- if (wafer.IsEmpty)
- return false;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- {
- // should not go here
- //LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Wafer:{wafer.WaferOrigin} NextSequenceStep {wafer.NextSequenceStep} exceeds {wafer.ProcessJob.Sequence.Name} max steps number");
- return false;
- }
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod))
- return false;
- foreach (var module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- if (ModuleHelper.IsLoadLock(module) || ModuleHelper.IsPm(module))
- return true;
- }
- return false;
- }
- #endregion Vacuum System
- #region Atm System
- private void driveAtmSystem()
- {
- if (_efemMovingItems.Count == 0 && _efemRobot.IsAvailable && _efemRobot.RobotStatus != RState.Running)
- {
- PumpingEFEMRobotTask();
- RuningEFEMRobotTask();
- }
- }
- private void PumpingEFEMRobotTask()
- {
- if (ProcessAtmManaulReturnWafers())
- return;
- var aligners = _atmSchedulers.Where(x => ModuleHelper.IsAligner(x.Key) && x.Value.IsAvailable).ToDictionary(k => k.Key, v => v.Value);
- foreach (var aligner in aligners)
- {
- if (_atmModules[aligner.Key].MovingStatus != MovingStatus.Idle)
- {
- ProcessAlignerTask();
- if (_atmModules[aligner.Key].MovingStatus != MovingStatus.Idle)
- return;
- }
- if (ProcessAlignerEFEMRobotTask(aligner.Key))
- return;
- }
- var lls = _atmSchedulers.Where(x => ModuleHelper.IsLoadLock(x.Key) && x.Value.IsAvailable && !IsLoadLockReservedByTM(x.Key)).ToDictionary(k => k.Key, v => v.Value);
- foreach (var ll in lls)
- {
- if (ProcessLLEFEMRobotTask(ll.Key))
- return;
- }
- var lps = _atmSchedulers.Where(x => ModuleHelper.IsLoadPort(x.Key) && x.Value.IsAvailable).ToDictionary(k => k.Key, v => v.Value);
- foreach (var lp in lps)
- {
- if (ProcessLPEFEMRobotTask(lp.Key))
- return;
- }
- }
- List<int> GetEfemRobotWaferReadyInHands(ModuleName mod)
- {
- var slots = new List<int>();
- for (int i = 0; i < 2; i++)
- {
- if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != i + 1)
- continue;
- var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
- if (wafer.IsEmpty)
- continue;
- if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep == wafer.ProcessJob.Sequence.Steps.Count)
- continue;
- if (wafer.NextSequenceStep > wafer.ProcessJob.Sequence.Steps.Count)
- {
- // should not go here
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Wafer:{wafer.WaferOrigin} NextSequenceStep {wafer.NextSequenceStep} exceeds {wafer.ProcessJob.Sequence.Name} max steps number");
- continue;
- }
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod))
- {
- slots.Add(i);
- }
- }
- return slots;
- }
- bool IsAtmWaferReadyOut(ModuleName mod, int slot)
- {
- if (!IsWaferCtrlJobRuning(mod, slot))
- return false;
- var wafer = WaferManager.Instance.GetWafer(mod, slot);
- if (_lstReturnWafers.Contains(wafer.InnerId))
- return false;
- if (wafer.NextSequenceStep > wafer.ProcessJob.Sequence.Steps.Count)
- {
- // should not go here
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Wafer:{wafer.WaferOrigin} NextSequenceStep {wafer.NextSequenceStep} exceeds {wafer.ProcessJob.Sequence.Name} max steps number in IsAtmWaferReadyOut()");
- return false;
- }
- else if (wafer.NextSequenceStep < wafer.ProcessJob.Sequence.Steps.Count)
- {
- if(wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(mod))
- return false;
- foreach (var module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- if (ModuleHelper.IsPm(module))
- return false;
- }
- }
-
- // Wafer Delay
- if (ModuleHelper.IsLoadLock(mod) && (wafer.ProcessState == EnumWaferProcessStatus.Completed))
- {
- if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep - 1].StepParameter.ContainsKey("LLDelayTime"))
- {
- var delayTime = (string)wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep - 1].StepParameter["LLDelayTime"];
- int delay = int.Parse(delayTime);
- return _atmSchedulers[mod].WaferArrivedTicks(slot) >= delay * 1000;
- }
- // need return
- return true;
- }
- return true;
- }
- private bool ProcessLLEFEMRobotTask(ModuleName ll)
- {
- if (_vacModules[ll].MovingStatus != MovingStatus.Idle)
- return false;
- var robotSlots = GetEfemRobotWaferReadyInHands(ll);
- var inSlots = ll == ModuleName.LLA ? _LLAInSlot : _LLBInSlot;
- foreach (var slot in inSlots)
- {
- if (robotSlots.Count >= 1)
- {
- if (WaferManager.Instance.CheckNoWafer(ll, slot))
- {
- _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, robotSlots.First(), ll, slot, (Hand)robotSlots.First()));
- robotSlots.RemoveAt(0);
- }
- }
- }
- var slotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- Dictionary<int, long> slot_delays = new Dictionary<int, long>();
- for (int i = 0; i < slotNumber; i++)
- {
- if (IsAtmWaferReadyOut(ll, i))
- {
- slot_delays[i] = _atmSchedulers[ll].WaferArrivedTicks(i);
- }
- }
- slot_delays = slot_delays.OrderByDescending(item => item.Value).ToDictionary(k => k.Key, v => v.Value);
- if (slot_delays.Count > 0)
- {
- var robotHand = GetEFEMRobotFreeHand();
- if (robotHand != Hand.None)
- {
- _efemMovingItems.Add(new MoveItem(ll, slot_delays.ElementAt(0).Key, ModuleName.EfemRobot, (int)robotHand, robotHand));
- }
- if (slot_delays.Count > 1)
- {
- var secondHand = GetEFEMRobotFreeHand();
- if (secondHand != Hand.None)
- {
- _efemMovingItems.Add(new MoveItem(ll, slot_delays.ElementAt(1).Key, ModuleName.EfemRobot, (int)secondHand, secondHand));
- }
- }
- }
- return _efemMovingItems.Count > 0;
- }
- private (int exist, int empty) GetPMWaferExistence()
- {
- int exist = 0;
- int empty = 0;
- List<ModuleName> usedPMs = GetPmUsedInRunningPj();
- foreach (var module in _vacModules)
- {
- if (ModuleHelper.IsPm(module.Key) && ((_vacSchedulers[module.Key].IsOnline && usedPMs.Contains(module.Key)) || _cycleState == RState.End))
- {
- if (WaferManager.Instance.CheckHasWafer(module.Key, 0))
- exist++;
- else
- empty++;
- }
- }
- return (exist, empty);
- }
- private (int Processed, int Empty) GetPMValidSlotsStatus()
- {
- int Processed = 0;
- int Empty = 0;
- List<ModuleName> usedPMs = GetPmUsedInRunningPj();
- foreach (var module in _vacModules)
- {
- if (ModuleHelper.IsPm(module.Key) && usedPMs.Contains(module.Key) && _vacSchedulers[module.Key].IsAvailable && _vacModules[module.Key].MovingStatus == MovingStatus.Idle)
- {
- var wafer = WaferManager.Instance.GetWafer(module.Key, 0);
- if (wafer.IsEmpty)
- {
- Empty++;
- }
- else if (wafer.ProcessState == EnumWaferProcessStatus.Completed)
- {
- Processed++;
- }
- }
- }
- return (Processed, Empty);
- }
- private int GetTMRobotWaferCount()
- {
- return (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) ? 1 : 0);
- }
- private int GetEfemRoborWaferCount()
- {
- return (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) ? 1 : 0);
- }
- private bool IsLoadLockReservedByEFEM(ModuleName ll)
- {
- List<ModuleName> unfinished = new List<ModuleName>();
- foreach (var item in _atmWaferTargets)
- {
- var moving = _efemMovingItems.Find(m_item => m_item.DestinationModule == item.Key.Module && m_item.DestinationSlot == item.Key.Slot);
- if (!unfinished.Contains(moving.SourceModule))
- unfinished.Add(moving.SourceModule);
- if (!unfinished.Contains(moving.DestinationModule))
- unfinished.Add(moving.DestinationModule);
- }
- return unfinished.Contains(ll);
- }
- private bool IsLoadLockReservedByTM(ModuleName ll)
- {
- List<ModuleName> unfinished = new List<ModuleName>();
- foreach (var item in _vacWaferTargets)
- {
- var moving = _movingItems.Find(m_item => m_item.DestinationModule == item.Key.Module && m_item.DestinationSlot == item.Key.Slot);
- if (!unfinished.Contains(moving.SourceModule))
- unfinished.Add(moving.SourceModule);
- if (!unfinished.Contains(moving.DestinationModule))
- unfinished.Add(moving.DestinationModule);
- }
- return unfinished.Contains(ll);
- }
- private bool IsLoadReadyForTM(ModuleName ll)
- {
- return _vacSchedulers[ll].IsAvailable && _vacModules[ll].MovingStatus == MovingStatus.Idle && !IsLoadLockReservedByEFEM(ll);
- }
- private bool IsLoadLockReadyForEFEMManualMove(ModuleName ll)
- {
- return ((_vacSchedulers[ll].IsIdle && !_vacSchedulers[ll].IsOnline) || _vacSchedulers[ll].IsAvailable) && _vacModules[ll].MovingStatus == MovingStatus.Idle && !IsLoadLockReservedByTM(ll);
- }
- private bool IsPMKeepEmpty(ModuleName pm)
- {
- return WaferManager.Instance.CheckNoWafer(pm, 0) && _movingItems.FindIndex(item => item.DestinationModule == pm) == -1;
- }
- private bool IsPreJobCleanPending(ModuleName pm, out string preCleanRecipe)
- {
- preCleanRecipe = string.Empty;
- foreach (var cj in _lstControlJobs)
- {
- if (cj.JetState == EnumJetCtrlJobState.PreJobClean && _waitPreCleanPMs.Contains(pm))
- {
- preCleanRecipe = cj.PreJobClean;
- return true;
- }
- }
- return false;
- }
- private bool IsPostJobCleanPending(ModuleName pm, out string postCleanRecipe)
- {
- postCleanRecipe = string.Empty;
- foreach (var cj in _lstControlJobs)
- {
- if (cj.JetState == EnumJetCtrlJobState.PostJobClean && _waitPostCleanPMs.Contains(pm))
- {
- postCleanRecipe = cj.PostJobClean;
- return true;
- }
- }
- return false;
- }
- private (int processed, int unprocessed, int empty) GetLLProcessStatusCount(ModuleName ll)
- {
- int processedCount = 0;
- int unprocessCount = 0;
- int slotCount = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- if (ModuleHelper.IsLoadLock(ll))
- {
- for (int i = 0; i < slotCount; i++)
- {
- if (WaferManager.Instance.CheckHasWafer(ll, i))
- {
- if (CheckWaferNeedProcessAndPMAvailable(ll, i))
- unprocessCount++;
- else
- processedCount++;
- }
- }
- }
- return (processedCount, unprocessCount, slotCount - processedCount - unprocessCount);
- }
- private int GetAtmInerWaferCount()
- {
- int nCount = 0;
- foreach (var atmModule in _atmModules)
- {
- if (!ModuleHelper.IsEFEMRobot(atmModule.Key) && !ModuleHelper.IsLoadPort(atmModule.Key) && WaferManager.Instance.CheckHasWafer(atmModule.Key, 0))
- nCount++;
- }
- return nCount;
- }
- private int CanPushInWaferNumber()
- {
- if (_tmRobot.RobotStatus == RState.Running)
- return 0;
- var llaWaferStatus = GetLLProcessStatusCount(ModuleName.LLA);
- var llbWaferStatus = GetLLProcessStatusCount(ModuleName.LLB);
- var pmWaferStatus = GetPMWaferExistence();
- if (_LLInOutPath == SequenceLLInOutPath.AInBOut)
- {
- if (_atmSchedulers[ModuleName.LLB].IsAtm && llbWaferStatus.processed >= 2)
- return 0;
- int canPushIn = llbWaferStatus.processed == _LLBSlotNumber ? 0 :
- pmWaferStatus.empty + llaWaferStatus.empty
- - GetTMRobotWaferCount() - GetAtmInerWaferCount() - GetEfemRoborWaferCount();
- // 修正 单手臂占用影响Throughput的问题
- if (canPushIn == 1/* && llbWaferStatus.processed >= 2*/)
- return 0;
- return canPushIn;
- }
- else if (_LLInOutPath == SequenceLLInOutPath.BInAOut)
- {
- if (_atmSchedulers[ModuleName.LLA].IsAtm && llaWaferStatus.processed >= 2)
- return 0;
- int canPushIn = llaWaferStatus.processed == _LLASlotNumber ? 0 :
- pmWaferStatus.empty + llbWaferStatus.empty
- - GetTMRobotWaferCount() - GetAtmInerWaferCount() - GetEfemRoborWaferCount();
- if (canPushIn == 1 && llaWaferStatus.processed >= 2)
- return 0;
- return canPushIn;
- }
- else if (_LLInOutPath == SequenceLLInOutPath.AInAOut || (_LLInOutPath == SequenceLLInOutPath.DInDOut && _vacSchedulers[ModuleName.LLA].IsOnline && !_vacSchedulers[ModuleName.LLB].IsOnline))
- {
- return llaWaferStatus.processed > 0 ? 0 :
- _LLASlotNumber / 2 + pmWaferStatus.empty - llaWaferStatus.unprocessed
- - GetTMRobotWaferCount() - GetEfemRoborWaferCount() - GetAtmInerWaferCount();
- }
- else if (_LLInOutPath == SequenceLLInOutPath.BInBOut || (_LLInOutPath == SequenceLLInOutPath.DInDOut && !_vacSchedulers[ModuleName.LLA].IsOnline && _vacSchedulers[ModuleName.LLB].IsOnline))
- {
- return llbWaferStatus.processed > 0 ? 0 :
- _LLBSlotNumber / 2 + pmWaferStatus.empty - llbWaferStatus.unprocessed
- - GetTMRobotWaferCount() - GetEfemRoborWaferCount() - GetAtmInerWaferCount();
- }
- else if (_LLInOutPath == SequenceLLInOutPath.DInDOut && _vacSchedulers[ModuleName.LLA].IsOnline && _vacSchedulers[ModuleName.LLB].IsOnline)
- {
- return llaWaferStatus.processed + llbWaferStatus.processed > 1 ? 0 :
- (llaWaferStatus.empty + llbWaferStatus.empty) / 2 + pmWaferStatus.empty
- - GetTMRobotWaferCount() - GetEfemRoborWaferCount() - GetAtmInerWaferCount();
- }
- else
- {
- _cycleState = RState.Failed;
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, "Both LLA/LLB offline, stop runing.");
- return 0;
- }
- }
- private bool IsForwardPathBlocking(ModuleName mod, int slot)
- {
- var wafer = WaferManager.Instance.GetWafer(mod, slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
- return false;
- foreach (var next_module in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
- {
- var SlotNumber = GetModuleSlotCount(next_module);
- for (int i = 0; i < SlotNumber; i++)
- {
- if (WaferManager.Instance.CheckNoWafer(next_module, i))
- return false;
- }
- }
- return true;
- }
- private bool ProcessLPEFEMRobotTask(ModuleName lp)
- {
- // check return
- for (int i = 0; i < 2; i++)
- {
- if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != i + 1)
- continue;
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i))
- {
- var returnWafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
- if (returnWafer.IsEmpty)
- continue;
- if (returnWafer.ProcessJob == null || returnWafer.ProcessJob.Sequence == null)
- continue;
- if (returnWafer.NextSequenceStep >= returnWafer.ProcessJob.Sequence.Steps.Count && lp == (ModuleName)returnWafer.OriginStation) // need return
- {
- _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, i, lp, returnWafer.OriginSlot, (Hand)i));
- }
- }
- }
- var canPushInWafers = CanPushInWaferNumber();
- if (_efemMovingItems.Count == 0 && canPushInWafers > 0)
- {
- var outSlots = GetNextWaferInJobQueue(lp);
- var hand = GetEFEMRobotFreeHand();
- if (hand != Hand.None && outSlots.Count > 0 && !IsForwardPathBlocking(lp, outSlots[0]))
- {
- _efemMovingItems.Add(new MoveItem(lp, outSlots[0], ModuleName.EfemRobot, (int)hand, hand));
- }
- if (canPushInWafers > 1)
- {
- hand = GetEFEMRobotFreeHand();
- if (hand != Hand.None && outSlots.Count > 1 && !IsForwardPathBlocking(lp, outSlots[1]))
- {
- _efemMovingItems.Add(new MoveItem(lp, outSlots[1], ModuleName.EfemRobot, (int)hand, hand));
- }
- }
- }
- return _efemMovingItems.Count > 0;
- }
- private List<int> GetNextWaferInJobQueue(ModuleName lp)
- {
- var inSlots = new List<int>();
- foreach (var cj in _lstControlJobs)
- {
- if (lp != ModuleName.System && (cj.Module != lp.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))
- {
- var wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- if (!wafer.IsEmpty && wafer.NextSequenceStep == 0)
- {
- inSlots.Add(pjSlotWafer.Item2);
- }
- }
- }
- }
- }
- }
- }
- return inSlots.OrderBy(item => item).Take(2).ToList();
- }
- private bool ProcessAlignerEFEMRobotTask(ModuleName aligner)
- {
- if (WaferManager.Instance.CheckHasWafer(aligner, 0) && IsAtmWaferReadyOut(aligner, 0) && _atmModules[aligner].MovingStatus == MovingStatus.Idle)
- {
- var hand = GetEFEMRobotFreeHand();
- if (hand != Hand.None)
- {
- _efemMovingItems.Add(new MoveItem(aligner, 0, ModuleName.EfemRobot, (int)hand, hand));
- }
- //// check with whether another robot arm wafer wait go to aligner
- //var robotSlots = GetEfemRobotWaferReadyInHands(aligner);
- //if (robotSlots.Count > 0)
- //{
- // _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, robotSlots.First(), aligner, 0, (Hand)robotSlots.First()));
- //}
- }
- else if (WaferManager.Instance.CheckNoWafer(aligner, 0))
- {
- var robotSlots = GetEfemRobotWaferReadyInHands(aligner);
- if (robotSlots.Count > 0)
- {
- _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, robotSlots.First(), aligner, 0, (Hand)robotSlots.First()));
- }
- }
- return _efemMovingItems.Count > 0;
- }
- private bool ProcessCoolingEFEMRobotTask(ModuleName cooling)
- {
- if (WaferManager.Instance.CheckHasWafer(cooling, 0) && IsAtmWaferReadyOut(cooling, 0))
- {
- var hand = GetEFEMRobotFreeHand();
- if (hand != Hand.None)
- {
- _efemMovingItems.Add(new MoveItem(cooling, 0, ModuleName.EfemRobot, (int)hand, hand));
- }
- }
- else
- {
- var robotSlots = GetEfemRobotWaferReadyInHands(cooling);
- if (robotSlots.Count > 0)
- {
- _efemMovingItems.Add(new MoveItem(cooling, 0, ModuleName.EfemRobot, robotSlots.First(), (Hand)robotSlots.First()));
- }
- }
- return _efemMovingItems.Count > 0;
- }
- private void RuningEFEMRobotTask()
- {
- if (_efemMovingItems.Count > 0)
- {
- if (_efemRobot.PostMoveItems(_efemMovingItems.ToArray()))
- {
- foreach (var item in _efemMovingItems)
- {
- var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
- if (wafer.IsEmpty)
- {
- // post alarm
- _cycleState = RState.Failed;
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run EFEM moving task as Get {item.SourceModule}{item.SourceModule} Wafer Info failed");
- return;
- }
- var slot = new SlotItem(item.DestinationModule, item.DestinationSlot);
- _atmWaferTargets[slot] = wafer.InnerId;
- if (ModuleHelper.IsLoadLock(item.Module))
- {
- _vacModules[item.Module].MovingStatus = MovingStatus.Moving;
- }
- }
- }
- }
- }
- private Hand GetEFEMRobotFreeHand()
- {
- for (int i = 0; i < 2; i++)
- {
- if (_efemRobotSingleArmOption != 0 && _efemRobotSingleArmOption != i + 1)
- continue;
- if ((WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, i) &&
- !_efemMovingItems.Exists(item => item.DestinationModule == ModuleName.EfemRobot && item.DestinationSlot == i)) ||
- (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i) &&
- _efemMovingItems.Exists(item => item.SourceModule == ModuleName.EfemRobot && item.SourceSlot == i) &&
- !_efemMovingItems.Exists(item => item.DestinationModule == ModuleName.EfemRobot && item.DestinationSlot == i)))
- return (Hand)i;
- }
- return Hand.None;
- }
- private void ProcessAlignerTask()
- {
- foreach (var align in _atmModules)
- {
- if (ModuleHelper.IsAligner(align.Key))
- {
- switch (align.Value.MovingStatus)
- {
- case MovingStatus.WaitAlign:
- if (_efemRobot.IsAvailable)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(align.Key, 0);
- if (!wafer.IsEmpty)
- {
- if (_efemRobot.Align(0F))
- {
- align.Value.MovingStatus = MovingStatus.StartAlign;
- return;
- }
- }
- align.Value.MovingStatus = MovingStatus.Idle;
- }
- break;
- case MovingStatus.StartAlign:
- if (!_efemRobot.IsAvailable)
- {
- align.Value.MovingStatus = MovingStatus.Aligning;
- }
- break;
- case MovingStatus.Aligning:
- {
- if (_efemRobot.IsAvailable)
- {
- align.Value.MovingStatus = MovingStatus.Idle;
- }
- }
- break;
- }
- }
- }
- }
- private bool ProcessAtmManaulReturnWafers()
- {
- if (_lstReturnWafers.Count == 0)
- return false;
- for (int i = 0; i < 2; i++)
- {
- if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, i))
- {
- var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
- if (_lstReturnWafers.FindIndex(id => id == wafer.InnerId) != -1)
- {
- _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i));
- _lstReturnWafers.Remove(wafer.InnerId);
- }
- }
- }
- if (_efemMovingItems.Count > 0)
- return true;
- var lls = _atmSchedulers.Where(x => ModuleHelper.IsLoadLock(x.Key) && IsLoadLockReadyForEFEMManualMove(x.Key)).ToDictionary(k => k.Key, v => v.Value);
- foreach (var ll in lls)
- {
- int slotNumber = ll.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- for (int i = 0; i < slotNumber; i++)
- {
- if (_efemMovingItems.Count >= 2)
- return true;
- if (WaferManager.Instance.CheckHasWafer(ll.Key, i))
- {
- var wafer = WaferManager.Instance.GetWafer(ll.Key, i);
- var robotHand = GetEFEMRobotFreeHand();
- if (robotHand != Hand.None && _lstReturnWafers.FindIndex(id => id == wafer.InnerId) != -1)
- {
- _efemMovingItems.Add(new MoveItem(ll.Key, i, ModuleName.EfemRobot, (int)robotHand, robotHand));
- }
- }
- }
- }
- return _efemMovingItems.Count > 0;
- }
- #endregion Atm System
- #region Sequence validation
- 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;
- }
- if (ModuleHelper.IsInstalled(module) && (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 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}Recipe";
- 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($"{module}", recipeName, false, "Process");
- if (string.IsNullOrEmpty(recipeContent))
- {
- reason = $"Can not find recipe file{recipeName}";
- return false;
- }
- }
- }
- }
- }
- }
- reason = "";
- return true;
- }
- private 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++)
- {
- foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
- {
- if (!_vacSchedulers.Keys.Contains(stepModule))
- continue;
- if (!_vacSchedulers[stepModule].IsOnline)
- continue;
- if (ModuleHelper.IsPm(stepModule))
- {
- if (stepModule == processIn || processIn == ModuleName.System)
- return true;
- }
- else
- break;
- }
- }
- return false;
- }
- private List<ModuleName> GetPmUsedInRunningPj()
- {
- var pmUsed = new List<ModuleName>();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.JetState != EnumJetCtrlJobState.PreJobClean && cj.JetState != EnumJetCtrlJobState.PostJobClean && cj.JetState != EnumJetCtrlJobState.Processing)
- 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 void UpateSequenceStep(List<MoveItem> items)
- {
- foreach (var item in items)
- {
- if (!ModuleHelper.IsTMRobot(item.DestinationModule) && !ModuleHelper.IsEFEMRobot(item.DestinationModule))
- {
- var wafer = WaferManager.Instance.GetWafer(item.DestinationModule, item.DestinationSlot);
- if (!wafer.IsEmpty && wafer.ProcessJob != null)
- {
- if (wafer.NextSequenceStep < wafer.ProcessJob.Sequence.Steps.Count && wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(item.DestinationModule))
- wafer.NextSequenceStep++;
- }
- else
- {
- // should not go here
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"UpateSequenceStep() failed, location: {item.DestinationModule}:{item.DestinationSlot + 1}, NextSequenceStep: {wafer.NextSequenceStep}");
- }
- }
- }
- }
- private void CheckWaferArrived()
- {
- if (_cycleState != RState.Running)
- return;
- foreach (var mod in _vacSchedulers.Append(new KeyValuePair<ModuleName, SchedulerModule>(ModuleName.TMRobot, _tmRobot)))
- {
- var tars = _vacWaferTargets.Where(item => item.Key.Module == mod.Key).ToArray();
- foreach (var tar in tars)
- {
- var wafer = WaferManager.Instance.GetWafer(tar.Key.Module, tar.Key.Slot);
- if (wafer.IsEmpty || wafer.InnerId.ToString().Length < 10)
- continue;
- if (wafer.InnerId == tar.Value && _tmRobot.RobotStatus != RState.Running)
- {
- // wafer arrive
- _vacWaferTargets.Remove(tar.Key);
- if (!ModuleHelper.IsTMRobot(tar.Key.Module))
- _vacSchedulers[tar.Key.Module].WaferArrived(tar.Key.Slot);
- //LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"wafer {wafer.WaferOrigin}: {wafer.InnerId} arrived {tar.Key.Module}{tar.Key.Slot + 1}");
- if (ModuleHelper.IsPm(tar.Key.Module))
- {
- _vacModules[tar.Key.Module].MovingStatus = MovingStatus.WaitProcess;
- }
- else
- {
- var curItem = _movingItems.Find(item => item.DestinationModule == tar.Key.Module && item.DestinationSlot == tar.Key.Slot);
- if (ModuleHelper.IsPm(curItem.SourceModule) && _movingItems.FindIndex(item => item.DestinationModule == curItem.SourceModule) == -1)
- {
- if (_waitWTWCleanPMs.ContainsKey(curItem.SourceModule))
- {
- _vacModules[curItem.SourceModule].MovingStatus = MovingStatus.WaitWTWClean;
- }
- else if (_waitPostCleanPMs.Contains(curItem.SourceModule))
- {
- _vacModules[curItem.SourceModule].MovingStatus = MovingStatus.WaitPostJobClean;
- }
- }
- }
- if (!ModuleHelper.IsTMRobot(tar.Key.Module))
- wafer.NextSequenceStep++;
- }
- }
- if (ModuleHelper.IsLoadLock(mod.Key))
- {
- if (!IsLoadLockReservedByTM(mod.Key) && mod.Value.IsAvailable)
- {
- _vacModules[mod.Key].MovingStatus = MovingStatus.Idle;
- }
- }
- }
- _vacMoveFinishTrig.CLK = _vacWaferTargets.Count == 0 && _tmRobot.RobotStatus != RState.Running;
- if (_vacMoveFinishTrig.Q)
- {
- foreach (var item in _movingItems)
- {
- if (!ModuleHelper.IsTMRobot(item.DestinationModule) && _vacModules[item.DestinationModule].MovingStatus == MovingStatus.Moving)
- {
- _vacModules[item.DestinationModule].MovingStatus = MovingStatus.Idle;
- }
- if (!ModuleHelper.IsTMRobot(item.SourceModule) && _vacModules[item.SourceModule].MovingStatus == MovingStatus.Moving)
- {
- _vacModules[item.SourceModule].MovingStatus = MovingStatus.Idle;
- }
- }
- //UpateSequenceStep(_movingItems);
- _movingItems.Clear();
- }
- foreach (var mod in _atmSchedulers.Append(new KeyValuePair<ModuleName, SchedulerModule>(ModuleName.EfemRobot, _efemRobot)))
- {
- var tars = _atmWaferTargets.Where(item => item.Key.Module == mod.Key).ToArray();
- foreach (var tar in tars)
- {
- var wafer = WaferManager.Instance.GetWafer(tar.Key.Module, tar.Key.Slot);
- if (wafer.IsEmpty || wafer.InnerId.ToString().Length < 10)
- continue;
- if (wafer.InnerId == tar.Value && _efemRobot.RobotStatus != RState.Running)
- {
- //LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"wafer {wafer.WaferOrigin}: {wafer.InnerId} arrived {tar.Key.Module}{tar.Key.Slot + 1}");
- // wafer arrive
- if (!ModuleHelper.IsLoadPort(tar.Key.Module) && !ModuleHelper.IsEFEMRobot(tar.Key.Module))
- _atmSchedulers[tar.Key.Module].WaferArrived(tar.Key.Slot);
- _atmWaferTargets.Remove(tar.Key);
- if (ModuleHelper.IsAligner(tar.Key.Module))
- {
- _atmModules[tar.Key.Module].MovingStatus = MovingStatus.WaitAlign;
- }
- if (!ModuleHelper.IsEFEMRobot(tar.Key.Module))
- wafer.NextSequenceStep++;
- }
- }
- if (ModuleHelper.IsLoadLock(mod.Key))
- {
- if (!IsLoadLockReservedByEFEM(mod.Key) && mod.Value.IsAvailable)
- {
- _vacModules[mod.Key].MovingStatus = MovingStatus.Idle;
- }
- }
- }
- //_atmMoveFinishTrig.CLK = _atmWaferTargets.Count == 0 && _efemRobot.RobotStatus != RState.Running;
- if (_atmWaferTargets.Count == 0 && _efemRobot.RobotStatus != RState.Running && _efemMovingItems.Count > 0)
- {
- foreach (var item in _efemMovingItems)
- {
- if (ModuleHelper.IsLoadLock(item.Module))
- {
- _vacModules[item.Module].MovingStatus = MovingStatus.Idle;
- }
- }
- //UpateSequenceStep(_efemMovingItems);
- _efemMovingItems.Clear();
- //LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"All EFEM commands complete!");
- }
- }
- 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);
- return true;
- }
- private void DispatchCtrlJobs()
- {
- var quequedJobs = _lstControlJobs.FindAll(job => job.JetState == EnumJetCtrlJobState.Quequed);
- if (quequedJobs.Count > 0)
- {
- var runingJobs = _lstControlJobs.FindAll(job => IsCtrlJobRuning(job));
- if (runingJobs.Count >= 2)
- return;
- if (runingJobs.Count == 0 || IsCtrlJobEndingState(runingJobs.First()))
- {
- var startJob = quequedJobs.OrderBy(job => job.StartTime).First();
- if (IsCtrlJobNeedPreClean(startJob))
- {
- startJob.JetState = EnumJetCtrlJobState.PreJobClean;
- _waitPreCleanPMs.Clear();
- var PMs = GetWaitPreCleanPMsByCtrlJob(startJob);
- foreach (var pm in PMs)
- {
- _waitPreCleanPMs.Add(pm);
- }
- }
- else
- {
- startJob.JetState = EnumJetCtrlJobState.Processing;
- foreach (var pjName in startJob.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {startJob.Name}");
- continue;
- }
- if (pj.State == EnumProcessJobState.Queued)
- {
- ActiveProcessJob(pj);
- //break; 先将所有的 Process Job全部激活, 不做PreJobClean, PreJobClean 逻辑 引入 ProcessPMTask()
- }
- }
- }
- }
- }
- var preJobClean = _lstControlJobs.Find(job => job.JetState == EnumJetCtrlJobState.PreJobClean);
- if (preJobClean != null && _waitPreCleanPMs.Count == 0)
- {
- preJobClean.JetState = EnumJetCtrlJobState.Processing;
- foreach (var pjName in preJobClean.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {preJobClean.Name}");
- continue;
- }
- if (pj.State == EnumProcessJobState.Queued)
- {
- ActiveProcessJob(pj);
- //break; 先将所有的 Process Job全部激活, 不做PreJobClean, PreJobClean 逻辑 引入 ProcessPMTask()
- }
- }
- }
- }
- private static bool IsWaferNeedGotoModule(WaferInfo wafer, ModuleName module)
- {
- 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(module))
- return true;
- }
- return false;
- }
- private bool IsWaferCtrlJobRuning(ModuleName mod, int slot)
- {
- var wafer = WaferManager.Instance.GetWafer(mod, slot);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
- return false;
- var waferCtrlJob = _lstControlJobs.Find(item => (int)ModuleHelper.Converter(item.Module) == wafer.OriginStation);
- if(waferCtrlJob != null)
- {
- return waferCtrlJob.State == EnumControlJobState.Executing;
- }
- return false;
- }
- private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
- {
- bool allWaferReturn = true;
- 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)
- {
- allWaferReturn = false;
- continue;
- }
- foreach (var mod in _vacModules)
- {
- if (ModuleHelper.IsPm(mod.Key))
- {
- if (checkAllProcessed && IsWaferNeedGotoModule(wafer, mod.Key))
- {
- allWaferReturn = false;
- }
- }
- }
- }
- return allWaferReturn;
- }
- private void UpdateProcessJobStatus()
- {
- if (_efemRobot.RobotStatus == RState.Running ||_tmRobot.RobotStatus == RState.Running)
- return;
- 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;
- if (_efemRobot.RobotStatus == RState.Running || _tmRobot.RobotStatus == RState.Running)
- return;
- bool allControlJobComplete = true;
- List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
- foreach (var cj in _lstControlJobs)
- {
- if(cj.JetState == EnumJetCtrlJobState.Quequed)
- {
- var runingJobs = _lstControlJobs.FindAll(job => IsCtrlJobRuning(job));
- if(runingJobs.Count == 0 || (runingJobs.Count == 1 && IsCtrlJobEndingState(runingJobs.First())))
- {
- var quequedJobs = _lstControlJobs.FindAll(job => job.JetState == EnumJetCtrlJobState.Quequed);
- var firstQuequeJob = quequedJobs.OrderBy(job => job.StartTime).First();
- if(firstQuequeJob.InnerId == cj.InnerId)
- {
- if (IsCtrlJobNeedPreClean(cj))
- {
- cj.JetState = EnumJetCtrlJobState.PreJobClean;
- _waitPreCleanPMs.Clear();
- var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
- foreach (var pm in PMs)
- {
- _waitPreCleanPMs.Add(pm);
- }
- }
- else
- {
- cj.JetState = EnumJetCtrlJobState.Processing;
- foreach (var pjName in cj.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
- continue;
- }
- if (pj.State == EnumProcessJobState.Queued)
- {
- ActiveProcessJob(pj);
- }
- }
- }
- }
- }
- }
- else if(IsCtrlJobRuning(cj))
- {
- if (cj.JetState == EnumJetCtrlJobState.PreJobClean)
- {
- if (_waitPreCleanPMs.Count == 0)
- {
- cj.JetState = EnumJetCtrlJobState.Processing;
- foreach (var pjName in cj.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
- continue;
- }
- if (pj.State == EnumProcessJobState.Queued)
- {
- ActiveProcessJob(pj);
- }
- }
- }
- }
- else
- {
- if (cj.JetState == EnumJetCtrlJobState.Processing && IsCtrlJobNeedPostClean(cj))
- {
- if (IsAllJobWaferProcessedOrProcessing(cj))
- {
- cj.JetState = EnumJetCtrlJobState.PostJobClean;
- _waitPostCleanPMs.Clear();
- var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
- foreach (var pm in PMs)
- {
- _waitPostCleanPMs.Add(pm);
- }
- }
- }
- if (IsAllProcessJobComplete(cj) && (!IsCtrlJobNeedPostClean(cj) || cj.JetState == EnumJetCtrlJobState.PostJobClean && _waitPostCleanPMs.Count == 0))
- {
- cj.JetState = EnumJetCtrlJobState.Completed;
- cj.SetState(EnumControlJobState.Completed);
- cj.EndTime = DateTime.Now;
- _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
- _dbCallback.LotFinished(cj);
- if (!(_isCycleMode && _cycledCount < _cycleSetPoint))
- (Singleton<TransferModule>.Instance.GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
- _lpCycleCount[ModuleHelper.Converter(cj.Module)]++;
- }
- }
- int countProcessed = 0;
- foreach (var pjName in cj.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
- continue;
- }
- // caculate process wafer by process
- if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
- {
- foreach (var pjSlotWafer in pj.SlotWafers)
- {
- WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
- if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
- countProcessed++;
- }
- }
- }
- int lpCycleWafer = _lpCycleCount[ModuleHelper.Converter(cj.Module)] * cj.LotWafers.Count + (cj.JetState == EnumJetCtrlJobState.Completed && cj.LotWafers.Count == countProcessed ? 0 : countProcessed);
- if (_lpCycleCount[ModuleHelper.Converter(cj.Module)] != _cycledCount || lpCycleWafer != _lpCycleWafer[ModuleHelper.Converter(cj.Module)])
- {
- _lpCycleWafer[ModuleHelper.Converter(cj.Module)] = lpCycleWafer;
- }
- }
- LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
- if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal && cj.JetState == EnumJetCtrlJobState.Completed)
- {
- cjRemoveList.Add(cj);
- }
- allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
- }
- if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
- {
- int totolCycleWafer = _lpCycleWafer.Sum(item => item.Value);
- if (totolCycleWafer != _cycledWafer || _lpCycleCount.Sum(item => item.Value) > 0 && _throughput < 0.01) // refresh _throughput in time
- {
- _cycledWafer = totolCycleWafer;
- if (_cycledCount > 0)
- {
- _throughput = (float)(_cycledWafer / _cycleWatch.Elapsed.TotalHours);
- }
- else
- {
- _throughput = 0;
- }
- }
- if (allControlJobComplete)
- {
- _cycledCount++;
- if (_cycledCount < _cycleSetPoint)
- {
- foreach (var cj in _lstControlJobs)
- {
- cj.SetState(EnumControlJobState.Executing);
- cj.JetState = EnumJetCtrlJobState.Quequed;
- cj.LotInnerId = Guid.NewGuid();
- _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;
- }
- }
- }
- else
- _cycleState = RState.End;
- }
- }
- 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);
- }
- }
- private void UpdateLLInOutPathProperty()
- {
- if (_lstControlJobs.Count == 0)
- return;
- List<SequenceLLInOutPath> inOutPaths = new List<SequenceLLInOutPath>();
- foreach (var cj in _lstControlJobs)
- {
- if (cj.State == EnumControlJobState.Executing)
- {
- foreach (var pjName in cj.ProcessJobNameList)
- {
- var pj = _lstProcessJobs.Find(x => x.Name == pjName);
- if (pj == null || pj.State != EnumProcessJobState.Processing)
- continue;
- if (!inOutPaths.Exists(item => item == pj.Sequence.LLInOutPath))
- inOutPaths.Add(pj.Sequence.LLInOutPath);
- }
- }
- }
- if (inOutPaths.Count == 1)
- {
- _LLInOutPath = inOutPaths[0];
- }
- }
- private bool IsAllJobWaferProcessedOrProcessing(ControlJobInfo cj)
- {
- List<ModuleName> allModules = _vacModules.Keys.ToList().Union(_atmModules.Keys.ToList()).ToList();
- allModules.Add(ModuleName.EfemRobot);
- allModules.Add(ModuleName.TMRobot);
- int original = (int)ModuleHelper.Converter(cj.Module);
- foreach (var mod in allModules)
- {
- if (ModuleHelper.IsLoadPort(mod) && (int)mod != original)
- continue;
- var wafers = WaferManager.Instance.GetWafers(mod);
- foreach (var wafer in wafers)
- {
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.ControlJobName != cj.Name)
- continue;
- if (wafer.ProcessState != EnumWaferProcessStatus.Completed && wafer.ProcessState != EnumWaferProcessStatus.InProcess)
- return false; ;
- }
- }
- return true;
- }
- private bool IsAllProcessJobComplete(ControlJobInfo cj)
- {
- foreach(var pj in _lstProcessJobs)
- {
- if(pj.ControlJobName == cj.Name && pj.State != EnumProcessJobState.ProcessingComplete)
- {
- return false;
- }
- }
- return true;
- }
- private bool IsCtrlJobRuning(ControlJobInfo cj)
- {
- return cj.JetState == EnumJetCtrlJobState.PreJobClean ||
- cj.JetState == EnumJetCtrlJobState.Processing ||
- cj.JetState == EnumJetCtrlJobState.PostJobClean;
- }
- private bool IsCtrlJobEndingState(ControlJobInfo cj)
- {
- return cj.JetState == EnumJetCtrlJobState.PostJobClean ||
- (cj.JetState == EnumJetCtrlJobState.Processing
- && IsAllJobWaferProcessedOrProcessing(cj)
- && !IsCtrlJobNeedPostClean(cj));
- }
- private bool IsCtrlJobNeedPreClean(ControlJobInfo cj)
- {
- return cj.PreJobClean.Trim().Length > 0;
- }
- private bool IsCtrlJobNeedPostClean(ControlJobInfo cj)
- {
- return cj.PostJobClean.Trim().Length > 0;
- }
- private bool IsPMWaferNeedWTWClean(ModuleName pm, out string WTWCleanRecipe)
- {
- WTWCleanRecipe = string.Empty;
- var wafer = WaferManager.Instance.GetWafer(pm, 0);
- if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.WTWCleanRecipe.Trim().Length == 0)
- return false;
- WTWCleanRecipe = wafer.ProcessJob.Sequence.WTWCleanRecipe;
- return true;
- }
- private List<ModuleName> GetWaitPreCleanPMsByCtrlJob(ControlJobInfo cj)
- {
- var pmlist = new List<ModuleName>();
- foreach(var pj in _lstProcessJobs)
- {
- if(pj.ControlJobName == cj.Name)
- {
- foreach(var pm in pj.Sequence.PMs)
- {
- if (!pmlist.Contains(pm))
- pmlist.Add(pm);
- }
- }
- }
- return pmlist;
- }
- private static WaferInfo GetCloneWafer(ModuleName mod, int slot)
- {
- var Wafer = WaferManager.Instance.GetWafer(mod, slot);
- if (Wafer.IsEmpty || Wafer.ProcessJob == null || Wafer.ProcessJob.Sequence == null)
- return Wafer;
- var cloneWafer = SerializeHelper.DeepCopyJson(Wafer);
- if (Wafer.IsEmpty || Wafer.ProcessJob == null || Wafer.ProcessJob.Sequence == null)
- return Wafer;
- return cloneWafer;
- }
- #endregion
- #region Manual Return All Wafer
- public RState CheckManualReturnWafer()
- {
- if(!_tmRobot.IsIdle && (GetPMWaferExistence().exist + GetTMRobotWaferCount() > 0))
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.TMRobot, $"The TM Robot is not ready for return wafer.");
- return RState.Failed;
- }
- if (!_efemRobot.IsIdle)
- {
- LOG.Write(eEvent.ERR_ROUTER, ModuleName.EfemRobot, $"The EFEM Robot is not ready for return wafer.");
- return RState.Failed;
- }
- var schedulers = _vacSchedulers.Concat(_atmSchedulers);
- foreach(var mod in schedulers)
- {
- if (ModuleHelper.IsLoadPort(mod.Key))
- continue;
- int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
- for(int slot = 0; slot < nSlotNumber; slot++)
- {
- var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
- if (wafer.IsEmpty)
- continue;
- if(!mod.Value.IsIdle)
- {
- LOG.Write(eEvent.ERR_ROUTER, mod.Key, $"{mod.Key} is not ready for return wafer.");
- return RState.Failed;
- }
- var destLP = (ModuleName)wafer.OriginStation;
- if(!_atmSchedulers[destLP].IsAvailable)
- {
- LOG.Write(eEvent.ERR_ROUTER, destLP, $"The destination Loadport {destLP} is not ready for return wafer.");
- return RState.Failed;
- }
- }
- }
- Clear();
- return RState.Running;
- }
- public RState ReturnAllWafers()
- {
- var llaWaferStatus = GetLLProcessStatusCount(ModuleName.LLA);
- var llbWaferStatus = GetLLProcessStatusCount(ModuleName.LLB);
- var pmWaferStatus = GetPMWaferExistence();
- if (pmWaferStatus.exist + (_LLASlotNumber - llaWaferStatus.empty) + (_LLBSlotNumber - llbWaferStatus.empty) + GetTMRobotWaferCount() + GetAtmInerWaferCount() + GetEfemRoborWaferCount() == 0)
- {
- Clear();
- return RState.End;
- }
- ReturnAtmWafers();
- ReturnVacWafers();
- CheckReturnWafersArrived();
- return RState.Running;
- }
- private void ReturnVacWafers()
- {
- if(_tmRobot.IsAvailable && _tmRobot.RobotStatus != RState.Running && _movingItems.Count == 0)
- {
- var tmRobotWaferCount = GetTMRobotWaferCount();
- if(tmRobotWaferCount > 0 || GetPMWaferExistence().exist > 0)
- {
- var llaWaferStatus = GetLLProcessStatusCount(ModuleName.LLA);
- var llbWaferStatus = GetLLProcessStatusCount(ModuleName.LLB);
- if (IsLoadReadyForTM(ModuleName.LLA) && llaWaferStatus.empty > 0 && (!IsLoadReadyForTM(ModuleName.LLB) || (!_vacSchedulers[ModuleName.LLB].IsVac && llaWaferStatus.empty == llbWaferStatus.empty) || llaWaferStatus.empty > llbWaferStatus.empty))
- {
- if (tmRobotWaferCount > 0)
- ReturnTMRobotWafersToLL(ModuleName.LLA);
- else
- ReturnPMWafersToLL(ModuleName.LLA);
- }
- else if (IsLoadReadyForTM(ModuleName.LLB) && llbWaferStatus.empty > 0)
- {
- if (tmRobotWaferCount > 0)
- ReturnTMRobotWafersToLL(ModuleName.LLB);
- else
- ReturnPMWafersToLL(ModuleName.LLB);
- }
- }
- RuningTMRobotTask();
- }
- }
- private void ReturnAtmWafers()
- {
- if(_efemRobot.IsAvailable && _efemRobot.RobotStatus != RState.Running && _efemMovingItems.Count == 0)
- {
- var aligners = _atmSchedulers.Where(x => ModuleHelper.IsAligner(x.Key) && x.Value.IsAvailable && WaferManager.Instance.CheckHasWafer(x.Key, 0)).ToDictionary(k => k.Key, v => v.Value);
- var lls = _vacSchedulers.Where(x => ModuleHelper.IsLoadLock(x.Key) && IsLoadLockReadyForEFEMManualMove(x.Key) && GetLLProcessStatusCount(x.Key).processed + GetLLProcessStatusCount(x.Key).unprocessed > 0).ToDictionary(k => k.Key, v => v.Value);
- if (GetEfemRoborWaferCount() > 0)
- {
- for(int slot = 0; slot < 2; slot++)
- {
- var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, slot);
- if(!wafer.IsEmpty)
- {
- _efemMovingItems.Add(new MoveItem(ModuleName.EfemRobot, slot, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)slot));
- }
- }
- }
- else if(aligners.Count > 0)
- {
- foreach(var align in aligners)
- {
- var wafer = WaferManager.Instance.GetWafer(align.Key, 0);
- var hand = GetEFEMRobotFreeHand();
- if (!wafer.IsEmpty && hand != Hand.None)
- {
- _efemMovingItems.Add(new MoveItem(align.Key, 0, ModuleName.EfemRobot, (int)hand, hand));
- }
- }
- }
- else if(lls.Count > 0)
- {
- ModuleName source = lls.First().Key;
- if(lls.Count > 1)
- {
- if (GetLLProcessStatusCount(ModuleName.LLB).empty < GetLLProcessStatusCount(ModuleName.LLA).empty)
- source = ModuleName.LLB;
- else
- source = ModuleName.LLA;
- }
- int slotNumber = source == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
- for(int i = 0; i < slotNumber; i++)
- {
- var wafer = WaferManager.Instance.GetWafer(source, i);
- var hand = GetEFEMRobotFreeHand();
- if (!wafer.IsEmpty && hand != Hand.None)
- {
- _efemMovingItems.Add(new MoveItem(source, i, ModuleName.EfemRobot, (int)hand, hand));
- }
- }
- }
- RuningEFEMRobotTask();
- }
- }
- private void ReturnPMWafersToLL(ModuleName ll)
- {
- var validSlots = GetModuleValidSlots(ll);
- foreach(var pm in _vacSchedulers)
- {
- if (!ModuleHelper.IsPm(pm.Key))
- continue;
- if(pm.Value.IsIdle && WaferManager.Instance.CheckHasWafer(pm.Key, 0) && validSlots.Count > 0)
- {
- _movingItems.Add(new MoveItem( pm.Key, 0, ll, validSlots.Dequeue(), Hand.None));
- if (_movingItems.Count >= 2)
- return;
- }
- }
- }
- private void ReturnTMRobotWafersToLL(ModuleName ll)
- {
- var validSlots = GetModuleValidSlots(ll);
- for(int slot = 0; slot < 2; slot++)
- {
- if(WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, slot))
- {
- _movingItems.Add(new MoveItem(ModuleName.TMRobot, slot, ll, validSlots.Dequeue(), (Hand)slot));
- }
- }
- }
- private void CheckReturnWafersArrived()
- {
- foreach (var mod in _vacSchedulers.Append(new KeyValuePair<ModuleName, SchedulerModule>(ModuleName.TMRobot, _tmRobot)))
- {
- var tars = _vacWaferTargets.Where(item => item.Key.Module == mod.Key).ToArray();
- foreach (var tar in tars)
- {
- var wafer = WaferManager.Instance.GetWafer(tar.Key.Module, tar.Key.Slot);
- if (wafer.IsEmpty || wafer.InnerId.ToString().Length < 10)
- continue;
- if (wafer.InnerId == tar.Value && _tmRobot.RobotStatus != RState.Running)
- {
- // wafer arrive
- _vacWaferTargets.Remove(tar.Key);
- }
- }
- if (ModuleHelper.IsLoadLock(mod.Key))
- {
- if (!IsLoadLockReservedByTM(mod.Key) && mod.Value.IsAvailable)
- {
- _vacModules[mod.Key].MovingStatus = MovingStatus.Idle;
- }
- }
- }
- _vacMoveFinishTrig.CLK = _vacWaferTargets.Count == 0 && _tmRobot.RobotStatus != RState.Running;
- if (_vacMoveFinishTrig.Q)
- {
- foreach (var item in _movingItems)
- {
- if (!ModuleHelper.IsTMRobot(item.DestinationModule) && _vacModules[item.DestinationModule].MovingStatus == MovingStatus.Moving)
- {
- _vacModules[item.DestinationModule].MovingStatus = MovingStatus.Idle;
- }
- if (!ModuleHelper.IsTMRobot(item.SourceModule) && _vacModules[item.SourceModule].MovingStatus == MovingStatus.Moving)
- {
- _vacModules[item.SourceModule].MovingStatus = MovingStatus.Idle;
- }
- }
- _movingItems.Clear();
- }
- foreach (var mod in _atmSchedulers.Append(new KeyValuePair<ModuleName, SchedulerModule>(ModuleName.EfemRobot, _efemRobot)))
- {
- var tars = _atmWaferTargets.Where(item => item.Key.Module == mod.Key).ToArray();
- foreach (var tar in tars)
- {
- var wafer = WaferManager.Instance.GetWafer(tar.Key.Module, tar.Key.Slot);
- if (wafer.IsEmpty || wafer.InnerId.ToString().Length < 10)
- continue;
- if (wafer.InnerId == tar.Value && _efemRobot.RobotStatus != RState.Running)
- {
- if (!ModuleHelper.IsLoadPort(tar.Key.Module) && !ModuleHelper.IsEFEMRobot(tar.Key.Module))
- _atmSchedulers[tar.Key.Module].WaferArrived(tar.Key.Slot);
- _atmWaferTargets.Remove(tar.Key);
- if (ModuleHelper.IsAligner(tar.Key.Module))
- {
- _atmModules[tar.Key.Module].MovingStatus = MovingStatus.WaitAlign;
- }
- }
- }
- if (ModuleHelper.IsLoadLock(mod.Key))
- {
- if (!IsLoadLockReservedByEFEM(mod.Key) && mod.Value.IsAvailable)
- {
- _vacModules[mod.Key].MovingStatus = MovingStatus.Idle;
- }
- }
- }
- if (_atmWaferTargets.Count == 0 && _efemRobot.RobotStatus != RState.Running && _efemMovingItems.Count > 0)
- {
- foreach (var item in _efemMovingItems)
- {
- if (ModuleHelper.IsLoadLock(item.Module))
- {
- _vacModules[item.Module].MovingStatus = MovingStatus.Idle;
- }
- }
- _efemMovingItems.Clear();
- }
- }
- #endregion
- }
- }
|