SystemDispatcher.cs 220 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904
  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) && _lstWaferTasks.Count(wt => ModuleHelper.IsTMRobot(wt.currentMod)) == 0)
  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. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waferTask.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2837. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL.First().Key, slot, hands.First()) });
  2838. _qeReturnWafers.Dequeue();
  2839. return true;
  2840. }
  2841. }
  2842. }
  2843. return false;
  2844. }
  2845. private void RoutingVacWafers()
  2846. {
  2847. if(_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2848. {
  2849. RunSchdTMActions();
  2850. return;
  2851. }
  2852. if(_tmRobotStatus == RState.End)
  2853. {
  2854. // handle manual return wafer if exist
  2855. if(_qeReturnWafers.Count > 0)
  2856. {
  2857. if (ManaulReturnPMWafer())
  2858. return;
  2859. }
  2860. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2861. {
  2862. if (_LLASlotNumber == 2)
  2863. {
  2864. Routing2SlotVacSystem();
  2865. }
  2866. else if (_LLASlotNumber == 4)
  2867. {
  2868. Routing4SlotVacSystem();
  2869. }
  2870. }
  2871. else
  2872. {
  2873. RoutingFixedSlotVacSystem();
  2874. }
  2875. }
  2876. }
  2877. private void Routing2SlotVacSystem()
  2878. {
  2879. var robotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2880. var freeHands = GetTMFreeHand();
  2881. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2882. {
  2883. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2884. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2885. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2886. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2887. var inLLModule = _dictModuleTask[inLL] as LoadlockTask;
  2888. var outLLModule = _dictModuleTask[outLL] as LoadlockTask;
  2889. if(robotWafers.Count == 0)
  2890. {
  2891. #region special routing pattern
  2892. if (_specialRoutingPattern != SpecialRoutingPattern.Disable)
  2893. {
  2894. if(_specialRoutingPattern == SpecialRoutingPattern.LongTimeRecipe && freeHands.Count == 2)
  2895. {
  2896. if(_dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).Count() == 0 && inLLWaferStatus.inSlot.Count > 0)
  2897. {
  2898. var readyOutPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 25).OrderBy(mod => mod.Value.TimeToReady).ToList();
  2899. if(readyOutPMs.Count > 0 && inLLModule.ReayForTMInTime(5) && _lstWaferTasks.Exists(wt => wt.currentMod == inLL && readyOutPMs.Exists(kv => kv.Key == wt.destMod)))
  2900. {
  2901. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.destMod == readyOutPMs.First().Key);
  2902. if(llWafer != null)
  2903. {
  2904. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  2905. var pmSwap = new List<MoveItem>
  2906. { new MoveItem(readyOutPMs.First().Key, 0, ModuleName.TMRobot, (int)freeHands[1], freeHands[1]),
  2907. new MoveItem(ModuleName.TMRobot, (int)freeHands[0], readyOutPMs.First().Key, 0, freeHands[0])
  2908. };
  2909. _tmSchdActions.Enqueue(pmSwap);
  2910. if(outLLModule.ReayForTMInTime(25) && outLLWaferStatus.emptySlot.Count > 0)
  2911. {
  2912. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[1], outLL, outLLWaferStatus.emptySlot[0], freeHands[1]) });
  2913. }
  2914. }
  2915. }
  2916. return;
  2917. }
  2918. }
  2919. }
  2920. #endregion
  2921. if (_dictModuleTask.Count(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 5) > 0 && outLLModule.ReayForTMInTime(30) && outLLWaferStatus.emptySlot.Count > 0)
  2922. {
  2923. var readyOutPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 25).OrderBy(mod => mod.Value.TimeToReady).ToList();
  2924. var placeActions = new List<MoveItem>();
  2925. int pickCount = 0;
  2926. foreach (var pm in readyOutPMs)
  2927. {
  2928. var pmWafer = _lstWaferTasks.Find(wt => wt.currentMod == pm.Key);
  2929. if (pmWafer != null && pickCount < freeHands.Count && pickCount < outLLWaferStatus.emptySlot.Count)
  2930. {
  2931. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)freeHands[pickCount], freeHands[pickCount]) });
  2932. placeActions.Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[pickCount], outLL, outLLWaferStatus.emptySlot[pickCount], freeHands[pickCount]));
  2933. pickCount++;
  2934. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, pm.Key, $"{pm.Key} will be ready in {pm.Value.TimeToReady} seconds");
  2935. }
  2936. }
  2937. if (pickCount > 0)
  2938. {
  2939. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  2940. _tmSchdActions.Enqueue(placeActions);
  2941. return;
  2942. }
  2943. }
  2944. // push wafer from LL to PM and avoid blocking two robot arms
  2945. if (inLLModule.ReayForTMInTime(10) && inLLWaferStatus.inSlot.Count > 0)
  2946. {
  2947. var pickActions = new List<MoveItem>();
  2948. var inLLWafers = _lstWaferTasks.FindAll(wt => wt.currentMod == inLL).ToList();
  2949. if (inLLWaferStatus.inSlot.Count < 2 || inLLWafers.Exists(wt => !_dictModuleTask[wt.destMod].HasWafer && _dictModuleTask[wt.destMod].TimeToReady < 20))
  2950. {
  2951. for (int i = 0; i < Math.Min(inLLWaferStatus.inSlot.Count, freeHands.Count); i++)
  2952. {
  2953. pickActions.Add(new MoveItem(inLL, inLLWaferStatus.inSlot[i], ModuleName.TMRobot, (int)freeHands[i], freeHands[i]));
  2954. }
  2955. }
  2956. if(pickActions.Count > 0)
  2957. {
  2958. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  2959. _tmSchdActions.Enqueue(pickActions);
  2960. return;
  2961. }
  2962. }
  2963. }
  2964. else
  2965. {
  2966. #region special routing pattern
  2967. if (_specialRoutingPattern != SpecialRoutingPattern.Disable)
  2968. {
  2969. if (_specialRoutingPattern == SpecialRoutingPattern.LongTimeRecipe && _tmRobotSingleArmOption == 0)
  2970. {
  2971. if(_dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).Count() == 0 && ModuleHelper.IsLoadPort(robotWafers[0].destMod))
  2972. {
  2973. if (outLLModule.ReayForTMInTime(10) && outLLWaferStatus.emptySlot.Count > 0)
  2974. {
  2975. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)(robotWafers[0].currentSlot)) });
  2976. }
  2977. return;
  2978. }
  2979. }
  2980. }
  2981. #endregion
  2982. foreach (var robotWafer in robotWafers)
  2983. {
  2984. if (ModuleHelper.IsPm(robotWafer.destMod))
  2985. {
  2986. if (_dictModuleTask[robotWafer.destMod].TimeToReady < 5)
  2987. {
  2988. if (_dictModuleTask[robotWafer.destMod].HasWafer)
  2989. {
  2990. // PM Swap
  2991. if (freeHands.Count > 0)
  2992. {
  2993. var pmActions = new List<MoveItem>
  2994. {
  2995. new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]),
  2996. new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot)
  2997. };
  2998. _tmSchdActions.Enqueue(pmActions);
  2999. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, robotWafer.destMod, $"{robotWafer.destMod} will be ready in {_dictModuleTask[robotWafer.destMod].TimeToReady} seconds");
  3000. return;
  3001. }
  3002. }
  3003. else
  3004. {
  3005. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, robotWafer.destMod, $"{robotWafer.destMod} will be ready in {_dictModuleTask[robotWafer.destMod].TimeToReady} seconds");
  3006. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3007. return;
  3008. }
  3009. }
  3010. else if (_dictModuleTask[robotWafer.destMod].TimeToReady > 20 && freeHands.Count > 0)
  3011. {
  3012. if (outLLWaferStatus.emptySlot.Count > 0 && outLLModule.ReayForTMInTime(10) && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)) > 0)
  3013. {
  3014. // try to return one wafer from PM to LL
  3015. var readyOutWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod));
  3016. if (readyOutWafer != null && _dictModuleTask[readyOutWafer.currentMod].TimeToReady < 5)
  3017. {
  3018. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, readyOutWafer.currentMod, $"{readyOutWafer.currentMod} will be ready in {_dictModuleTask[readyOutWafer.currentMod].TimeToReady} seconds");
  3019. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3020. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafer.currentMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3021. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot[0], freeHands[0]) });
  3022. return;
  3023. }
  3024. }
  3025. if (inLLModule.ReayForTMInTime(5) && inLLWaferStatus.inSlot.Count > 0)
  3026. {
  3027. var inLLWafers = _lstWaferTasks.FindAll(wt => wt.currentMod == inLL).OrderBy(wt => _dictModuleTask[wt.destMod].TimeToReady);
  3028. foreach (var inWafer in inLLWafers)
  3029. {
  3030. if (!_dictModuleTask[inWafer.destMod].HasWafer && _dictModuleTask[inWafer.destMod].TimeToReady < 10)
  3031. {
  3032. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inWafer.destMod, $"{inWafer.destMod} will be ready in {_dictModuleTask[inWafer.destMod].TimeToReady} seconds");
  3033. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3034. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inWafer.currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3035. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], inWafer.destMod, 0, freeHands[0]) });
  3036. return;
  3037. }
  3038. }
  3039. }
  3040. }
  3041. }
  3042. else
  3043. {
  3044. if (freeHands.Count > 0 &&
  3045. outLLWaferStatus.emptySlot.Count == 2 &&
  3046. outLLModule.ReayForTMInTime(10) &&
  3047. _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)) > 0 )
  3048. {
  3049. // try to get one wafer from PM, and match a double place next time
  3050. var readyOutWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod));
  3051. if(readyOutWafer != null && _dictModuleTask[readyOutWafer.currentMod].TimeToReady < 5)
  3052. {
  3053. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafer.currentMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3054. return;
  3055. }
  3056. }
  3057. if (outLLModule.ReayForTMInTime(5))
  3058. {
  3059. // try match a double place
  3060. if (robotWafers.Count == 2 && robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)) && outLLWaferStatus.emptySlot.Count == 2)
  3061. {
  3062. var doublePlace = new List<MoveItem>
  3063. {
  3064. new MoveItem(ModuleName.TMRobot, 0, outLL, 0, Hand.Blade1),
  3065. new MoveItem(ModuleName.TMRobot, 1, outLL, 1, Hand.Blade2)
  3066. };
  3067. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3068. _tmSchdActions.Enqueue(doublePlace);
  3069. return;
  3070. }
  3071. if(outLLWaferStatus.emptySlot.Count > 0)
  3072. {
  3073. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3074. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)robotWafer.currentSlot) });
  3075. return;
  3076. }
  3077. }
  3078. }
  3079. }
  3080. if (freeHands.Count == 0)
  3081. return;
  3082. // try to push one wafer in pm
  3083. if(inLLWaferStatus.inSlot.Count == 1 && inLLModule.ReayForTMInTime(5))
  3084. {
  3085. var inWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == inLLWaferStatus.inSlot.First());
  3086. if(inWafer != null && !_dictModuleTask[inWafer.destMod].HasWafer && _dictModuleTask[inWafer.destMod].TimeToReady < 20)
  3087. {
  3088. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inWafer.destMod, $"{inWafer.destMod} will be ready in {_dictModuleTask[inWafer.destMod].TimeToReady} seconds");
  3089. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3090. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inLLWaferStatus.inSlot.First(), ModuleName.TMRobot, (int)freeHands[0], freeHands[0])});
  3091. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], inWafer.destMod, 0, freeHands[0]) });
  3092. return;
  3093. }
  3094. }
  3095. // try to return one wafer
  3096. if(outLLModule.ReayForTMInTime(15) && outLLWaferStatus.emptySlot.Count > 0)
  3097. {
  3098. var readyReturnPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 5).OrderBy(mod => mod.Value.TimeToReady).ToList();
  3099. if(readyReturnPMs.Count > 0)
  3100. {
  3101. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, readyReturnPMs.First().Key, $"{readyReturnPMs.First().Key} will be ready in {readyReturnPMs.First().Value.TimeToReady} seconds");
  3102. LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3103. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnPMs.First().Key, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3104. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot.First(), freeHands[0]) });
  3105. return;
  3106. }
  3107. }
  3108. }
  3109. }
  3110. else
  3111. {
  3112. if (robotWafers.Count == 2)
  3113. {
  3114. foreach (var wafer in robotWafers)
  3115. {
  3116. if (wafer.movingStatus == RState.End &&
  3117. ModuleHelper.IsPm(wafer.destMod) &&
  3118. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  3119. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  3120. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  3121. {
  3122. wafer.RouteTo(wafer.destMod, 0);
  3123. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3124. }
  3125. }
  3126. if (_tmSchdActions.Count == 0)
  3127. {
  3128. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3129. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3130. {
  3131. RoutingTMSwapActions(swapActions.swapActions);
  3132. _tmSchdActions.Enqueue(swapActions.swapActions);
  3133. }
  3134. }
  3135. }
  3136. else if (robotWafers.Count == 1)
  3137. {
  3138. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  3139. {
  3140. var pmActions = new List<MoveItem>();
  3141. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  3142. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  3143. {
  3144. int pickSlot = 1 - robotWafers[0].currentSlot;
  3145. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  3146. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  3147. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  3148. _tmSchdActions.Enqueue(pmActions);
  3149. return;
  3150. }
  3151. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  3152. {
  3153. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  3154. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  3155. _tmSchdActions.Enqueue(pmActions);
  3156. return;
  3157. }
  3158. }
  3159. // try to pick a wafer from LL
  3160. if (_tmSchdActions.Count == 0)
  3161. {
  3162. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3163. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3164. {
  3165. RoutingTMSwapActions(swapActions.swapActions);
  3166. _tmSchdActions.Enqueue(swapActions.swapActions);
  3167. return;
  3168. }
  3169. }
  3170. // try to return a wafer from PM
  3171. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3172. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3173. if (moveActions.pmWafers.Count > 0)
  3174. {
  3175. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3176. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  3177. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  3178. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  3179. if (pickAction != null)
  3180. {
  3181. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  3182. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  3183. }
  3184. _tmSchdActions.Enqueue(moveActions.swapAction);
  3185. }
  3186. }
  3187. else // robot arm is empty
  3188. {
  3189. // try return wafers from PM
  3190. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3191. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3192. if (moveActions.pmWafers.Count > 0)
  3193. {
  3194. int handIndex = 0;
  3195. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3196. foreach (var action in placeActions)
  3197. {
  3198. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3199. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3200. handIndex++;
  3201. }
  3202. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3203. foreach (var ac in pickActions)
  3204. {
  3205. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3206. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3207. }
  3208. _tmSchdActions.Enqueue(moveActions.swapAction);
  3209. }
  3210. if (_tmSchdActions.Count == 0)
  3211. {
  3212. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3213. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3214. {
  3215. RoutingTMSwapActions(swapActions.swapActions);
  3216. _tmSchdActions.Enqueue(swapActions.swapActions);
  3217. }
  3218. }
  3219. }
  3220. }
  3221. }
  3222. private void Routing4SlotVacSystem()
  3223. {
  3224. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  3225. if (robotWafers.Count == 2)
  3226. {
  3227. foreach (var wafer in robotWafers)
  3228. {
  3229. if (wafer.movingStatus == RState.End &&
  3230. ModuleHelper.IsPm(wafer.destMod) &&
  3231. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  3232. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  3233. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  3234. {
  3235. wafer.RouteTo(wafer.destMod, 0);
  3236. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3237. }
  3238. }
  3239. if (_tmSchdActions.Count == 0)
  3240. {
  3241. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3242. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3243. {
  3244. RoutingTMSwapActions(swapActions.swapActions);
  3245. _tmSchdActions.Enqueue(swapActions.swapActions);
  3246. }
  3247. }
  3248. }
  3249. else if (robotWafers.Count == 1)
  3250. {
  3251. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  3252. {
  3253. var pmActions = new List<MoveItem>();
  3254. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  3255. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  3256. {
  3257. int pickSlot = 1 - robotWafers[0].currentSlot;
  3258. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  3259. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  3260. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  3261. _tmSchdActions.Enqueue(pmActions);
  3262. return;
  3263. }
  3264. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  3265. {
  3266. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  3267. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  3268. _tmSchdActions.Enqueue(pmActions);
  3269. return;
  3270. }
  3271. }
  3272. // try to pick a wafer from LL
  3273. if (_tmSchdActions.Count == 0)
  3274. {
  3275. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3276. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3277. {
  3278. RoutingTMSwapActions(swapActions.swapActions);
  3279. _tmSchdActions.Enqueue(swapActions.swapActions);
  3280. return;
  3281. }
  3282. }
  3283. // try to return a wafer from PM
  3284. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3285. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3286. if (moveActions.pmWafers.Count > 0)
  3287. {
  3288. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3289. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  3290. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  3291. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  3292. if (pickAction != null)
  3293. {
  3294. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  3295. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  3296. }
  3297. _tmSchdActions.Enqueue(moveActions.swapAction);
  3298. }
  3299. }
  3300. else // robot arm is empty
  3301. {
  3302. // try return wafers from PM
  3303. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3304. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3305. if (moveActions.pmWafers.Count > 0)
  3306. {
  3307. int handIndex = 0;
  3308. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3309. foreach (var action in placeActions)
  3310. {
  3311. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3312. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3313. handIndex++;
  3314. }
  3315. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3316. foreach (var ac in pickActions)
  3317. {
  3318. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3319. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3320. }
  3321. _tmSchdActions.Enqueue(moveActions.swapAction);
  3322. }
  3323. if (_tmSchdActions.Count == 0)
  3324. {
  3325. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3326. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3327. {
  3328. RoutingTMSwapActions(swapActions.swapActions);
  3329. _tmSchdActions.Enqueue(swapActions.swapActions);
  3330. }
  3331. }
  3332. }
  3333. }
  3334. private void RoutingFixedSlotVacSystem()
  3335. {
  3336. var robotWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod));
  3337. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  3338. if (_LLASlotNumber == 2)
  3339. {
  3340. if (robotWafers.Count() == 1)
  3341. {
  3342. if(ModuleHelper.IsPm(robotWafers.First().destMod))
  3343. {
  3344. var destPM = robotWafers.First().destMod;
  3345. if(_dictModuleTask[destPM].TimeToReady <= 5)
  3346. {
  3347. if(_lstWaferTasks.Exists(wt => wt.currentMod == destPM))
  3348. {
  3349. var pickHand = SelectTMPickArm(destPM);
  3350. if(pickHand != Hand.None)
  3351. {
  3352. var pmSwap = new List<MoveItem>
  3353. {
  3354. new MoveItem(destPM, 0, ModuleName.TMRobot, (int)pickHand, pickHand),
  3355. new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot)
  3356. };
  3357. _tmSchdActions.Enqueue(pmSwap);
  3358. return;
  3359. }
  3360. }
  3361. else
  3362. {
  3363. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot) });
  3364. return;
  3365. }
  3366. }
  3367. }
  3368. else
  3369. {
  3370. var readySwapLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3371. GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 &&
  3372. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3373. ll.Value.TimeToReady <= 10);
  3374. if (readySwapLL.Count() > 0)
  3375. {
  3376. var destLL = readySwapLL.First().Key;
  3377. Hand pickHand = SelectTMPickArm(destLL);
  3378. if (pickHand != Hand.None)
  3379. {
  3380. Hand placeHand = (Hand)robotWafers.First().currentSlot;
  3381. var llSwap = new List<MoveItem>();
  3382. var llSlots = GetLLFixedReadyInOutSlots(destLL);
  3383. llSwap.Add(new MoveItem(destLL, llSlots.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3384. llSwap.Add(new MoveItem(ModuleName.TMRobot, (int)placeHand, destLL, llSlots.tInSlot.First(), placeHand));
  3385. _tmSchdActions.Enqueue(llSwap);
  3386. return;
  3387. }
  3388. }
  3389. var emptyLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3390. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3391. ll.Value.TimeToReady <= 2);
  3392. if (emptyLL.Count() > 0)
  3393. {
  3394. var destLL = emptyLL.First().Key;
  3395. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem( ModuleName.TMRobot,
  3396. robotWafers.First().currentSlot,
  3397. destLL,
  3398. GetLLFixedReadyInOutSlots(destLL).tInSlot.First(),
  3399. (Hand)robotWafers.First().currentSlot) });
  3400. return;
  3401. }
  3402. }
  3403. // try to return a wafer
  3404. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3405. foreach(var pmWafer in readyReturnWafers)
  3406. {
  3407. 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);
  3408. if(readyLL.Count() > 0)
  3409. {
  3410. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3411. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3412. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand , readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3413. return;
  3414. }
  3415. }
  3416. // try to push in a wafer
  3417. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3418. foreach(var ll in readyInLL)
  3419. {
  3420. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3421. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3422. if( wafer != null &&
  3423. ModuleHelper.IsPm(wafer.destMod) &&
  3424. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3425. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3426. {
  3427. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3428. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3429. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3430. return;
  3431. }
  3432. }
  3433. }
  3434. else if (robotWafers.Count() == 0)
  3435. {
  3436. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  3437. if(readyReturnWafers.Count > 0)
  3438. {
  3439. // try to do a LL swap action
  3440. var readySwapLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 10);
  3441. foreach (var pmWafer in readyReturnWafers)
  3442. {
  3443. foreach (var ll in readySwapLL)
  3444. {
  3445. if (CanWaferGotoLL(pmWafer, ll.Key))
  3446. {
  3447. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3448. var pickHand = SelectTMPickArm(ll.Key);
  3449. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3450. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3451. var llSwapActions = new List<MoveItem>();
  3452. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, llWaferStatus.tInSlot.First(), returnHand));
  3453. llSwapActions.Add(new MoveItem(ll.Key, llWaferStatus.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3454. _tmSchdActions.Enqueue(llSwapActions);
  3455. return;
  3456. }
  3457. }
  3458. }
  3459. // just return to LL
  3460. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 5);
  3461. foreach(var pmWafer in readyReturnWafers)
  3462. {
  3463. foreach(var ll in readyInLL)
  3464. {
  3465. if(CanWaferGotoLL(pmWafer, ll.Key))
  3466. {
  3467. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3468. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3469. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, GetLLFixedReadyInOutSlots(ll.Key).tInSlot.First(), returnHand) });
  3470. return;
  3471. }
  3472. }
  3473. }
  3474. }
  3475. var readyPushInLLs = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && ll.Value.TimeToReady <= 2);
  3476. if(readyPushInLLs.Count() > 0)
  3477. {
  3478. var destLL = readyPushInLLs.First().Key;
  3479. if(readyPushInLLs.Count() == 2 && readyPushInLLs.First().Value.Scheduler.IsAtm && readyPushInLLs.Last().Value.Scheduler.IsVac)
  3480. {
  3481. destLL = readyPushInLLs.Last().Key;
  3482. }
  3483. var pickHand = SelectTMPickArm(destLL);
  3484. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(destLL, GetLLFixedReadyInOutSlots(destLL).tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand) });
  3485. return;
  3486. }
  3487. }
  3488. else
  3489. {
  3490. // should not go here
  3491. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Had better avoid picking two wafers on TM robot arms under Loadlock fixed slot pattern");
  3492. foreach(var wafer in robotWafers)
  3493. {
  3494. if(ModuleHelper.IsPm(wafer.destMod))
  3495. {
  3496. if(!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3497. {
  3498. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3499. return;
  3500. }
  3501. }
  3502. else
  3503. {
  3504. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 2);
  3505. if(readyInLL.Count() > 0)
  3506. {
  3507. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, readyInLL.First().Key, GetLLFixedReadyInOutSlots(readyInLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3508. return;
  3509. }
  3510. }
  3511. }
  3512. }
  3513. }
  3514. else // 4 slot Loadlock
  3515. {
  3516. if(robotWafers.Count() > 0)
  3517. {
  3518. if (robotWafers.Count() == 2)
  3519. {
  3520. if (robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)))
  3521. {
  3522. var destLL = lls.Where(ll => robotWafers.All(wt => CanWaferGotoLL(wt, ll.Key)) &&
  3523. ll.Value.TimeToReady <= 10 &&
  3524. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 2).
  3525. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3526. OrderBy(ll => ll.Value.TimeToReady);
  3527. if (destLL.Count() > 0)
  3528. {
  3529. var swapLL = destLL.First().Key;
  3530. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3531. var swapActions = new List<MoveItem>();
  3532. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafers.First().currentSlot));
  3533. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.Last().currentSlot, swapLL, llWaferStatus.tInSlot.Last(), (Hand)robotWafers.Last().currentSlot));
  3534. int pickCount = 0;
  3535. foreach (var slot in llWaferStatus.eOutSlot)
  3536. {
  3537. swapActions.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3538. }
  3539. _tmSchdActions.Enqueue(swapActions);
  3540. return;
  3541. }
  3542. }
  3543. foreach (var wafer in robotWafers)
  3544. {
  3545. if (ModuleHelper.IsPm(wafer.destMod))
  3546. {
  3547. if (!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 5)
  3548. {
  3549. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3550. return;
  3551. }
  3552. }
  3553. else
  3554. {
  3555. var placeLL = lls.Where(ll => CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 5 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).OrderBy(ll => ll.Value.TimeToReady);
  3556. if (placeLL.Count() > 0)
  3557. {
  3558. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, placeLL.First().Key, GetLLFixedReadyInOutSlots(placeLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3559. return;
  3560. }
  3561. }
  3562. }
  3563. }
  3564. else if (robotWafers.Count() == 1)
  3565. {
  3566. var robotWafer = robotWafers.First();
  3567. if (ModuleHelper.IsPm(robotWafer.destMod))
  3568. {
  3569. if (_dictModuleTask[robotWafer.destMod].TimeToReady <= 5)
  3570. {
  3571. if (_lstWaferTasks.Exists(wt => wt.currentMod == robotWafer.destMod))
  3572. {
  3573. var pmSwap = new List<MoveItem>();
  3574. pmSwap.Add(new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, 1 - robotWafer.currentSlot, (Hand)(1 - robotWafer.currentSlot)));
  3575. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot));
  3576. _tmSchdActions.Enqueue(pmSwap);
  3577. return;
  3578. }
  3579. else
  3580. {
  3581. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3582. return;
  3583. }
  3584. }
  3585. }
  3586. else
  3587. {
  3588. var destLL = lls.Where(ll => CanWaferGotoLL(robotWafer, ll.Key) &&
  3589. ll.Value.TimeToReady <= 10 &&
  3590. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).
  3591. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3592. OrderBy(ll => ll.Value.TimeToReady);
  3593. if (destLL.Count() > 0)
  3594. {
  3595. var swapLL = destLL.First().Key;
  3596. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3597. var llSwap = new List<MoveItem>();
  3598. llSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafer.currentSlot));
  3599. int pickCount = 0;
  3600. foreach (var slot in llWaferStatus.tOutSlot)
  3601. {
  3602. llSwap.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3603. pickCount++;
  3604. }
  3605. _tmSchdActions.Enqueue(llSwap);
  3606. return;
  3607. }
  3608. }
  3609. // try to return a wafer
  3610. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3611. foreach (var pmWafer in readyReturnWafers)
  3612. {
  3613. 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);
  3614. if (readyLL.Count() > 0)
  3615. {
  3616. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3617. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3618. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3619. return;
  3620. }
  3621. }
  3622. // try to push in a wafer
  3623. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3624. foreach (var ll in readyInLL)
  3625. {
  3626. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3627. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3628. if (wafer != null &&
  3629. ModuleHelper.IsPm(wafer.destMod) &&
  3630. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3631. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3632. {
  3633. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3634. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3635. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3636. return;
  3637. }
  3638. }
  3639. }
  3640. }
  3641. else // robot empty
  3642. {
  3643. 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();
  3644. var readyLL = lls.Where(ll => ll.Value.TimeToReady <= 10);
  3645. if(readyLL.Count() > 0)
  3646. {
  3647. var llPath = FindTheBestMovePathWithFixSlot(readyLL, nearlyReadyReturnWafers);
  3648. if(ModuleHelper.IsLoadLock(llPath))
  3649. {
  3650. int returnCount = 0;
  3651. var llWaferStatus = GetLLFixedReadyInOutSlots(llPath);
  3652. var llSwapActions = new List<MoveItem>();
  3653. foreach(var wafer in nearlyReadyReturnWafers)
  3654. {
  3655. if(CanWaferGotoLL(wafer, llPath) && returnCount < Math.Min(llWaferStatus.tInSlot.Count, 2))
  3656. {
  3657. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, 0, ModuleName.TMRobot, returnCount, (Hand)returnCount) });
  3658. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, returnCount, llPath, llWaferStatus.tInSlot[returnCount], (Hand)returnCount));
  3659. returnCount++;
  3660. }
  3661. }
  3662. int pickCount = 0;
  3663. foreach(var slot in llWaferStatus.tOutSlot)
  3664. {
  3665. if (pickCount < 2)
  3666. {
  3667. llSwapActions.Add(new MoveItem(llPath, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3668. pickCount++;
  3669. }
  3670. }
  3671. if(llSwapActions.Count > 0)
  3672. {
  3673. _tmSchdActions.Enqueue(llSwapActions);
  3674. }
  3675. return;
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. private bool IsTMRobotArmNotReserved(Hand hand)
  3682. {
  3683. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)hand) || _lstWaferTasks.Exists(wt => wt.currentMod == ModuleName.TMRobot && wt.currentSlot == (int)hand))
  3684. return false;
  3685. foreach(var acs in _tmSchdActions)
  3686. {
  3687. foreach(var ac in acs)
  3688. {
  3689. if ((ac.DestinationModule == ModuleName.TMRobot || ac.SourceModule == ModuleName.TMRobot) && ac.DestinationSlot == (int)hand)
  3690. return false;
  3691. }
  3692. }
  3693. return true;
  3694. }
  3695. private Hand SelectTMPickArm(ModuleName mod)
  3696. {
  3697. switch (_tmRobotSingleArmOption)
  3698. {
  3699. case 0:
  3700. {
  3701. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3702. return Hand.Blade1;
  3703. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3704. return Hand.Blade2;
  3705. }
  3706. break;
  3707. case 1:
  3708. {
  3709. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3710. return Hand.Blade1;
  3711. }
  3712. break;
  3713. case 2:
  3714. {
  3715. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3716. return Hand.Blade2;
  3717. }
  3718. break;
  3719. // Blade1 In Blade2 Out
  3720. case 3:
  3721. {
  3722. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3723. return Hand.Blade1;
  3724. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3725. return Hand.Blade2;
  3726. }
  3727. break;
  3728. // Blade2 In Blade1 Out
  3729. case 4:
  3730. {
  3731. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3732. return Hand.Blade2;
  3733. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3734. return Hand.Blade1;
  3735. }
  3736. break;
  3737. }
  3738. return Hand.None;
  3739. }
  3740. private List<Hand> GetTMFreeHand()
  3741. {
  3742. var lstHands = new List<Hand>();
  3743. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  3744. lstHands.Add(Hand.Blade1);
  3745. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  3746. lstHands.Add(Hand.Blade2);
  3747. return lstHands;
  3748. }
  3749. private List<Hand> GetEFEMFreeHand()
  3750. {
  3751. var lstHands = new List<Hand>();
  3752. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && _efemRobotSingleArmOption != 2)
  3753. lstHands.Add(Hand.Blade1);
  3754. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && _efemRobotSingleArmOption != 1)
  3755. lstHands.Add(Hand.Blade2);
  3756. return lstHands;
  3757. }
  3758. private bool CanWaferGotoLL(WaferTask task, ModuleName ll)
  3759. {
  3760. bool bVacWafer = ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod);
  3761. if (bVacWafer)
  3762. {
  3763. if (ModuleHelper.IsPm(task.destMod))
  3764. return false;
  3765. switch (task.llInOutPath)
  3766. {
  3767. case SequenceLLInOutPath.AInAOut:
  3768. case SequenceLLInOutPath.BInAOut:
  3769. return ll == ModuleName.LLA;
  3770. case SequenceLLInOutPath.AInBOut:
  3771. case SequenceLLInOutPath.BInBOut:
  3772. return ll == ModuleName.LLB;
  3773. case SequenceLLInOutPath.DInDOut:
  3774. return true;
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if (ModuleHelper.IsLoadPort(task.destMod))
  3780. return false;
  3781. switch (task.llInOutPath)
  3782. {
  3783. case SequenceLLInOutPath.AInAOut:
  3784. case SequenceLLInOutPath.AInBOut:
  3785. return ll == ModuleName.LLA;
  3786. case SequenceLLInOutPath.BInAOut:
  3787. case SequenceLLInOutPath.BInBOut:
  3788. return ll == ModuleName.LLB;
  3789. case SequenceLLInOutPath.DInDOut:
  3790. return true;
  3791. }
  3792. }
  3793. return false;
  3794. }
  3795. private (List<int> inSlot, List<int> outSlot, List<int> emptySlot) GetLLReadyInOutSlots(ModuleName ll)
  3796. {
  3797. var readInSlots = new List<int>();
  3798. var readyOutSlots = new List<int>();
  3799. var emptySlots = new List<int>();
  3800. for(int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3801. {
  3802. 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)))
  3803. {
  3804. emptySlots.Add(slot);
  3805. }
  3806. if(WaferManager.Instance.CheckHasWafer(ll, slot))
  3807. {
  3808. Guid waferID = WaferManager.Instance.GetWafer(ll, slot).InnerId;
  3809. var waferTask = _lstWaferTasks.Find(wafer => wafer.waferId == waferID);
  3810. if(waferTask != null && waferTask.movingStatus == RState.End)
  3811. {
  3812. if (ModuleHelper.IsPm(waferTask.destMod))
  3813. readInSlots.Add(slot);
  3814. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3815. readyOutSlots.Add(slot);
  3816. }
  3817. }
  3818. }
  3819. return (readInSlots, readyOutSlots, emptySlots);
  3820. }
  3821. private (List<int> eInSlot, List<int> eOutSlot, List<int> tInSlot, List<int> tOutSlot) GetLLFixedReadyInOutSlots(ModuleName ll)
  3822. {
  3823. var eInSlot = new List<int>();
  3824. var eOutSlot = new List<int>();
  3825. var tInSlot = new List<int>();
  3826. var tOutSlot = new List<int>();
  3827. int SlotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  3828. for (int slot = 0; slot < SlotNumber; slot++)
  3829. {
  3830. 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)))
  3831. {
  3832. if ((slot >= SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.UpperInLowerOut) ||
  3833. (slot < SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.LowerInUpperOut))
  3834. {
  3835. eInSlot.Add(slot);
  3836. }
  3837. else
  3838. {
  3839. tInSlot.Add(slot);
  3840. }
  3841. }
  3842. if (WaferManager.Instance.CheckHasWafer(ll, slot))
  3843. {
  3844. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3845. var waferTask = _lstWaferTasks.Find(wt => wt.waferId == wafer.InnerId && wt.currentMod == ll && wt.currentSlot == slot);
  3846. if(waferTask == null)
  3847. {
  3848. LOG.Write(eEvent.EV_ROUTER, ll, $"Routing trace: did not find inner task associated with {wafer.WaferOrigin} at {ll}.{slot + 1}");
  3849. }
  3850. else if (waferTask.movingStatus == RState.End)
  3851. {
  3852. if (ModuleHelper.IsPm(waferTask.destMod))
  3853. tOutSlot.Add(slot);
  3854. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3855. eOutSlot.Add(slot);
  3856. }
  3857. }
  3858. }
  3859. return (eInSlot, eOutSlot, tInSlot, tOutSlot);
  3860. }
  3861. private (List<WaferInfo> wafers, List<int> emptySlots) GetLLWaferExistance(ModuleName ll)
  3862. {
  3863. var lstWafers = new List<WaferInfo>();
  3864. var lstEmptySlots = new List<int>();
  3865. for (int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3866. {
  3867. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3868. if(wafer != null && !wafer.IsEmpty)
  3869. {
  3870. lstWafers.Add(wafer);
  3871. }
  3872. else
  3873. {
  3874. lstEmptySlots.Add(slot);
  3875. }
  3876. }
  3877. return (lstWafers, lstEmptySlots);
  3878. }
  3879. private void PrepareLLPressure()
  3880. {
  3881. if (RouteManager.IsATMMode)
  3882. return;
  3883. var schdPumpingLLs = new List<ModuleName>();
  3884. var schdVentingLLs = new List<ModuleName>();
  3885. var schdCoolingLLs = new List<ModuleName>();
  3886. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  3887. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  3888. // pre pumping/venting for schedule actions
  3889. if (_efemSchdActions.Count > 0)
  3890. {
  3891. var ventLLs = _efemSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3892. foreach(var ll in ventLLs)
  3893. {
  3894. if (!schdVentingLLs.Contains(ll))
  3895. schdVentingLLs.Add(ll);
  3896. }
  3897. }
  3898. if(_tmSchdActions.Count > 0)
  3899. {
  3900. var pumpLLs = _tmSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3901. foreach(var ll in pumpLLs)
  3902. {
  3903. if (!schdPumpingLLs.Contains(ll))
  3904. schdPumpingLLs.Add(ll);
  3905. }
  3906. }
  3907. // loadlock in out path advance check
  3908. if (_LLInOutPath == SequenceLLInOutPath.AInBOut)
  3909. {
  3910. if(llaWaferStatus.emptySlot.Count == _LLASlotNumber)
  3911. {
  3912. if (!schdVentingLLs.Contains(ModuleName.LLA))
  3913. schdVentingLLs.Add(ModuleName.LLA);
  3914. }
  3915. else if ((llaWaferStatus.inSlot.Count == _LLASlotNumber) ||
  3916. (llaWaferStatus.inSlot.Count > 0 && llaWaferStatus.inSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  3917. {
  3918. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  3919. schdPumpingLLs.Add(ModuleName.LLA);
  3920. }
  3921. if(llbWaferStatus.emptySlot.Count == _LLBSlotNumber)
  3922. {
  3923. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  3924. schdPumpingLLs.Add(ModuleName.LLB);
  3925. }
  3926. else if ((llbWaferStatus.outSlot.Count == _LLBSlotNumber) ||
  3927. (llbWaferStatus.outSlot.Count > 0 && llbWaferStatus.outSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) || ModuleHelper.IsTMRobot(wt.currentMod)) == 0))
  3928. {
  3929. schdCoolingLLs.Add(ModuleName.LLB);
  3930. }
  3931. }
  3932. else if(_LLInOutPath == SequenceLLInOutPath.BInAOut)
  3933. {
  3934. if (llbWaferStatus.emptySlot.Count == _LLBSlotNumber)
  3935. {
  3936. if (!schdVentingLLs.Contains(ModuleName.LLA))
  3937. schdVentingLLs.Add(ModuleName.LLB);
  3938. }
  3939. else if ((llbWaferStatus.inSlot.Count == _LLBSlotNumber) ||
  3940. (llbWaferStatus.inSlot.Count > 0 && llbWaferStatus.inSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  3941. {
  3942. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  3943. schdPumpingLLs.Add(ModuleName.LLB);
  3944. }
  3945. if (llaWaferStatus.emptySlot.Count == _LLASlotNumber)
  3946. {
  3947. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  3948. schdPumpingLLs.Add(ModuleName.LLA);
  3949. }
  3950. else if ((llaWaferStatus.outSlot.Count == _LLASlotNumber) ||
  3951. (llaWaferStatus.outSlot.Count > 0 && llaWaferStatus.outSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod)) == 0))
  3952. {
  3953. schdCoolingLLs.Add(ModuleName.LLA);
  3954. }
  3955. }
  3956. else
  3957. {
  3958. if ((llaWaferStatus.inSlot.Count == _LLASlotNumber) ||
  3959. (llaWaferStatus.inSlot.Count > 0 && llaWaferStatus.inSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  3960. {
  3961. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  3962. schdPumpingLLs.Add(ModuleName.LLA);
  3963. }
  3964. else if ((llaWaferStatus.outSlot.Count == _LLASlotNumber) ||
  3965. (llaWaferStatus.outSlot.Count > 0 && llaWaferStatus.outSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod)) == 0))
  3966. {
  3967. if (!schdVentingLLs.Contains(ModuleName.LLA))
  3968. schdCoolingLLs.Add(ModuleName.LLA);
  3969. }
  3970. if ((llbWaferStatus.inSlot.Count == _LLBSlotNumber) ||
  3971. (llbWaferStatus.inSlot.Count > 0 && llbWaferStatus.inSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  3972. {
  3973. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  3974. schdPumpingLLs.Add(ModuleName.LLB);
  3975. }
  3976. else if ((llbWaferStatus.outSlot.Count == _LLBSlotNumber) ||
  3977. (llbWaferStatus.outSlot.Count > 0 && llbWaferStatus.outSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod)) == 0))
  3978. {
  3979. if (!schdVentingLLs.Contains(ModuleName.LLB))
  3980. schdCoolingLLs.Add(ModuleName.LLB);
  3981. }
  3982. }
  3983. foreach (var ventLL in schdVentingLLs)
  3984. {
  3985. if (_dictModuleTask[ventLL].Scheduler.IsAvailable && !_dictModuleTask[ventLL].Scheduler.IsAtm && !schdCoolingLLs.Contains(ventLL))
  3986. (_dictModuleTask[ventLL] as LoadlockTask).PreVent();
  3987. }
  3988. foreach (var pumpLL in schdPumpingLLs)
  3989. {
  3990. if (_dictModuleTask[pumpLL].Scheduler.IsAvailable && !_dictModuleTask[pumpLL].Scheduler.IsVac && !schdVentingLLs.Contains(pumpLL))
  3991. (_dictModuleTask[pumpLL] as LoadlockTask).PrePump();
  3992. }
  3993. foreach (var coolLL in schdCoolingLLs)
  3994. {
  3995. if (_dictModuleTask[coolLL].Scheduler.IsOnline && !_dictModuleTask[coolLL].Scheduler.IsAtm)
  3996. (_dictModuleTask[coolLL] as LoadlockTask).Cooling();
  3997. }
  3998. }
  3999. private void ReturnVacWafers()
  4000. {
  4001. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  4002. {
  4003. RunSchdTMReturnActions();
  4004. return;
  4005. }
  4006. if (_tmRobotStatus != RState.End)
  4007. return;
  4008. var hands = GetTMFreeHand();
  4009. 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);
  4010. if(lls.Count() > 0)
  4011. {
  4012. // return robot wafers
  4013. int moveCount = 0;
  4014. var llActions = new List<MoveItem>();
  4015. var emptySlots = GetLLWaferExistance(lls.First().Key).emptySlots;
  4016. for(int arm = 0; arm < 2; arm++)
  4017. {
  4018. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, arm);
  4019. if(wafer != null && !wafer.IsEmpty && moveCount < emptySlots.Count)
  4020. {
  4021. llActions.Add(new MoveItem(ModuleName.TMRobot, arm, lls.First().Key, emptySlots[moveCount], (Hand)arm));
  4022. moveCount++;
  4023. }
  4024. }
  4025. if(moveCount > 0)
  4026. {
  4027. _tmSchdActions.Enqueue(llActions);
  4028. return;
  4029. }
  4030. // return PM wafers
  4031. var PickActions = new List<MoveItem>();
  4032. var hasWaferPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsIdle && mod.Value.Scheduler.IsInclude && WaferManager.Instance.CheckHasWafer(mod.Key, 0));
  4033. foreach(var pm in hasWaferPMs)
  4034. {
  4035. if (moveCount < hands.Count && moveCount < emptySlots.Count)
  4036. {
  4037. PickActions.Add(new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)hands[moveCount], hands[moveCount]));
  4038. llActions.Add(new MoveItem(ModuleName.TMRobot, (int)hands[moveCount], lls.First().Key, emptySlots[moveCount], hands[moveCount]));
  4039. moveCount++;
  4040. }
  4041. }
  4042. if(moveCount > 0)
  4043. {
  4044. foreach(var ac in PickActions)
  4045. {
  4046. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  4047. }
  4048. _tmSchdActions.Enqueue(llActions);
  4049. }
  4050. }
  4051. }
  4052. private void ReturnAtmWafers()
  4053. {
  4054. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  4055. {
  4056. RunSchdEFEMReturnActions();
  4057. return;
  4058. }
  4059. if (_efemRobotStatus != RState.End)
  4060. return;
  4061. // return Robot Wafer
  4062. for(int i = 0; i < 2; i++)
  4063. {
  4064. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  4065. if(wafer != null && !wafer.IsEmpty)
  4066. {
  4067. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  4068. }
  4069. }
  4070. if (_efemSchdActions.Count > 0)
  4071. return;
  4072. var hands = GetEFEMFreeHand();
  4073. // return Aligner wafer
  4074. var aligner = ModuleHelper.InstalledModules.Where(mod => ModuleHelper.IsAligner(mod)).ToList();
  4075. if(aligner.Count > 0 && WaferManager.Instance.CheckHasWafer(aligner.First(), 0) && hands.Count > 0)
  4076. {
  4077. var wafer = WaferManager.Instance.GetWafer(aligner.First(), 0);
  4078. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(aligner.First(), 0, ModuleName.EfemRobot, (int)hands.First(), hands.First()) });
  4079. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)hands.First(), (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands.First()) });
  4080. return;
  4081. }
  4082. // return Loadlock wafer
  4083. 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);
  4084. if(lls.Count() > 0)
  4085. {
  4086. int returnCount = 0;
  4087. var llActions = new List<MoveItem>();
  4088. var placActions = new List<MoveItem>();
  4089. foreach(var wafer in GetLLWaferExistance(lls.First().Key).wafers)
  4090. {
  4091. if(returnCount < hands.Count)
  4092. {
  4093. llActions.Add(new MoveItem(lls.First().Key, wafer.Slot, ModuleName.EfemRobot, (int)hands[returnCount], hands[returnCount]));
  4094. placActions.Add(new MoveItem(ModuleName.EfemRobot, (int)hands[returnCount], (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands[returnCount]));
  4095. returnCount++;
  4096. }
  4097. }
  4098. if (returnCount > 0)
  4099. {
  4100. _efemSchdActions.Enqueue(llActions);
  4101. foreach (var ac in placActions)
  4102. {
  4103. _efemSchdActions.Enqueue(new List<MoveItem> { ac });
  4104. }
  4105. }
  4106. }
  4107. }
  4108. private void RunSchdEFEMReturnActions()
  4109. {
  4110. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  4111. if (efemRobot == null || !efemRobot.IsAvailable)
  4112. return;
  4113. if (_efemSchdActions.Count > 0)
  4114. {
  4115. if (_curEfemAction.Count == 0 || isReturnActionsDone(_curEfemAction))
  4116. {
  4117. var nextActions = _efemSchdActions.First();
  4118. var nextModule = nextActions.First().Module;
  4119. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  4120. return;
  4121. _curEfemAction = _efemSchdActions.Dequeue();
  4122. efemRobot.PostMoveItems(_curEfemAction.ToArray());
  4123. }
  4124. }
  4125. else if (_curEfemAction.Count >= 0 && isReturnActionsDone(_curEfemAction)) // all scheduled actions done
  4126. {
  4127. _curEfemAction.Clear();
  4128. }
  4129. }
  4130. private void RunSchdTMReturnActions()
  4131. {
  4132. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerTMRobot;
  4133. if (tmRobot == null || !tmRobot.IsAvailable)
  4134. return;
  4135. if (_tmSchdActions.Count > 0)
  4136. {
  4137. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  4138. {
  4139. var nextActions = _tmSchdActions.First();
  4140. var nextModule = nextActions.First().Module;
  4141. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  4142. return;
  4143. _curTmAction = _tmSchdActions.Dequeue();
  4144. tmRobot.SendMoveItems(_curTmAction.ToArray());
  4145. }
  4146. }
  4147. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  4148. {
  4149. _curTmAction.Clear();
  4150. }
  4151. }
  4152. #endregion
  4153. #region sequence/recipe operation
  4154. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  4155. {
  4156. reason = "";
  4157. foreach(var pm in seq.PMs)
  4158. {
  4159. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  4160. return true;
  4161. }
  4162. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  4163. return false;
  4164. }
  4165. private bool CheckSequenceKepler2200TemperatureReady(SequenceInfo seq)
  4166. {
  4167. for (int i = 0; i < seq.Steps.Count; i++)
  4168. {
  4169. SequenceStepInfo stepInfo = seq.Steps[i];
  4170. foreach (var module in stepInfo.StepModules)
  4171. {
  4172. if (ModuleHelper.IsPm(module))
  4173. {
  4174. string attr = $"{module}Recipe";
  4175. if (stepInfo.StepParameter.ContainsKey(attr)
  4176. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4177. {
  4178. var recipeName = (string)stepInfo.StepParameter[attr];
  4179. var recipeContent =
  4180. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4181. var recipe = Recipe.Load(recipeContent);
  4182. float currentChamberTemperature;
  4183. switch (module)
  4184. {
  4185. case ModuleName.PMA:
  4186. currentChamberTemperature = Singleton<RouteManager>.Instance.PMA.ChamberTemperature;
  4187. break;
  4188. case ModuleName.PMB:
  4189. currentChamberTemperature = Singleton<RouteManager>.Instance.PMB.ChamberTemperature;
  4190. break;
  4191. case ModuleName.PMC:
  4192. currentChamberTemperature = Singleton<RouteManager>.Instance.PMC.ChamberTemperature;
  4193. break;
  4194. case ModuleName.PMD:
  4195. currentChamberTemperature = Singleton<RouteManager>.Instance.PMD.ChamberTemperature;
  4196. break;
  4197. default:
  4198. currentChamberTemperature = 0;
  4199. break;
  4200. }
  4201. if (recipe.Header.Temperature != null && recipe.Header.Temperature != "" && (currentChamberTemperature > Convert.ToSingle(recipe.Header.Temperature) + 10 || currentChamberTemperature < Convert.ToSingle(recipe.Header.Temperature) - 10))
  4202. {
  4203. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Start job失败,由于{module}腔体温度{currentChamberTemperature}与{recipeName} Recipe温度{recipe.Header.Temperature}不匹配");
  4204. return false;
  4205. }
  4206. }
  4207. }
  4208. }
  4209. }
  4210. return true;
  4211. }
  4212. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  4213. {
  4214. for (int i = 0; i < seq.Steps.Count; i++)
  4215. {
  4216. SequenceStepInfo stepInfo = seq.Steps[i];
  4217. foreach (var module in stepInfo.StepModules)
  4218. {
  4219. if (ModuleHelper.IsPm(module))
  4220. {
  4221. string attr = $"{module}Recipe";
  4222. if (stepInfo.StepParameter.ContainsKey(attr)
  4223. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4224. {
  4225. var recipeName = (string)stepInfo.StepParameter[attr];
  4226. if (!string.IsNullOrWhiteSpace(recipeName))
  4227. {
  4228. var recipeContent =
  4229. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4230. if (string.IsNullOrWhiteSpace(recipeContent))
  4231. {
  4232. reason = $"Can not find recipe file{recipeName}";
  4233. return false;
  4234. }
  4235. }
  4236. }
  4237. }
  4238. }
  4239. }
  4240. reason = "";
  4241. return true;
  4242. }
  4243. private void UpdateLLInOutPathProperty()
  4244. {
  4245. if (_lstControlJobs.Count == 0)
  4246. return;
  4247. var inOutPaths = new List<SequenceLLInOutPath>();
  4248. foreach(var wt in _lstWaferTasks)
  4249. {
  4250. if (!inOutPaths.Contains(wt.llInOutPath))
  4251. inOutPaths.Add(wt.llInOutPath);
  4252. }
  4253. if (inOutPaths.Count == 1)
  4254. {
  4255. _LLInOutPath = inOutPaths[0];
  4256. }
  4257. else
  4258. _LLInOutPath = SequenceLLInOutPath.DInDOut;
  4259. }
  4260. private bool GetAllJobRecipe(ControlJobInfo cj,SequenceInfo seq)
  4261. {
  4262. for (int i = 0; i < seq.Steps.Count; i++)
  4263. {
  4264. SequenceStepInfo stepInfo = seq.Steps[i];
  4265. foreach (var module in stepInfo.StepModules)
  4266. {
  4267. if (ModuleHelper.IsPm(module))
  4268. {
  4269. string attr = $"{module}Recipe";
  4270. if (stepInfo.StepParameter.ContainsKey(attr)
  4271. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4272. {
  4273. var recipeName = (string)stepInfo.StepParameter[attr];
  4274. var recipeContent =
  4275. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4276. var recipe = Recipe.Load(recipeContent);
  4277. if (recipe.Header.ChuckRecipe != null && recipe.Header.ChuckRecipe != "")
  4278. {
  4279. InUseRecipes.Add($"{module}.ChuckRecipe.{recipe.Header.ChuckRecipe}");
  4280. }
  4281. if (recipe.Header.DechuckRecipe != null && recipe.Header.DechuckRecipe != "")
  4282. {
  4283. InUseRecipes.Add($"{module}.DechuckRecipe.{recipe.Header.DechuckRecipe}");
  4284. }
  4285. InUseRecipes.Add($"{module}.Process.{recipeName}");
  4286. if (cj.PreJobClean != "")
  4287. {
  4288. InUseRecipes.Add($"{module}.Clean.{cj.PreJobClean}");
  4289. }
  4290. if (cj.PostJobClean != "")
  4291. {
  4292. InUseRecipes.Add($"{module}.Clean.{cj.PostJobClean}");
  4293. }
  4294. if (stepInfo.StepParameter["WTWClean"].ToString() != "")
  4295. {
  4296. InUseRecipes.Add($"{module}.Clean.{stepInfo.StepParameter["WTWClean"]}");
  4297. }
  4298. }
  4299. }
  4300. }
  4301. }
  4302. return true;
  4303. }
  4304. private bool IsSequenceNeedAlign(SequenceInfo sequence)
  4305. {
  4306. // check wether need align
  4307. foreach (var step in sequence.Steps)
  4308. {
  4309. foreach(var mod in step.StepModules)
  4310. {
  4311. if(ModuleHelper.IsAligner(mod))
  4312. return true;
  4313. }
  4314. }
  4315. return false;
  4316. }
  4317. #endregion
  4318. }
  4319. }