SystemDispatcher.cs 203 KB

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