SystemDispatcher.cs 209 KB

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