SystemDispatcher.cs 231 KB

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