SystemDispatcher.cs 223 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Diagnostics;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Sorter.Common;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.Util;
  11. using Aitex.Core.RT.DataCenter;
  12. using Aitex.Core.RT.RecipeCenter;
  13. using Aitex.Core.RT.Fsm;
  14. using MECF.Framework.Common.Jobs;
  15. using MECF.Framework.Common.Routine;
  16. using MECF.Framework.Common.Equipment;
  17. using MECF.Framework.Common.SubstrateTrackings;
  18. using MECF.Framework.Common.Schedulers;
  19. using MECF.Framework.Common.DBCore;
  20. using Venus_Core;
  21. using Venus_RT.Modules.Schedulers;
  22. using Venus_RT.Scheduler;
  23. using Venus_Unity;
  24. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  25. using System.Linq.Expressions;
  26. namespace Venus_RT.Modules
  27. {
  28. public class WaferTask
  29. {
  30. public ModuleName sourceMod { get; }
  31. public int sourceSlot { get; }
  32. public ModuleName destMod { get; private set; }
  33. public int destSlot { get; private set; }
  34. public ModuleName currentMod { get; private set; }
  35. public int currentSlot { get; private set; }
  36. public ModuleName nextMod { get; private set; }
  37. public int nextSlot { get; private set; }
  38. public ModuleName routedMod { get; private set; }
  39. public int routedSlot { get; private set; }
  40. public Hand hand { get; private set; }
  41. public SequenceLLInOutPath llInOutPath { get; }
  42. public string processRecipe { get; }
  43. public string wtwCleanRecipe { get; }
  44. public float temperature { get; }
  45. public Guid waferId { get; }
  46. public int elapseTime { get { return (int)(DateTime.Now - _scheduledTime).TotalSeconds; } }
  47. public int llDelayTime { get; }
  48. public RState pressureStatus { get; private set; }
  49. public RState temperatureStatus { get; private set; }
  50. public RState movingStatus { get; private set; }
  51. public bool IsCompleted { get { return movingStatus == RState.End && currentMod == destMod && currentSlot == destSlot; } }
  52. public bool IsTimeout { get { return elapseTime > 600; } }
  53. public bool IsAligned { get; set; }
  54. public bool IsWaitingAtmMoving
  55. {
  56. get
  57. {
  58. if (movingStatus != RState.Init)
  59. return false;
  60. return !IsWaitingVacMoving;
  61. }
  62. }
  63. public bool IsWaitingVacMoving
  64. {
  65. get
  66. {
  67. if ( movingStatus == RState.Init &&
  68. (ModuleHelper.IsPm(nextMod) ||
  69. ModuleHelper.IsTMRobot(nextMod) ||
  70. ModuleHelper.IsPm(currentMod) ||
  71. ModuleHelper.IsTMRobot(currentMod)))
  72. return true;
  73. return false;
  74. }
  75. }
  76. public delegate void WaferMoveHandler(WaferTask wafer, MoveItem item);
  77. public event WaferMoveHandler OnWaferArrived;
  78. public event WaferMoveHandler OnWaferLeaved;
  79. private DateTime _scheduledTime;
  80. public WaferTask(ModuleName source, int srcSlot, ModuleName dest, int dstSlot, float temp, Guid waferID, string recipeName, string wtwClean, SequenceLLInOutPath inOutPath, int LLDelay, bool needAlign)
  81. {
  82. sourceMod = currentMod = nextMod = routedMod = source;
  83. sourceSlot = currentSlot = nextSlot = routedSlot = srcSlot;
  84. destMod = dest;
  85. destSlot = dstSlot;
  86. hand = Hand.None;
  87. temperature = temp;
  88. waferId = waferID;
  89. processRecipe = recipeName;
  90. wtwCleanRecipe = wtwClean;
  91. llInOutPath = inOutPath;
  92. llDelayTime = LLDelay;
  93. IsAligned = !needAlign;
  94. pressureStatus = RState.Init;
  95. temperatureStatus = RState.End;
  96. movingStatus = RState.Init;
  97. _scheduledTime = DateTime.Now;
  98. }
  99. public RState Run()
  100. {
  101. if (movingStatus == RState.Running)
  102. {
  103. var wafer = WaferManager.Instance.GetWafer(nextMod, nextSlot);
  104. if (!wafer.IsEmpty && wafer.InnerId == waferId)
  105. {
  106. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Wafer {wafer.WaferOrigin} from {currentMod}.{currentSlot + 1} move to {nextMod}.{nextSlot + 1}");
  107. if (!ModuleHelper.IsTMRobot(currentMod) && !ModuleHelper.IsEFEMRobot(currentMod))
  108. {
  109. OnWaferLeaved(this, new MoveItem(currentMod, currentSlot, nextMod, nextSlot, hand));
  110. }
  111. if (!ModuleHelper.IsTMRobot(nextMod) && !ModuleHelper.IsEFEMRobot(nextMod))
  112. {
  113. _scheduledTime = DateTime.Now;
  114. wafer.NextSequenceStep++;
  115. OnWaferArrived(this, new MoveItem(currentMod, currentSlot, nextMod, nextSlot, hand));
  116. }
  117. currentMod = nextMod;
  118. currentSlot = nextSlot;
  119. movingStatus = RState.End;
  120. }
  121. }
  122. return RState.Running;
  123. }
  124. public void RouteTo(ModuleName mod, int slot)
  125. {
  126. routedMod = mod;
  127. routedSlot = slot;
  128. movingStatus = RState.Init;
  129. }
  130. public void MoveTo(ModuleName mod, int slot)
  131. {
  132. nextMod = mod;
  133. nextSlot = slot;
  134. movingStatus = RState.Running;
  135. if(ModuleHelper.IsLoadLock(currentMod) && ModuleHelper.IsTMRobot(nextMod) && ModuleHelper.IsLoadLock(routedMod))
  136. {
  137. routedMod = ModuleName.TMRobot; // fix the bug which missing call RouteTo() on Vac side
  138. }
  139. }
  140. public void ReAssignPM(ModuleName pm, int slot)
  141. {
  142. destMod = pm;
  143. destSlot = slot;
  144. }
  145. public void Return()
  146. {
  147. destMod = sourceMod;
  148. destSlot = sourceSlot;
  149. movingStatus = RState.End;
  150. pressureStatus = RState.End;
  151. temperatureStatus = RState.End;
  152. }
  153. }
  154. public enum ModuleStatus
  155. {
  156. Idle,
  157. WaitMove,
  158. Moving,
  159. NotReady,
  160. // PM Status
  161. WaitProcess,
  162. StartProcess,
  163. Processing,
  164. StartIdleClean,
  165. IdleClean,
  166. WaitPreJobClean,
  167. StartPreJobClean,
  168. PreJobClean,
  169. WaitPostJobClean,
  170. StartPostJobClean,
  171. PostJobClean,
  172. WaitWTWClean,
  173. StartWTWClean,
  174. WTWClean,
  175. // Align Status
  176. WaitAlign,
  177. StartAlign,
  178. Aligning,
  179. // Loadlock Status
  180. StartPump,
  181. Pumping,
  182. VacReady,
  183. StartVent,
  184. Venting,
  185. AtmReady,
  186. WaitCooling,
  187. StartCooling,
  188. Cooling,
  189. CoolingDone,
  190. // Unknown
  191. Unknown,
  192. }
  193. public class ModuleTask
  194. {
  195. public ModuleName Module { get; }
  196. public ModuleStatus Status { get; set; }
  197. public SchedulerModule Scheduler { get; }
  198. public virtual int SlotNum { get; protected set; }
  199. public virtual bool IsIdle { get { return Status == ModuleStatus.Idle; } }
  200. public virtual bool HasWafer { get { return WaferManager.Instance.CheckHasWafer(Module, 0); } }
  201. private int _currentActionTime = 0;
  202. public virtual int IdleTime
  203. {
  204. get
  205. {
  206. if (Status != ModuleStatus.Idle)
  207. return 0;
  208. return (int)(DateTime.Now - _moduleTimer).TotalSeconds;
  209. }
  210. }
  211. public virtual int BusyTime
  212. {
  213. get
  214. {
  215. if (Status == ModuleStatus.Idle)
  216. return 0;
  217. return (int)(DateTime.Now - _moduleTimer).TotalSeconds;
  218. }
  219. }
  220. public virtual int BusyLastTime
  221. {
  222. get
  223. {
  224. if (Status == ModuleStatus.Idle)
  225. return 0;
  226. return _currentActionTime - BusyTime;
  227. }
  228. }
  229. public virtual int TimeToReady
  230. {
  231. get
  232. {
  233. if(Scheduler.IsAvailable)
  234. return 0;
  235. return int.MaxValue / 2;
  236. }
  237. }
  238. protected DateTime _moduleTimer;
  239. public ModuleTask(ModuleName mod)
  240. {
  241. Module = mod;
  242. Scheduler = Singleton<TransferModule>.Instance.GetScheduler(mod);
  243. SlotNum = 1;
  244. _moduleTimer = DateTime.Now;
  245. }
  246. public virtual RState Run()
  247. {
  248. Status = Scheduler.IsAvailable ? ModuleStatus.Idle : ModuleStatus.NotReady;
  249. return RState.Running;
  250. }
  251. public virtual void WaferArrived(WaferTask wafer, int slot)
  252. {
  253. }
  254. public virtual void WaferLeaved(WaferTask wafer, int slot)
  255. {
  256. }
  257. public virtual void ResetTask()
  258. {
  259. }
  260. }
  261. public class PMTask : ModuleTask
  262. {
  263. enum CleanType
  264. {
  265. IdleClean,
  266. PreJobClean,
  267. PostJobClean,
  268. WTWClean,
  269. }
  270. public override int TimeToReady
  271. {
  272. get
  273. {
  274. switch(Status)
  275. {
  276. case ModuleStatus.Idle:
  277. case ModuleStatus.Processing:
  278. case ModuleStatus.IdleClean:
  279. case ModuleStatus.PreJobClean:
  280. {
  281. return Scheduler.IsAvailable ? 0 : (Scheduler.TimeToReady + 500) / 1000;
  282. }
  283. case ModuleStatus.PostJobClean:
  284. case ModuleStatus.WTWClean:
  285. {
  286. if(_pendingCleanTask.Count == 0)
  287. {
  288. return Scheduler.IsAvailable ? 0 : (Scheduler.TimeToReady + 500) / 1000;
  289. }
  290. }
  291. break;
  292. }
  293. return int.MaxValue / 2;
  294. }
  295. }
  296. private WaferTask _wafer;
  297. private SchedulerPM _pmScheduler => Scheduler as SchedulerPM;
  298. private string _preJobCleanRecipe;
  299. private string _postJobCleanRecipe;
  300. private string _wtwCleanRecipe;
  301. private Queue<CleanType> _pendingCleanTask = new Queue<CleanType>();
  302. public PMTask(ModuleName pm) : base(pm)
  303. {
  304. }
  305. public override RState Run()
  306. {
  307. if(Scheduler.IsIdle)
  308. {
  309. switch (Status)
  310. {
  311. case ModuleStatus.Idle:
  312. {
  313. if(WaferManager.Instance.CheckNoWafer(Module, 0) && Scheduler.IsOnline)
  314. {
  315. if (_pendingCleanTask.Count > 0)
  316. {
  317. var cleanTask = _pendingCleanTask.Dequeue();
  318. if (cleanTask == CleanType.PostJobClean && !string.IsNullOrWhiteSpace(_postJobCleanRecipe))
  319. {
  320. Status = ModuleStatus.WaitPostJobClean;
  321. }
  322. else if (cleanTask == CleanType.PreJobClean && !string.IsNullOrWhiteSpace(_preJobCleanRecipe))
  323. {
  324. Status = ModuleStatus.WaitPreJobClean;
  325. }
  326. }
  327. else if (_pmScheduler.RunIdleCleanTask()) // Check Idle Clean
  328. {
  329. Status = ModuleStatus.StartIdleClean;
  330. }
  331. }
  332. }
  333. break;
  334. case ModuleStatus.WaitProcess:
  335. {
  336. Scheduler.EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.TMRobot, 0, Module, 0));
  337. Status = ModuleStatus.StartProcess;
  338. }
  339. break;
  340. case ModuleStatus.WaitPreJobClean:
  341. {
  342. if(WaferManager.Instance.CheckNoWafer(Module, 0))
  343. {
  344. if (_pmScheduler.RunJobCleanTask(_preJobCleanRecipe))
  345. {
  346. Status = ModuleStatus.StartPreJobClean;
  347. }
  348. else
  349. {
  350. LOG.Write(eEvent.WARN_ROUTER, Module, $"Run Prejob clean recipe{_preJobCleanRecipe} failed");
  351. Status = ModuleStatus.Idle;
  352. _preJobCleanRecipe = string.Empty;
  353. }
  354. }
  355. }
  356. break;
  357. case ModuleStatus.WaitPostJobClean:
  358. {
  359. if (WaferManager.Instance.CheckNoWafer(Module, 0))
  360. {
  361. if (_pmScheduler.RunJobCleanTask(_postJobCleanRecipe))
  362. {
  363. Status = ModuleStatus.StartPostJobClean;
  364. }
  365. else
  366. {
  367. LOG.Write(eEvent.WARN_ROUTER, Module, $"Run Postjob clean recipe{_postJobCleanRecipe} failed");
  368. Status = ModuleStatus.Idle;
  369. _postJobCleanRecipe = string.Empty;
  370. }
  371. }
  372. }
  373. break;
  374. case ModuleStatus.WaitWTWClean:
  375. {
  376. if (WaferManager.Instance.CheckNoWafer(Module, 0))
  377. {if (_pmScheduler.RunJobCleanTask(_wtwCleanRecipe))
  378. {
  379. Status = ModuleStatus.StartWTWClean;
  380. }
  381. else
  382. {
  383. LOG.Write(eEvent.WARN_ROUTER, Module, $"Run WTW Wafer clean recipe{_wtwCleanRecipe} failed");
  384. Status = ModuleStatus.Idle;
  385. _wtwCleanRecipe = string.Empty;
  386. }
  387. }
  388. }
  389. break;
  390. case ModuleStatus.Processing:
  391. {
  392. var wafer = WaferManager.Instance.GetWafer(Module, 0);
  393. if(Scheduler.IsOnline)
  394. {
  395. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  396. {
  397. _wafer.Return();
  398. Status = ModuleStatus.Idle;
  399. }
  400. }
  401. else // handle offline exception situation
  402. {
  403. Status = ModuleStatus.Idle;
  404. }
  405. }
  406. break;
  407. case ModuleStatus.PreJobClean:
  408. {
  409. _preJobCleanRecipe = string.Empty;
  410. Status = ModuleStatus.Idle;
  411. }
  412. break;
  413. case ModuleStatus.PostJobClean:
  414. {
  415. _postJobCleanRecipe = string.Empty;
  416. if (_pendingCleanTask.Count > 0)
  417. {
  418. var cleanTask = _pendingCleanTask.Dequeue();
  419. if(cleanTask == CleanType.PreJobClean && !string.IsNullOrWhiteSpace(_preJobCleanRecipe))
  420. {
  421. Status = ModuleStatus.WaitPreJobClean;
  422. break;
  423. }
  424. }
  425. Status = ModuleStatus.Idle;
  426. }
  427. break;
  428. case ModuleStatus.WTWClean:
  429. {
  430. if(_pendingCleanTask.Count > 0)
  431. {
  432. var cleanTask = _pendingCleanTask.Dequeue();
  433. if (cleanTask == CleanType.PostJobClean && !string.IsNullOrWhiteSpace(_postJobCleanRecipe))
  434. {
  435. Status = ModuleStatus.WaitPostJobClean;
  436. }
  437. else if (cleanTask == CleanType.PreJobClean && !string.IsNullOrWhiteSpace(_preJobCleanRecipe))
  438. {
  439. Status = ModuleStatus.WaitPreJobClean;
  440. }
  441. }
  442. else
  443. {
  444. Status = ModuleStatus.Idle;
  445. }
  446. _wtwCleanRecipe = string.Empty;
  447. }
  448. break;
  449. case ModuleStatus.IdleClean:
  450. {
  451. Status = ModuleStatus.Idle;
  452. }
  453. break;
  454. case ModuleStatus.StartProcess:
  455. {
  456. if(RouteManager.IsATMMode)
  457. {
  458. Status = ModuleStatus.Processing;
  459. }
  460. }
  461. break;
  462. }
  463. }
  464. else
  465. {
  466. switch(Status)
  467. {
  468. case ModuleStatus.StartProcess:
  469. Status = ModuleStatus.Processing;
  470. break;
  471. case ModuleStatus.StartIdleClean:
  472. Status = ModuleStatus.IdleClean;
  473. break;
  474. case ModuleStatus.StartPreJobClean:
  475. Status = ModuleStatus.PreJobClean;
  476. break;
  477. case ModuleStatus.StartPostJobClean:
  478. Status = ModuleStatus.PostJobClean;
  479. break;
  480. case ModuleStatus.StartWTWClean:
  481. Status = ModuleStatus.WTWClean;
  482. break;
  483. }
  484. }
  485. return RState.Running;
  486. }
  487. public override void WaferArrived(WaferTask wafer, int slot)
  488. {
  489. _wafer = wafer;
  490. Status = ModuleStatus.WaitProcess;
  491. }
  492. public override void WaferLeaved(WaferTask wafer, int slot)
  493. {
  494. if(!string.IsNullOrWhiteSpace(_wafer.wtwCleanRecipe.Trim()))
  495. {
  496. Status = ModuleStatus.WaitWTWClean;
  497. _wtwCleanRecipe = _wafer.wtwCleanRecipe;
  498. }
  499. else if(_pendingCleanTask.Count > 0)
  500. {
  501. var cleanTask = _pendingCleanTask.Dequeue();
  502. if (cleanTask == CleanType.PostJobClean && !string.IsNullOrWhiteSpace(_postJobCleanRecipe))
  503. {
  504. Status = ModuleStatus.WaitPostJobClean;
  505. }
  506. else if (cleanTask == CleanType.PreJobClean && !string.IsNullOrWhiteSpace(_preJobCleanRecipe))
  507. {
  508. Status = ModuleStatus.WaitPreJobClean;
  509. }
  510. }
  511. _wafer = null;
  512. }
  513. public void InvokePreJobClean(string preJobClean)
  514. {
  515. _preJobCleanRecipe = preJobClean;
  516. _pendingCleanTask.Enqueue(CleanType.PreJobClean);
  517. }
  518. public bool IsPreJobCleanDone()
  519. {
  520. return !_pendingCleanTask.Contains(CleanType.PreJobClean) && string.IsNullOrWhiteSpace(_preJobCleanRecipe);
  521. }
  522. public void InvokePostJobClean(string postJobClean)
  523. {
  524. _postJobCleanRecipe = postJobClean;
  525. _pendingCleanTask.Enqueue(CleanType.PostJobClean);
  526. }
  527. public bool IsPostJobCleanDone()
  528. {
  529. return !_pendingCleanTask.Contains(CleanType.PostJobClean) && string.IsNullOrWhiteSpace(_postJobCleanRecipe);
  530. }
  531. }
  532. public class AlignerTask : ModuleTask
  533. {
  534. private WaferTask _wafer;
  535. public AlignerTask(ModuleName aligner) : base(aligner)
  536. {
  537. }
  538. public override RState Run()
  539. {
  540. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  541. if (efemRobot == null || !efemRobot.IsAvailable)
  542. return RState.Running;
  543. switch (Status)
  544. {
  545. case ModuleStatus.WaitAlign:
  546. {
  547. efemRobot.Align(0);
  548. Status = ModuleStatus.Aligning;
  549. }
  550. break;
  551. case ModuleStatus.Aligning:
  552. {
  553. _wafer.IsAligned = true;
  554. Status = ModuleStatus.Idle;
  555. }
  556. break;
  557. }
  558. return RState.Running;
  559. }
  560. public override void WaferArrived(WaferTask wafer, int slot)
  561. {
  562. _wafer = wafer;
  563. Status = ModuleStatus.WaitAlign;
  564. }
  565. public override void WaferLeaved(WaferTask wafer, int slot)
  566. {
  567. _wafer = null;
  568. }
  569. }
  570. public class LoadPortTask : ModuleTask
  571. {
  572. public LoadPortTask(ModuleName lp) : base(lp)
  573. {
  574. SlotNum = SC.GetValue<int>($"EFEM.LoadPort.SlotNumber");
  575. }
  576. public override RState Run()
  577. {
  578. return base.Run();
  579. }
  580. }
  581. public class TMRobotTask : ModuleTask
  582. {
  583. public TMRobotTask(ModuleName tmRobot) : base(tmRobot)
  584. {
  585. SlotNum = 2;
  586. }
  587. public override RState Run()
  588. {
  589. return base.Run();
  590. }
  591. }
  592. public class EFEMRobotTask : ModuleTask
  593. {
  594. public EFEMRobotTask(ModuleName efemRobot) : base(efemRobot)
  595. {
  596. SlotNum = 2;
  597. }
  598. public override RState Run()
  599. {
  600. return base.Run();
  601. }
  602. public bool PostMoveItems(MoveItem[] items)
  603. {
  604. Status = ModuleStatus.Moving;
  605. return (Scheduler as SchedulerEfemRobot).PostMoveItems(items);
  606. }
  607. }
  608. public enum LLStatus
  609. {
  610. StartPump,
  611. Pumping,
  612. VacReady,
  613. StartVent,
  614. Venting,
  615. AtmReady,
  616. Unknow,
  617. }
  618. public class LoadlockTask : ModuleTask
  619. {
  620. private Dictionary<int, int> _wafersDelayTime = new Dictionary<int, int>();
  621. public LoadlockTask(ModuleName ll) : base(ll)
  622. {
  623. SlotNum = SC.GetValue<int>($"{ll}.SlotNumber");
  624. for (int slot = 0; slot < SlotNum; slot++)
  625. _wafersDelayTime[slot] = -1;
  626. }
  627. public override int TimeToReady
  628. {
  629. get { return Scheduler.IsAvailable ? 0 : (Scheduler.TimeToReady + 500) / 1000; }
  630. }
  631. public bool ReayForTMInTime(int seconds)
  632. {
  633. return (Status == ModuleStatus.Pumping && TimeToReady < seconds) || Status == ModuleStatus.VacReady;
  634. }
  635. public bool ReayForEfemInTime(int seconds)
  636. {
  637. return (Status == ModuleStatus.Venting && TimeToReady < seconds) || Status == ModuleStatus.AtmReady;
  638. }
  639. public override void WaferArrived(WaferTask wafer, int slot)
  640. {
  641. Scheduler.WaferArrived(slot);
  642. if(ModuleHelper.IsLoadPort(wafer.destMod))
  643. {
  644. _wafersDelayTime[slot] = wafer.llDelayTime;
  645. }
  646. else
  647. {
  648. _wafersDelayTime[slot] = -1;
  649. }
  650. }
  651. public override void WaferLeaved(WaferTask wafer, int slot)
  652. {
  653. _wafersDelayTime[slot] = -1;
  654. }
  655. public bool PreVent()
  656. {
  657. if (Scheduler.IsAvailable && !Scheduler.IsAtm)
  658. {
  659. if ((Scheduler as SchedulerLoadLock).PreVent())
  660. {
  661. Status = ModuleStatus.StartVent;
  662. return true;
  663. }
  664. }
  665. return false;
  666. }
  667. public bool PrePump()
  668. {
  669. if (Scheduler.IsAvailable && !Scheduler.IsVac)
  670. {
  671. if ((Scheduler as SchedulerLoadLock).PrePump())
  672. {
  673. Status = ModuleStatus.StartPump;
  674. return true;
  675. }
  676. }
  677. return false;
  678. }
  679. public bool Cooling()
  680. {
  681. if (Scheduler.IsAvailable && !Scheduler.IsAtm)
  682. {
  683. if((Scheduler as SchedulerLoadLock).Cooling())
  684. {
  685. Status = ModuleStatus.StartCooling;
  686. return true;
  687. }
  688. }
  689. return false;
  690. }
  691. public override RState Run()
  692. {
  693. if (Scheduler.IsIdle)
  694. {
  695. if (Scheduler.IsAvailable)
  696. {
  697. switch(Status)
  698. {
  699. case ModuleStatus.Pumping:
  700. if(Scheduler.IsVac)
  701. {
  702. Status = ModuleStatus.VacReady;
  703. }
  704. break;
  705. case ModuleStatus.Venting:
  706. if(Scheduler.IsAtm)
  707. {
  708. Status = ModuleStatus.AtmReady;
  709. }
  710. break;
  711. case ModuleStatus.Cooling:
  712. if(Scheduler.IsAtm)
  713. {
  714. Status = ModuleStatus.CoolingDone;
  715. }
  716. break;
  717. default:
  718. {
  719. Status = Scheduler.IsAtm ? ModuleStatus.AtmReady : Scheduler.IsVac ? ModuleStatus.VacReady : Status;
  720. }
  721. break;
  722. }
  723. }
  724. }
  725. else
  726. {
  727. switch(Status)
  728. {
  729. case ModuleStatus.StartPump:
  730. Status = ModuleStatus.Pumping;
  731. break;
  732. case ModuleStatus.StartVent:
  733. Status = ModuleStatus.Venting;
  734. break;
  735. case ModuleStatus.StartCooling:
  736. Status = ModuleStatus.Cooling;
  737. break;
  738. }
  739. }
  740. return RState.Running;
  741. }
  742. }
  743. enum LLSlotInOutOpt
  744. {
  745. AllInAllOut,
  746. UpperInLowerOut,
  747. LowerInUpperOut,
  748. }
  749. enum SpecialRoutingPattern
  750. {
  751. Disable,
  752. LongTimeRecipe,
  753. }
  754. class SystemDispatcher : ICycle
  755. {
  756. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  757. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  758. private Queue<ControlJobInfo> _qePollingJobs = new Queue<ControlJobInfo>();
  759. private List<WaferTask> _lstWaferTasks = new List<WaferTask>();
  760. private Dictionary<ModuleName, ModuleTask> _dictModuleTask = new Dictionary<ModuleName, ModuleTask>();
  761. private Queue<WaferInfo> _qeReturnWafers = new Queue<WaferInfo>();
  762. private Queue<Guid> _qeWaitInWafers = new Queue<Guid>();
  763. private Queue<List<MoveItem>> _efemSchdActions = new Queue<List<MoveItem>>();
  764. private Queue<List<MoveItem>> _tmSchdActions = new Queue<List<MoveItem>>();
  765. private List<MoveItem> _curEfemAction = new List<MoveItem>();
  766. private List<MoveItem> _curTmAction = new List<MoveItem>();
  767. private RState _efemRobotStatus { get { return (_dictModuleTask[ModuleName.EfemRobot].Scheduler as SchedulerEfemRobot).RobotStatus; } }
  768. private RState _tmRobotStatus { get { return (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerTMRobot).RobotStatus; } }
  769. private SchedulerFACallback _faCallback;
  770. private SchedulerDBCallback _dbCallback;
  771. private readonly int _LLASlotNumber = 4;
  772. private readonly int _LLBSlotNumber = 4;
  773. private int _efemRobotSingleArmOption = 0;
  774. private int _tmRobotSingleArmOption = 0;
  775. private LLSlotInOutOpt _LLSlotInOutOption = 0;
  776. private Dictionary<ModuleName, int> _lpCycleWafer = new Dictionary<ModuleName, int> { {ModuleName.LP1, 0}, { ModuleName.LP2, 0}, { ModuleName.LP3, 0} };
  777. private Dictionary<ModuleName, int> _lpCycleCount = new Dictionary<ModuleName, int> { { ModuleName.LP1, 0 }, { ModuleName.LP2, 0 }, { ModuleName.LP3, 0 } };
  778. private Dictionary<ModuleName, int> _lpCycleSP = new Dictionary<ModuleName, int> { { ModuleName.LP1, 1 }, { ModuleName.LP2, 1 }, { ModuleName.LP3, 1 } };
  779. private Dictionary<ModuleName, float> _lpThroughput = new Dictionary<ModuleName, float>{ {ModuleName.LP1, 0}, { ModuleName.LP2, 0}, { ModuleName.LP3, 0} };
  780. private Dictionary<ModuleName, Stopwatch> _lpCycleWatch = new Dictionary<ModuleName, Stopwatch> { { ModuleName.LP1, new Stopwatch() }, { ModuleName.LP2, new Stopwatch()}, { ModuleName.LP3, new Stopwatch()} };
  781. private Stopwatch _cycleWatch = new Stopwatch();
  782. private SequenceLLInOutPath _LLInOutPath = SequenceLLInOutPath.DInDOut;
  783. private SpecialRoutingPattern _specialRoutingPattern = SpecialRoutingPattern.Disable;
  784. public SequenceLLInOutPath LLInOutPath => _LLInOutPath;
  785. public bool HasJobRunning => _lstControlJobs.Count > 0;
  786. private RState _cycleState = RState.Init;
  787. public RState CycleState => _cycleState;
  788. private Dictionary<string, ControlJobInfo> _loadportControlJobDic = new Dictionary<string, ControlJobInfo>();
  789. public List<string> InUseRecipes = new List<string>();
  790. public List<string> LP1InUseRecipes = new List<string>();
  791. public List<string> LP2InUseRecipes = new List<string>();
  792. public List<string> LP3InUseRecipes = new List<string>();
  793. #region public interface
  794. public SystemDispatcher()
  795. {
  796. _faCallback = new SchedulerFACallback();
  797. _dbCallback = new SchedulerDBCallback();
  798. _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
  799. _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
  800. _LLASlotNumber = SC.GetValue<int>("LLA.SlotNumber");
  801. _LLBSlotNumber = SC.GetValue<int>("LLB.SlotNumber");
  802. InitModules();
  803. DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
  804. DATA.Subscribe("Scheduler.PjNameList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.LotName.ToString()).ToList());
  805. DATA.Subscribe("Scheduler.InUsingRecipe", () => InUseRecipes);
  806. foreach (var lp in new List<ModuleName> { ModuleName.LP1, ModuleName.LP2, ModuleName.LP3})
  807. {
  808. _loadportControlJobDic[lp.ToString()] = null;
  809. DATA.Subscribe($"{lp}.CurrentControlJob", () => _loadportControlJobDic[lp.ToString()], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  810. DATA.Subscribe($"{lp}.CycledCount", () => _lpCycleCount[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  811. DATA.Subscribe($"{lp}.CycledWafer", () => _lpCycleWafer[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  812. DATA.Subscribe($"{lp}.CycleSetPoint", () => _lpCycleSP[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  813. DATA.Subscribe($"{lp}.Throughput", () => _lpThroughput[lp], SubscriptionAttribute.FLAG.IgnoreSaveDB);
  814. }
  815. DATA.Subscribe("Scheduler.LP1.InUsingRecipe", () => LP1InUseRecipes);
  816. DATA.Subscribe("Scheduler.LP2.InUsingRecipe", () => LP2InUseRecipes);
  817. DATA.Subscribe("Scheduler.LP3.InUsingRecipe", () => LP3InUseRecipes);
  818. }
  819. /// <summary>
  820. /// 获取lp当前的ControlJob
  821. /// </summary>
  822. /// <param name="lp"></param>
  823. /// <returns></returns>
  824. public ControlJobInfo GetLoadPortCurrentControlJob(ModuleName lp)
  825. {
  826. if(ModuleHelper.IsLoadPort(lp))
  827. {
  828. return _loadportControlJobDic.ContainsKey(lp.ToString()) ? _loadportControlJobDic[lp.ToString()] : null;
  829. }
  830. else
  831. {
  832. return null;
  833. }
  834. }
  835. public RState Start(params object[] objs)
  836. {
  837. if(WaferManager.Instance.HasDuplicatedWafer)
  838. {
  839. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, "System has dummy wafers, please verify all the wafer position, and delete the invalid wafer");
  840. return RState.Failed;
  841. }
  842. _efemRobotSingleArmOption = SC.GetValue<int>("EFEM.SingleArmOption");
  843. _tmRobotSingleArmOption = SC.GetValue<int>("TM.SingleArmOption");
  844. _LLSlotInOutOption = (LLSlotInOutOpt)SC.GetValue<int>("System.LoadlockSlotInOutOption");
  845. _specialRoutingPattern = (SpecialRoutingPattern)SC.GetValue<int>("System.SpecialRoutingPattern");
  846. // rounding TM robot single arm option
  847. if(_tmRobotSingleArmOption > 2 && _LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  848. {
  849. _tmRobotSingleArmOption = 0;
  850. }
  851. _cycleWatch.Stop();
  852. Clear();
  853. // reset cycle/throughput couter
  854. _lpCycleWafer = new Dictionary<ModuleName, int> { { ModuleName.LP1, 0 }, { ModuleName.LP2, 0 }, { ModuleName.LP3, 0 } };
  855. _lpCycleCount = new Dictionary<ModuleName, int> { { ModuleName.LP1, 0 }, { ModuleName.LP2, 0 }, { ModuleName.LP3, 0 } };
  856. _lpCycleSP = new Dictionary<ModuleName, int> { { ModuleName.LP1, 1 }, { ModuleName.LP2, 1 }, { ModuleName.LP3, 1 } };
  857. _lpThroughput = new Dictionary<ModuleName, float> { { ModuleName.LP1, 0 }, { ModuleName.LP2, 0 }, { ModuleName.LP3, 0 } };
  858. _lpCycleWatch = new Dictionary<ModuleName, Stopwatch> { { ModuleName.LP1, new Stopwatch() }, { ModuleName.LP2, new Stopwatch() }, { ModuleName.LP3, new Stopwatch() } };
  859. return RState.Running;
  860. }
  861. public RState Monitor()
  862. {
  863. prelude();
  864. RunWaferTask();
  865. RunModuleTasks();
  866. RoutingATMWafers();
  867. RoutingVacWafers();
  868. epilogue();
  869. return _cycleState;
  870. }
  871. public void Abort()
  872. {
  873. }
  874. public bool CreateJob(Dictionary<string, object> param, out string reason)
  875. {
  876. reason = "";
  877. string[] slotSequence = (string[])param["SlotSequence"];
  878. string module = (string)param["Module"];
  879. string jobId = (string)param["JobId"];
  880. if (string.IsNullOrEmpty(jobId))
  881. {
  882. jobId = "CJ_Local_" + module;
  883. }
  884. foreach (var item in _loadportControlJobDic.Values)
  885. {
  886. if (item?.Name == jobId)
  887. {
  888. reason = $"The same jobid {jobId} already exists, please re-enter the jobid";
  889. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  890. return false;
  891. }
  892. }
  893. string lotId = (string)param["LotId"];
  894. if (string.IsNullOrEmpty(lotId))
  895. {
  896. lotId = "CJ_Local_" + module;
  897. }
  898. string preCleanRecipe = param.ContainsKey("PreCleanRecipeName") ? (string)param["PreCleanRecipeName"] : string.Empty;
  899. string postCleanRecipe = param.ContainsKey("PostCleanRecipeName") ? (string)param["PostCleanRecipeName"] : string.Empty;
  900. int cycleNumber = param.ContainsKey("CycleNumber") ? (int)param["CycleNumber"] : 1;
  901. if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  902. {
  903. reason = $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}";
  904. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  905. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  906. return false;
  907. }
  908. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  909. {
  910. reason = $"{module} should be LoadPort";
  911. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  912. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  913. return false;
  914. }
  915. if (_lstControlJobs.Exists(x => x.Name == jobId))
  916. {
  917. reason = $"{jobId} already created";
  918. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  919. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  920. return false;
  921. }
  922. ControlJobInfo cj = new ControlJobInfo();
  923. cj.Name = jobId;
  924. cj.Module = module;
  925. cj.LotName = lotId;
  926. cj.LotInnerId = Guid.NewGuid();
  927. cj.LotWafers = new List<WaferInfo>();
  928. cj.SetState(EnumControlJobState.WaitingForStart);
  929. cj.JetState = EnumJetCtrlJobState.Created;
  930. cj.PreJobClean = preCleanRecipe;
  931. cj.PostJobClean = postCleanRecipe;
  932. cj.SequenceNameList = slotSequence;
  933. cj.CycleNumber = cycleNumber;
  934. _lpCycleSP[ModuleHelper.Converter(module)] = cj.CycleNumber;
  935. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  936. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  937. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  938. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  939. for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
  940. {
  941. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  942. continue;
  943. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  944. indexSequence[groupName] = slotSequence[i];
  945. if (!seqSlot.ContainsKey(groupName))
  946. {
  947. seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  948. }
  949. if (!seqSlotWafers.ContainsKey(groupName))
  950. {
  951. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  952. }
  953. seqSlot[groupName][i] = true;
  954. if (!WaferManager.Instance.CheckHasWafer(module, i))
  955. {
  956. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} not in the carrier");
  957. return false;
  958. }
  959. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  960. {
  961. reason = $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}";
  962. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  963. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  964. return false;
  965. }
  966. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  967. {
  968. reason = $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}";
  969. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  970. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  971. return false;
  972. }
  973. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 start---
  974. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i);
  975. cj.LotWafers.Add(waferInfo);
  976. waferInfo.SequenceName = slotSequence[i];
  977. waferInfo.LotId = lotId;
  978. //--- 2024-03-21 增加了waferinfo 相应的lotId信息 end---
  979. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  980. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  981. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  982. }
  983. if (seqSlotWafers.Count == 0)
  984. {
  985. reason = $"job has not assign wafer";
  986. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  987. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  988. return false;
  989. }
  990. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  991. string[] seqs = seqSlot.Keys.ToArray();
  992. for (int i = 0; i < seqs.Length; i++)
  993. {
  994. ProcessJobInfo pj = new ProcessJobInfo();
  995. pj.Name = jobId + "_" + (i + 1);
  996. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  997. if (pj.Sequence == null)
  998. {
  999. reason = $"invalid sequence[{indexSequence[seqs[i]]}]";
  1000. return false;
  1001. }
  1002. pj.ControlJobName = cj.Name;
  1003. pj.LotName = lotId;
  1004. pj.SlotWafers = seqSlotWafers[seqs[i]];
  1005. pj.SetState(EnumProcessJobState.Queued);
  1006. if (!CheckSequencePmReady(pj.Sequence, out reason))
  1007. {
  1008. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"no valid chamber for the {reason}");
  1009. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1010. return false;
  1011. }
  1012. if (!RouteManager.IsATMMode && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  1013. {
  1014. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"recipe file not valid in the sequence, {reason}");
  1015. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1016. return false;
  1017. }
  1018. pjs.Add(pj);
  1019. }
  1020. _dbCallback.LotUpdate(cj);
  1021. foreach (var pj in pjs)
  1022. {
  1023. cj.ProcessJobNameList.Add(pj.Name);
  1024. _lstProcessJobs.Add(pj);
  1025. }
  1026. _lstControlJobs.Add(cj);
  1027. //AssociatedPMWithLP(cj);
  1028. _loadportControlJobDic[cj.Module] = cj;
  1029. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  1030. return true;
  1031. }
  1032. public bool CheckAllJobDone()
  1033. {
  1034. foreach (var cj in _lstControlJobs)
  1035. {
  1036. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1037. return false;
  1038. }
  1039. InUseRecipes.Clear();
  1040. LP1InUseRecipes.Clear();
  1041. LP2InUseRecipes.Clear();
  1042. LP3InUseRecipes.Clear();
  1043. return true;
  1044. }
  1045. public bool CheckJobJustDone(out string sJobName)
  1046. {
  1047. foreach (var cj in _lstControlJobs)
  1048. {
  1049. if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
  1050. {
  1051. if (cj.Module == "LP1")
  1052. {
  1053. LP1InUseRecipes.Clear();
  1054. }
  1055. else if (cj.Module == "LP2")
  1056. {
  1057. LP2InUseRecipes.Clear();
  1058. }
  1059. else if (cj.Module == "LP3")
  1060. {
  1061. LP3InUseRecipes.Clear();
  1062. }
  1063. //_lstControlJobs.Remove(doneJob);
  1064. _loadportControlJobDic[cj.Module] = null;
  1065. //LP;WaferSize;Lot;Number;Start;End;
  1066. sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
  1067. cj.BeenPosted = true;
  1068. return true;
  1069. }
  1070. }
  1071. //var doneJob = _lstControlJobs.Where(cj => cj.State == EnumControlJobState.Completed && !cj.BeenPosted).FirstOrDefault();
  1072. //if (doneJob != null)
  1073. //{
  1074. // return true;
  1075. //}
  1076. sJobName = "NULL";
  1077. return false;
  1078. }
  1079. public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  1080. {
  1081. foreach (var pj in _lstProcessJobs)
  1082. {
  1083. if (pj.ControlJobName == cj.Name)
  1084. return pj;
  1085. }
  1086. return null;
  1087. }
  1088. public bool AbortJob(string jobName, out string reason)
  1089. {
  1090. reason = "";
  1091. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1092. if (cj == null)
  1093. {
  1094. reason = $"abort job rejected, not found job with id {jobName}";
  1095. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  1096. return false;
  1097. }
  1098. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  1099. foreach (var pj in _lstProcessJobs)
  1100. {
  1101. if (pj.ControlJobName == cj.Name)
  1102. {
  1103. pj.SetState(EnumProcessJobState.Aborting);
  1104. pjAbortList.Add(pj);
  1105. int unprocessed = 0;
  1106. int aborted = 0;
  1107. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  1108. foreach (var waferInfo in wafers)
  1109. {
  1110. waferInfo.ProcessJob = null;
  1111. waferInfo.NextSequenceStep = 0;
  1112. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  1113. unprocessed++;
  1114. }
  1115. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  1116. }
  1117. }
  1118. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  1119. _dbCallback.LotFinished(cj);
  1120. // remove control job
  1121. var deletedPollingJobs = new Queue<ControlJobInfo>();
  1122. foreach (var item in _qePollingJobs)
  1123. {
  1124. if (cj.InnerId != item.InnerId)
  1125. deletedPollingJobs.Enqueue(item);
  1126. }
  1127. _qePollingJobs = deletedPollingJobs;
  1128. foreach (var pj in pjAbortList)
  1129. {
  1130. _lstProcessJobs.Remove(pj);
  1131. }
  1132. _lstControlJobs.Remove(cj);
  1133. if (_loadportControlJobDic.ContainsKey(cj.Module))
  1134. {
  1135. _loadportControlJobDic[cj.Module] = null;
  1136. }
  1137. return true;
  1138. }
  1139. public bool StopJob(string jobName, out string reason)
  1140. {
  1141. reason = "";
  1142. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1143. if (cj == null)
  1144. {
  1145. reason = $"stop job rejected, not found job with id {jobName}";
  1146. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  1147. return false;
  1148. }
  1149. foreach (var pj in _lstProcessJobs)
  1150. {
  1151. if (pj.ControlJobName == cj.Name)
  1152. {
  1153. pj.SetState(EnumProcessJobState.Stopping);
  1154. }
  1155. }
  1156. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  1157. _dbCallback.LotFinished(cj);
  1158. if (_loadportControlJobDic.ContainsKey(cj.Module))
  1159. {
  1160. _loadportControlJobDic[cj.Module] = null;
  1161. }
  1162. var deletedPollingJobs = new Queue<ControlJobInfo>();
  1163. foreach (var item in _qePollingJobs)
  1164. {
  1165. if (cj.InnerId != item.InnerId)
  1166. deletedPollingJobs.Enqueue(item);
  1167. }
  1168. _qePollingJobs = deletedPollingJobs;
  1169. return true;
  1170. }
  1171. public bool ResumeJob(string jobName, out string reason)
  1172. {
  1173. reason = "";
  1174. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1175. if (cj == null)
  1176. {
  1177. reason = $"resume job rejected, not found job with id {jobName}";
  1178. //LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"resume job rejected, not found job with id {jobName}");
  1179. return false;
  1180. }
  1181. if (cj.State == EnumControlJobState.Paused)
  1182. {
  1183. cj.SetState(EnumControlJobState.Executing);
  1184. }
  1185. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  1186. _cycleState = RState.Running;
  1187. return true;
  1188. }
  1189. public bool PauseJob(string jobName, out string reason)
  1190. {
  1191. reason = "";
  1192. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1193. if (cj == null)
  1194. {
  1195. reason = $"pause job rejected, not found job with id {jobName}";
  1196. //LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"pause job rejected, not found job with id {jobName}");
  1197. return false;
  1198. }
  1199. if (cj.State == EnumControlJobState.Executing)
  1200. {
  1201. cj.SetState(EnumControlJobState.Paused);
  1202. }
  1203. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  1204. var deletedPollingJobs = new Queue<ControlJobInfo>();
  1205. foreach (var item in _qePollingJobs)
  1206. {
  1207. if (cj.InnerId != item.InnerId)
  1208. deletedPollingJobs.Enqueue(item);
  1209. }
  1210. _qePollingJobs = deletedPollingJobs;
  1211. if (!_lstControlJobs.Exists(job => job.State == EnumControlJobState.Executing))
  1212. _cycleState = RState.Paused;
  1213. return true;
  1214. }
  1215. public bool StartJob(string jobName, out string reason)
  1216. {
  1217. reason = "";
  1218. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1219. if (cj == null)
  1220. {
  1221. reason = $"start job rejected, not found job with id {jobName}";
  1222. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  1223. return false;
  1224. }
  1225. if (RtInstance.ConfigType == ConfigType.Kepler2200)
  1226. {
  1227. var item = _lstProcessJobs.Where(x => x.LotName == cj.LotName).FirstOrDefault();
  1228. if (item != null && item.ControlJobName == cj.Name && !CheckSequenceKepler2200TemperatureReady(item.Sequence))
  1229. {
  1230. return false;
  1231. }
  1232. if (cj.Module == "LP1")
  1233. {
  1234. GetAllJobRecipe(LP1InUseRecipes, cj, item.Sequence);
  1235. }
  1236. else if (cj.Module == "LP2")
  1237. {
  1238. GetAllJobRecipe(LP2InUseRecipes, cj, item.Sequence);
  1239. }
  1240. else if (cj.Module == "LP3")
  1241. {
  1242. GetAllJobRecipe(LP3InUseRecipes, cj, item.Sequence);
  1243. }
  1244. }
  1245. if (cj.State == EnumControlJobState.WaitingForStart)
  1246. {
  1247. cj.SetState(EnumControlJobState.Executing);
  1248. //PreJobClean(cj);
  1249. cj.JetState = EnumJetCtrlJobState.Quequed;
  1250. cj.StartTime = DateTime.Now;
  1251. _dbCallback.LotCreated(cj);
  1252. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  1253. //if (!_blockingWatcher.IsRunning)
  1254. // _blockingWatcher.Restart();
  1255. //ResetTraceFlag();
  1256. }
  1257. if (!_cycleWatch.IsRunning)
  1258. {
  1259. _cycleWatch.Restart();
  1260. }
  1261. var lp = ModuleHelper.Converter(cj.Module);
  1262. _lpCycleCount[lp] = 0;
  1263. _lpCycleWafer[lp] = 0;
  1264. _lpThroughput[lp] = 0;
  1265. _cycleState = RState.Running;
  1266. return true;
  1267. }
  1268. public void Clear()
  1269. {
  1270. foreach (var module in _dictModuleTask)
  1271. {
  1272. module.Value.Status = ModuleStatus.Idle;
  1273. module.Value.Scheduler.ResetTask();
  1274. }
  1275. List<string> keys = _loadportControlJobDic.Keys.ToList();
  1276. foreach (var key in keys)
  1277. {
  1278. _loadportControlJobDic[key] = null;
  1279. }
  1280. _lstWaferTasks.Clear();
  1281. _qeWaitInWafers.Clear();
  1282. _tmSchdActions.Clear();
  1283. _curTmAction.Clear();
  1284. _efemSchdActions.Clear();
  1285. _curEfemAction.Clear();
  1286. _lstControlJobs.Clear();
  1287. _lstProcessJobs.Clear();
  1288. InUseRecipes.Clear();
  1289. LP1InUseRecipes.Clear();
  1290. LP2InUseRecipes.Clear();
  1291. LP3InUseRecipes.Clear();
  1292. _qePollingJobs.Clear();
  1293. _cycleState = RState.End;
  1294. }
  1295. // manual return one wafer while system is auto running
  1296. public bool ManualReturnWafer(object[] objs)
  1297. {
  1298. ModuleName SourceModule = (ModuleName)objs[0];
  1299. int SourceSlot = (int)objs[1];
  1300. if (!_dictModuleTask.Keys.Contains(SourceModule))
  1301. {
  1302. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Invalid source module {SourceModule} for manual return wafer");
  1303. return false;
  1304. }
  1305. if (WaferManager.Instance.CheckNoWafer(SourceModule, SourceSlot))
  1306. {
  1307. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Can not return wafer as {SourceModule} {SourceSlot} has no wafer");
  1308. return false;
  1309. }
  1310. if (!_dictModuleTask[SourceModule].Scheduler.IsIdle)
  1311. {
  1312. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"The module: {SourceModule} is not ready for return wafer");
  1313. return false;
  1314. }
  1315. var wafer = WaferManager.Instance.GetWafer(SourceModule, SourceSlot);
  1316. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Manual return wafer: {wafer.WaferOrigin} at {SourceModule} {SourceSlot} while system is auto running");
  1317. _qeReturnWafers.Enqueue(wafer);
  1318. return true;
  1319. }
  1320. public RState CheckManualReturnWafer()
  1321. {
  1322. var pmWaferCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && WaferManager.Instance.CheckHasWafer(mod.Key, 0)).Count();
  1323. var tmRobotWaferCount = (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) ? 1 : 0);
  1324. if (!_dictModuleTask[ModuleName.TMRobot].Scheduler.IsIdle && (pmWaferCount > 0 || tmRobotWaferCount > 0))
  1325. {
  1326. LOG.Write(eEvent.ERR_ROUTER, ModuleName.TMRobot, $"The TM Robot is not ready for return wafer.");
  1327. return RState.Failed;
  1328. }
  1329. if (!_dictModuleTask[ModuleName.EfemRobot].Scheduler.IsIdle)
  1330. {
  1331. LOG.Write(eEvent.ERR_ROUTER, ModuleName.EfemRobot, $"The EFEM Robot is not ready for return wafer.");
  1332. return RState.Failed;
  1333. }
  1334. foreach (var mod in _dictModuleTask)
  1335. {
  1336. if (ModuleHelper.IsLoadPort(mod.Key))
  1337. continue;
  1338. if (!mod.Value.Scheduler.IsInclude)
  1339. continue;
  1340. if (!mod.Value.Scheduler.IsIdle)
  1341. {
  1342. LOG.Write(eEvent.ERR_ROUTER, mod.Key, $"{mod.Key} is not ready for return wafer.");
  1343. return RState.Failed;
  1344. }
  1345. int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
  1346. for (int slot = 0; slot < nSlotNumber; slot++)
  1347. {
  1348. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  1349. if (wafer.IsEmpty)
  1350. continue;
  1351. var destLP = (ModuleName)wafer.OriginStation;
  1352. if (!_dictModuleTask[destLP].Scheduler.IsAvailable)
  1353. {
  1354. LOG.Write(eEvent.ERR_ROUTER, destLP, $"The destination Loadport {destLP} is not ready for return wafer.");
  1355. return RState.Failed;
  1356. }
  1357. if(!ModuleHelper.IsLoadPort(destLP))
  1358. {
  1359. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"The wafer {wafer.WaferOrigin} cannot be return, please manually drag it.");
  1360. return RState.Failed;
  1361. }
  1362. }
  1363. }
  1364. Clear();
  1365. return RState.Running;
  1366. }
  1367. public RState ReturnAllWafers()
  1368. {
  1369. int systemWaferCount = 0;
  1370. foreach (var mod in _dictModuleTask)
  1371. {
  1372. if (ModuleHelper.IsLoadPort(mod.Key) || !mod.Value.Scheduler.IsInclude)
  1373. continue;
  1374. int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
  1375. for (int slot = 0; slot < nSlotNumber; slot++)
  1376. {
  1377. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  1378. if (!wafer.IsEmpty)
  1379. systemWaferCount++;
  1380. }
  1381. }
  1382. if (systemWaferCount == 0)
  1383. return RState.End;
  1384. ReturnVacWafers();
  1385. ReturnAtmWafers();
  1386. return RState.Running;
  1387. }
  1388. #endregion
  1389. #region internal implementation
  1390. private void InitModules()
  1391. {
  1392. foreach (var module in ModuleHelper.InstalledModules)
  1393. {
  1394. if (ModuleHelper.IsInstalled(module))
  1395. {
  1396. if(ModuleHelper.IsPm(module))
  1397. {
  1398. _dictModuleTask[module] = new PMTask(module);
  1399. }
  1400. else if (ModuleHelper.IsLoadLock(module))
  1401. {
  1402. _dictModuleTask[module] = new LoadlockTask(module);
  1403. }
  1404. else if(ModuleHelper.IsLoadPort(module))
  1405. {
  1406. _dictModuleTask[module] = new LoadPortTask(module);
  1407. }
  1408. else if(ModuleHelper.IsTMRobot(module))
  1409. {
  1410. _dictModuleTask[module] = new TMRobotTask(module);
  1411. }
  1412. else if(ModuleHelper.IsEFEMRobot(module))
  1413. {
  1414. _dictModuleTask[module] = new EFEMRobotTask(module);
  1415. }
  1416. else if(ModuleHelper.IsAligner(module))
  1417. {
  1418. _dictModuleTask[module] = new AlignerTask(module);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. private void prelude()
  1424. {
  1425. bool available = true;
  1426. foreach(var mod in _dictModuleTask)
  1427. {
  1428. available = mod.Value.Scheduler.IsAvailable; // force scheduler update
  1429. }
  1430. }
  1431. private void epilogue()
  1432. {
  1433. UpdateProcessJobStatus();
  1434. UpdateControlJobStatus();
  1435. UpdateLLInOutPathProperty();
  1436. PrepareLLPressure();
  1437. CreateNewWaferTask();
  1438. _lstWaferTasks.RemoveAll(item => ModuleHelper.IsLoadPort(item.destMod) && ModuleHelper.IsLoadPort(item.currentMod) && item.pressureStatus == RState.End);
  1439. ReDispatchBlockingWafers();
  1440. }
  1441. private void RunWaferTask()
  1442. {
  1443. foreach (var task in _lstWaferTasks)
  1444. {
  1445. task.Run();
  1446. }
  1447. }
  1448. private void RunModuleTasks()
  1449. {
  1450. foreach (var task in _dictModuleTask)
  1451. {
  1452. task.Value.Run();
  1453. }
  1454. }
  1455. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1456. {
  1457. bool allWaferReturn = true;
  1458. foreach (var slot in pj.SlotWafers)
  1459. {
  1460. var wafer = WaferManager.Instance.GetWafer(slot.Item1, slot.Item2);
  1461. if(wafer.IsEmpty || (wafer.ProcessState != EnumWaferProcessStatus.Completed && checkAllProcessed))
  1462. {
  1463. allWaferReturn = false;
  1464. break;
  1465. }
  1466. }
  1467. return allWaferReturn;
  1468. }
  1469. private void UpdateProcessJobStatus()
  1470. {
  1471. if (_efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1472. return;
  1473. foreach (var pj in _lstProcessJobs)
  1474. {
  1475. if (CheckAllWaferReturned(pj, pj.State != EnumProcessJobState.Stopping))
  1476. {
  1477. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1478. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1479. }
  1480. }
  1481. }
  1482. private bool IsControlJobIntersect(ControlJobInfo cj1, ControlJobInfo cj2)
  1483. {
  1484. var cj1Pms = GetWaitPreCleanPMsByCtrlJob(cj1);
  1485. var cj2Pms = GetWaitPreCleanPMsByCtrlJob(cj2);
  1486. return cj1Pms.Intersect(cj2Pms).Count() > 0;
  1487. }
  1488. private void UpdateControlJobStatus()
  1489. {
  1490. if (_lstControlJobs.Count == 0 || _efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1491. return;
  1492. var runningJobs = _lstControlJobs.FindAll(cj => IsCtrlJobRuning(cj));
  1493. var queueJobs = _lstControlJobs.FindAll(cj => cj.JetState == EnumJetCtrlJobState.Quequed).OrderBy(cj => cj.StartTime);
  1494. if (runningJobs.Count == 0)
  1495. {
  1496. if(queueJobs.Count() > 0)
  1497. {
  1498. // start the first waiting job
  1499. RunControlJob(queueJobs.First());
  1500. }
  1501. }
  1502. else
  1503. {
  1504. foreach(var runningjob in runningJobs)
  1505. {
  1506. // update the running job
  1507. RunControlJob(runningjob);
  1508. }
  1509. foreach(var queueJob in queueJobs)
  1510. {
  1511. if(!runningJobs.Exists(cj => IsControlJobIntersect(cj, queueJob)))
  1512. {
  1513. // parallelly start the not intersect job
  1514. RunControlJob(queueJob);
  1515. }
  1516. else
  1517. {
  1518. foreach(var cj in runningJobs)
  1519. {
  1520. if(!_qePollingJobs.Contains(cj))
  1521. _qePollingJobs.Enqueue(cj);
  1522. }
  1523. RunControlJob(queueJob);
  1524. if (!_qePollingJobs.Contains(queueJob))
  1525. _qePollingJobs.Enqueue(queueJob);
  1526. }
  1527. }
  1528. }
  1529. // update system cycle status
  1530. if (_lstControlJobs.All(cj => cj.State == EnumControlJobState.Completed))
  1531. _cycleState = RState.End;
  1532. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1533. foreach (var cj in _lstControlJobs)
  1534. {
  1535. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1536. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  1537. {
  1538. cjRemoveList.Add(cj);
  1539. }
  1540. }
  1541. foreach (var cj in cjRemoveList)
  1542. {
  1543. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1544. foreach (var pj in _lstProcessJobs)
  1545. {
  1546. if (pj.ControlJobName == cj.Name)
  1547. pjRemoveList.Add(pj);
  1548. }
  1549. foreach (var pj in pjRemoveList)
  1550. {
  1551. _lstProcessJobs.Remove(pj);
  1552. }
  1553. _lstControlJobs.Remove(cj);
  1554. }
  1555. }
  1556. private bool ActiveProcessJob(ProcessJobInfo pj)
  1557. {
  1558. foreach (var pjSlotWafer in pj.SlotWafers)
  1559. {
  1560. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1561. wafer.ProcessJob = pj;
  1562. wafer.NextSequenceStep = 0;
  1563. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1564. }
  1565. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1566. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1567. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1568. pj.SetState(EnumProcessJobState.Processing);
  1569. return true;
  1570. }
  1571. private bool ActiveControlJob(ControlJobInfo cj)
  1572. {
  1573. cj.JetState = EnumJetCtrlJobState.Processing;
  1574. foreach (var pjName in cj.ProcessJobNameList)
  1575. {
  1576. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1577. if (pj == null)
  1578. {
  1579. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1580. continue;
  1581. }
  1582. if (pj.State == EnumProcessJobState.Queued)
  1583. {
  1584. ActiveProcessJob(pj);
  1585. }
  1586. }
  1587. return true;
  1588. }
  1589. private bool RunControlJob(ControlJobInfo cj)
  1590. {
  1591. // polling the sequencial jobs
  1592. if (_qePollingJobs.Contains(cj))
  1593. {
  1594. if (_qePollingJobs.First() == cj)
  1595. {
  1596. if ( !cj.LotWafers.Exists(wafer => !wafer.IsEmpty && wafer.NextSequenceStep == 0) &&
  1597. ( (!IsCtrlJobNeedPostClean(cj) && !_lstWaferTasks.Exists(wt => !string.IsNullOrEmpty(wt.wtwCleanRecipe) && (_qePollingJobs.Count <= 1 || !IsCtrlJobNeedPreClean(_qePollingJobs.ElementAt(1)))) ) ||
  1598. (IsAllProcessJobComplete(cj) && IsPostJobCleanDone(cj))))
  1599. {
  1600. _qePollingJobs.Dequeue();
  1601. _qePollingJobs.Enqueue(cj);
  1602. }
  1603. }
  1604. }
  1605. switch (cj.JetState)
  1606. {
  1607. case EnumJetCtrlJobState.Quequed:
  1608. {
  1609. if(IsCtrlJobNeedPreClean(cj))
  1610. {
  1611. cj.JetState = EnumJetCtrlJobState.PreJobClean;
  1612. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1613. foreach (var pm in PMs)
  1614. {
  1615. var pmTask = _dictModuleTask[pm] as PMTask;
  1616. if (pmTask != null && pmTask.Scheduler.IsOnline)
  1617. {
  1618. pmTask.InvokePreJobClean(cj.PreJobClean);
  1619. }
  1620. }
  1621. }
  1622. else
  1623. {
  1624. ActiveControlJob(cj);
  1625. }
  1626. }
  1627. break;
  1628. case EnumJetCtrlJobState.PreJobClean:
  1629. {
  1630. if (IsPreJobCleanDone(cj))
  1631. {
  1632. ActiveControlJob(cj);
  1633. }
  1634. }
  1635. break;
  1636. case EnumJetCtrlJobState.Processing:
  1637. {
  1638. if (IsCtrlJobNeedPostClean(cj))
  1639. {
  1640. if (IsAllJobWaferProcessedOrProcessing(cj))
  1641. {
  1642. cj.JetState = EnumJetCtrlJobState.PostJobClean;
  1643. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1644. foreach (var pm in PMs)
  1645. {
  1646. var pmTask = _dictModuleTask[pm] as PMTask;
  1647. if (pmTask != null && pmTask.Scheduler.IsOnline)
  1648. {
  1649. pmTask.InvokePostJobClean(cj.PostJobClean);
  1650. }
  1651. }
  1652. }
  1653. }
  1654. else
  1655. {
  1656. if (IsAllProcessJobComplete(cj))
  1657. {
  1658. cj.JetState = EnumJetCtrlJobState.Completed;
  1659. }
  1660. }
  1661. }
  1662. break;
  1663. case EnumJetCtrlJobState.PostJobClean:
  1664. {
  1665. if (IsPostJobCleanDone(cj))
  1666. {
  1667. cj.JetState = EnumJetCtrlJobState.Completed;
  1668. }
  1669. }
  1670. break;
  1671. }
  1672. // caculate processed wafer by control job
  1673. var lp = ModuleHelper.Converter(cj.Module);
  1674. int countProcessed = 0;
  1675. foreach (var pjName in cj.ProcessJobNameList)
  1676. {
  1677. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1678. if (pj == null)
  1679. {
  1680. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1681. continue;
  1682. }
  1683. // caculate process wafer by process
  1684. if (_lpCycleCount[lp] < cj.CycleNumber)
  1685. {
  1686. foreach (var pjSlotWafer in pj.SlotWafers)
  1687. {
  1688. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1689. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  1690. countProcessed++;
  1691. }
  1692. }
  1693. }
  1694. int lpCycleWafer = 0;
  1695. if (cj.JetState == EnumJetCtrlJobState.Completed)
  1696. {
  1697. cj.EndTime = DateTime.Now;
  1698. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1699. _dbCallback.LotFinished(cj);
  1700. if (_lpCycleCount[lp] >= cj.CycleNumber)
  1701. (Singleton<TransferModule>.Instance.GetScheduler(lp) as SchedulerLoadPort).NoteJobComplete();
  1702. _lpCycleCount[lp]++;
  1703. lpCycleWafer = _lpCycleCount[lp] * cj.LotWafers.Count;
  1704. _lpThroughput[lp] = (float)(lpCycleWafer / (DateTime.Now - cj.StartTime).TotalHours);
  1705. LOG.Write(eEvent.EV_ROUTER, lp, $"Cycle Count: {_lpCycleCount[lp]}, Total Processed Wafer: {lpCycleWafer}, Throughput: {_lpThroughput[lp]}");
  1706. if (_lpCycleCount[lp] < cj.CycleNumber)
  1707. {
  1708. cj.SetState(EnumControlJobState.Executing);
  1709. cj.JetState = EnumJetCtrlJobState.Quequed;
  1710. cj.LotInnerId = Guid.NewGuid();
  1711. _dbCallback.LotCreated(cj);
  1712. foreach (var pj in _lstProcessJobs)
  1713. {
  1714. if(pj.ControlJobName == cj.Name)
  1715. {
  1716. pj.SetState(EnumProcessJobState.Queued);
  1717. pj.InnerId = Guid.NewGuid();
  1718. foreach (var pjSlotWafer in pj.SlotWafers)
  1719. {
  1720. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1721. wafer.ProcessJob = null;
  1722. wafer.NextSequenceStep = 0;
  1723. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1724. }
  1725. }
  1726. }
  1727. _lstWaferTasks.RemoveAll(wt => wt.currentMod == lp);
  1728. }
  1729. else
  1730. {
  1731. cj.SetState(EnumControlJobState.Completed);
  1732. if (_qePollingJobs.Contains(cj))
  1733. {
  1734. Queue<ControlJobInfo> removedPolingJobs = new Queue<ControlJobInfo>();
  1735. foreach (var pj in _qePollingJobs)
  1736. {
  1737. if (pj != cj)
  1738. removedPolingJobs.Enqueue(pj);
  1739. }
  1740. if(removedPolingJobs.Count > 1)
  1741. _qePollingJobs = removedPolingJobs;
  1742. else
  1743. _qePollingJobs.Clear();
  1744. }
  1745. }
  1746. }
  1747. else
  1748. {
  1749. lpCycleWafer = _lpCycleCount[lp] * cj.LotWafers.Count + countProcessed;
  1750. }
  1751. if (lpCycleWafer != _lpCycleWafer[lp])
  1752. {
  1753. _lpCycleWafer[lp] = lpCycleWafer;
  1754. RefreshThroughput();
  1755. }
  1756. return cj.State == EnumControlJobState.Completed;
  1757. }
  1758. void RefreshThroughput()
  1759. {
  1760. foreach(var cj in _lstControlJobs)
  1761. {
  1762. if(cj.State == EnumControlJobState.Executing)
  1763. {
  1764. var lp = ModuleHelper.Converter(cj.Module);
  1765. if (_lpCycleCount[lp] > 0)
  1766. {
  1767. _lpThroughput[lp] = (float)((_lpCycleWafer[lp] - 2) / _lpCycleWatch[lp].Elapsed.TotalHours);
  1768. }
  1769. }
  1770. }
  1771. }
  1772. private bool IsAllJobWaferProcessedOrProcessing(ControlJobInfo cj)
  1773. {
  1774. List<ModuleName> allModules = _dictModuleTask.Keys.ToList();
  1775. int original = (int)ModuleHelper.Converter(cj.Module);
  1776. foreach (var mod in allModules)
  1777. {
  1778. if (ModuleHelper.IsLoadPort(mod) && (int)mod != original)
  1779. continue;
  1780. var wafers = WaferManager.Instance.GetWafers(mod);
  1781. foreach (var wafer in wafers)
  1782. {
  1783. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.ControlJobName != cj.Name)
  1784. continue;
  1785. if (wafer.ProcessState != EnumWaferProcessStatus.Completed && wafer.ProcessState != EnumWaferProcessStatus.InProcess)
  1786. return false; ;
  1787. }
  1788. }
  1789. return true;
  1790. }
  1791. private bool IsAllProcessJobComplete(ControlJobInfo cj)
  1792. {
  1793. foreach (var pj in _lstProcessJobs)
  1794. {
  1795. if (pj.ControlJobName == cj.Name && pj.State != EnumProcessJobState.ProcessingComplete)
  1796. {
  1797. return false;
  1798. }
  1799. }
  1800. return true;
  1801. }
  1802. private bool IsCtrlJobExecuting(ModuleName lp)
  1803. {
  1804. var cJob = _lstControlJobs.Find(cj => ModuleHelper.Converter(cj.Module) == lp);
  1805. if (cJob != null && cJob.State == EnumControlJobState.Executing)
  1806. return true;
  1807. return false;
  1808. }
  1809. private bool IsCtrlJobRuning(ControlJobInfo cj)
  1810. {
  1811. return cj.JetState == EnumJetCtrlJobState.PreJobClean ||
  1812. cj.JetState == EnumJetCtrlJobState.Processing ||
  1813. cj.JetState == EnumJetCtrlJobState.PostJobClean;
  1814. }
  1815. private bool IsCtrlJobEndingState(ControlJobInfo cj)
  1816. {
  1817. return cj.JetState == EnumJetCtrlJobState.PostJobClean ||
  1818. (cj.JetState == EnumJetCtrlJobState.Processing
  1819. && IsAllJobWaferProcessedOrProcessing(cj)
  1820. && !IsCtrlJobNeedPostClean(cj));
  1821. }
  1822. private bool IsCtrlJobNeedPreClean(ControlJobInfo cj)
  1823. {
  1824. return !string.IsNullOrWhiteSpace(cj.PreJobClean);
  1825. }
  1826. private bool IsCtrlJobNeedPostClean(ControlJobInfo cj)
  1827. {
  1828. return !string.IsNullOrWhiteSpace(cj.PostJobClean.Trim());
  1829. }
  1830. private List<ModuleName> GetWaitPreCleanPMsByCtrlJob(ControlJobInfo cj)
  1831. {
  1832. var pmlist = new List<ModuleName>();
  1833. foreach (var pj in _lstProcessJobs)
  1834. {
  1835. if (pj.ControlJobName == cj.Name)
  1836. {
  1837. foreach (var pm in pj.Sequence.PMs)
  1838. {
  1839. if (!pmlist.Contains(pm))
  1840. pmlist.Add(pm);
  1841. }
  1842. }
  1843. }
  1844. return pmlist;
  1845. }
  1846. private bool IsPreJobCleanDone(ControlJobInfo cj)
  1847. {
  1848. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1849. foreach(var pm in pms)
  1850. {
  1851. var pmTask = _dictModuleTask[pm] as PMTask;
  1852. if (pmTask.Scheduler.IsOnline && !pmTask.IsPreJobCleanDone())
  1853. return false;
  1854. }
  1855. return true;
  1856. }
  1857. private bool IsPostJobCleanDone(ControlJobInfo cj)
  1858. {
  1859. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1860. foreach (var pm in pms)
  1861. {
  1862. var pmTask = _dictModuleTask[pm] as PMTask;
  1863. if (pmTask.Scheduler.IsOnline && !pmTask.IsPostJobCleanDone())
  1864. return false;
  1865. }
  1866. return true;
  1867. }
  1868. private void WaferArrived(WaferTask wafer, MoveItem item)
  1869. {
  1870. _dictModuleTask[item.DestinationModule].WaferArrived(wafer, item.DestinationSlot);
  1871. //--2024-03-21 增加了PortJobWaferEnd 上报事件 start--
  1872. if (ModuleHelper.IsLoadPort(item.DestinationModule))
  1873. {
  1874. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.DestinationModule);
  1875. if (currentControlJob != null)
  1876. {
  1877. _faCallback.JobWaferEnd(currentControlJob, item.SourceSlot);
  1878. }
  1879. }
  1880. if(ModuleHelper.IsLoadPort(item.DestinationModule))
  1881. {
  1882. if (!_lpCycleWatch[wafer.sourceMod].IsRunning)
  1883. _lpCycleWatch[wafer.sourceMod].Start();
  1884. }
  1885. //--2024-03-21 增加了PortJobWaferEnd 上报事件 end--
  1886. }
  1887. private void WaferLeaved(WaferTask wafer, MoveItem item)
  1888. {
  1889. _dictModuleTask[item.SourceModule].WaferLeaved(wafer, item.DestinationSlot);
  1890. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  1891. if (ModuleHelper.IsLoadPort(item.SourceModule))
  1892. {
  1893. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.SourceModule);
  1894. if (currentControlJob != null)
  1895. {
  1896. _faCallback.JobWaferStart(currentControlJob, item.SourceSlot);
  1897. }
  1898. }
  1899. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  1900. }
  1901. private ModuleName GetComingAvailablePM(ControlJobInfo cj)
  1902. {
  1903. var lstInProcessPMs = new List<ModuleName>();
  1904. foreach (var wafer in cj.LotWafers)
  1905. {
  1906. if(!wafer.IsEmpty && wafer.NextSequenceStep == 0 && wafer.ProcessJob != null)
  1907. {
  1908. foreach(var pm in wafer.ProcessJob.Sequence.PMs)
  1909. {
  1910. if (!lstInProcessPMs.Contains(pm) && _dictModuleTask[pm].Scheduler.IsOnline)
  1911. lstInProcessPMs.Add(pm);
  1912. }
  1913. }
  1914. }
  1915. // blocking check while only one loadlock in out
  1916. if (LLInOutPath == SequenceLLInOutPath.AInAOut ||
  1917. LLInOutPath == SequenceLLInOutPath.BInBOut ||
  1918. !_dictModuleTask[ModuleName.LLA].Scheduler.IsOnline ||
  1919. !_dictModuleTask[ModuleName.LLB].Scheduler.IsOnline)
  1920. {
  1921. if (_lstWaferTasks.Count >= lstInProcessPMs.Count + _LLASlotNumber / 2)
  1922. return ModuleName.System;
  1923. }
  1924. Dictionary<ModuleName, int> pmAssociatedWaferCount = new Dictionary<ModuleName, int>();
  1925. foreach (var mod in _dictModuleTask)
  1926. {
  1927. if (ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline && lstInProcessPMs.Contains(mod.Key))
  1928. {
  1929. pmAssociatedWaferCount[mod.Key] = 0;
  1930. }
  1931. }
  1932. var unprocessedWafer = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.destMod));
  1933. foreach (var wafer in unprocessedWafer)
  1934. {
  1935. if (ModuleHelper.IsPm(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && lstInProcessPMs.Contains(wafer.destMod))
  1936. {
  1937. pmAssociatedWaferCount[wafer.destMod]++;
  1938. }
  1939. }
  1940. var oderedPMCount = pmAssociatedWaferCount.OrderBy(p => p.Value).ToDictionary(p => p.Key, o => o.Value);
  1941. if (oderedPMCount.Count > 0 && oderedPMCount.First().Value < 2)
  1942. return oderedPMCount.First().Key;
  1943. return ModuleName.System;
  1944. }
  1945. private void CreateNewWaferTask()
  1946. {
  1947. var runningJobs = _lstControlJobs.FindAll(cj => cj.JetState == EnumJetCtrlJobState.PreJobClean || cj.JetState == EnumJetCtrlJobState.Processing);
  1948. var onDutyPms = new Dictionary<ModuleName, int>();
  1949. foreach (var job in runningJobs)
  1950. {
  1951. var pms = GetWaitPreCleanPMsByCtrlJob(job);
  1952. foreach(var pm in pms)
  1953. {
  1954. if (_dictModuleTask[pm].Scheduler.IsOnline && !onDutyPms.ContainsKey(pm))
  1955. {
  1956. onDutyPms[pm] = _lstWaferTasks.Where(wt => wt.destMod == pm || wt.currentMod == pm).Count();
  1957. }
  1958. }
  1959. }
  1960. if (runningJobs.Count == 0 || onDutyPms.Count == 0)
  1961. return;
  1962. var oderedPMs = onDutyPms.OrderBy(kv => kv.Value).OrderBy(kv => _dictModuleTask[kv.Key].TimeToReady);
  1963. if (oderedPMs.First().Value < 1)
  1964. {
  1965. foreach(var runningJob in runningJobs)
  1966. {
  1967. if (_qePollingJobs.Contains(runningJob) && _qePollingJobs.First() != runningJob)
  1968. continue;
  1969. foreach (var wafer in runningJob.LotWafers)
  1970. {
  1971. if (wafer.IsEmpty || wafer.ProcessJob == null)
  1972. continue;
  1973. if (wafer.ProcessJob.Sequence.PMs.Contains(oderedPMs.First().Key) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  1974. {
  1975. CreateWaferTasks(wafer, oderedPMs.First().Key);
  1976. return;
  1977. }
  1978. }
  1979. }
  1980. }
  1981. if (_tmRobotStatus == RState.Running)
  1982. return;
  1983. // keep two raw atm wafer, try match a double place to LL
  1984. var atmWaferCount = _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.destMod) && (ModuleHelper.IsLoadPort(wt.currentMod) || ModuleHelper.IsAligner(wt.currentMod) || ModuleHelper.IsEFEMRobot(wt.currentMod) || ModuleHelper.IsLoadLock(wt.currentMod)));
  1985. if (atmWaferCount < 2)
  1986. {
  1987. var busyPMs = oderedPMs.Where(pv => pv.Value == 1 && _dictModuleTask[pv.Key].HasWafer).OrderBy(pv => _dictModuleTask[pv.Key].TimeToReady);
  1988. if (busyPMs.Count() == 0)
  1989. return;
  1990. ModuleName nextPM = busyPMs.First().Key;
  1991. if (_lpCycleWafer.Sum(kv => kv.Value) == 0)
  1992. {
  1993. if (busyPMs.ToList().Exists(kv => _dictModuleTask[kv.Key].TimeToReady > 36000) && busyPMs.ToList().Exists(pv => _dictModuleTask[pv.Key].TimeToReady < 3600))
  1994. {
  1995. foreach (var pm in busyPMs)
  1996. {
  1997. if (_dictModuleTask[pm.Key].TimeToReady > 36000)
  1998. {
  1999. nextPM = pm.Key;
  2000. break;
  2001. }
  2002. }
  2003. }
  2004. }
  2005. foreach (var runningJob in runningJobs)
  2006. {
  2007. if (_qePollingJobs.Contains(runningJob) && _qePollingJobs.First() != runningJob)
  2008. continue;
  2009. foreach (var wafer in runningJob.LotWafers)
  2010. {
  2011. if (wafer.IsEmpty || wafer.ProcessJob == null)
  2012. continue;
  2013. if (wafer.ProcessJob.Sequence.PMs.Contains(nextPM) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  2014. {
  2015. CreateWaferTasks(wafer, nextPM);
  2016. return;
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. private void CreateWaferTasks(WaferInfo wafer, ModuleName pm)
  2023. {
  2024. var recipeName = wafer.ProcessJob.Sequence.GetRecipe(pm);
  2025. var recipeContent = RecipeFileManager.Instance.LoadRecipe(pm.ToString(), recipeName, false, RecipeType.Process.ToString());
  2026. Recipe recipe = Recipe.Load(recipeContent);
  2027. int temperature = 0;
  2028. if(int.TryParse(recipe.Header.Temperature, out int temp))
  2029. {
  2030. temperature = temp;
  2031. }
  2032. var waferTask = new WaferTask((ModuleName)wafer.OriginStation,
  2033. wafer.OriginSlot,
  2034. pm,
  2035. 0,
  2036. temperature,
  2037. wafer.InnerId,
  2038. recipeName,
  2039. wafer.ProcessJob.Sequence.WTWCleanRecipe,
  2040. wafer.ProcessJob.Sequence.LLInOutPath,
  2041. wafer.ProcessJob.Sequence.LLDelayTime,
  2042. IsSequenceNeedAlign(wafer.ProcessJob.Sequence));
  2043. waferTask.OnWaferArrived += WaferArrived;
  2044. waferTask.OnWaferLeaved += WaferLeaved;
  2045. _lstWaferTasks.Add(waferTask);
  2046. _qeWaitInWafers.Enqueue(wafer.InnerId);
  2047. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, waferTask.sourceMod, $"Routing wafer: {waferTask.sourceMod}.{waferTask.sourceSlot + 1} to {pm}");
  2048. }
  2049. private void ReDispatchBlockingWafers()
  2050. {
  2051. foreach (var wt in _lstWaferTasks)
  2052. {
  2053. if (ModuleHelper.IsPm(wt.destMod) && !ModuleHelper.IsPm(wt.currentMod) && !ModuleHelper.IsLoadPort(wt.currentMod))
  2054. {
  2055. if (!_dictModuleTask[wt.destMod].Scheduler.IsOnline && wt.elapseTime > 120)
  2056. {
  2057. var wafer = WaferManager.Instance.GetWafer(wt.currentMod, wt.currentSlot);
  2058. var otherPMs = _dictModuleTask.Where(mod => wafer.ProcessJob.Sequence.PMs.Contains(mod.Key) && mod.Value.Scheduler.IsOnline).OrderBy(mod => _lstWaferTasks.Where(task => task.destMod == mod.Key).Count()).ToList();
  2059. if(otherPMs.Count > 0)
  2060. {
  2061. LOG.Write(eEvent.WARN_ROUTER, wt.currentMod, $"Re-assign process chamber {otherPMs.First().Key} for {wafer.WaferOrigin} as {wt.destMod} unexpected offline");
  2062. wt.ReAssignPM(otherPMs.First().Key, 0);
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. private bool ForwardATMWafers(ModuleName ll)
  2069. {
  2070. if (_qeWaitInWafers.Count == 0)
  2071. return false;
  2072. var emptySlots = GetLLReadyInOutSlots(ll).emptySlot;
  2073. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End ||wafer.movingStatus == RState.Init) && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  2074. var notAlignedWafer = atmWafers.Where(wafer => !wafer.IsAligned).ToList();
  2075. var freeHands = GetEFEMFreeHand();
  2076. var waitInWafer = _lstWaferTasks.Find(wt => wt.waferId == _qeWaitInWafers.First());
  2077. if (atmWafers.Count >= 2 && freeHands.Count == 0 || waitInWafer == null)
  2078. return false;
  2079. // do not need pass by aligner
  2080. if (waitInWafer.IsAligned)
  2081. {
  2082. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafer.currentMod, waitInWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2083. _qeWaitInWafers.Dequeue();
  2084. }
  2085. else
  2086. {
  2087. if (atmWafers.Count == 0)
  2088. {
  2089. // push one wafer to aligner
  2090. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafer.currentMod, waitInWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2091. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ModuleName.Aligner1, 0, freeHands[0]) });
  2092. _qeWaitInWafers.Dequeue();
  2093. }
  2094. else if (_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)) && freeHands.Count == 2)
  2095. {
  2096. // forward another wafer to aligner
  2097. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafer.currentMod, waitInWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[1], freeHands[1]) });
  2098. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.Aligner1, 0, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2099. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[1], ModuleName.Aligner1, 0, freeHands[1]) });
  2100. _qeWaitInWafers.Dequeue();
  2101. }
  2102. }
  2103. return _efemSchdActions.Count > 0;
  2104. }
  2105. private bool ExchangeWaferWithLL(ModuleName ll)
  2106. {
  2107. if (IsLLReservedByTM(ll))
  2108. return false;
  2109. var waferStaus = GetLLReadyInOutSlots(ll);
  2110. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  2111. var freeHands = GetEFEMFreeHand();
  2112. var swapActions = new List<MoveItem>();
  2113. var validHands = new List<Hand>();
  2114. int placeCount = 0;
  2115. if ( waferStaus.emptySlot.Count > 0 &&
  2116. freeHands.Count >= 1 &&
  2117. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  2118. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || waferStaus.emptySlot.Count >= 2))
  2119. {
  2120. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  2121. if (CanWaferGotoLL(alignerWafer, ll))
  2122. {
  2123. alignerWafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  2124. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2125. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, waferStaus.emptySlot[placeCount], freeHands[0]));
  2126. validHands.Add(freeHands[0]);
  2127. placeCount++;
  2128. }
  2129. }
  2130. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  2131. foreach(var wafer in armWafers)
  2132. {
  2133. if (CanWaferGotoLL(wafer, ll) && placeCount < waferStaus.emptySlot.Count)
  2134. {
  2135. wafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  2136. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, waferStaus.emptySlot[placeCount], (Hand)wafer.currentSlot));
  2137. if(!validHands.Contains((Hand)wafer.currentSlot))
  2138. validHands.Add((Hand)wafer.currentSlot);
  2139. placeCount++;
  2140. }
  2141. }
  2142. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  2143. validHands.Add(Hand.Blade1);
  2144. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  2145. validHands.Add(Hand.Blade2);
  2146. int pickCount = 0;
  2147. var returnActions = new List<MoveItem>();
  2148. foreach(var slot in waferStaus.outSlot)
  2149. {
  2150. if(pickCount < validHands.Count)
  2151. {
  2152. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  2153. if(outWafer != null)
  2154. {
  2155. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  2156. swapActions.Add(new MoveItem(ll, waferStaus.outSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  2157. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  2158. pickCount++;
  2159. }
  2160. }
  2161. }
  2162. if(swapActions.Count > 0)
  2163. {
  2164. _efemSchdActions.Enqueue(swapActions);
  2165. }
  2166. foreach(var action in returnActions)
  2167. {
  2168. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  2169. }
  2170. return _efemSchdActions.Count > 0;
  2171. }
  2172. private bool ExchangeWaferWithFixedSlotLL(ModuleName ll)
  2173. {
  2174. if (IsLLReservedByTM(ll))
  2175. return false;
  2176. var llWaferStatus = GetLLFixedReadyInOutSlots(ll);
  2177. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  2178. var freeHands = GetEFEMFreeHand();
  2179. var swapActions = new List<MoveItem>();
  2180. var validHands = new List<Hand>();
  2181. int placeCount = 0;
  2182. if (llWaferStatus.eInSlot.Count > 0 &&
  2183. freeHands.Count >= 1 &&
  2184. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  2185. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || llWaferStatus.eInSlot.Count >= 2))
  2186. {
  2187. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  2188. if (CanWaferGotoLL(alignerWafer, ll))
  2189. {
  2190. alignerWafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  2191. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2192. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, llWaferStatus.eInSlot[placeCount], freeHands[0]));
  2193. validHands.Add(freeHands[0]);
  2194. placeCount++;
  2195. }
  2196. }
  2197. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  2198. foreach (var wafer in armWafers)
  2199. {
  2200. if (CanWaferGotoLL(wafer, ll) && placeCount < llWaferStatus.eInSlot.Count)
  2201. {
  2202. wafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  2203. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, llWaferStatus.eInSlot[placeCount], (Hand)wafer.currentSlot));
  2204. if (!validHands.Contains((Hand)wafer.currentSlot))
  2205. validHands.Add((Hand)wafer.currentSlot);
  2206. placeCount++;
  2207. }
  2208. }
  2209. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  2210. validHands.Add(Hand.Blade1);
  2211. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  2212. validHands.Add(Hand.Blade2);
  2213. int pickCount = 0;
  2214. var returnActions = new List<MoveItem>();
  2215. foreach (var slot in llWaferStatus.eOutSlot)
  2216. {
  2217. if (pickCount < validHands.Count)
  2218. {
  2219. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  2220. if (outWafer != null)
  2221. {
  2222. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  2223. swapActions.Add(new MoveItem(ll, llWaferStatus.eOutSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  2224. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  2225. pickCount++;
  2226. }
  2227. }
  2228. }
  2229. if (swapActions.Count > 0)
  2230. {
  2231. _efemSchdActions.Enqueue(swapActions);
  2232. }
  2233. foreach (var action in returnActions)
  2234. {
  2235. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  2236. }
  2237. return _efemSchdActions.Count > 0;
  2238. }
  2239. private void RoutingATMWafers()
  2240. {
  2241. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  2242. {
  2243. RunSchdEFEMActions();
  2244. return;
  2245. }
  2246. if (_efemRobotStatus != RState.End)
  2247. return;
  2248. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2249. {
  2250. if (_LLASlotNumber == 2)
  2251. {
  2252. Routing2SlotATMSystem();
  2253. }
  2254. else if (_LLASlotNumber == 4)
  2255. {
  2256. Routing4SlotATMSystem();
  2257. }
  2258. }
  2259. else
  2260. {
  2261. RoutingFixedSlotATMSystem();
  2262. }
  2263. }
  2264. private void Routing4SlotATMSystem()
  2265. {
  2266. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2267. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  2268. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  2269. {
  2270. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2271. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2272. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2273. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2274. if (efemRobotWafers.Count() >= 1)
  2275. {
  2276. if (inLLWaferStatus.emptySlot.Count >= 2 && !IsLLReservedByTM(inLL)) // wait for in loadlock ready
  2277. {
  2278. if (_dictModuleTask[inLL].TimeToReady < 2)
  2279. {
  2280. ExchangeWaferWithLL(inLL);
  2281. }
  2282. }
  2283. if ((inLLWaferStatus.emptySlot.Count == 0 || (outLLWaferStatus.outSlot.Count >= 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL)) // ready return wafer
  2284. {
  2285. ExchangeWaferWithLL(outLL);
  2286. }
  2287. }
  2288. else
  2289. {
  2290. if (((outLLWaferStatus.outSlot.Count >= 2 && _dictModuleTask[outLL].TimeToReady < 10) ||
  2291. (outLLWaferStatus.outSlot.Count == 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL))
  2292. {
  2293. ExchangeWaferWithLL(outLL);
  2294. }
  2295. else if (inLLWaferStatus.emptySlot.Count >= 2)
  2296. {
  2297. if (((_dictModuleTask[inLL].TimeToReady > 20 || _dictModuleTask[inLL].Scheduler.IsVac) && atmWaferCount < 2) || atmWaferCount == 0)
  2298. {
  2299. ForwardATMWafers(inLL);
  2300. }
  2301. else if (atmWaferCount >= 2 && !IsLLReservedByTM(inLL))
  2302. {
  2303. ExchangeWaferWithLL(inLL);
  2304. }
  2305. }
  2306. }
  2307. }
  2308. else
  2309. {
  2310. RoutingSameLLInOutATMSystem();
  2311. }
  2312. }
  2313. private void Routing2SlotATMSystem()
  2314. {
  2315. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2316. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  2317. var validHands = (_efemRobotSingleArmOption == 0 ? 2 : 1);
  2318. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  2319. {
  2320. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2321. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2322. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2323. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2324. var inLLModule = _dictModuleTask[inLL] as LoadlockTask;
  2325. var outLLModule = _dictModuleTask[outLL] as LoadlockTask;
  2326. var needAlign = _lstProcessJobs.Exists(pj => pj.State == EnumProcessJobState.Processing && IsSequenceNeedAlign(pj.Sequence));
  2327. // return wafer while out LL ready or cooling state
  2328. //if ((outLLWaferStatus.outSlot.Count > 0 && outLLWaferStatus.outSlot.Count <= (validHands - efemRobotWafers.Count)) && outLLModule.ReayForEfemInTime(10))
  2329. if (outLLWaferStatus.outSlot.Count > 0 && outLLModule.ReayForEfemInTime(10))
  2330. {
  2331. if (ExchangeWaferWithLL(outLL))
  2332. {
  2333. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady}");
  2334. return;
  2335. }
  2336. }
  2337. if (needAlign)
  2338. {
  2339. if (atmWaferCount == 0 ||
  2340. (inLLModule.ReayForEfemInTime(20) && Math.Min(validHands, inLLWaferStatus.emptySlot.Count) > atmWaferCount))
  2341. {
  2342. if (ForwardATMWafers(inLL))
  2343. {
  2344. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady}");
  2345. return;
  2346. }
  2347. }
  2348. }
  2349. else
  2350. {
  2351. if (inLLModule.ReayForEfemInTime(20) && inLLWaferStatus.emptySlot.Count > efemRobotWafers.Count && ((outLLModule.TimeToReady - inLLModule.TimeToReady > 10) || !outLLModule.ReayForEfemInTime(30) || outLLWaferStatus.emptySlot.Count < efemRobotWafers.Count))
  2352. {
  2353. if (ForwardATMWafers(inLL))
  2354. {
  2355. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady}");
  2356. return;
  2357. }
  2358. }
  2359. }
  2360. if (inLLModule.ReayForEfemInTime(5) &&
  2361. (Math.Min(validHands, inLLWaferStatus.emptySlot.Count) == atmWaferCount || _qeWaitInWafers.Count == 0))
  2362. {
  2363. if (ExchangeWaferWithLL(inLL))
  2364. {
  2365. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady}");
  2366. return;
  2367. }
  2368. }
  2369. }
  2370. else
  2371. {
  2372. RoutingSameLLInOutATMSystem();
  2373. }
  2374. }
  2375. private void RoutingFixedSlotATMSystem()
  2376. {
  2377. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2378. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  2379. if ( atmWaferCount == 0 || (_efemRobotSingleArmOption == 0 && atmWaferCount == 1 ))
  2380. {
  2381. foreach(var ll in lls)
  2382. {
  2383. if (ForwardATMWafers(ll.Key))
  2384. return;
  2385. }
  2386. }
  2387. // try to match a ll swap action
  2388. var readyReturnLL = lls.Where(ll => (GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count > 0) && ll.Value.TimeToReady <= 10)
  2389. .OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count)
  2390. .OrderBy(ll => ll.Value.TimeToReady);
  2391. foreach (var ll in readyReturnLL)
  2392. {
  2393. if (ExchangeWaferWithFixedSlotLL(ll.Key))
  2394. return;
  2395. }
  2396. }
  2397. private void RoutingSameLLInOutATMSystem()
  2398. {
  2399. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2400. var vacWaferCount = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod) || ModuleHelper.IsLoadLock(task.currentMod)).Count();
  2401. var preferWaferVacCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline).Count() +
  2402. (LLInOutPath == SequenceLLInOutPath.AInAOut ? _LLASlotNumber / 2 : (LLInOutPath == SequenceLLInOutPath.BInBOut ? _LLBSlotNumber / 2 : _LLASlotNumber));
  2403. var inOutIndicator = vacWaferCount - preferWaferVacCount;
  2404. if (inOutIndicator < 0)
  2405. {
  2406. // ready to push in
  2407. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2408. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2409. mod.Value.TimeToReady <= 10 &&
  2410. !IsLLReservedByTM(mod.Key) &&
  2411. GetLLReadyInOutSlots(mod.Key).emptySlot.Count >= 1).
  2412. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2413. if (atmWaferCount >= 1)
  2414. {
  2415. foreach(var ll in readyLLs)
  2416. {
  2417. if (ExchangeWaferWithLL(ll.Key))
  2418. return;
  2419. }
  2420. }
  2421. // forward wafer to system
  2422. if (atmWaferCount < 2)
  2423. {
  2424. var targetLL = readyLLs.Count > 0 ? readyLLs.First().Key : (LLInOutPath == SequenceLLInOutPath.BInBOut ? ModuleName.LLB : ModuleName.LLA);
  2425. ForwardATMWafers(targetLL);
  2426. }
  2427. if (_efemSchdActions.Count == 0)
  2428. {
  2429. var readyReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2430. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2431. mod.Value.TimeToReady <= 5 &&
  2432. !IsLLReservedByTM(mod.Key) &&
  2433. GetLLReadyInOutSlots(mod.Key).outSlot.Count >= 1).
  2434. OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).outSlot.Count).ToList();
  2435. foreach(var ll in readyReturnLL)
  2436. {
  2437. if (ExchangeWaferWithLL(readyReturnLL.First().Key))
  2438. return;
  2439. }
  2440. }
  2441. }
  2442. else
  2443. {
  2444. // ready double return LL
  2445. var readyDoubleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2446. mod.Value.TimeToReady < 10 &&
  2447. !IsLLReservedByTM(mod.Key) &&
  2448. GetLLReadyInOutSlots(mod.Key).outSlot.Count > 1).
  2449. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2450. foreach(var ll in readyDoubleReturnLL)
  2451. {
  2452. if (ExchangeWaferWithLL(ll.Key))
  2453. return;
  2454. }
  2455. // ready single return LL
  2456. var readySingleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2457. mod.Value.TimeToReady < 2 &&
  2458. !IsLLReservedByTM(mod.Key) &&
  2459. GetLLReadyInOutSlots(mod.Key).outSlot.Count == 1).
  2460. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2461. foreach (var ll in readySingleReturnLL)
  2462. {
  2463. if (ExchangeWaferWithLL(ll.Key))
  2464. return;
  2465. }
  2466. if (atmWaferCount == 0)
  2467. {
  2468. // ready to push in
  2469. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2470. ((mod.Key != ModuleName.LLA && LLInOutPath == SequenceLLInOutPath.BInBOut) || (mod.Key != ModuleName.LLB && LLInOutPath == SequenceLLInOutPath.AInAOut)) &&
  2471. mod.Value.TimeToReady <= 10 &&
  2472. !IsLLReservedByTM(mod.Key) &&
  2473. GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 1).
  2474. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2475. foreach(var ll in readyLLs)
  2476. {
  2477. if (ForwardATMWafers(ll.Key))
  2478. return;
  2479. }
  2480. }
  2481. }
  2482. }
  2483. private bool isReturnActionsDone(List<MoveItem> items)
  2484. {
  2485. foreach(var item in items)
  2486. {
  2487. if (WaferManager.Instance.CheckHasWafer(item.SourceModule, item.SourceSlot) || WaferManager.Instance.CheckNoWafer(item.DestinationModule, item.DestinationSlot))
  2488. return false;
  2489. }
  2490. return true;
  2491. }
  2492. private bool IsMovingActionsDone(List<MoveItem> actions)
  2493. {
  2494. bool CheckWaferExistence(ModuleName mod, int slot)
  2495. {
  2496. return ModuleHelper.IsLoadPort(mod) ? WaferManager.Instance.CheckHasWafer(mod, slot) : _lstWaferTasks.Exists(wt => wt.currentMod == mod && wt.currentSlot == slot);
  2497. }
  2498. if(actions.Count == 1)
  2499. {
  2500. if ( CheckWaferExistence(actions.First().SourceModule, actions.First().SourceSlot) ||
  2501. !CheckWaferExistence(actions.First().DestinationModule, actions.First().DestinationSlot) )
  2502. return false;
  2503. }
  2504. else
  2505. {
  2506. // initialize all the wafer existance before move
  2507. var slotWafers = new Dictionary<KeyValuePair<ModuleName, int>, bool>();
  2508. foreach (var ac in actions)
  2509. {
  2510. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2511. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2512. if (!slotWafers.ContainsKey(scrSlot))
  2513. {
  2514. slotWafers[scrSlot] = true;
  2515. }
  2516. if (!slotWafers.ContainsKey(destSlot))
  2517. {
  2518. slotWafers[destSlot] = false;
  2519. }
  2520. }
  2521. // simulate moved result
  2522. foreach (var ac in actions)
  2523. {
  2524. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2525. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2526. if (!slotWafers[scrSlot])
  2527. {
  2528. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[scrSlot]} do not has a wafer");
  2529. }
  2530. else
  2531. {
  2532. slotWafers[scrSlot] = false;
  2533. }
  2534. if (slotWafers[destSlot])
  2535. {
  2536. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[destSlot]} has a wafer");
  2537. }
  2538. else
  2539. {
  2540. slotWafers[destSlot] = true;
  2541. }
  2542. }
  2543. foreach (var slot in slotWafers)
  2544. {
  2545. if (slot.Value != CheckWaferExistence(slot.Key.Key, slot.Key.Value))
  2546. return false;
  2547. }
  2548. }
  2549. return true;
  2550. }
  2551. private bool IsLLReservedByTM(ModuleName ll)
  2552. {
  2553. foreach(var item in _curTmAction)
  2554. {
  2555. if (item.DestinationModule == ll || item.SourceModule == ll)
  2556. return true;
  2557. }
  2558. foreach(var action in _tmSchdActions)
  2559. {
  2560. foreach(var item in action)
  2561. {
  2562. if (item.DestinationModule == ll || item.SourceModule == ll)
  2563. return true;
  2564. }
  2565. }
  2566. return false;
  2567. }
  2568. private bool IsLLReservedByEFEM(ModuleName ll)
  2569. {
  2570. foreach (var item in _curEfemAction)
  2571. {
  2572. if (item.DestinationModule == ll || item.SourceModule == ll)
  2573. return true;
  2574. }
  2575. foreach (var action in _efemSchdActions)
  2576. {
  2577. foreach (var item in action)
  2578. {
  2579. if (item.DestinationModule == ll || item.SourceModule == ll)
  2580. return true;
  2581. }
  2582. }
  2583. return false;
  2584. }
  2585. private void RunSchdEFEMActions()
  2586. {
  2587. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  2588. if (efemRobot == null || !efemRobot.IsAvailable)
  2589. return;
  2590. if (_dictModuleTask[ModuleName.EfemRobot].IsIdle)
  2591. {
  2592. if(_efemSchdActions.Count > 0 )
  2593. {
  2594. if(_curEfemAction.Count == 0 || IsMovingActionsDone(_curEfemAction))
  2595. {
  2596. var nextActions = _efemSchdActions.First();
  2597. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2598. return;
  2599. var nextModule = nextActions.First().Module;
  2600. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].Scheduler.IsAvailable)
  2601. return;
  2602. _curEfemAction = _efemSchdActions.Dequeue();
  2603. foreach (var action in _curEfemAction)
  2604. {
  2605. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2606. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2607. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  2608. if (ModuleHelper.IsLoadPort(action.SourceModule))
  2609. {
  2610. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.SourceModule);
  2611. if(currentControlJob!=null)
  2612. {
  2613. _faCallback.JobWaferStart(currentControlJob, action.SourceSlot);
  2614. }
  2615. }
  2616. if(ModuleHelper.IsLoadPort(action.DestinationModule))
  2617. {
  2618. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.DestinationModule);
  2619. if (currentControlJob != null)
  2620. {
  2621. _faCallback.JobWaferEnd(currentControlJob, action.SourceSlot);
  2622. }
  2623. }
  2624. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  2625. }
  2626. (_dictModuleTask[ModuleName.EfemRobot].Scheduler as SchedulerEfemRobot).PostMoveItems(_curEfemAction.ToArray());
  2627. }
  2628. }
  2629. else if(_curEfemAction.Count >= 0 && IsMovingActionsDone(_curEfemAction)) // all scheduled actions done
  2630. {
  2631. _curEfemAction.Clear();
  2632. }
  2633. }
  2634. }
  2635. private void RunSchdTMActions()
  2636. {
  2637. if (_dictModuleTask[ModuleName.TMRobot].IsIdle)
  2638. {
  2639. if (_tmSchdActions.Count > 0)
  2640. {
  2641. if (_curTmAction.Count == 0 || IsMovingActionsDone(_curTmAction))
  2642. {
  2643. var nextActions = _tmSchdActions.First();
  2644. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2645. return;
  2646. if (ModuleHelper.IsPm(nextActions.First().Module) && !_dictModuleTask[nextActions.First().Module].IsIdle) /// wait PMTask status update to idle
  2647. return;
  2648. _curTmAction = _tmSchdActions.Dequeue();
  2649. foreach(var action in _curTmAction)
  2650. {
  2651. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2652. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2653. }
  2654. (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerTMRobot).SendMoveItems(_curTmAction.ToArray());
  2655. }
  2656. }
  2657. else if (_curTmAction.Count >= 0 && IsMovingActionsDone(_curTmAction)) // all scheduled actions done
  2658. {
  2659. _curTmAction.Clear();
  2660. }
  2661. }
  2662. }
  2663. private int TimeForNextModuleReady(WaferTask task)
  2664. {
  2665. if (ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2666. return _dictModuleTask[task.destMod].TimeToReady;
  2667. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  2668. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  2669. if (ModuleHelper.IsLoadPort(task.destMod) && (ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2670. {
  2671. if (task.llInOutPath == SequenceLLInOutPath.AInBOut || task.llInOutPath == SequenceLLInOutPath.BInBOut)
  2672. {
  2673. if(llbWaferStatus.emptySlot.Count > 0)
  2674. {
  2675. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2676. }
  2677. }
  2678. else if(task.llInOutPath == SequenceLLInOutPath.BInAOut || task.llInOutPath == SequenceLLInOutPath.AInAOut)
  2679. {
  2680. if(llaWaferStatus.emptySlot.Count > 0)
  2681. {
  2682. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2683. }
  2684. }
  2685. else if(task.llInOutPath == SequenceLLInOutPath.DInDOut)
  2686. {
  2687. if(llaWaferStatus.emptySlot.Count > 0 && llbWaferStatus.emptySlot.Count > 0)
  2688. {
  2689. if (_dictModuleTask[ModuleName.LLA].TimeToReady == _dictModuleTask[ModuleName.LLB].TimeToReady)
  2690. {
  2691. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2692. }
  2693. else
  2694. {
  2695. return Math.Min(_dictModuleTask[ModuleName.LLA].TimeToReady, _dictModuleTask[ModuleName.LLB].TimeToReady);
  2696. }
  2697. }
  2698. else if(llaWaferStatus.emptySlot.Count > 0)
  2699. {
  2700. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2701. }
  2702. else if(llbWaferStatus.emptySlot.Count > 0)
  2703. {
  2704. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2705. }
  2706. }
  2707. }
  2708. else if(ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2709. {
  2710. if(_lstWaferTasks.Find(wafer => wafer.currentMod == task.destMod || wafer.routedMod == task.destMod) == null)
  2711. {
  2712. return _dictModuleTask[task.destMod].TimeToReady;
  2713. }
  2714. }
  2715. return int.MaxValue / 2;
  2716. }
  2717. List<Hand> GetTMValidFreeHands(List<WaferTask> robotWafers, List<MoveItem> swapActions)
  2718. {
  2719. var hands = new List<Hand>();
  2720. for(int i = 0; i < 2; i++)
  2721. {
  2722. if(_tmRobotSingleArmOption == 0 || _tmRobotSingleArmOption == i + 1)
  2723. {
  2724. if ((!robotWafers.Exists(wafer => wafer.currentSlot == i) ||
  2725. ( robotWafers.Exists(wafer => wafer.currentSlot == i) &&
  2726. swapActions.Exists(item => item.SourceModule == ModuleName.TMRobot && item.SourceSlot == i))) &&
  2727. !swapActions.Exists(item => item.DestinationModule == ModuleName.TMRobot && item.DestinationSlot == i))
  2728. hands.Add((Hand)i);
  2729. }
  2730. }
  2731. return hands;
  2732. }
  2733. (ModuleName llPath, List<MoveItem> swapActions) FindBestLLSwapPlan(ModuleName ll, List<WaferTask> robotWafers)
  2734. {
  2735. ModuleName path = ll == ModuleName.System ? ModuleName.System : ll;
  2736. List<ModuleName> lls = ll == ModuleName.System ? new List<ModuleName> { ModuleName.LLA, ModuleName.LLB } : new List<ModuleName> { ll };
  2737. List<MoveItem> actions = new List<MoveItem>();
  2738. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2739. foreach (var loadlock in lls)
  2740. {
  2741. llSwapActions[loadlock] = new List<MoveItem>();
  2742. if (IsLLReservedByEFEM(loadlock))
  2743. continue;
  2744. var llWaferStatus = GetLLReadyInOutSlots(loadlock);
  2745. foreach(var wafer in robotWafers)
  2746. {
  2747. if(_dictModuleTask[loadlock].TimeToReady == 0 && !IsLLReservedByEFEM(loadlock) && CanWaferGotoLL(wafer,loadlock) && llWaferStatus.emptySlot.Count > llSwapActions[loadlock].Count)
  2748. {
  2749. llSwapActions[loadlock].Add(new MoveItem(ModuleName.TMRobot, wafer.currentSlot, loadlock, llWaferStatus.emptySlot[llSwapActions[loadlock].Count], (Hand)wafer.currentSlot));
  2750. }
  2751. }
  2752. int prePickTime = 20;
  2753. int prePickCount = 0;
  2754. var hands = GetTMValidFreeHands(robotWafers, llSwapActions[loadlock]);
  2755. foreach (var slot in llWaferStatus.inSlot)
  2756. {
  2757. var wafer = _lstWaferTasks.Find(task => task.currentMod == loadlock && task.currentSlot == slot);
  2758. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && hands.Count > prePickCount)
  2759. {
  2760. if(_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2761. {
  2762. if( hands.Count == 2 && prePickCount == 0 && (_dictModuleTask.Count(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.TimeToReady < prePickTime && WaferManager.Instance.CheckNoWafer(mod.Key, 0)) == 0 || llWaferStatus.inSlot.Count == 1))
  2763. {
  2764. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2765. prePickCount++;
  2766. break;
  2767. }
  2768. }
  2769. else
  2770. {
  2771. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2772. prePickCount++;
  2773. }
  2774. }
  2775. }
  2776. }
  2777. var validateActions = llSwapActions.Where(item => item.Value.Count > 0).ToDictionary(k => k.Key, v => v.Value);
  2778. if(validateActions.Count == 1)
  2779. {
  2780. (path, actions) = (validateActions.First().Key, validateActions.First().Value);
  2781. }
  2782. else if(validateActions.Count == 2)
  2783. {
  2784. var sortedActions = validateActions.OrderByDescending(item => item.Value.Count + (_dictModuleTask[item.Key].Scheduler.IsVac ? 2 : 0)).ToDictionary(k => k.Key, v => v.Value);
  2785. (path, actions) = (sortedActions.First().Key, sortedActions.First().Value);
  2786. }
  2787. return (path, actions);
  2788. }
  2789. (List<WaferTask> pmWafers, ModuleName destLL, List<MoveItem> swapAction) FindBestReturnWafersPlan(Hand[] freeHands)
  2790. {
  2791. Dictionary<ModuleName, List<WaferTask>> returnWafers = new Dictionary<ModuleName, List<WaferTask>>();
  2792. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2793. Dictionary<ModuleName, int> llValues = new Dictionary<ModuleName, int>();
  2794. foreach(var ll in new List<ModuleName> { ModuleName.LLA, ModuleName.LLB})
  2795. {
  2796. var llWaferStatus = GetLLReadyInOutSlots(ll);
  2797. returnWafers[ll] = new List<WaferTask>();
  2798. llSwapActions[ll] = new List<MoveItem>();
  2799. llValues[ll] = 0;
  2800. if (IsLLReservedByEFEM(ll))
  2801. continue;
  2802. var readyReturnWafers = _lstWaferTasks.Where( wafer => ModuleHelper.IsPm(wafer.currentMod) &&
  2803. ModuleHelper.IsLoadPort(wafer.destMod) &&
  2804. wafer.movingStatus == RState.End &&
  2805. _dictModuleTask[wafer.currentMod].TimeToReady <= 2 &&
  2806. CanWaferGotoLL(wafer, ll)).Take(Math.Min(freeHands.Length, llWaferStatus.emptySlot.Count)).ToList();
  2807. int prePickTime = 10 * llSwapActions[ll].Count;
  2808. int handIndex = 0;
  2809. if(_dictModuleTask[ll].TimeToReady <= prePickTime)
  2810. {
  2811. foreach (var wafer in readyReturnWafers)
  2812. {
  2813. if(handIndex < freeHands.Length)
  2814. {
  2815. returnWafers[ll].Add(wafer);
  2816. llSwapActions[ll].Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[handIndex], ll, llWaferStatus.emptySlot[handIndex], freeHands[handIndex]));
  2817. handIndex++;
  2818. }
  2819. }
  2820. int prePickCount = 0;
  2821. handIndex = 0;
  2822. foreach (var slot in llWaferStatus.inSlot)
  2823. {
  2824. var wafer = _lstWaferTasks.Find(task => task.currentMod == ll && task.currentSlot == slot);
  2825. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && freeHands.Length > prePickCount)
  2826. {
  2827. if (_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2828. {
  2829. if (freeHands.Length == 2 && prePickCount == 0 && (_dictModuleTask.Count(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.TimeToReady <= prePickTime && WaferManager.Instance.CheckNoWafer(mod.Key, 0)) == 0 || llWaferStatus.inSlot.Count == 1))
  2830. {
  2831. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2832. prePickCount++;
  2833. break;
  2834. }
  2835. }
  2836. else
  2837. {
  2838. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2839. prePickCount++;
  2840. }
  2841. }
  2842. }
  2843. llValues[ll] = returnWafers[ll].Count * 2 + llSwapActions[ll].Count + (_dictModuleTask[ll].Scheduler.IsVac && returnWafers[ll].Count > 0 ? 2 : 0);
  2844. }
  2845. }
  2846. var preferLL = llValues.OrderByDescending(v => v.Value).First().Key;
  2847. return (returnWafers[preferLL], preferLL, llSwapActions[preferLL]);
  2848. }
  2849. ModuleName FindTheBestMovePathWithFixSlot(IEnumerable<KeyValuePair<ModuleName, ModuleTask>> lls, List<WaferTask> pmWafers)
  2850. {
  2851. Dictionary<ModuleName, int> moveValues = new Dictionary<ModuleName, int>();
  2852. foreach(var ll in lls)
  2853. {
  2854. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  2855. moveValues[ll.Key] = Math.Min(pmWafers.Where(wt => CanWaferGotoLL(wt, ll.Key)).Count(), GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count) + llWaferStatus.tOutSlot.Count;
  2856. }
  2857. var preferLL = moveValues.OrderByDescending(v => v.Value).First().Key;
  2858. return moveValues[preferLL] > 0 ? preferLL : ModuleName.System;
  2859. }
  2860. void RoutingTMSwapActions(List<MoveItem> actions)
  2861. {
  2862. foreach (var action in actions)
  2863. {
  2864. if (ModuleHelper.IsTMRobot(action.SourceModule))
  2865. {
  2866. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == ModuleName.TMRobot && wafer.currentSlot == action.SourceSlot);
  2867. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2868. }
  2869. else
  2870. {
  2871. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2872. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2873. }
  2874. }
  2875. }
  2876. private bool ManaulReturnPMWafer()
  2877. {
  2878. var mReturnWafer = _qeReturnWafers.Peek();
  2879. if (ModuleHelper.IsPm((ModuleName)mReturnWafer.Station) && _lstWaferTasks.Count(wt => ModuleHelper.IsTMRobot(wt.currentMod)) == 0)
  2880. {
  2881. var hands = GetTMValidFreeHands(_lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod)).ToList(), new List<MoveItem>());
  2882. var waferTask = _lstWaferTasks.Find(wt => wt.currentMod == (ModuleName)mReturnWafer.Station && wt.waferId == mReturnWafer.InnerId);
  2883. if (waferTask != null && hands.Count > 0)
  2884. {
  2885. waferTask.Return();
  2886. var outLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && CanWaferGotoLL(waferTask, mod.Key) && GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 0 && !IsLLReservedByEFEM(mod.Key));
  2887. if (outLL.Count() > 0)
  2888. {
  2889. var slot = GetLLReadyInOutSlots(outLL.First().Key).emptySlot.First();
  2890. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waferTask.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2891. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL.First().Key, slot, hands.First()) });
  2892. _qeReturnWafers.Dequeue();
  2893. return true;
  2894. }
  2895. }
  2896. }
  2897. return false;
  2898. }
  2899. private void RoutingVacWafers()
  2900. {
  2901. if(_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2902. {
  2903. RunSchdTMActions();
  2904. return;
  2905. }
  2906. if(_tmRobotStatus == RState.End)
  2907. {
  2908. // handle manual return wafer if exist
  2909. if(_qeReturnWafers.Count > 0)
  2910. {
  2911. if (ManaulReturnPMWafer())
  2912. return;
  2913. }
  2914. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2915. {
  2916. if (_LLASlotNumber == 2)
  2917. {
  2918. Routing2SlotVacSystem();
  2919. }
  2920. else if (_LLASlotNumber == 4)
  2921. {
  2922. Routing4SlotVacSystem();
  2923. }
  2924. }
  2925. else
  2926. {
  2927. RoutingFixedSlotVacSystem();
  2928. }
  2929. }
  2930. }
  2931. private void Routing2SlotVacSystem()
  2932. {
  2933. var robotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2934. var freeHands = GetTMFreeHand();
  2935. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2936. {
  2937. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2938. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2939. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2940. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2941. var inLLModule = _dictModuleTask[inLL] as LoadlockTask;
  2942. var outLLModule = _dictModuleTask[outLL] as LoadlockTask;
  2943. if(robotWafers.Count == 0)
  2944. {
  2945. #region special routing pattern
  2946. if (_specialRoutingPattern != SpecialRoutingPattern.Disable)
  2947. {
  2948. if(_specialRoutingPattern == SpecialRoutingPattern.LongTimeRecipe && freeHands.Count == 2)
  2949. {
  2950. if(_dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).Count() == 0 && inLLWaferStatus.inSlot.Count > 0)
  2951. {
  2952. var readyOutPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 25).OrderBy(mod => mod.Value.TimeToReady).ToList();
  2953. if(readyOutPMs.Count > 0 && inLLModule.ReayForTMInTime(5) && _lstWaferTasks.Exists(wt => wt.currentMod == inLL && readyOutPMs.Exists(kv => kv.Key == wt.destMod)))
  2954. {
  2955. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.destMod == readyOutPMs.First().Key);
  2956. if(llWafer != null)
  2957. {
  2958. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  2959. var pmSwap = new List<MoveItem>
  2960. { new MoveItem(readyOutPMs.First().Key, 0, ModuleName.TMRobot, (int)freeHands[1], freeHands[1]),
  2961. new MoveItem(ModuleName.TMRobot, (int)freeHands[0], readyOutPMs.First().Key, 0, freeHands[0])
  2962. };
  2963. _tmSchdActions.Enqueue(pmSwap);
  2964. if(outLLModule.ReayForTMInTime(25) && outLLWaferStatus.emptySlot.Count > 0)
  2965. {
  2966. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[1], outLL, outLLWaferStatus.emptySlot[0], freeHands[1]) });
  2967. }
  2968. }
  2969. }
  2970. return;
  2971. }
  2972. }
  2973. }
  2974. #endregion
  2975. if (_dictModuleTask.Count(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 5) > 0 && outLLModule.ReayForTMInTime(30) && outLLWaferStatus.emptySlot.Count > 0)
  2976. {
  2977. var readyOutPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 25).OrderBy(mod => mod.Value.TimeToReady).ToList();
  2978. var placeActions = new List<MoveItem>();
  2979. int pickCount = 0;
  2980. foreach (var pm in readyOutPMs)
  2981. {
  2982. var pmWafer = _lstWaferTasks.Find(wt => wt.currentMod == pm.Key);
  2983. if (pmWafer != null && pickCount < freeHands.Count && pickCount < outLLWaferStatus.emptySlot.Count)
  2984. {
  2985. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)freeHands[pickCount], freeHands[pickCount]) });
  2986. placeActions.Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[pickCount], outLL, outLLWaferStatus.emptySlot[pickCount], freeHands[pickCount]));
  2987. pickCount++;
  2988. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, pm.Key, $"{pm.Key} will be ready in {pm.Value.TimeToReady} seconds");
  2989. }
  2990. }
  2991. if (pickCount > 0)
  2992. {
  2993. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  2994. _tmSchdActions.Enqueue(placeActions);
  2995. return;
  2996. }
  2997. }
  2998. // push wafer from LL to PM and avoid blocking two robot arms
  2999. if (inLLModule.ReayForTMInTime(10) && inLLWaferStatus.inSlot.Count > 0)
  3000. {
  3001. var pickActions = new List<MoveItem>();
  3002. var inLLWafers = _lstWaferTasks.FindAll(wt => wt.currentMod == inLL).ToList();
  3003. if (inLLWaferStatus.inSlot.Count < 2 || inLLWafers.Exists(wt => !_dictModuleTask[wt.destMod].HasWafer && _dictModuleTask[wt.destMod].TimeToReady < 20))
  3004. {
  3005. for (int i = 0; i < Math.Min(inLLWaferStatus.inSlot.Count, freeHands.Count); i++)
  3006. {
  3007. pickActions.Add(new MoveItem(inLL, inLLWaferStatus.inSlot[i], ModuleName.TMRobot, (int)freeHands[i], freeHands[i]));
  3008. }
  3009. }
  3010. if(pickActions.Count > 0)
  3011. {
  3012. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3013. _tmSchdActions.Enqueue(pickActions);
  3014. return;
  3015. }
  3016. }
  3017. }
  3018. else
  3019. {
  3020. #region special routing pattern
  3021. if (_specialRoutingPattern != SpecialRoutingPattern.Disable)
  3022. {
  3023. if (_specialRoutingPattern == SpecialRoutingPattern.LongTimeRecipe && _tmRobotSingleArmOption == 0)
  3024. {
  3025. if(_dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).Count() == 0 && ModuleHelper.IsLoadPort(robotWafers[0].destMod))
  3026. {
  3027. if (outLLModule.ReayForTMInTime(10) && outLLWaferStatus.emptySlot.Count > 0)
  3028. {
  3029. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)(robotWafers[0].currentSlot)) });
  3030. }
  3031. return;
  3032. }
  3033. }
  3034. }
  3035. #endregion
  3036. foreach (var robotWafer in robotWafers)
  3037. {
  3038. if (ModuleHelper.IsPm(robotWafer.destMod))
  3039. {
  3040. if (_dictModuleTask[robotWafer.destMod].TimeToReady < 5)
  3041. {
  3042. if (_dictModuleTask[robotWafer.destMod].HasWafer)
  3043. {
  3044. // PM Swap
  3045. if (freeHands.Count > 0)
  3046. {
  3047. var pmActions = new List<MoveItem>
  3048. {
  3049. new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]),
  3050. new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot)
  3051. };
  3052. _tmSchdActions.Enqueue(pmActions);
  3053. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, robotWafer.destMod, $"{robotWafer.destMod} will be ready in {_dictModuleTask[robotWafer.destMod].TimeToReady} seconds");
  3054. return;
  3055. }
  3056. }
  3057. else
  3058. {
  3059. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, robotWafer.destMod, $"{robotWafer.destMod} will be ready in {_dictModuleTask[robotWafer.destMod].TimeToReady} seconds");
  3060. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3061. return;
  3062. }
  3063. }
  3064. else if (_dictModuleTask[robotWafer.destMod].TimeToReady > 20 && freeHands.Count > 0)
  3065. {
  3066. if (outLLWaferStatus.emptySlot.Count > 0 && outLLModule.ReayForTMInTime(10) && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)) > 0)
  3067. {
  3068. // try to return one wafer from PM to LL
  3069. var readyOutWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod));
  3070. if (readyOutWafer != null && _dictModuleTask[readyOutWafer.currentMod].TimeToReady < 5)
  3071. {
  3072. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, readyOutWafer.currentMod, $"{readyOutWafer.currentMod} will be ready in {_dictModuleTask[readyOutWafer.currentMod].TimeToReady} seconds");
  3073. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3074. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafer.currentMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3075. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot[0], freeHands[0]) });
  3076. return;
  3077. }
  3078. }
  3079. if (inLLModule.ReayForTMInTime(5) && inLLWaferStatus.inSlot.Count > 0)
  3080. {
  3081. var inLLWafers = _lstWaferTasks.FindAll(wt => wt.currentMod == inLL).OrderBy(wt => _dictModuleTask[wt.destMod].TimeToReady);
  3082. foreach (var inWafer in inLLWafers)
  3083. {
  3084. if (!_dictModuleTask[inWafer.destMod].HasWafer && _dictModuleTask[inWafer.destMod].TimeToReady < 10)
  3085. {
  3086. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inWafer.destMod, $"{inWafer.destMod} will be ready in {_dictModuleTask[inWafer.destMod].TimeToReady} seconds");
  3087. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3088. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inWafer.currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3089. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], inWafer.destMod, 0, freeHands[0]) });
  3090. return;
  3091. }
  3092. }
  3093. }
  3094. }
  3095. }
  3096. else
  3097. {
  3098. if (freeHands.Count > 0 &&
  3099. outLLWaferStatus.emptySlot.Count == 2 &&
  3100. outLLModule.ReayForTMInTime(10) &&
  3101. _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)) > 0 )
  3102. {
  3103. // try to get one wafer from PM, and match a double place next time
  3104. var readyOutWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod));
  3105. if(readyOutWafer != null && _dictModuleTask[readyOutWafer.currentMod].TimeToReady < 5)
  3106. {
  3107. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafer.currentMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3108. return;
  3109. }
  3110. }
  3111. if (outLLModule.ReayForTMInTime(5))
  3112. {
  3113. // try match a double place
  3114. if (robotWafers.Count == 2 && robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)) && outLLWaferStatus.emptySlot.Count == 2)
  3115. {
  3116. var doublePlace = new List<MoveItem>
  3117. {
  3118. new MoveItem(ModuleName.TMRobot, 0, outLL, 0, Hand.Blade1),
  3119. new MoveItem(ModuleName.TMRobot, 1, outLL, 1, Hand.Blade2)
  3120. };
  3121. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3122. _tmSchdActions.Enqueue(doublePlace);
  3123. return;
  3124. }
  3125. if(outLLWaferStatus.emptySlot.Count > 0)
  3126. {
  3127. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3128. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)robotWafer.currentSlot) });
  3129. return;
  3130. }
  3131. }
  3132. }
  3133. }
  3134. if (freeHands.Count == 0)
  3135. return;
  3136. // try to push one wafer in pm
  3137. if(inLLWaferStatus.inSlot.Count == 1 && inLLModule.ReayForTMInTime(5))
  3138. {
  3139. var inWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == inLLWaferStatus.inSlot.First());
  3140. if(inWafer != null && !_dictModuleTask[inWafer.destMod].HasWafer && _dictModuleTask[inWafer.destMod].TimeToReady < 20)
  3141. {
  3142. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inWafer.destMod, $"{inWafer.destMod} will be ready in {_dictModuleTask[inWafer.destMod].TimeToReady} seconds");
  3143. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3144. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inLLWaferStatus.inSlot.First(), ModuleName.TMRobot, (int)freeHands[0], freeHands[0])});
  3145. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], inWafer.destMod, 0, freeHands[0]) });
  3146. return;
  3147. }
  3148. }
  3149. // try to return one wafer
  3150. if(outLLModule.ReayForTMInTime(15) && outLLWaferStatus.emptySlot.Count > 0)
  3151. {
  3152. var readyReturnPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 5).OrderBy(mod => mod.Value.TimeToReady).ToList();
  3153. if(readyReturnPMs.Count > 0)
  3154. {
  3155. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, readyReturnPMs.First().Key, $"{readyReturnPMs.First().Key} will be ready in {readyReturnPMs.First().Value.TimeToReady} seconds");
  3156. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3157. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnPMs.First().Key, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3158. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot.First(), freeHands[0]) });
  3159. return;
  3160. }
  3161. }
  3162. }
  3163. }
  3164. else
  3165. {
  3166. if (robotWafers.Count == 2)
  3167. {
  3168. foreach (var wafer in robotWafers)
  3169. {
  3170. if (wafer.movingStatus == RState.End &&
  3171. ModuleHelper.IsPm(wafer.destMod) &&
  3172. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  3173. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  3174. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  3175. {
  3176. wafer.RouteTo(wafer.destMod, 0);
  3177. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3178. }
  3179. }
  3180. if (_tmSchdActions.Count == 0)
  3181. {
  3182. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3183. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3184. {
  3185. RoutingTMSwapActions(swapActions.swapActions);
  3186. _tmSchdActions.Enqueue(swapActions.swapActions);
  3187. }
  3188. }
  3189. }
  3190. else if (robotWafers.Count == 1)
  3191. {
  3192. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  3193. {
  3194. var pmActions = new List<MoveItem>();
  3195. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  3196. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  3197. {
  3198. int pickSlot = 1 - robotWafers[0].currentSlot;
  3199. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  3200. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  3201. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  3202. _tmSchdActions.Enqueue(pmActions);
  3203. return;
  3204. }
  3205. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  3206. {
  3207. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  3208. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  3209. _tmSchdActions.Enqueue(pmActions);
  3210. return;
  3211. }
  3212. }
  3213. // try to pick a wafer from LL
  3214. if (_tmSchdActions.Count == 0)
  3215. {
  3216. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3217. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3218. {
  3219. RoutingTMSwapActions(swapActions.swapActions);
  3220. _tmSchdActions.Enqueue(swapActions.swapActions);
  3221. return;
  3222. }
  3223. }
  3224. // try to return a wafer from PM
  3225. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3226. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3227. if (moveActions.pmWafers.Count > 0)
  3228. {
  3229. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3230. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  3231. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  3232. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  3233. if (pickAction != null)
  3234. {
  3235. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  3236. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  3237. }
  3238. _tmSchdActions.Enqueue(moveActions.swapAction);
  3239. }
  3240. }
  3241. else // robot arm is empty
  3242. {
  3243. // try return wafers from PM
  3244. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3245. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3246. if (moveActions.pmWafers.Count > 0)
  3247. {
  3248. int handIndex = 0;
  3249. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3250. foreach (var action in placeActions)
  3251. {
  3252. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3253. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3254. handIndex++;
  3255. }
  3256. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3257. foreach (var ac in pickActions)
  3258. {
  3259. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3260. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3261. }
  3262. _tmSchdActions.Enqueue(moveActions.swapAction);
  3263. }
  3264. if (_tmSchdActions.Count == 0)
  3265. {
  3266. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3267. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3268. {
  3269. RoutingTMSwapActions(swapActions.swapActions);
  3270. _tmSchdActions.Enqueue(swapActions.swapActions);
  3271. }
  3272. }
  3273. }
  3274. }
  3275. }
  3276. private void Routing4SlotVacSystem()
  3277. {
  3278. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  3279. if (robotWafers.Count == 2)
  3280. {
  3281. foreach (var wafer in robotWafers)
  3282. {
  3283. if (wafer.movingStatus == RState.End &&
  3284. ModuleHelper.IsPm(wafer.destMod) &&
  3285. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  3286. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  3287. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  3288. {
  3289. wafer.RouteTo(wafer.destMod, 0);
  3290. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3291. }
  3292. }
  3293. if (_tmSchdActions.Count == 0)
  3294. {
  3295. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3296. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3297. {
  3298. RoutingTMSwapActions(swapActions.swapActions);
  3299. _tmSchdActions.Enqueue(swapActions.swapActions);
  3300. }
  3301. }
  3302. }
  3303. else if (robotWafers.Count == 1)
  3304. {
  3305. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  3306. {
  3307. var pmActions = new List<MoveItem>();
  3308. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  3309. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  3310. {
  3311. int pickSlot = 1 - robotWafers[0].currentSlot;
  3312. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  3313. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  3314. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  3315. _tmSchdActions.Enqueue(pmActions);
  3316. return;
  3317. }
  3318. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  3319. {
  3320. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  3321. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  3322. _tmSchdActions.Enqueue(pmActions);
  3323. return;
  3324. }
  3325. }
  3326. // try to pick a wafer from LL
  3327. if (_tmSchdActions.Count == 0)
  3328. {
  3329. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3330. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3331. {
  3332. RoutingTMSwapActions(swapActions.swapActions);
  3333. _tmSchdActions.Enqueue(swapActions.swapActions);
  3334. return;
  3335. }
  3336. }
  3337. // try to return a wafer from PM
  3338. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3339. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3340. if (moveActions.pmWafers.Count > 0)
  3341. {
  3342. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3343. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  3344. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  3345. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  3346. if (pickAction != null)
  3347. {
  3348. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  3349. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  3350. }
  3351. _tmSchdActions.Enqueue(moveActions.swapAction);
  3352. }
  3353. }
  3354. else // robot arm is empty
  3355. {
  3356. // try return wafers from PM
  3357. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3358. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3359. if (moveActions.pmWafers.Count > 0)
  3360. {
  3361. int handIndex = 0;
  3362. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3363. foreach (var action in placeActions)
  3364. {
  3365. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3366. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3367. handIndex++;
  3368. }
  3369. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3370. foreach (var ac in pickActions)
  3371. {
  3372. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3373. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3374. }
  3375. _tmSchdActions.Enqueue(moveActions.swapAction);
  3376. }
  3377. if (_tmSchdActions.Count == 0)
  3378. {
  3379. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3380. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3381. {
  3382. RoutingTMSwapActions(swapActions.swapActions);
  3383. _tmSchdActions.Enqueue(swapActions.swapActions);
  3384. }
  3385. }
  3386. }
  3387. }
  3388. private void RoutingFixedSlotVacSystem()
  3389. {
  3390. var robotWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod));
  3391. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  3392. if (_LLASlotNumber == 2)
  3393. {
  3394. if (robotWafers.Count() == 1)
  3395. {
  3396. if(ModuleHelper.IsPm(robotWafers.First().destMod))
  3397. {
  3398. var destPM = robotWafers.First().destMod;
  3399. if(_dictModuleTask[destPM].TimeToReady <= 5)
  3400. {
  3401. if(_lstWaferTasks.Exists(wt => wt.currentMod == destPM))
  3402. {
  3403. var pickHand = SelectTMPickArm(destPM);
  3404. if(pickHand != Hand.None)
  3405. {
  3406. var pmSwap = new List<MoveItem>
  3407. {
  3408. new MoveItem(destPM, 0, ModuleName.TMRobot, (int)pickHand, pickHand),
  3409. new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot)
  3410. };
  3411. _tmSchdActions.Enqueue(pmSwap);
  3412. return;
  3413. }
  3414. }
  3415. else
  3416. {
  3417. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot) });
  3418. return;
  3419. }
  3420. }
  3421. }
  3422. else
  3423. {
  3424. var readySwapLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3425. GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 &&
  3426. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3427. ll.Value.TimeToReady <= 10);
  3428. if (readySwapLL.Count() > 0)
  3429. {
  3430. var destLL = readySwapLL.First().Key;
  3431. Hand pickHand = SelectTMPickArm(destLL);
  3432. if (pickHand != Hand.None)
  3433. {
  3434. Hand placeHand = (Hand)robotWafers.First().currentSlot;
  3435. var llSwap = new List<MoveItem>();
  3436. var llSlots = GetLLFixedReadyInOutSlots(destLL);
  3437. llSwap.Add(new MoveItem(destLL, llSlots.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3438. llSwap.Add(new MoveItem(ModuleName.TMRobot, (int)placeHand, destLL, llSlots.tInSlot.First(), placeHand));
  3439. _tmSchdActions.Enqueue(llSwap);
  3440. return;
  3441. }
  3442. }
  3443. var emptyLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3444. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3445. ll.Value.TimeToReady <= 2);
  3446. if (emptyLL.Count() > 0)
  3447. {
  3448. var destLL = emptyLL.First().Key;
  3449. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem( ModuleName.TMRobot,
  3450. robotWafers.First().currentSlot,
  3451. destLL,
  3452. GetLLFixedReadyInOutSlots(destLL).tInSlot.First(),
  3453. (Hand)robotWafers.First().currentSlot) });
  3454. return;
  3455. }
  3456. }
  3457. // try to return a wafer
  3458. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3459. foreach(var pmWafer in readyReturnWafers)
  3460. {
  3461. var readyLL = lls.Where(ll => CanWaferGotoLL(pmWafer, ll.Key) && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3462. if(readyLL.Count() > 0)
  3463. {
  3464. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3465. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3466. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand , readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3467. return;
  3468. }
  3469. }
  3470. // try to push in a wafer
  3471. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3472. foreach(var ll in readyInLL)
  3473. {
  3474. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3475. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3476. if( wafer != null &&
  3477. ModuleHelper.IsPm(wafer.destMod) &&
  3478. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3479. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3480. {
  3481. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3482. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3483. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3484. return;
  3485. }
  3486. }
  3487. }
  3488. else if (robotWafers.Count() == 0)
  3489. {
  3490. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  3491. if(readyReturnWafers.Count > 0)
  3492. {
  3493. // try to do a LL swap action
  3494. var readySwapLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 10);
  3495. foreach (var pmWafer in readyReturnWafers)
  3496. {
  3497. foreach (var ll in readySwapLL)
  3498. {
  3499. if (CanWaferGotoLL(pmWafer, ll.Key))
  3500. {
  3501. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3502. var pickHand = SelectTMPickArm(ll.Key);
  3503. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3504. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3505. var llSwapActions = new List<MoveItem>();
  3506. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, llWaferStatus.tInSlot.First(), returnHand));
  3507. llSwapActions.Add(new MoveItem(ll.Key, llWaferStatus.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3508. _tmSchdActions.Enqueue(llSwapActions);
  3509. return;
  3510. }
  3511. }
  3512. }
  3513. // just return to LL
  3514. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 5);
  3515. foreach(var pmWafer in readyReturnWafers)
  3516. {
  3517. foreach(var ll in readyInLL)
  3518. {
  3519. if(CanWaferGotoLL(pmWafer, ll.Key))
  3520. {
  3521. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3522. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3523. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, GetLLFixedReadyInOutSlots(ll.Key).tInSlot.First(), returnHand) });
  3524. return;
  3525. }
  3526. }
  3527. }
  3528. }
  3529. var readyPushInLLs = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && ll.Value.TimeToReady <= 2);
  3530. if(readyPushInLLs.Count() > 0)
  3531. {
  3532. var destLL = readyPushInLLs.First().Key;
  3533. if(readyPushInLLs.Count() == 2 && readyPushInLLs.First().Value.Scheduler.IsAtm && readyPushInLLs.Last().Value.Scheduler.IsVac)
  3534. {
  3535. destLL = readyPushInLLs.Last().Key;
  3536. }
  3537. var pickHand = SelectTMPickArm(destLL);
  3538. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(destLL, GetLLFixedReadyInOutSlots(destLL).tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand) });
  3539. return;
  3540. }
  3541. }
  3542. else
  3543. {
  3544. // should not go here
  3545. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Had better avoid picking two wafers on TM robot arms under Loadlock fixed slot pattern");
  3546. foreach(var wafer in robotWafers)
  3547. {
  3548. if(ModuleHelper.IsPm(wafer.destMod))
  3549. {
  3550. if(!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3551. {
  3552. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3553. return;
  3554. }
  3555. }
  3556. else
  3557. {
  3558. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 2);
  3559. if(readyInLL.Count() > 0)
  3560. {
  3561. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, readyInLL.First().Key, GetLLFixedReadyInOutSlots(readyInLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3562. return;
  3563. }
  3564. }
  3565. }
  3566. }
  3567. }
  3568. else // 4 slot Loadlock
  3569. {
  3570. if(robotWafers.Count() > 0)
  3571. {
  3572. if (robotWafers.Count() == 2)
  3573. {
  3574. if (robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)))
  3575. {
  3576. var destLL = lls.Where(ll => robotWafers.All(wt => CanWaferGotoLL(wt, ll.Key)) &&
  3577. ll.Value.TimeToReady <= 10 &&
  3578. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 2).
  3579. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3580. OrderBy(ll => ll.Value.TimeToReady);
  3581. if (destLL.Count() > 0)
  3582. {
  3583. var swapLL = destLL.First().Key;
  3584. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3585. var swapActions = new List<MoveItem>();
  3586. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafers.First().currentSlot));
  3587. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.Last().currentSlot, swapLL, llWaferStatus.tInSlot.Last(), (Hand)robotWafers.Last().currentSlot));
  3588. int pickCount = 0;
  3589. foreach (var slot in llWaferStatus.eOutSlot)
  3590. {
  3591. swapActions.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3592. }
  3593. _tmSchdActions.Enqueue(swapActions);
  3594. return;
  3595. }
  3596. }
  3597. foreach (var wafer in robotWafers)
  3598. {
  3599. if (ModuleHelper.IsPm(wafer.destMod))
  3600. {
  3601. if (!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 5)
  3602. {
  3603. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3604. return;
  3605. }
  3606. }
  3607. else
  3608. {
  3609. var placeLL = lls.Where(ll => CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 5 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).OrderBy(ll => ll.Value.TimeToReady);
  3610. if (placeLL.Count() > 0)
  3611. {
  3612. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, placeLL.First().Key, GetLLFixedReadyInOutSlots(placeLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3613. return;
  3614. }
  3615. }
  3616. }
  3617. }
  3618. else if (robotWafers.Count() == 1)
  3619. {
  3620. var robotWafer = robotWafers.First();
  3621. if (ModuleHelper.IsPm(robotWafer.destMod))
  3622. {
  3623. if (_dictModuleTask[robotWafer.destMod].TimeToReady <= 5)
  3624. {
  3625. if (_lstWaferTasks.Exists(wt => wt.currentMod == robotWafer.destMod))
  3626. {
  3627. var pmSwap = new List<MoveItem>();
  3628. pmSwap.Add(new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, 1 - robotWafer.currentSlot, (Hand)(1 - robotWafer.currentSlot)));
  3629. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot));
  3630. _tmSchdActions.Enqueue(pmSwap);
  3631. return;
  3632. }
  3633. else
  3634. {
  3635. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3636. return;
  3637. }
  3638. }
  3639. }
  3640. else
  3641. {
  3642. var destLL = lls.Where(ll => CanWaferGotoLL(robotWafer, ll.Key) &&
  3643. ll.Value.TimeToReady <= 10 &&
  3644. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).
  3645. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3646. OrderBy(ll => ll.Value.TimeToReady);
  3647. if (destLL.Count() > 0)
  3648. {
  3649. var swapLL = destLL.First().Key;
  3650. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3651. var llSwap = new List<MoveItem>();
  3652. llSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafer.currentSlot));
  3653. int pickCount = 0;
  3654. foreach (var slot in llWaferStatus.tOutSlot)
  3655. {
  3656. llSwap.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3657. pickCount++;
  3658. }
  3659. _tmSchdActions.Enqueue(llSwap);
  3660. return;
  3661. }
  3662. }
  3663. // try to return a wafer
  3664. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3665. foreach (var pmWafer in readyReturnWafers)
  3666. {
  3667. var readyLL = lls.Where(ll => CanWaferGotoLL(pmWafer, ll.Key) && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3668. if (readyLL.Count() > 0)
  3669. {
  3670. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3671. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3672. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3673. return;
  3674. }
  3675. }
  3676. // try to push in a wafer
  3677. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3678. foreach (var ll in readyInLL)
  3679. {
  3680. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3681. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3682. if (wafer != null &&
  3683. ModuleHelper.IsPm(wafer.destMod) &&
  3684. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3685. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3686. {
  3687. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3688. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3689. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3690. return;
  3691. }
  3692. }
  3693. }
  3694. }
  3695. else // robot empty
  3696. {
  3697. var nearlyReadyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && (ModuleHelper.IsLoadPort(wt.destMod) || _dictModuleTask[wt.currentMod].TimeToReady <= 10)).OrderBy(wt => _dictModuleTask[wt.currentMod].TimeToReady).ToList();
  3698. var readyLL = lls.Where(ll => ll.Value.TimeToReady <= 10);
  3699. if(readyLL.Count() > 0)
  3700. {
  3701. var llPath = FindTheBestMovePathWithFixSlot(readyLL, nearlyReadyReturnWafers);
  3702. if(ModuleHelper.IsLoadLock(llPath))
  3703. {
  3704. int returnCount = 0;
  3705. var llWaferStatus = GetLLFixedReadyInOutSlots(llPath);
  3706. var llSwapActions = new List<MoveItem>();
  3707. foreach(var wafer in nearlyReadyReturnWafers)
  3708. {
  3709. if(CanWaferGotoLL(wafer, llPath) && returnCount < Math.Min(llWaferStatus.tInSlot.Count, 2))
  3710. {
  3711. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, 0, ModuleName.TMRobot, returnCount, (Hand)returnCount) });
  3712. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, returnCount, llPath, llWaferStatus.tInSlot[returnCount], (Hand)returnCount));
  3713. returnCount++;
  3714. }
  3715. }
  3716. int pickCount = 0;
  3717. foreach(var slot in llWaferStatus.tOutSlot)
  3718. {
  3719. if (pickCount < 2)
  3720. {
  3721. llSwapActions.Add(new MoveItem(llPath, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3722. pickCount++;
  3723. }
  3724. }
  3725. if(llSwapActions.Count > 0)
  3726. {
  3727. _tmSchdActions.Enqueue(llSwapActions);
  3728. }
  3729. return;
  3730. }
  3731. }
  3732. }
  3733. }
  3734. }
  3735. private bool IsTMRobotArmNotReserved(Hand hand)
  3736. {
  3737. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)hand) || _lstWaferTasks.Exists(wt => wt.currentMod == ModuleName.TMRobot && wt.currentSlot == (int)hand))
  3738. return false;
  3739. foreach(var acs in _tmSchdActions)
  3740. {
  3741. foreach(var ac in acs)
  3742. {
  3743. if ((ac.DestinationModule == ModuleName.TMRobot || ac.SourceModule == ModuleName.TMRobot) && ac.DestinationSlot == (int)hand)
  3744. return false;
  3745. }
  3746. }
  3747. return true;
  3748. }
  3749. private Hand SelectTMPickArm(ModuleName mod)
  3750. {
  3751. switch (_tmRobotSingleArmOption)
  3752. {
  3753. case 0:
  3754. {
  3755. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3756. return Hand.Blade1;
  3757. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3758. return Hand.Blade2;
  3759. }
  3760. break;
  3761. case 1:
  3762. {
  3763. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3764. return Hand.Blade1;
  3765. }
  3766. break;
  3767. case 2:
  3768. {
  3769. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3770. return Hand.Blade2;
  3771. }
  3772. break;
  3773. // Blade1 In Blade2 Out
  3774. case 3:
  3775. {
  3776. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3777. return Hand.Blade1;
  3778. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3779. return Hand.Blade2;
  3780. }
  3781. break;
  3782. // Blade2 In Blade1 Out
  3783. case 4:
  3784. {
  3785. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3786. return Hand.Blade2;
  3787. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3788. return Hand.Blade1;
  3789. }
  3790. break;
  3791. }
  3792. return Hand.None;
  3793. }
  3794. private List<Hand> GetTMFreeHand()
  3795. {
  3796. var lstHands = new List<Hand>();
  3797. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  3798. lstHands.Add(Hand.Blade1);
  3799. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  3800. lstHands.Add(Hand.Blade2);
  3801. return lstHands;
  3802. }
  3803. private List<Hand> GetEFEMFreeHand()
  3804. {
  3805. var lstHands = new List<Hand>();
  3806. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && _efemRobotSingleArmOption != 2)
  3807. lstHands.Add(Hand.Blade1);
  3808. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && _efemRobotSingleArmOption != 1)
  3809. lstHands.Add(Hand.Blade2);
  3810. return lstHands;
  3811. }
  3812. private bool CanWaferGotoLL(WaferTask task, ModuleName ll)
  3813. {
  3814. bool bVacWafer = ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod);
  3815. if (bVacWafer)
  3816. {
  3817. if (ModuleHelper.IsPm(task.destMod))
  3818. return false;
  3819. switch (task.llInOutPath)
  3820. {
  3821. case SequenceLLInOutPath.AInAOut:
  3822. case SequenceLLInOutPath.BInAOut:
  3823. return ll == ModuleName.LLA;
  3824. case SequenceLLInOutPath.AInBOut:
  3825. case SequenceLLInOutPath.BInBOut:
  3826. return ll == ModuleName.LLB;
  3827. case SequenceLLInOutPath.DInDOut:
  3828. return true;
  3829. }
  3830. }
  3831. else
  3832. {
  3833. if (ModuleHelper.IsLoadPort(task.destMod))
  3834. return false;
  3835. switch (task.llInOutPath)
  3836. {
  3837. case SequenceLLInOutPath.AInAOut:
  3838. case SequenceLLInOutPath.AInBOut:
  3839. return ll == ModuleName.LLA;
  3840. case SequenceLLInOutPath.BInAOut:
  3841. case SequenceLLInOutPath.BInBOut:
  3842. return ll == ModuleName.LLB;
  3843. case SequenceLLInOutPath.DInDOut:
  3844. return true;
  3845. }
  3846. }
  3847. return false;
  3848. }
  3849. private (List<int> inSlot, List<int> outSlot, List<int> emptySlot) GetLLReadyInOutSlots(ModuleName ll)
  3850. {
  3851. var readInSlots = new List<int>();
  3852. var readyOutSlots = new List<int>();
  3853. var emptySlots = new List<int>();
  3854. for(int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3855. {
  3856. if(WaferManager.Instance.CheckNoWafer(ll, slot) && !_lstWaferTasks.Exists(wafer => (wafer.routedMod == ll && wafer.routedSlot == slot) || (wafer.currentMod == ll && wafer.currentSlot == slot) || (wafer.nextMod == ll && wafer.nextSlot == slot)))
  3857. {
  3858. emptySlots.Add(slot);
  3859. }
  3860. if(WaferManager.Instance.CheckHasWafer(ll, slot))
  3861. {
  3862. Guid waferID = WaferManager.Instance.GetWafer(ll, slot).InnerId;
  3863. var waferTask = _lstWaferTasks.Find(wafer => wafer.waferId == waferID);
  3864. if(waferTask != null && waferTask.movingStatus == RState.End)
  3865. {
  3866. if (ModuleHelper.IsPm(waferTask.destMod))
  3867. readInSlots.Add(slot);
  3868. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3869. readyOutSlots.Add(slot);
  3870. }
  3871. }
  3872. }
  3873. return (readInSlots, readyOutSlots, emptySlots);
  3874. }
  3875. private (List<int> eInSlot, List<int> eOutSlot, List<int> tInSlot, List<int> tOutSlot) GetLLFixedReadyInOutSlots(ModuleName ll)
  3876. {
  3877. var eInSlot = new List<int>();
  3878. var eOutSlot = new List<int>();
  3879. var tInSlot = new List<int>();
  3880. var tOutSlot = new List<int>();
  3881. int SlotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  3882. for (int slot = 0; slot < SlotNumber; slot++)
  3883. {
  3884. if (WaferManager.Instance.CheckNoWafer(ll, slot) && !_lstWaferTasks.Exists(wafer => (wafer.routedMod == ll && wafer.routedSlot == slot) || (wafer.currentMod == ll && wafer.currentSlot == slot) || (wafer.nextMod == ll && wafer.nextSlot == slot)))
  3885. {
  3886. if ((slot >= SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.UpperInLowerOut) ||
  3887. (slot < SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.LowerInUpperOut))
  3888. {
  3889. eInSlot.Add(slot);
  3890. }
  3891. else
  3892. {
  3893. tInSlot.Add(slot);
  3894. }
  3895. }
  3896. if (WaferManager.Instance.CheckHasWafer(ll, slot))
  3897. {
  3898. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3899. var waferTask = _lstWaferTasks.Find(wt => wt.waferId == wafer.InnerId && wt.currentMod == ll && wt.currentSlot == slot);
  3900. if(waferTask == null)
  3901. {
  3902. LOG.Write(eEvent.EV_ROUTER, ll, $"Routing trace: did not find inner task associated with {wafer.WaferOrigin} at {ll}.{slot + 1}");
  3903. }
  3904. else if (waferTask.movingStatus == RState.End)
  3905. {
  3906. if (ModuleHelper.IsPm(waferTask.destMod))
  3907. tOutSlot.Add(slot);
  3908. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3909. eOutSlot.Add(slot);
  3910. }
  3911. }
  3912. }
  3913. return (eInSlot, eOutSlot, tInSlot, tOutSlot);
  3914. }
  3915. private (List<WaferInfo> wafers, List<int> emptySlots) GetLLWaferExistance(ModuleName ll)
  3916. {
  3917. var lstWafers = new List<WaferInfo>();
  3918. var lstEmptySlots = new List<int>();
  3919. for (int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3920. {
  3921. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3922. if(wafer != null && !wafer.IsEmpty)
  3923. {
  3924. lstWafers.Add(wafer);
  3925. }
  3926. else
  3927. {
  3928. lstEmptySlots.Add(slot);
  3929. }
  3930. }
  3931. return (lstWafers, lstEmptySlots);
  3932. }
  3933. private void PrepareLLPressure()
  3934. {
  3935. if (RouteManager.IsATMMode)
  3936. return;
  3937. var schdPumpingLLs = new List<ModuleName>();
  3938. var schdVentingLLs = new List<ModuleName>();
  3939. var schdCoolingLLs = new List<ModuleName>();
  3940. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  3941. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  3942. // pre pumping/venting for schedule actions
  3943. if (_efemSchdActions.Count > 0)
  3944. {
  3945. var ventLLs = _efemSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3946. foreach(var ll in ventLLs)
  3947. {
  3948. if (!schdVentingLLs.Contains(ll))
  3949. schdVentingLLs.Add(ll);
  3950. }
  3951. }
  3952. if(_tmSchdActions.Count > 0)
  3953. {
  3954. var pumpLLs = _tmSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3955. foreach(var ll in pumpLLs)
  3956. {
  3957. if (!schdPumpingLLs.Contains(ll))
  3958. schdPumpingLLs.Add(ll);
  3959. }
  3960. }
  3961. // loadlock in out path advance check
  3962. if (_LLInOutPath == SequenceLLInOutPath.AInBOut)
  3963. {
  3964. if(llaWaferStatus.emptySlot.Count == _LLASlotNumber)
  3965. {
  3966. if (!schdVentingLLs.Contains(ModuleName.LLA))
  3967. schdVentingLLs.Add(ModuleName.LLA);
  3968. }
  3969. else if ((llaWaferStatus.inSlot.Count == _LLASlotNumber) ||
  3970. (llaWaferStatus.inSlot.Count > 0 && llaWaferStatus.inSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  3971. {
  3972. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  3973. schdPumpingLLs.Add(ModuleName.LLA);
  3974. }
  3975. if(llbWaferStatus.emptySlot.Count == _LLBSlotNumber)
  3976. {
  3977. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  3978. schdPumpingLLs.Add(ModuleName.LLB);
  3979. }
  3980. else if ((llbWaferStatus.outSlot.Count == _LLBSlotNumber) ||
  3981. (llbWaferStatus.outSlot.Count > 0 && llbWaferStatus.outSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) || ModuleHelper.IsTMRobot(wt.currentMod)) == 0))
  3982. {
  3983. schdCoolingLLs.Add(ModuleName.LLB);
  3984. }
  3985. }
  3986. else if(_LLInOutPath == SequenceLLInOutPath.BInAOut)
  3987. {
  3988. if (llbWaferStatus.emptySlot.Count == _LLBSlotNumber)
  3989. {
  3990. if (!schdVentingLLs.Contains(ModuleName.LLA))
  3991. schdVentingLLs.Add(ModuleName.LLB);
  3992. }
  3993. else if ((llbWaferStatus.inSlot.Count == _LLBSlotNumber) ||
  3994. (llbWaferStatus.inSlot.Count > 0 && llbWaferStatus.inSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  3995. {
  3996. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  3997. schdPumpingLLs.Add(ModuleName.LLB);
  3998. }
  3999. if (llaWaferStatus.emptySlot.Count == _LLASlotNumber)
  4000. {
  4001. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  4002. schdPumpingLLs.Add(ModuleName.LLA);
  4003. }
  4004. else if ((llaWaferStatus.outSlot.Count == _LLASlotNumber) ||
  4005. (llaWaferStatus.outSlot.Count > 0 && llaWaferStatus.outSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod)) == 0))
  4006. {
  4007. schdCoolingLLs.Add(ModuleName.LLA);
  4008. }
  4009. }
  4010. else
  4011. {
  4012. if ((llaWaferStatus.inSlot.Count == _LLASlotNumber) ||
  4013. (llaWaferStatus.inSlot.Count > 0 && llaWaferStatus.inSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  4014. {
  4015. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  4016. schdPumpingLLs.Add(ModuleName.LLA);
  4017. }
  4018. else if ((llaWaferStatus.outSlot.Count == _LLASlotNumber) ||
  4019. (llaWaferStatus.outSlot.Count > 0 && llaWaferStatus.outSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod)) == 0))
  4020. {
  4021. if (!schdVentingLLs.Contains(ModuleName.LLA))
  4022. schdCoolingLLs.Add(ModuleName.LLA);
  4023. }
  4024. if ((llbWaferStatus.inSlot.Count == _LLBSlotNumber) ||
  4025. (llbWaferStatus.inSlot.Count > 0 && llbWaferStatus.inSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  4026. {
  4027. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  4028. schdPumpingLLs.Add(ModuleName.LLB);
  4029. }
  4030. else if ((llbWaferStatus.outSlot.Count == _LLBSlotNumber) ||
  4031. (llbWaferStatus.outSlot.Count > 0 && llbWaferStatus.outSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod)) == 0))
  4032. {
  4033. if (!schdVentingLLs.Contains(ModuleName.LLB))
  4034. schdCoolingLLs.Add(ModuleName.LLB);
  4035. }
  4036. }
  4037. foreach (var ventLL in schdVentingLLs)
  4038. {
  4039. if (_dictModuleTask[ventLL].Scheduler.IsAvailable && !_dictModuleTask[ventLL].Scheduler.IsAtm && !schdCoolingLLs.Contains(ventLL))
  4040. (_dictModuleTask[ventLL] as LoadlockTask).PreVent();
  4041. }
  4042. foreach (var pumpLL in schdPumpingLLs)
  4043. {
  4044. if (_dictModuleTask[pumpLL].Scheduler.IsAvailable && !_dictModuleTask[pumpLL].Scheduler.IsVac && !schdVentingLLs.Contains(pumpLL))
  4045. (_dictModuleTask[pumpLL] as LoadlockTask).PrePump();
  4046. }
  4047. foreach (var coolLL in schdCoolingLLs)
  4048. {
  4049. if (_dictModuleTask[coolLL].Scheduler.IsOnline && !_dictModuleTask[coolLL].Scheduler.IsAtm)
  4050. (_dictModuleTask[coolLL] as LoadlockTask).Cooling();
  4051. }
  4052. }
  4053. private void ReturnVacWafers()
  4054. {
  4055. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  4056. {
  4057. RunSchdTMReturnActions();
  4058. return;
  4059. }
  4060. if (_tmRobotStatus != RState.End)
  4061. return;
  4062. var hands = GetTMFreeHand();
  4063. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && !IsLLReservedByEFEM(mod.Key) && mod.Value.Scheduler.IsIdle && mod.Value.Scheduler.IsInclude && GetLLWaferExistance(mod.Key).emptySlots.Count > 0).OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).emptySlot.Count);
  4064. if(lls.Count() > 0)
  4065. {
  4066. // return robot wafers
  4067. int moveCount = 0;
  4068. var llActions = new List<MoveItem>();
  4069. var emptySlots = GetLLWaferExistance(lls.First().Key).emptySlots;
  4070. for(int arm = 0; arm < 2; arm++)
  4071. {
  4072. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, arm);
  4073. if(wafer != null && !wafer.IsEmpty && moveCount < emptySlots.Count)
  4074. {
  4075. llActions.Add(new MoveItem(ModuleName.TMRobot, arm, lls.First().Key, emptySlots[moveCount], (Hand)arm));
  4076. moveCount++;
  4077. }
  4078. }
  4079. if(moveCount > 0)
  4080. {
  4081. _tmSchdActions.Enqueue(llActions);
  4082. return;
  4083. }
  4084. // return PM wafers
  4085. var PickActions = new List<MoveItem>();
  4086. var hasWaferPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsIdle && mod.Value.Scheduler.IsInclude && WaferManager.Instance.CheckHasWafer(mod.Key, 0));
  4087. foreach(var pm in hasWaferPMs)
  4088. {
  4089. if (moveCount < hands.Count && moveCount < emptySlots.Count)
  4090. {
  4091. PickActions.Add(new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)hands[moveCount], hands[moveCount]));
  4092. llActions.Add(new MoveItem(ModuleName.TMRobot, (int)hands[moveCount], lls.First().Key, emptySlots[moveCount], hands[moveCount]));
  4093. moveCount++;
  4094. }
  4095. }
  4096. if(moveCount > 0)
  4097. {
  4098. foreach(var ac in PickActions)
  4099. {
  4100. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  4101. }
  4102. _tmSchdActions.Enqueue(llActions);
  4103. }
  4104. }
  4105. }
  4106. private void ReturnAtmWafers()
  4107. {
  4108. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  4109. {
  4110. RunSchdEFEMReturnActions();
  4111. return;
  4112. }
  4113. if (_efemRobotStatus != RState.End)
  4114. return;
  4115. // return Robot Wafer
  4116. for(int i = 0; i < 2; i++)
  4117. {
  4118. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  4119. if(wafer != null && !wafer.IsEmpty)
  4120. {
  4121. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  4122. }
  4123. }
  4124. if (_efemSchdActions.Count > 0)
  4125. return;
  4126. var hands = GetEFEMFreeHand();
  4127. // return Aligner wafer
  4128. var aligner = ModuleHelper.InstalledModules.Where(mod => ModuleHelper.IsAligner(mod)).ToList();
  4129. if(aligner.Count > 0 && WaferManager.Instance.CheckHasWafer(aligner.First(), 0) && hands.Count > 0)
  4130. {
  4131. var wafer = WaferManager.Instance.GetWafer(aligner.First(), 0);
  4132. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(aligner.First(), 0, ModuleName.EfemRobot, (int)hands.First(), hands.First()) });
  4133. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)hands.First(), (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands.First()) });
  4134. return;
  4135. }
  4136. // return Loadlock wafer
  4137. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && !IsLLReservedByTM(mod.Key) && mod.Value.Scheduler.IsIdle && GetLLWaferExistance(mod.Key).wafers.Count > 0).OrderByDescending(mod => GetLLWaferExistance(mod.Key).wafers.Count);
  4138. if(lls.Count() > 0)
  4139. {
  4140. int returnCount = 0;
  4141. var llActions = new List<MoveItem>();
  4142. var placActions = new List<MoveItem>();
  4143. foreach(var wafer in GetLLWaferExistance(lls.First().Key).wafers)
  4144. {
  4145. if(returnCount < hands.Count)
  4146. {
  4147. llActions.Add(new MoveItem(lls.First().Key, wafer.Slot, ModuleName.EfemRobot, (int)hands[returnCount], hands[returnCount]));
  4148. placActions.Add(new MoveItem(ModuleName.EfemRobot, (int)hands[returnCount], (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands[returnCount]));
  4149. returnCount++;
  4150. }
  4151. }
  4152. if (returnCount > 0)
  4153. {
  4154. _efemSchdActions.Enqueue(llActions);
  4155. foreach (var ac in placActions)
  4156. {
  4157. _efemSchdActions.Enqueue(new List<MoveItem> { ac });
  4158. }
  4159. }
  4160. }
  4161. }
  4162. private void RunSchdEFEMReturnActions()
  4163. {
  4164. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  4165. if (efemRobot == null || !efemRobot.IsAvailable)
  4166. return;
  4167. if (_efemSchdActions.Count > 0)
  4168. {
  4169. if (_curEfemAction.Count == 0 || isReturnActionsDone(_curEfemAction))
  4170. {
  4171. var nextActions = _efemSchdActions.First();
  4172. var nextModule = nextActions.First().Module;
  4173. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  4174. return;
  4175. _curEfemAction = _efemSchdActions.Dequeue();
  4176. efemRobot.PostMoveItems(_curEfemAction.ToArray());
  4177. }
  4178. }
  4179. else if (_curEfemAction.Count >= 0 && isReturnActionsDone(_curEfemAction)) // all scheduled actions done
  4180. {
  4181. _curEfemAction.Clear();
  4182. }
  4183. }
  4184. private void RunSchdTMReturnActions()
  4185. {
  4186. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerTMRobot;
  4187. if (tmRobot == null || !tmRobot.IsAvailable)
  4188. return;
  4189. if (_tmSchdActions.Count > 0)
  4190. {
  4191. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  4192. {
  4193. var nextActions = _tmSchdActions.First();
  4194. var nextModule = nextActions.First().Module;
  4195. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  4196. return;
  4197. _curTmAction = _tmSchdActions.Dequeue();
  4198. tmRobot.SendMoveItems(_curTmAction.ToArray());
  4199. }
  4200. }
  4201. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  4202. {
  4203. _curTmAction.Clear();
  4204. }
  4205. }
  4206. #endregion
  4207. #region sequence/recipe operation
  4208. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  4209. {
  4210. reason = "";
  4211. foreach(var pm in seq.PMs)
  4212. {
  4213. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  4214. return true;
  4215. }
  4216. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  4217. return false;
  4218. }
  4219. private bool CheckSequenceKepler2200TemperatureReady(SequenceInfo seq)
  4220. {
  4221. for (int i = 0; i < seq.Steps.Count; i++)
  4222. {
  4223. SequenceStepInfo stepInfo = seq.Steps[i];
  4224. foreach (var module in stepInfo.StepModules)
  4225. {
  4226. if (ModuleHelper.IsPm(module))
  4227. {
  4228. string attr = $"{module}Recipe";
  4229. if (stepInfo.StepParameter.ContainsKey(attr)
  4230. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4231. {
  4232. var recipeName = (string)stepInfo.StepParameter[attr];
  4233. var recipeContent =
  4234. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4235. var recipe = Recipe.Load(recipeContent);
  4236. float currentChamberTemperature;
  4237. switch (module)
  4238. {
  4239. case ModuleName.PMA:
  4240. currentChamberTemperature = Singleton<RouteManager>.Instance.PMA.ChamberTemperature;
  4241. break;
  4242. case ModuleName.PMB:
  4243. currentChamberTemperature = Singleton<RouteManager>.Instance.PMB.ChamberTemperature;
  4244. break;
  4245. case ModuleName.PMC:
  4246. currentChamberTemperature = Singleton<RouteManager>.Instance.PMC.ChamberTemperature;
  4247. break;
  4248. case ModuleName.PMD:
  4249. currentChamberTemperature = Singleton<RouteManager>.Instance.PMD.ChamberTemperature;
  4250. break;
  4251. default:
  4252. currentChamberTemperature = 0;
  4253. break;
  4254. }
  4255. if (recipe.Header.Temperature != null && recipe.Header.Temperature != "" && (currentChamberTemperature > Convert.ToSingle(recipe.Header.Temperature) + 10 || currentChamberTemperature < Convert.ToSingle(recipe.Header.Temperature) - 10))
  4256. {
  4257. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Start job失败,由于{module}腔体温度{currentChamberTemperature}与{recipeName} Recipe温度{recipe.Header.Temperature}不匹配");
  4258. return false;
  4259. }
  4260. }
  4261. }
  4262. }
  4263. }
  4264. return true;
  4265. }
  4266. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  4267. {
  4268. for (int i = 0; i < seq.Steps.Count; i++)
  4269. {
  4270. SequenceStepInfo stepInfo = seq.Steps[i];
  4271. foreach (var module in stepInfo.StepModules)
  4272. {
  4273. if (ModuleHelper.IsPm(module))
  4274. {
  4275. string attr = $"{module}Recipe";
  4276. if (stepInfo.StepParameter.ContainsKey(attr)
  4277. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4278. {
  4279. var recipeName = (string)stepInfo.StepParameter[attr];
  4280. if (!string.IsNullOrWhiteSpace(recipeName))
  4281. {
  4282. var recipeContent =
  4283. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4284. if (string.IsNullOrWhiteSpace(recipeContent))
  4285. {
  4286. reason = $"Can not find recipe file{recipeName}";
  4287. return false;
  4288. }
  4289. }
  4290. }
  4291. }
  4292. }
  4293. }
  4294. reason = "";
  4295. return true;
  4296. }
  4297. private void UpdateLLInOutPathProperty()
  4298. {
  4299. if (_lstControlJobs.Count == 0)
  4300. return;
  4301. var inOutPaths = new List<SequenceLLInOutPath>();
  4302. foreach(var wt in _lstWaferTasks)
  4303. {
  4304. if (!inOutPaths.Contains(wt.llInOutPath))
  4305. inOutPaths.Add(wt.llInOutPath);
  4306. }
  4307. if (inOutPaths.Count == 1)
  4308. {
  4309. _LLInOutPath = inOutPaths[0];
  4310. }
  4311. else
  4312. _LLInOutPath = SequenceLLInOutPath.DInDOut;
  4313. }
  4314. private bool GetAllJobRecipe(List<string> InUseRecipes, ControlJobInfo cj,SequenceInfo seq)
  4315. {
  4316. for (int i = 0; i < seq.Steps.Count; i++)
  4317. {
  4318. SequenceStepInfo stepInfo = seq.Steps[i];
  4319. foreach (var module in stepInfo.StepModules)
  4320. {
  4321. if (ModuleHelper.IsPm(module))
  4322. {
  4323. string attr = $"{module}Recipe";
  4324. if (stepInfo.StepParameter.ContainsKey(attr)
  4325. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4326. {
  4327. var recipeName = (string)stepInfo.StepParameter[attr];
  4328. var recipeContent =
  4329. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4330. var recipe = Recipe.Load(recipeContent);
  4331. if (recipe.Header.ChuckRecipe != null && recipe.Header.ChuckRecipe != "")
  4332. {
  4333. InUseRecipes.Add($"{module}.ChuckRecipe.{recipe.Header.ChuckRecipe}");
  4334. }
  4335. if (recipe.Header.DechuckRecipe != null && recipe.Header.DechuckRecipe != "")
  4336. {
  4337. InUseRecipes.Add($"{module}.DechuckRecipe.{recipe.Header.DechuckRecipe}");
  4338. }
  4339. InUseRecipes.Add($"{module}.Process.{recipeName}");
  4340. if (cj.PreJobClean != "")
  4341. {
  4342. InUseRecipes.Add($"{module}.Clean.{cj.PreJobClean}");
  4343. }
  4344. if (cj.PostJobClean != "")
  4345. {
  4346. InUseRecipes.Add($"{module}.Clean.{cj.PostJobClean}");
  4347. }
  4348. if (stepInfo.StepParameter["WTWClean"].ToString() != "")
  4349. {
  4350. InUseRecipes.Add($"{module}.Clean.{stepInfo.StepParameter["WTWClean"]}");
  4351. }
  4352. }
  4353. }
  4354. }
  4355. }
  4356. return true;
  4357. }
  4358. private bool IsSequenceNeedAlign(SequenceInfo sequence)
  4359. {
  4360. // check wether need align
  4361. foreach (var step in sequence.Steps)
  4362. {
  4363. foreach(var mod in step.StepModules)
  4364. {
  4365. if(ModuleHelper.IsAligner(mod))
  4366. return true;
  4367. }
  4368. }
  4369. return false;
  4370. }
  4371. #endregion
  4372. }
  4373. }