SystemDispatcher.cs 220 KB

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