SystemDispatcher.cs 209 KB

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