SystemDispatcher.cs 205 KB

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