SystemDispatcher.cs 204 KB

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