SystemDispatcher.cs 221 KB

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