SystemDispatcher.cs 202 KB

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