SystemDispatcher.cs 206 KB

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