SystemDispatcher.cs 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494
  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.IsIdle)
  1161. {
  1162. LOG.Write(eEvent.ERR_ROUTER, mod.Key, $"{mod.Key} is not ready for return wafer.");
  1163. return RState.Failed;
  1164. }
  1165. int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
  1166. for (int slot = 0; slot < nSlotNumber; slot++)
  1167. {
  1168. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  1169. if (wafer.IsEmpty)
  1170. continue;
  1171. var destLP = (ModuleName)wafer.OriginStation;
  1172. if (!_dictModuleTask[destLP].Scheduler.IsAvailable)
  1173. {
  1174. LOG.Write(eEvent.ERR_ROUTER, destLP, $"The destination Loadport {destLP} is not ready for return wafer.");
  1175. return RState.Failed;
  1176. }
  1177. if(!ModuleHelper.IsLoadPort(destLP))
  1178. {
  1179. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"The wafer {wafer.WaferOrigin} cannot be return, please manually drag it.");
  1180. return RState.Failed;
  1181. }
  1182. }
  1183. }
  1184. Clear();
  1185. return RState.Running;
  1186. }
  1187. public RState ReturnAllWafers()
  1188. {
  1189. int systemWaferCount = 0;
  1190. foreach (var mod in _dictModuleTask)
  1191. {
  1192. if (ModuleHelper.IsLoadPort(mod.Key))
  1193. continue;
  1194. int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
  1195. for (int slot = 0; slot < nSlotNumber; slot++)
  1196. {
  1197. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  1198. if (!wafer.IsEmpty)
  1199. systemWaferCount++;
  1200. }
  1201. }
  1202. if (systemWaferCount == 0)
  1203. return RState.End;
  1204. ReturnVacWafers();
  1205. ReturnAtmWafers();
  1206. return RState.Running;
  1207. }
  1208. #endregion
  1209. #region internal implementation
  1210. private void InitModules()
  1211. {
  1212. foreach (var module in ModuleHelper.InstalledModules)
  1213. {
  1214. if (ModuleHelper.IsInstalled(module))
  1215. {
  1216. if(ModuleHelper.IsPm(module))
  1217. {
  1218. _dictModuleTask[module] = new PMTask(module);
  1219. }
  1220. else if (ModuleHelper.IsLoadLock(module))
  1221. {
  1222. _dictModuleTask[module] = new LoadlockTask(module);
  1223. }
  1224. else if(ModuleHelper.IsLoadPort(module))
  1225. {
  1226. _dictModuleTask[module] = new LoadPortTask(module);
  1227. }
  1228. else if(ModuleHelper.IsTMRobot(module))
  1229. {
  1230. _dictModuleTask[module] = new TMRobotTask(module);
  1231. }
  1232. else if(ModuleHelper.IsEFEMRobot(module))
  1233. {
  1234. _dictModuleTask[module] = new EFEMRobotTask(module);
  1235. }
  1236. else if(ModuleHelper.IsAligner(module))
  1237. {
  1238. _dictModuleTask[module] = new AlignerTask(module);
  1239. }
  1240. }
  1241. }
  1242. }
  1243. private void prelude()
  1244. {
  1245. bool available = true;
  1246. foreach(var mod in _dictModuleTask)
  1247. {
  1248. available = mod.Value.Scheduler.IsAvailable; // force scheduler update
  1249. }
  1250. }
  1251. private void epilogue()
  1252. {
  1253. UpdateProcessJobStatus();
  1254. UpdateControlJobStatus();
  1255. UpdateLLInOutPathProperty();
  1256. PrepareLLPressure();
  1257. CreateNewWaferTask();
  1258. _lstWaferTasks.RemoveAll(item => ModuleHelper.IsLoadPort(item.destMod) && ModuleHelper.IsLoadPort(item.currentMod) && item.pressureStatus == RState.End);
  1259. }
  1260. private void RunWaferTask()
  1261. {
  1262. foreach (var task in _lstWaferTasks)
  1263. {
  1264. task.Run();
  1265. }
  1266. }
  1267. private void RunModuleTasks()
  1268. {
  1269. foreach (var task in _dictModuleTask)
  1270. {
  1271. task.Value.Run();
  1272. }
  1273. }
  1274. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1275. {
  1276. bool allWaferReturn = true;
  1277. foreach (var slot in pj.SlotWafers)
  1278. {
  1279. var wafer = WaferManager.Instance.GetWafer(slot.Item1, slot.Item2);
  1280. if(wafer.IsEmpty || (wafer.ProcessState != EnumWaferProcessStatus.Completed && checkAllProcessed))
  1281. {
  1282. allWaferReturn = false;
  1283. break;
  1284. }
  1285. }
  1286. return allWaferReturn;
  1287. }
  1288. private void UpdateProcessJobStatus()
  1289. {
  1290. if (_efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1291. return;
  1292. foreach (var pj in _lstProcessJobs)
  1293. {
  1294. if (CheckAllWaferReturned(pj, pj.State != EnumProcessJobState.Stopping))
  1295. {
  1296. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1297. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1298. }
  1299. }
  1300. }
  1301. private void UpdateControlJobStatus()
  1302. {
  1303. if (_lstControlJobs.Count == 0 || _efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1304. return;
  1305. bool allControlJobComplete = true;
  1306. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1307. foreach (var cj in _lstControlJobs)
  1308. {
  1309. if (cj.JetState == EnumJetCtrlJobState.Quequed) // active quequed control job: need prejob clean or don need prejob clean
  1310. {
  1311. var runingJobs = _lstControlJobs.FindAll(job => IsCtrlJobRuning(job));
  1312. if (runingJobs.Count == 0 || (runingJobs.Count == 1 && IsCtrlJobEndingState(runingJobs.First())))
  1313. {
  1314. var quequedJobs = _lstControlJobs.FindAll(job => job.JetState == EnumJetCtrlJobState.Quequed);
  1315. var firstQuequeJob = quequedJobs.OrderBy(job => job.StartTime).First();
  1316. if (firstQuequeJob.InnerId == cj.InnerId)
  1317. {
  1318. if (IsCtrlJobNeedPreClean(cj))
  1319. {
  1320. cj.JetState = EnumJetCtrlJobState.PreJobClean;
  1321. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1322. foreach (var pm in PMs)
  1323. {
  1324. var pmTask = _dictModuleTask[pm] as PMTask;
  1325. if(pmTask != null && pmTask.Scheduler.IsOnline)
  1326. {
  1327. pmTask.InvokePreJobClean(cj.PreJobClean);
  1328. }
  1329. }
  1330. }
  1331. else
  1332. {
  1333. ActiveControlJob(cj);
  1334. }
  1335. }
  1336. }
  1337. }
  1338. else if (IsCtrlJobRuning(cj))
  1339. {
  1340. if (cj.JetState == EnumJetCtrlJobState.PreJobClean)
  1341. {
  1342. if (IsPreJobCleanDone(cj))
  1343. {
  1344. ActiveControlJob(cj);
  1345. }
  1346. }
  1347. else
  1348. {
  1349. if (cj.JetState == EnumJetCtrlJobState.Processing && IsCtrlJobNeedPostClean(cj)) // active post job clean
  1350. {
  1351. if (IsAllJobWaferProcessedOrProcessing(cj))
  1352. {
  1353. cj.JetState = EnumJetCtrlJobState.PostJobClean;
  1354. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1355. foreach (var pm in PMs)
  1356. {
  1357. var pmTask = _dictModuleTask[pm] as PMTask;
  1358. if (pmTask != null && pmTask.Scheduler.IsOnline)
  1359. {
  1360. pmTask.InvokePostJobClean(cj.PostJobClean);
  1361. }
  1362. }
  1363. }
  1364. }
  1365. // control job complete
  1366. if (IsAllProcessJobComplete(cj) && (!IsCtrlJobNeedPostClean(cj) || cj.JetState == EnumJetCtrlJobState.PostJobClean && IsPostJobCleanDone(cj)))
  1367. {
  1368. cj.JetState = EnumJetCtrlJobState.Completed;
  1369. cj.SetState(EnumControlJobState.Completed);
  1370. cj.EndTime = DateTime.Now;
  1371. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1372. _dbCallback.LotFinished(cj);
  1373. if (!(_isCycleMode && _cycledCount < _cycleSetPoint))
  1374. (Singleton<TransferModule>.Instance.GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
  1375. _lpCycleCount[ModuleHelper.Converter(cj.Module)]++;
  1376. }
  1377. }
  1378. int countProcessed = 0;
  1379. foreach (var pjName in cj.ProcessJobNameList)
  1380. {
  1381. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1382. if (pj == null)
  1383. {
  1384. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1385. continue;
  1386. }
  1387. // caculate process wafer by process
  1388. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1389. {
  1390. foreach (var pjSlotWafer in pj.SlotWafers)
  1391. {
  1392. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1393. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  1394. countProcessed++;
  1395. }
  1396. }
  1397. }
  1398. int lpCycleWafer = _lpCycleCount[ModuleHelper.Converter(cj.Module)] * cj.LotWafers.Count + (cj.JetState == EnumJetCtrlJobState.Completed && cj.LotWafers.Count == countProcessed ? 0 : countProcessed);
  1399. if (_lpCycleCount[ModuleHelper.Converter(cj.Module)] != _cycledCount || lpCycleWafer != _lpCycleWafer[ModuleHelper.Converter(cj.Module)])
  1400. {
  1401. _lpCycleWafer[ModuleHelper.Converter(cj.Module)] = lpCycleWafer;
  1402. }
  1403. }
  1404. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1405. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal && cj.JetState == EnumJetCtrlJobState.Completed)
  1406. {
  1407. cjRemoveList.Add(cj);
  1408. }
  1409. allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
  1410. }
  1411. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1412. {
  1413. int totolCycleWafer = _lpCycleWafer.Sum(item => item.Value);
  1414. if (totolCycleWafer != _cycledWafer || _lpCycleCount.Sum(item => item.Value) > 0 && _throughput < 0.01) // refresh _throughput in time
  1415. {
  1416. _cycledWafer = totolCycleWafer;
  1417. if (_cycledCount > 0 || allControlJobComplete)
  1418. {
  1419. _throughput = (float)(_cycledWafer / _cycleWatch.Elapsed.TotalHours);
  1420. }
  1421. else
  1422. {
  1423. _throughput = 0;
  1424. }
  1425. }
  1426. if (allControlJobComplete)
  1427. {
  1428. _cycledCount++;
  1429. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Cycle Count: {_cycledCount}, Total Processed Wafer: {_cycledWafer}, Throughput: {_throughput}");
  1430. if (_cycledCount < _cycleSetPoint)
  1431. {
  1432. foreach (var cj in _lstControlJobs)
  1433. {
  1434. cj.SetState(EnumControlJobState.Executing);
  1435. cj.JetState = EnumJetCtrlJobState.Quequed;
  1436. cj.LotInnerId = Guid.NewGuid();
  1437. _dbCallback.LotCreated(cj);
  1438. }
  1439. foreach (var pj in _lstProcessJobs)
  1440. {
  1441. pj.SetState(EnumProcessJobState.Queued);
  1442. pj.InnerId = Guid.NewGuid();
  1443. foreach (var pjSlotWafer in pj.SlotWafers)
  1444. {
  1445. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1446. wafer.ProcessJob = null;
  1447. wafer.NextSequenceStep = 0;
  1448. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1449. }
  1450. }
  1451. _lstWaferTasks.Clear();
  1452. }
  1453. else
  1454. _cycleState = RState.End;
  1455. }
  1456. }
  1457. foreach (var cj in cjRemoveList)
  1458. {
  1459. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1460. foreach (var pj in _lstProcessJobs)
  1461. {
  1462. if (pj.ControlJobName == cj.Name)
  1463. pjRemoveList.Add(pj);
  1464. }
  1465. foreach (var pj in pjRemoveList)
  1466. {
  1467. _lstProcessJobs.Remove(pj);
  1468. }
  1469. _lstControlJobs.Remove(cj);
  1470. }
  1471. }
  1472. private bool ActiveProcessJob(ProcessJobInfo pj)
  1473. {
  1474. foreach (var pjSlotWafer in pj.SlotWafers)
  1475. {
  1476. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1477. wafer.ProcessJob = pj;
  1478. wafer.NextSequenceStep = 0;
  1479. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1480. }
  1481. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1482. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1483. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1484. pj.SetState(EnumProcessJobState.Processing);
  1485. return true;
  1486. }
  1487. private bool ActiveControlJob(ControlJobInfo cj)
  1488. {
  1489. cj.JetState = EnumJetCtrlJobState.Processing;
  1490. foreach (var pjName in cj.ProcessJobNameList)
  1491. {
  1492. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1493. if (pj == null)
  1494. {
  1495. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1496. continue;
  1497. }
  1498. if (pj.State == EnumProcessJobState.Queued)
  1499. {
  1500. ActiveProcessJob(pj);
  1501. }
  1502. }
  1503. return true;
  1504. }
  1505. private bool IsAllJobWaferProcessedOrProcessing(ControlJobInfo cj)
  1506. {
  1507. List<ModuleName> allModules = _dictModuleTask.Keys.ToList();
  1508. int original = (int)ModuleHelper.Converter(cj.Module);
  1509. foreach (var mod in allModules)
  1510. {
  1511. if (ModuleHelper.IsLoadPort(mod) && (int)mod != original)
  1512. continue;
  1513. var wafers = WaferManager.Instance.GetWafers(mod);
  1514. foreach (var wafer in wafers)
  1515. {
  1516. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.ControlJobName != cj.Name)
  1517. continue;
  1518. if (wafer.ProcessState != EnumWaferProcessStatus.Completed && wafer.ProcessState != EnumWaferProcessStatus.InProcess)
  1519. return false; ;
  1520. }
  1521. }
  1522. return true;
  1523. }
  1524. private bool IsAllProcessJobComplete(ControlJobInfo cj)
  1525. {
  1526. foreach (var pj in _lstProcessJobs)
  1527. {
  1528. if (pj.ControlJobName == cj.Name && pj.State != EnumProcessJobState.ProcessingComplete)
  1529. {
  1530. return false;
  1531. }
  1532. }
  1533. return true;
  1534. }
  1535. private bool IsCtrlJobExecuting(ModuleName lp)
  1536. {
  1537. var cJob = _lstControlJobs.Find(cj => ModuleHelper.Converter(cj.Module) == lp);
  1538. if (cJob != null && cJob.State == EnumControlJobState.Executing)
  1539. return true;
  1540. return false;
  1541. }
  1542. private bool IsCtrlJobRuning(ControlJobInfo cj)
  1543. {
  1544. return cj.JetState == EnumJetCtrlJobState.PreJobClean ||
  1545. cj.JetState == EnumJetCtrlJobState.Processing ||
  1546. cj.JetState == EnumJetCtrlJobState.PostJobClean;
  1547. }
  1548. private bool IsCtrlJobEndingState(ControlJobInfo cj)
  1549. {
  1550. return cj.JetState == EnumJetCtrlJobState.PostJobClean ||
  1551. (cj.JetState == EnumJetCtrlJobState.Processing
  1552. && IsAllJobWaferProcessedOrProcessing(cj)
  1553. && !IsCtrlJobNeedPostClean(cj));
  1554. }
  1555. private bool IsCtrlJobNeedPreClean(ControlJobInfo cj)
  1556. {
  1557. return !string.IsNullOrWhiteSpace(cj.PreJobClean);
  1558. }
  1559. private bool IsCtrlJobNeedPostClean(ControlJobInfo cj)
  1560. {
  1561. return !string.IsNullOrWhiteSpace(cj.PostJobClean.Trim());
  1562. }
  1563. private List<ModuleName> GetWaitPreCleanPMsByCtrlJob(ControlJobInfo cj)
  1564. {
  1565. var pmlist = new List<ModuleName>();
  1566. foreach (var pj in _lstProcessJobs)
  1567. {
  1568. if (pj.ControlJobName == cj.Name)
  1569. {
  1570. foreach (var pm in pj.Sequence.PMs)
  1571. {
  1572. if (!pmlist.Contains(pm))
  1573. pmlist.Add(pm);
  1574. }
  1575. }
  1576. }
  1577. return pmlist;
  1578. }
  1579. private bool IsPreJobCleanDone(ControlJobInfo cj)
  1580. {
  1581. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1582. foreach(var pm in pms)
  1583. {
  1584. var pmTask = _dictModuleTask[pm] as PMTask;
  1585. if (pmTask.Scheduler.IsOnline && !pmTask.IsPreJobCleanDone())
  1586. return false;
  1587. }
  1588. return true;
  1589. }
  1590. private bool IsPostJobCleanDone(ControlJobInfo cj)
  1591. {
  1592. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1593. foreach (var pm in pms)
  1594. {
  1595. var pmTask = _dictModuleTask[pm] as PMTask;
  1596. if (pmTask.Scheduler.IsOnline && !pmTask.IsPostJobCleanDone())
  1597. return false;
  1598. }
  1599. return true;
  1600. }
  1601. private void WaferArrived(WaferTask wafer, MoveItem item)
  1602. {
  1603. _dictModuleTask[item.DestinationModule].WaferArrived(wafer, item.DestinationSlot);
  1604. //--2024-03-21 增加了PortJobWaferEnd 上报事件 start--
  1605. if (ModuleHelper.IsLoadPort(item.DestinationModule))
  1606. {
  1607. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.DestinationModule);
  1608. if (currentControlJob != null)
  1609. {
  1610. _faCallback.JobWaferEnd(currentControlJob, item.SourceSlot);
  1611. }
  1612. }
  1613. //--2024-03-21 增加了PortJobWaferEnd 上报事件 end--
  1614. }
  1615. private void WaferLeaved(WaferTask wafer, MoveItem item)
  1616. {
  1617. _dictModuleTask[item.SourceModule].WaferLeaved(wafer, item.DestinationSlot);
  1618. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  1619. if (ModuleHelper.IsLoadPort(item.SourceModule))
  1620. {
  1621. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.SourceModule);
  1622. if (currentControlJob != null)
  1623. {
  1624. _faCallback.JobWaferStart(currentControlJob, item.SourceSlot);
  1625. }
  1626. }
  1627. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  1628. }
  1629. private ModuleName GetComingAvailablePM(ControlJobInfo cj)
  1630. {
  1631. var lstInProcessPMs = new List<ModuleName>();
  1632. foreach (var wafer in cj.LotWafers)
  1633. {
  1634. if(!wafer.IsEmpty && wafer.NextSequenceStep == 0 && wafer.ProcessJob != null)
  1635. {
  1636. foreach(var pm in wafer.ProcessJob.Sequence.PMs)
  1637. {
  1638. if (!lstInProcessPMs.Contains(pm) && _dictModuleTask[pm].Scheduler.IsOnline)
  1639. lstInProcessPMs.Add(pm);
  1640. }
  1641. }
  1642. }
  1643. // blocking check while only one loadlock in out
  1644. if (LLInOutPath == SequenceLLInOutPath.AInAOut ||
  1645. LLInOutPath == SequenceLLInOutPath.BInBOut ||
  1646. !_dictModuleTask[ModuleName.LLA].Scheduler.IsOnline ||
  1647. !_dictModuleTask[ModuleName.LLB].Scheduler.IsOnline)
  1648. {
  1649. if (_lstWaferTasks.Count >= lstInProcessPMs.Count + _LLASlotNumber / 2)
  1650. return ModuleName.System;
  1651. }
  1652. Dictionary<ModuleName, int> pmAssociatedWaferCount = new Dictionary<ModuleName, int>();
  1653. foreach (var mod in _dictModuleTask)
  1654. {
  1655. if (ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline && lstInProcessPMs.Contains(mod.Key))
  1656. {
  1657. pmAssociatedWaferCount[mod.Key] = 0;
  1658. }
  1659. }
  1660. var unprocessedWafer = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.destMod));
  1661. foreach (var wafer in unprocessedWafer)
  1662. {
  1663. if (ModuleHelper.IsPm(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && lstInProcessPMs.Contains(wafer.destMod))
  1664. {
  1665. pmAssociatedWaferCount[wafer.destMod]++;
  1666. }
  1667. }
  1668. var oderedPMCount = pmAssociatedWaferCount.OrderBy(p => p.Value).ToDictionary(p => p.Key, o => o.Value);
  1669. if (oderedPMCount.Count > 0 && oderedPMCount.First().Value < 2)
  1670. return oderedPMCount.First().Key;
  1671. return ModuleName.System;
  1672. }
  1673. private void CreateNewWaferTask()
  1674. {
  1675. var cj = _lstControlJobs.Find(c => (c.JetState == EnumJetCtrlJobState.PreJobClean || c.JetState == EnumJetCtrlJobState.Processing) && c.State == EnumControlJobState.Executing);
  1676. if (cj != null)
  1677. {
  1678. var pm = GetComingAvailablePM(cj);
  1679. if (pm != ModuleName.System)
  1680. {
  1681. foreach (var wafer in cj.LotWafers)
  1682. {
  1683. if (wafer.IsEmpty || wafer.ProcessJob == null)
  1684. continue;
  1685. if (wafer.ProcessJob.Sequence.PMs.Contains(pm) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  1686. {
  1687. CreateWaferTasks(wafer, pm);
  1688. return;
  1689. }
  1690. }
  1691. }
  1692. }
  1693. }
  1694. private void CreateWaferTasks(WaferInfo wafer, ModuleName pm)
  1695. {
  1696. var recipeName = wafer.ProcessJob.Sequence.GetRecipe(pm);
  1697. var recipeContent = RecipeFileManager.Instance.LoadRecipe(pm.ToString(), recipeName, false, RecipeType.Process.ToString());
  1698. Recipe recipe = Recipe.Load(recipeContent);
  1699. int temperature = 0;
  1700. if(int.TryParse(recipe.Header.Temperature, out int temp))
  1701. {
  1702. temperature = temp;
  1703. }
  1704. var waferTask = new WaferTask((ModuleName)wafer.OriginStation,
  1705. wafer.OriginSlot,
  1706. pm,
  1707. 0,
  1708. temperature,
  1709. wafer.InnerId,
  1710. recipeName,
  1711. wafer.ProcessJob.Sequence.WTWCleanRecipe,
  1712. wafer.ProcessJob.Sequence.LLInOutPath,
  1713. wafer.ProcessJob.Sequence.LLDelayTime,
  1714. IsSequenceNeedAlign(wafer.ProcessJob.Sequence));
  1715. waferTask.OnWaferArrived += WaferArrived;
  1716. waferTask.OnWaferLeaved += WaferLeaved;
  1717. _lstWaferTasks.Add(waferTask);
  1718. }
  1719. private bool ForwardATMWafers(ModuleName ll)
  1720. {
  1721. var emptySlots = _LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut ? GetLLReadyInOutSlots(ll).emptySlot : GetLLFixedReadyInOutSlots(ll).eInSlot;
  1722. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End ||wafer.movingStatus == RState.Init) && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1723. var notAlignedWafer = atmWafers.Where(wafer => !wafer.IsAligned).ToList();
  1724. 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();
  1725. var freeHands = GetEFEMFreeHand();
  1726. if ((atmWafers.Count >= 2 && !atmWafers.Exists(wafer => !wafer.IsAligned)) || freeHands.Count == 0 || readyInWafers.Length == 0)
  1727. return false;
  1728. // force all wafer aligned
  1729. if (notAlignedWafer.Count > 0 && _lstWaferTasks.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 0)
  1730. {
  1731. notAlignedWafer.First().RouteTo(ModuleName.Aligner1, 0);
  1732. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(notAlignedWafer.First().currentMod, notAlignedWafer.First().currentSlot, ModuleName.Aligner1, 0, (Hand)notAlignedWafer.First().currentSlot) });
  1733. }
  1734. // forward aligner wafer
  1735. else if (atmWafers.Count == 1 && emptySlots.Count >= 2 && ModuleHelper.IsAligner(atmWafers.First().currentMod) && freeHands.Count > 1)
  1736. {
  1737. atmWafers.First().RouteTo(ModuleName.EfemRobot, (int)freeHands[1]);
  1738. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(atmWafers.First().currentMod, atmWafers.First().currentSlot, ModuleName.EfemRobot, (int)freeHands[1], freeHands[1]) });
  1739. }
  1740. // forward one wafer
  1741. else if ((readyInWafers.Length > 0) && (atmWafers.Count == 0 || (atmWafers.Count == 1 && emptySlots.Count >= 2)))
  1742. {
  1743. if(readyInWafers[0].IsAligned)
  1744. {
  1745. // pick from LP
  1746. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyInWafers[0].currentMod, readyInWafers[0].currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1747. }
  1748. else if(!_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1749. {
  1750. readyInWafers[0].RouteTo(ModuleName.Aligner1, 0);
  1751. // pick from LP
  1752. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyInWafers[0].currentMod, readyInWafers[0].currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1753. // place to aligner
  1754. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ModuleName.Aligner1, 0, freeHands[0]) });
  1755. }
  1756. }
  1757. return _efemSchdActions.Count > 0;
  1758. }
  1759. private bool ExchangeWaferWithLL(ModuleName ll)
  1760. {
  1761. if (IsLLReservedByTM(ll))
  1762. return false;
  1763. var waferStaus = GetLLReadyInOutSlots(ll);
  1764. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1765. var freeHands = GetEFEMFreeHand();
  1766. var swapActions = new List<MoveItem>();
  1767. var validHands = new List<Hand>();
  1768. int placeCount = 0;
  1769. if ( waferStaus.emptySlot.Count > 0 &&
  1770. freeHands.Count >= 1 &&
  1771. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  1772. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || waferStaus.emptySlot.Count >= 2))
  1773. {
  1774. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  1775. if (CanWaferGotoLL(alignerWafer, ll))
  1776. {
  1777. alignerWafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  1778. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1779. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, waferStaus.emptySlot[placeCount], freeHands[0]));
  1780. validHands.Add(freeHands[0]);
  1781. placeCount++;
  1782. }
  1783. }
  1784. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  1785. foreach(var wafer in armWafers)
  1786. {
  1787. if (CanWaferGotoLL(wafer, ll) && placeCount < waferStaus.emptySlot.Count)
  1788. {
  1789. wafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  1790. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, waferStaus.emptySlot[placeCount], (Hand)wafer.currentSlot));
  1791. if(!validHands.Contains((Hand)wafer.currentSlot))
  1792. validHands.Add((Hand)wafer.currentSlot);
  1793. placeCount++;
  1794. }
  1795. }
  1796. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  1797. validHands.Add(Hand.Blade1);
  1798. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  1799. validHands.Add(Hand.Blade2);
  1800. int pickCount = 0;
  1801. var returnActions = new List<MoveItem>();
  1802. foreach(var slot in waferStaus.outSlot)
  1803. {
  1804. if(pickCount < validHands.Count)
  1805. {
  1806. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  1807. if(outWafer != null)
  1808. {
  1809. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  1810. swapActions.Add(new MoveItem(ll, waferStaus.outSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  1811. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  1812. pickCount++;
  1813. }
  1814. }
  1815. }
  1816. if(swapActions.Count > 0)
  1817. {
  1818. _efemSchdActions.Enqueue(swapActions);
  1819. }
  1820. foreach(var action in returnActions)
  1821. {
  1822. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  1823. }
  1824. return _efemSchdActions.Count > 0;
  1825. }
  1826. private bool ExchangeWaferWithFixedSlotLL(ModuleName ll)
  1827. {
  1828. if (IsLLReservedByTM(ll))
  1829. return false;
  1830. var llWaferStatus = GetLLFixedReadyInOutSlots(ll);
  1831. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1832. var freeHands = GetEFEMFreeHand();
  1833. var swapActions = new List<MoveItem>();
  1834. var validHands = new List<Hand>();
  1835. int placeCount = 0;
  1836. if (llWaferStatus.eInSlot.Count > 0 &&
  1837. freeHands.Count >= 1 &&
  1838. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  1839. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || llWaferStatus.eInSlot.Count >= 2))
  1840. {
  1841. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  1842. if (CanWaferGotoLL(alignerWafer, ll))
  1843. {
  1844. alignerWafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  1845. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1846. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, llWaferStatus.eInSlot[placeCount], freeHands[0]));
  1847. validHands.Add(freeHands[0]);
  1848. placeCount++;
  1849. }
  1850. }
  1851. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  1852. foreach (var wafer in armWafers)
  1853. {
  1854. if (CanWaferGotoLL(wafer, ll) && placeCount < llWaferStatus.eInSlot.Count)
  1855. {
  1856. wafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  1857. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, llWaferStatus.eInSlot[placeCount], (Hand)wafer.currentSlot));
  1858. if (!validHands.Contains((Hand)wafer.currentSlot))
  1859. validHands.Add((Hand)wafer.currentSlot);
  1860. placeCount++;
  1861. }
  1862. }
  1863. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  1864. validHands.Add(Hand.Blade1);
  1865. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  1866. validHands.Add(Hand.Blade2);
  1867. int pickCount = 0;
  1868. var returnActions = new List<MoveItem>();
  1869. foreach (var slot in llWaferStatus.eOutSlot)
  1870. {
  1871. if (pickCount < validHands.Count)
  1872. {
  1873. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  1874. if (outWafer != null)
  1875. {
  1876. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  1877. swapActions.Add(new MoveItem(ll, llWaferStatus.eOutSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  1878. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  1879. pickCount++;
  1880. }
  1881. }
  1882. }
  1883. if (swapActions.Count > 0)
  1884. {
  1885. _efemSchdActions.Enqueue(swapActions);
  1886. }
  1887. foreach (var action in returnActions)
  1888. {
  1889. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  1890. }
  1891. return _efemSchdActions.Count > 0;
  1892. }
  1893. private void RoutingATMWafers()
  1894. {
  1895. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  1896. {
  1897. RunSchdEFEMActions();
  1898. return;
  1899. }
  1900. if (_efemRobotStatus != RState.End)
  1901. return;
  1902. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  1903. {
  1904. if (_LLASlotNumber == 2)
  1905. {
  1906. Routing2SlotATMSystem();
  1907. }
  1908. else if (_LLASlotNumber == 4)
  1909. {
  1910. Routing4SlotATMSystem();
  1911. }
  1912. }
  1913. else
  1914. {
  1915. RoutingFixedSlotATMSystem();
  1916. }
  1917. }
  1918. private void Routing4SlotATMSystem()
  1919. {
  1920. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1921. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  1922. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  1923. {
  1924. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  1925. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  1926. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  1927. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  1928. if (efemRobotWafers.Count() >= 1)
  1929. {
  1930. if (inLLWaferStatus.emptySlot.Count >= 2 && !IsLLReservedByTM(inLL)) // wait for in loadlock ready
  1931. {
  1932. if (_dictModuleTask[inLL].TimeToReady < 2)
  1933. {
  1934. ExchangeWaferWithLL(inLL);
  1935. }
  1936. }
  1937. if ((inLLWaferStatus.emptySlot.Count == 0 || (outLLWaferStatus.outSlot.Count >= 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL)) // ready return wafer
  1938. {
  1939. ExchangeWaferWithLL(outLL);
  1940. }
  1941. }
  1942. else
  1943. {
  1944. if (((outLLWaferStatus.outSlot.Count >= 2 && _dictModuleTask[outLL].TimeToReady < 10) ||
  1945. (outLLWaferStatus.outSlot.Count == 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL))
  1946. {
  1947. ExchangeWaferWithLL(outLL);
  1948. }
  1949. else if (inLLWaferStatus.emptySlot.Count >= 2)
  1950. {
  1951. if (((_dictModuleTask[inLL].TimeToReady > 20 || _dictModuleTask[inLL].Scheduler.IsVac) && atmWaferCount < 2) || atmWaferCount == 0)
  1952. {
  1953. ForwardATMWafers(inLL);
  1954. }
  1955. else if (atmWaferCount >= 2 && !IsLLReservedByTM(inLL))
  1956. {
  1957. ExchangeWaferWithLL(inLL);
  1958. }
  1959. }
  1960. }
  1961. }
  1962. else
  1963. {
  1964. RoutingSameLLInOutATMSystem();
  1965. }
  1966. }
  1967. private void Routing2SlotATMSystem()
  1968. {
  1969. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1970. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  1971. var validHands = (_efemRobotSingleArmOption == 0 ? 2 : 1);
  1972. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  1973. {
  1974. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  1975. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  1976. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  1977. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  1978. // whether can do double return in 5 second, single return with single arm option or LL under atm pressure
  1979. if ((outLLWaferStatus.outSlot.Count == 2 && _dictModuleTask[outLL].TimeToReady < 5 && (atmWaferCount < 2 || !_dictModuleTask[outLL].Scheduler.IsAtm)) ||
  1980. (outLLWaferStatus.outSlot.Count == 1 && ((_dictModuleTask[outLL].TimeToReady < 2 && _dictModuleTask[outLL].Scheduler.IsAtm)
  1981. || _efemRobotSingleArmOption != 0
  1982. || _lstWaferTasks.Where(wt => ModuleHelper.IsLoadPort(wt.destMod)).Count() == 1)))
  1983. {
  1984. if (ExchangeWaferWithLL(outLL))
  1985. return;
  1986. }
  1987. // need pass by aligner
  1988. if(_lstProcessJobs.Exists(pj => pj.State == EnumProcessJobState.Processing && IsSequenceNeedAlign(pj.Sequence)))
  1989. {
  1990. if (atmWaferCount == 0 || (atmWaferCount == 1 && inLLWaferStatus.emptySlot.Count == 2 && _efemRobotSingleArmOption == 0 && (outLLWaferStatus.outSlot.Count < 2)))
  1991. {
  1992. if (ForwardATMWafers(inLL))
  1993. return;
  1994. }
  1995. }
  1996. // don need pass by aligner
  1997. else
  1998. {
  1999. var outModule = _dictModuleTask[outLL] as LoadlockTask;
  2000. if ((atmWaferCount < validHands - outModule.ReayOutWafersInTime(20) || _dictModuleTask[inLL].TimeToReady < 5) && _lstWaferTasks.Count(wt => wt.currentMod == inLL || wt.currentMod == ModuleName.EfemRobot) < validHands)
  2001. {
  2002. if (ForwardATMWafers(inLL))
  2003. return;
  2004. }
  2005. }
  2006. if (inLLWaferStatus.emptySlot.Count >= validHands && _dictModuleTask[inLL].TimeToReady < 2)
  2007. {
  2008. ExchangeWaferWithLL(inLL);
  2009. }
  2010. }
  2011. else
  2012. {
  2013. RoutingSameLLInOutATMSystem();
  2014. }
  2015. }
  2016. private void RoutingFixedSlotATMSystem()
  2017. {
  2018. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2019. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  2020. if ( atmWaferCount == 0 || (_efemRobotSingleArmOption == 0 && atmWaferCount == 1 ))
  2021. {
  2022. foreach(var ll in lls)
  2023. {
  2024. if (ForwardATMWafers(ll.Key))
  2025. return;
  2026. }
  2027. }
  2028. // try to match a ll swap action
  2029. var readyReturnLL = lls.Where(ll => (GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count > 0) && ll.Value.TimeToReady <= 10)
  2030. .OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count)
  2031. .OrderBy(ll => ll.Value.TimeToReady);
  2032. foreach (var ll in readyReturnLL)
  2033. {
  2034. if (ExchangeWaferWithFixedSlotLL(ll.Key))
  2035. return;
  2036. }
  2037. }
  2038. private void RoutingSameLLInOutATMSystem()
  2039. {
  2040. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2041. var vacWaferCount = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod) || ModuleHelper.IsLoadLock(task.currentMod)).Count();
  2042. var preferWaferVacCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline).Count() +
  2043. (LLInOutPath == SequenceLLInOutPath.AInAOut ? _LLASlotNumber / 2 : (LLInOutPath == SequenceLLInOutPath.BInBOut ? _LLBSlotNumber / 2 : _LLASlotNumber));
  2044. var inOutIndicator = vacWaferCount - preferWaferVacCount;
  2045. if (inOutIndicator < 0)
  2046. {
  2047. // ready to push in
  2048. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2049. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2050. mod.Value.TimeToReady <= 10 &&
  2051. !IsLLReservedByTM(mod.Key) &&
  2052. GetLLReadyInOutSlots(mod.Key).emptySlot.Count >= 1).
  2053. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2054. if (atmWaferCount >= 1)
  2055. {
  2056. foreach(var ll in readyLLs)
  2057. {
  2058. if (ExchangeWaferWithLL(ll.Key))
  2059. return;
  2060. }
  2061. }
  2062. // forward wafer to system
  2063. if (atmWaferCount < 2)
  2064. {
  2065. var targetLL = readyLLs.Count > 0 ? readyLLs.First().Key : (LLInOutPath == SequenceLLInOutPath.BInBOut ? ModuleName.LLB : ModuleName.LLA);
  2066. ForwardATMWafers(targetLL);
  2067. }
  2068. if (_efemSchdActions.Count == 0)
  2069. {
  2070. var readyReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2071. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2072. mod.Value.TimeToReady <= 5 &&
  2073. !IsLLReservedByTM(mod.Key) &&
  2074. GetLLReadyInOutSlots(mod.Key).outSlot.Count >= 1).
  2075. OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).outSlot.Count).ToList();
  2076. foreach(var ll in readyReturnLL)
  2077. {
  2078. if (ExchangeWaferWithLL(readyReturnLL.First().Key))
  2079. return;
  2080. }
  2081. }
  2082. }
  2083. else
  2084. {
  2085. // ready double return LL
  2086. var readyDoubleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2087. mod.Value.TimeToReady < 10 &&
  2088. !IsLLReservedByTM(mod.Key) &&
  2089. GetLLReadyInOutSlots(mod.Key).outSlot.Count > 1).
  2090. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2091. foreach(var ll in readyDoubleReturnLL)
  2092. {
  2093. if (ExchangeWaferWithLL(ll.Key))
  2094. return;
  2095. }
  2096. // ready single return LL
  2097. var readySingleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2098. mod.Value.TimeToReady < 2 &&
  2099. !IsLLReservedByTM(mod.Key) &&
  2100. GetLLReadyInOutSlots(mod.Key).outSlot.Count == 1).
  2101. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2102. foreach (var ll in readySingleReturnLL)
  2103. {
  2104. if (ExchangeWaferWithLL(ll.Key))
  2105. return;
  2106. }
  2107. if (atmWaferCount == 0)
  2108. {
  2109. // ready to push in
  2110. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2111. ((mod.Key != ModuleName.LLA && LLInOutPath == SequenceLLInOutPath.BInBOut) || (mod.Key != ModuleName.LLB && LLInOutPath == SequenceLLInOutPath.AInAOut)) &&
  2112. mod.Value.TimeToReady <= 10 &&
  2113. !IsLLReservedByTM(mod.Key) &&
  2114. GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 1).
  2115. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2116. foreach(var ll in readyLLs)
  2117. {
  2118. if (ForwardATMWafers(ll.Key))
  2119. return;
  2120. }
  2121. }
  2122. }
  2123. }
  2124. private bool isReturnActionsDone(List<MoveItem> items)
  2125. {
  2126. foreach(var item in items)
  2127. {
  2128. if (WaferManager.Instance.CheckHasWafer(item.SourceModule, item.SourceSlot) || WaferManager.Instance.CheckNoWafer(item.DestinationModule, item.DestinationSlot))
  2129. return false;
  2130. }
  2131. return true;
  2132. }
  2133. private bool IsMovingActionsDone(List<MoveItem> actions)
  2134. {
  2135. bool CheckWaferExistence(ModuleName mod, int slot)
  2136. {
  2137. return ModuleHelper.IsLoadPort(mod) ? WaferManager.Instance.CheckHasWafer(mod, slot) : _lstWaferTasks.Exists(wt => wt.currentMod == mod && wt.currentSlot == slot);
  2138. }
  2139. if(actions.Count == 1)
  2140. {
  2141. if ( CheckWaferExistence(actions.First().SourceModule, actions.First().SourceSlot) ||
  2142. !CheckWaferExistence(actions.First().DestinationModule, actions.First().DestinationSlot) )
  2143. return false;
  2144. }
  2145. else
  2146. {
  2147. // initialize all the wafer existance before move
  2148. var slotWafers = new Dictionary<KeyValuePair<ModuleName, int>, bool>();
  2149. foreach (var ac in actions)
  2150. {
  2151. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2152. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2153. if (!slotWafers.ContainsKey(scrSlot))
  2154. {
  2155. slotWafers[scrSlot] = true;
  2156. }
  2157. if (!slotWafers.ContainsKey(destSlot))
  2158. {
  2159. slotWafers[destSlot] = false;
  2160. }
  2161. }
  2162. // simulate moved result
  2163. foreach (var ac in actions)
  2164. {
  2165. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2166. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2167. if (!slotWafers[scrSlot])
  2168. {
  2169. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[scrSlot]} do not has a wafer");
  2170. }
  2171. else
  2172. {
  2173. slotWafers[scrSlot] = false;
  2174. }
  2175. if (slotWafers[destSlot])
  2176. {
  2177. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[destSlot]} has a wafer");
  2178. }
  2179. else
  2180. {
  2181. slotWafers[destSlot] = true;
  2182. }
  2183. }
  2184. foreach (var slot in slotWafers)
  2185. {
  2186. if (slot.Value != CheckWaferExistence(slot.Key.Key, slot.Key.Value))
  2187. return false;
  2188. }
  2189. }
  2190. return true;
  2191. }
  2192. private bool IsLLReservedByTM(ModuleName ll)
  2193. {
  2194. foreach(var item in _curTmAction)
  2195. {
  2196. if (item.DestinationModule == ll || item.SourceModule == ll)
  2197. return true;
  2198. }
  2199. foreach(var action in _tmSchdActions)
  2200. {
  2201. foreach(var item in action)
  2202. {
  2203. if (item.DestinationModule == ll || item.SourceModule == ll)
  2204. return true;
  2205. }
  2206. }
  2207. return false;
  2208. }
  2209. private bool IsLLReservedByEFEM(ModuleName ll)
  2210. {
  2211. foreach (var item in _curEfemAction)
  2212. {
  2213. if (item.DestinationModule == ll || item.SourceModule == ll)
  2214. return true;
  2215. }
  2216. foreach (var action in _efemSchdActions)
  2217. {
  2218. foreach (var item in action)
  2219. {
  2220. if (item.DestinationModule == ll || item.SourceModule == ll)
  2221. return true;
  2222. }
  2223. }
  2224. return false;
  2225. }
  2226. private void RunSchdEFEMActions()
  2227. {
  2228. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  2229. if (efemRobot == null || !efemRobot.IsAvailable)
  2230. return;
  2231. if (_dictModuleTask[ModuleName.EfemRobot].IsIdle)
  2232. {
  2233. if(_efemSchdActions.Count > 0 )
  2234. {
  2235. if(_curEfemAction.Count == 0 || IsMovingActionsDone(_curEfemAction))
  2236. {
  2237. var nextActions = _efemSchdActions.First();
  2238. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2239. return;
  2240. var nextModule = nextActions.First().Module;
  2241. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  2242. return;
  2243. _curEfemAction = _efemSchdActions.Dequeue();
  2244. foreach (var action in _curEfemAction)
  2245. {
  2246. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2247. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2248. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  2249. if (ModuleHelper.IsLoadPort(action.SourceModule))
  2250. {
  2251. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.SourceModule);
  2252. if(currentControlJob!=null)
  2253. {
  2254. _faCallback.JobWaferStart(currentControlJob, action.SourceSlot);
  2255. }
  2256. }
  2257. if(ModuleHelper.IsLoadPort(action.DestinationModule))
  2258. {
  2259. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.DestinationModule);
  2260. if (currentControlJob != null)
  2261. {
  2262. _faCallback.JobWaferEnd(currentControlJob, action.SourceSlot);
  2263. }
  2264. }
  2265. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  2266. }
  2267. (_dictModuleTask[ModuleName.EfemRobot].Scheduler as SchedulerEfemRobot).PostMoveItems(_curEfemAction.ToArray());
  2268. }
  2269. }
  2270. else if(_curEfemAction.Count >= 0 && IsMovingActionsDone(_curEfemAction)) // all scheduled actions done
  2271. {
  2272. _curEfemAction.Clear();
  2273. }
  2274. }
  2275. }
  2276. private void RunSchdTMActions()
  2277. {
  2278. if (_dictModuleTask[ModuleName.TMRobot].IsIdle)
  2279. {
  2280. if (_tmSchdActions.Count > 0)
  2281. {
  2282. if (_curTmAction.Count == 0 || IsMovingActionsDone(_curTmAction))
  2283. {
  2284. var nextActions = _tmSchdActions.First();
  2285. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2286. return;
  2287. if (ModuleHelper.IsPm(nextActions.First().Module) && !_dictModuleTask[nextActions.First().Module].IsIdle) /// wait PMTask status update to idle
  2288. return;
  2289. _curTmAction = _tmSchdActions.Dequeue();
  2290. foreach(var action in _curTmAction)
  2291. {
  2292. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2293. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2294. }
  2295. (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerTMRobot).SendMoveItems(_curTmAction.ToArray());
  2296. }
  2297. }
  2298. else if (_curTmAction.Count >= 0 && IsMovingActionsDone(_curTmAction)) // all scheduled actions done
  2299. {
  2300. _curTmAction.Clear();
  2301. }
  2302. }
  2303. }
  2304. private int TimeForNextModuleReady(WaferTask task)
  2305. {
  2306. if (ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2307. return _dictModuleTask[task.destMod].TimeToReady;
  2308. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  2309. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  2310. if (ModuleHelper.IsLoadPort(task.destMod) && (ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2311. {
  2312. if (task.llInOutPath == SequenceLLInOutPath.AInBOut || task.llInOutPath == SequenceLLInOutPath.BInBOut)
  2313. {
  2314. if(llbWaferStatus.emptySlot.Count > 0)
  2315. {
  2316. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2317. }
  2318. }
  2319. else if(task.llInOutPath == SequenceLLInOutPath.BInAOut || task.llInOutPath == SequenceLLInOutPath.AInAOut)
  2320. {
  2321. if(llaWaferStatus.emptySlot.Count > 0)
  2322. {
  2323. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2324. }
  2325. }
  2326. else if(task.llInOutPath == SequenceLLInOutPath.DInDOut)
  2327. {
  2328. if(llaWaferStatus.emptySlot.Count > 0 && llbWaferStatus.emptySlot.Count > 0)
  2329. {
  2330. if (_dictModuleTask[ModuleName.LLA].TimeToReady == _dictModuleTask[ModuleName.LLB].TimeToReady)
  2331. {
  2332. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2333. }
  2334. else
  2335. {
  2336. return Math.Min(_dictModuleTask[ModuleName.LLA].TimeToReady, _dictModuleTask[ModuleName.LLB].TimeToReady);
  2337. }
  2338. }
  2339. else if(llaWaferStatus.emptySlot.Count > 0)
  2340. {
  2341. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2342. }
  2343. else if(llbWaferStatus.emptySlot.Count > 0)
  2344. {
  2345. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2346. }
  2347. }
  2348. }
  2349. else if(ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2350. {
  2351. if(_lstWaferTasks.Find(wafer => wafer.currentMod == task.destMod || wafer.routedMod == task.destMod) == null)
  2352. {
  2353. return _dictModuleTask[task.destMod].TimeToReady;
  2354. }
  2355. }
  2356. return int.MaxValue;
  2357. }
  2358. List<Hand> GetTMValidFreeHands(List<WaferTask> robotWafers, List<MoveItem> swapActions)
  2359. {
  2360. var hands = new List<Hand>();
  2361. for(int i = 0; i < 2; i++)
  2362. {
  2363. if(_tmRobotSingleArmOption == 0 || _tmRobotSingleArmOption == i + 1)
  2364. {
  2365. if ((!robotWafers.Exists(wafer => wafer.currentSlot == i) ||
  2366. ( robotWafers.Exists(wafer => wafer.currentSlot == i) &&
  2367. swapActions.Exists(item => item.SourceModule == ModuleName.TMRobot && item.SourceSlot == i))) &&
  2368. !swapActions.Exists(item => item.DestinationModule == ModuleName.TMRobot && item.DestinationSlot == i))
  2369. hands.Add((Hand)i);
  2370. }
  2371. }
  2372. return hands;
  2373. }
  2374. (ModuleName llPath, List<MoveItem> swapActions) FindBestLLSwapPlan(ModuleName ll, List<WaferTask> robotWafers)
  2375. {
  2376. ModuleName path = ll == ModuleName.System ? ModuleName.System : ll;
  2377. List<ModuleName> lls = ll == ModuleName.System ? new List<ModuleName> { ModuleName.LLA, ModuleName.LLB } : new List<ModuleName> { ll };
  2378. List<MoveItem> actions = new List<MoveItem>();
  2379. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2380. foreach (var loadlock in lls)
  2381. {
  2382. llSwapActions[loadlock] = new List<MoveItem>();
  2383. if (IsLLReservedByEFEM(loadlock))
  2384. continue;
  2385. var llWaferStatus = GetLLReadyInOutSlots(loadlock);
  2386. foreach(var wafer in robotWafers)
  2387. {
  2388. if(_dictModuleTask[loadlock].TimeToReady == 0 && !IsLLReservedByEFEM(loadlock) && CanWaferGotoLL(wafer,loadlock) && llWaferStatus.emptySlot.Count > llSwapActions[loadlock].Count)
  2389. {
  2390. llSwapActions[loadlock].Add(new MoveItem(ModuleName.TMRobot, wafer.currentSlot, loadlock, llWaferStatus.emptySlot[llSwapActions[loadlock].Count], (Hand)wafer.currentSlot));
  2391. }
  2392. }
  2393. int prePickTime = 20;
  2394. int prePickCount = 0;
  2395. var hands = GetTMValidFreeHands(robotWafers, llSwapActions[loadlock]);
  2396. foreach (var slot in llWaferStatus.inSlot)
  2397. {
  2398. var wafer = _lstWaferTasks.Find(task => task.currentMod == loadlock && task.currentSlot == slot);
  2399. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && hands.Count > prePickCount)
  2400. {
  2401. if(_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2402. {
  2403. 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))
  2404. {
  2405. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2406. prePickCount++;
  2407. break;
  2408. }
  2409. }
  2410. else
  2411. {
  2412. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2413. prePickCount++;
  2414. }
  2415. }
  2416. }
  2417. }
  2418. var validateActions = llSwapActions.Where(item => item.Value.Count > 0).ToDictionary(k => k.Key, v => v.Value);
  2419. if(validateActions.Count == 1)
  2420. {
  2421. (path, actions) = (validateActions.First().Key, validateActions.First().Value);
  2422. }
  2423. else if(validateActions.Count == 2)
  2424. {
  2425. var sortedActions = validateActions.OrderByDescending(item => item.Value.Count + (_dictModuleTask[item.Key].Scheduler.IsVac ? 2 : 0)).ToDictionary(k => k.Key, v => v.Value);
  2426. (path, actions) = (sortedActions.First().Key, sortedActions.First().Value);
  2427. }
  2428. return (path, actions);
  2429. }
  2430. (List<WaferTask> pmWafers, ModuleName destLL, List<MoveItem> swapAction) FindBestReturnWafersPlan(Hand[] freeHands)
  2431. {
  2432. Dictionary<ModuleName, List<WaferTask>> returnWafers = new Dictionary<ModuleName, List<WaferTask>>();
  2433. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2434. Dictionary<ModuleName, int> llValues = new Dictionary<ModuleName, int>();
  2435. foreach(var ll in new List<ModuleName> { ModuleName.LLA, ModuleName.LLB})
  2436. {
  2437. var llWaferStatus = GetLLReadyInOutSlots(ll);
  2438. returnWafers[ll] = new List<WaferTask>();
  2439. llSwapActions[ll] = new List<MoveItem>();
  2440. llValues[ll] = 0;
  2441. if (IsLLReservedByEFEM(ll))
  2442. continue;
  2443. var readyReturnWafers = _lstWaferTasks.Where( wafer => ModuleHelper.IsPm(wafer.currentMod) &&
  2444. ModuleHelper.IsLoadPort(wafer.destMod) &&
  2445. wafer.movingStatus == RState.End &&
  2446. _dictModuleTask[wafer.currentMod].TimeToReady <= 2 &&
  2447. CanWaferGotoLL(wafer, ll)).Take(Math.Min(freeHands.Length, llWaferStatus.emptySlot.Count)).ToList();
  2448. int prePickTime = 10 * llSwapActions[ll].Count;
  2449. int handIndex = 0;
  2450. if(_dictModuleTask[ll].TimeToReady <= prePickTime)
  2451. {
  2452. foreach (var wafer in readyReturnWafers)
  2453. {
  2454. if(handIndex < freeHands.Length)
  2455. {
  2456. returnWafers[ll].Add(wafer);
  2457. llSwapActions[ll].Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[handIndex], ll, llWaferStatus.emptySlot[handIndex], freeHands[handIndex]));
  2458. handIndex++;
  2459. }
  2460. }
  2461. int prePickCount = 0;
  2462. handIndex = 0;
  2463. foreach (var slot in llWaferStatus.inSlot)
  2464. {
  2465. var wafer = _lstWaferTasks.Find(task => task.currentMod == ll && task.currentSlot == slot);
  2466. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && freeHands.Length > prePickCount)
  2467. {
  2468. if (_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2469. {
  2470. 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))
  2471. {
  2472. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2473. prePickCount++;
  2474. break;
  2475. }
  2476. }
  2477. else
  2478. {
  2479. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2480. prePickCount++;
  2481. }
  2482. }
  2483. }
  2484. llValues[ll] = returnWafers[ll].Count * 2 + llSwapActions[ll].Count + (_dictModuleTask[ll].Scheduler.IsVac && returnWafers[ll].Count > 0 ? 2 : 0);
  2485. }
  2486. }
  2487. var preferLL = llValues.OrderByDescending(v => v.Value).First().Key;
  2488. return (returnWafers[preferLL], preferLL, llSwapActions[preferLL]);
  2489. }
  2490. ModuleName FindTheBestMovePathWithFixSlot(IEnumerable<KeyValuePair<ModuleName, ModuleTask>> lls, List<WaferTask> pmWafers)
  2491. {
  2492. Dictionary<ModuleName, int> moveValues = new Dictionary<ModuleName, int>();
  2493. foreach(var ll in lls)
  2494. {
  2495. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  2496. moveValues[ll.Key] = Math.Min(pmWafers.Where(wt => CanWaferGotoLL(wt, ll.Key)).Count(), GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count) + llWaferStatus.tOutSlot.Count;
  2497. }
  2498. var preferLL = moveValues.OrderByDescending(v => v.Value).First().Key;
  2499. return moveValues[preferLL] > 0 ? preferLL : ModuleName.System;
  2500. }
  2501. void RoutingTMSwapActions(List<MoveItem> actions)
  2502. {
  2503. foreach (var action in actions)
  2504. {
  2505. if (ModuleHelper.IsTMRobot(action.SourceModule))
  2506. {
  2507. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == ModuleName.TMRobot && wafer.currentSlot == action.SourceSlot);
  2508. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2509. }
  2510. else
  2511. {
  2512. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2513. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2514. }
  2515. }
  2516. }
  2517. private bool ManaulReturnPMWafer()
  2518. {
  2519. var mReturnWafer = _qeReturnWafers.Peek();
  2520. if (ModuleHelper.IsPm((ModuleName)mReturnWafer.Station))
  2521. {
  2522. var hands = GetTMValidFreeHands(_lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod)).ToList(), new List<MoveItem>());
  2523. var waferTask = _lstWaferTasks.Find(wt => wt.currentMod == (ModuleName)mReturnWafer.Station && wt.waferId == mReturnWafer.InnerId);
  2524. if (waferTask != null && hands.Count > 0)
  2525. {
  2526. waferTask.Return();
  2527. var outLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && CanWaferGotoLL(waferTask, mod.Key) && GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 0 && !IsLLReservedByEFEM(mod.Key));
  2528. if (outLL.Count() > 0)
  2529. {
  2530. var slot = GetLLReadyInOutSlots(outLL.First().Key).emptySlot.First();
  2531. waferTask.RouteTo(outLL.First().Key, slot);
  2532. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waferTask.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2533. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL.First().Key, slot, hands.First()) });
  2534. _qeReturnWafers.Dequeue();
  2535. return true;
  2536. }
  2537. }
  2538. }
  2539. return false;
  2540. }
  2541. private void RoutingVacWafers()
  2542. {
  2543. if(_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2544. {
  2545. RunSchdTMActions();
  2546. return;
  2547. }
  2548. if(_tmRobotStatus == RState.End)
  2549. {
  2550. // handle manual return wafer if exist
  2551. if(_qeReturnWafers.Count > 0)
  2552. {
  2553. if (ManaulReturnPMWafer())
  2554. return;
  2555. }
  2556. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2557. {
  2558. if (_LLASlotNumber == 2)
  2559. {
  2560. Routing2SlotVacSystem();
  2561. }
  2562. else if (_LLASlotNumber == 4)
  2563. {
  2564. Routing4SlotVacSystem();
  2565. }
  2566. }
  2567. else
  2568. {
  2569. RoutingFixedSlotVacSystem();
  2570. }
  2571. }
  2572. }
  2573. private void Routing2SlotVacSystem()
  2574. {
  2575. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2576. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2577. {
  2578. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2579. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2580. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2581. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2582. if(robotWafers.Count == 2)
  2583. {
  2584. int returnCount = 0;
  2585. foreach (var wafer in robotWafers)
  2586. {
  2587. if (ModuleHelper.IsPm(wafer.destMod))
  2588. {
  2589. if (_dictModuleTask[wafer.destMod].TimeToReady <= 5 &&
  2590. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2591. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2592. {
  2593. wafer.RouteTo(wafer.destMod, 0);
  2594. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2595. }
  2596. }
  2597. else
  2598. {
  2599. if (_dictModuleTask[outLL].TimeToReady <= 5 && !IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > returnCount)
  2600. {
  2601. wafer.RouteTo(outLL, outLLWaferStatus.emptySlot[returnCount]);
  2602. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, outLL, outLLWaferStatus.emptySlot[returnCount], (Hand)wafer.currentSlot) });
  2603. returnCount++;
  2604. }
  2605. }
  2606. }
  2607. }
  2608. else if(robotWafers.Count == 1)
  2609. {
  2610. int freeHand = 1 - robotWafers.First().currentSlot;
  2611. if (ModuleHelper.IsPm(robotWafers.First().destMod))
  2612. {
  2613. if(_dictModuleTask[robotWafers.First().destMod].TimeToReady <= 5)
  2614. {
  2615. if(_lstWaferTasks.Exists(waferT => waferT.currentMod == robotWafers.First().destMod))
  2616. {
  2617. var pmActions = new List<MoveItem>();
  2618. var pmWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == robotWafers.First().destMod);
  2619. pmWafer.RouteTo(ModuleName.TMRobot, freeHand);
  2620. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, freeHand, (Hand)freeHand));
  2621. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers.First().currentSlot));
  2622. _tmSchdActions.Enqueue(pmActions);
  2623. }
  2624. else
  2625. {
  2626. robotWafers.First().RouteTo(robotWafers.First().destMod, 0);
  2627. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, robotWafers.First().destMod, 0, (Hand)robotWafers.First().currentSlot) });
  2628. }
  2629. }
  2630. }
  2631. else
  2632. {
  2633. if (_dictModuleTask[outLL].TimeToReady <= 5 && !IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0)
  2634. {
  2635. robotWafers.First().RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2636. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)robotWafers.First().currentSlot) });
  2637. }
  2638. }
  2639. if (_tmSchdActions.Count == 0 && _tmRobotSingleArmOption == 0)
  2640. {
  2641. // try push in one wafer
  2642. if (!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].Scheduler.IsVac && inLLWaferStatus.inSlot.Count > 0)
  2643. {
  2644. foreach (var slot in inLLWaferStatus.inSlot)
  2645. {
  2646. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == inLL && wafer.currentSlot == slot);
  2647. if (llWafer != null && !_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].TimeToReady < 15)
  2648. {
  2649. llWafer.RouteTo(llWafer.destMod, 0);
  2650. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, slot, ModuleName.TMRobot, freeHand, (Hand)freeHand) });
  2651. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, freeHand, llWafer.destMod, 0, (Hand)freeHand) });
  2652. return;
  2653. }
  2654. }
  2655. }
  2656. // try to return one wafer
  2657. if (!IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0)
  2658. {
  2659. var reayReturnWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  2660. if (reayReturnWafer != null)
  2661. {
  2662. reayReturnWafer.RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2663. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(reayReturnWafer.currentMod, 0, ModuleName.TMRobot, freeHand, (Hand)freeHand) });
  2664. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, freeHand, outLL, outLLWaferStatus.emptySlot[0], (Hand)freeHand) });
  2665. return;
  2666. }
  2667. }
  2668. }
  2669. }
  2670. else // no wafer on robot arm
  2671. {
  2672. var readyInPms = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !_lstWaferTasks.Exists(wt => wt.currentMod == mod.Key) && mod.Value.Scheduler.IsOnline && mod.Value.TimeToReady <= 15);
  2673. var readyOutWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2).ToList() ;
  2674. if(_tmRobotSingleArmOption != 0)
  2675. {
  2676. var hands = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2677. if (hands.Count == 0)
  2678. return;
  2679. if(!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].TimeToReady <= 5 && inLLWaferStatus.inSlot.Count > 0 && readyInPms.Count() > 0)
  2680. {
  2681. foreach(var pm in readyInPms)
  2682. {
  2683. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && inLLWaferStatus.inSlot.Contains(wt.currentSlot) && wt.destMod == pm.Key);
  2684. if(llWafer != null)
  2685. {
  2686. llWafer.RouteTo(llWafer.destMod, 0);
  2687. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2688. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), llWafer.destMod, 0, hands.First()) });
  2689. return;
  2690. }
  2691. }
  2692. }
  2693. if(readyOutWafers.Count > 0 && !IsLLReservedByEFEM(outLL) && _dictModuleTask[outLL].TimeToReady < 50 && outLLWaferStatus.emptySlot.Count > 0)
  2694. {
  2695. var returnWafer = readyOutWafers.First();
  2696. returnWafer.RouteTo(outLL, outLLWaferStatus.emptySlot.First());
  2697. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(returnWafer.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2698. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL, outLLWaferStatus.emptySlot.First(), hands.First()) });
  2699. return;
  2700. }
  2701. return;
  2702. }
  2703. if(!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].TimeToReady <= 5 && inLLWaferStatus.inSlot.Count > 0)
  2704. {
  2705. if(inLLWaferStatus.inSlot.Count == 2)
  2706. {
  2707. if(readyInPms.Count() > 0) // double move from LL to PM
  2708. {
  2709. int pickCount = 0;
  2710. var swapActions = new List<MoveItem>();
  2711. var singleActions = new List<MoveItem>();
  2712. foreach(var pm in readyInPms)
  2713. {
  2714. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && inLLWaferStatus.inSlot.Contains(wt.currentSlot) && wt.destMod == pm.Key);
  2715. if(llWafer != null)
  2716. {
  2717. llWafer.RouteTo(pm.Key, 0);
  2718. swapActions.Add(new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  2719. singleActions.Add(new MoveItem(ModuleName.TMRobot, pickCount, pm.Key, 0, (Hand)pickCount));
  2720. pickCount++;
  2721. }
  2722. }
  2723. if(pickCount == 1)
  2724. {
  2725. int remainSlot = swapActions.First().SourceSlot == inLLWaferStatus.inSlot[0] ? inLLWaferStatus.inSlot[1] : inLLWaferStatus.inSlot[0];
  2726. var remainWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == remainSlot);
  2727. if (remainWafer != null)
  2728. {
  2729. remainWafer.RouteTo(ModuleName.TMRobot, 1);
  2730. swapActions.Add(new MoveItem(inLL, remainSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  2731. }
  2732. }
  2733. if(swapActions.Count > 0)
  2734. {
  2735. _tmSchdActions.Enqueue(swapActions);
  2736. foreach(var ac in singleActions)
  2737. {
  2738. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  2739. }
  2740. }
  2741. }
  2742. else
  2743. {
  2744. foreach(var slot in inLLWaferStatus.inSlot)
  2745. {
  2746. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == slot);
  2747. if (llWafer != null)
  2748. {
  2749. if(!_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].Scheduler.IsOnline)
  2750. {
  2751. var swapActions = new List<MoveItem>();
  2752. swapActions.Add(new MoveItem(inLL, slot, ModuleName.TMRobot, 0, Hand.Blade1));
  2753. int remainSlot = slot == inLLWaferStatus.inSlot[0] ? inLLWaferStatus.inSlot[1] : inLLWaferStatus.inSlot[0];
  2754. swapActions.Add(new MoveItem(inLL, remainSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  2755. _tmSchdActions.Enqueue(swapActions);
  2756. llWafer.RouteTo(ModuleName.TMRobot, 0);
  2757. if (_dictModuleTask[llWafer.destMod].TimeToReady <= 30)
  2758. {
  2759. llWafer.RouteTo(llWafer.destMod, 0);
  2760. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, 0, llWafer.destMod, 0, Hand.Blade1) });
  2761. }
  2762. return;
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. else
  2769. {
  2770. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == inLLWaferStatus.inSlot.First());
  2771. if (llWafer != null)
  2772. {
  2773. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inLLWaferStatus.inSlot.First(), ModuleName.TMRobot, 0, Hand.Blade1) });
  2774. if (!_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].TimeToReady < 15)
  2775. {
  2776. llWafer.RouteTo(llWafer.destMod, 0);
  2777. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, 0, llWafer.destMod, 0, Hand.Blade1) });
  2778. }
  2779. }
  2780. }
  2781. }
  2782. if (_tmSchdActions.Count > 0)
  2783. return;
  2784. if(!IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0 && readyOutWafers.Count > 0)
  2785. {
  2786. if(readyOutWafers.Count >= 2 && outLLWaferStatus.emptySlot.Count == 2)
  2787. {
  2788. readyOutWafers[0].RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2789. readyOutWafers[1].RouteTo(outLL, outLLWaferStatus.emptySlot[1]);
  2790. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[0].currentMod, readyOutWafers[0].currentSlot, ModuleName.TMRobot, 0, Hand.Blade1) });
  2791. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[1].currentMod, readyOutWafers[1].currentSlot, ModuleName.TMRobot, 1, Hand.Blade2) });
  2792. var swapActions = new List<MoveItem>();
  2793. swapActions.Add(new MoveItem(ModuleName.TMRobot, 0, outLL, outLLWaferStatus.emptySlot[0], Hand.Blade1));
  2794. swapActions.Add(new MoveItem(ModuleName.TMRobot, 1, outLL, outLLWaferStatus.emptySlot[1], Hand.Blade2));
  2795. _tmSchdActions.Enqueue(swapActions);
  2796. }
  2797. else
  2798. {
  2799. var freeHands = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2800. readyOutWafers[0].RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2801. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[0].currentMod, readyOutWafers[0].currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  2802. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot[0], freeHands[0]) });
  2803. }
  2804. }
  2805. }
  2806. }
  2807. else
  2808. {
  2809. if (robotWafers.Count == 2)
  2810. {
  2811. foreach (var wafer in robotWafers)
  2812. {
  2813. if (wafer.movingStatus == RState.End &&
  2814. ModuleHelper.IsPm(wafer.destMod) &&
  2815. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  2816. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2817. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2818. {
  2819. wafer.RouteTo(wafer.destMod, 0);
  2820. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2821. }
  2822. }
  2823. if (_tmSchdActions.Count == 0)
  2824. {
  2825. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2826. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2827. {
  2828. RoutingTMSwapActions(swapActions.swapActions);
  2829. _tmSchdActions.Enqueue(swapActions.swapActions);
  2830. }
  2831. }
  2832. }
  2833. else if (robotWafers.Count == 1)
  2834. {
  2835. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  2836. {
  2837. var pmActions = new List<MoveItem>();
  2838. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  2839. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  2840. {
  2841. int pickSlot = 1 - robotWafers[0].currentSlot;
  2842. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  2843. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  2844. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  2845. _tmSchdActions.Enqueue(pmActions);
  2846. return;
  2847. }
  2848. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  2849. {
  2850. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  2851. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  2852. _tmSchdActions.Enqueue(pmActions);
  2853. return;
  2854. }
  2855. }
  2856. // try to pick a wafer from LL
  2857. if (_tmSchdActions.Count == 0)
  2858. {
  2859. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2860. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2861. {
  2862. RoutingTMSwapActions(swapActions.swapActions);
  2863. _tmSchdActions.Enqueue(swapActions.swapActions);
  2864. return;
  2865. }
  2866. }
  2867. // try to return a wafer from PM
  2868. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2869. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2870. if (moveActions.pmWafers.Count > 0)
  2871. {
  2872. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2873. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  2874. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  2875. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  2876. if (pickAction != null)
  2877. {
  2878. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  2879. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  2880. }
  2881. _tmSchdActions.Enqueue(moveActions.swapAction);
  2882. }
  2883. }
  2884. else // robot arm is empty
  2885. {
  2886. // try return wafers from PM
  2887. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2888. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2889. if (moveActions.pmWafers.Count > 0)
  2890. {
  2891. int handIndex = 0;
  2892. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2893. foreach (var action in placeActions)
  2894. {
  2895. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  2896. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  2897. handIndex++;
  2898. }
  2899. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  2900. foreach (var ac in pickActions)
  2901. {
  2902. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  2903. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  2904. }
  2905. _tmSchdActions.Enqueue(moveActions.swapAction);
  2906. }
  2907. if (_tmSchdActions.Count == 0)
  2908. {
  2909. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2910. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2911. {
  2912. RoutingTMSwapActions(swapActions.swapActions);
  2913. _tmSchdActions.Enqueue(swapActions.swapActions);
  2914. }
  2915. }
  2916. }
  2917. }
  2918. }
  2919. private void Routing4SlotVacSystem()
  2920. {
  2921. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2922. if (robotWafers.Count == 2)
  2923. {
  2924. foreach (var wafer in robotWafers)
  2925. {
  2926. if (wafer.movingStatus == RState.End &&
  2927. ModuleHelper.IsPm(wafer.destMod) &&
  2928. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  2929. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2930. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2931. {
  2932. wafer.RouteTo(wafer.destMod, 0);
  2933. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2934. }
  2935. }
  2936. if (_tmSchdActions.Count == 0)
  2937. {
  2938. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2939. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2940. {
  2941. RoutingTMSwapActions(swapActions.swapActions);
  2942. _tmSchdActions.Enqueue(swapActions.swapActions);
  2943. }
  2944. }
  2945. }
  2946. else if (robotWafers.Count == 1)
  2947. {
  2948. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  2949. {
  2950. var pmActions = new List<MoveItem>();
  2951. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  2952. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  2953. {
  2954. int pickSlot = 1 - robotWafers[0].currentSlot;
  2955. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  2956. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  2957. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  2958. _tmSchdActions.Enqueue(pmActions);
  2959. return;
  2960. }
  2961. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  2962. {
  2963. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  2964. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  2965. _tmSchdActions.Enqueue(pmActions);
  2966. return;
  2967. }
  2968. }
  2969. // try to pick a wafer from LL
  2970. if (_tmSchdActions.Count == 0)
  2971. {
  2972. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2973. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2974. {
  2975. RoutingTMSwapActions(swapActions.swapActions);
  2976. _tmSchdActions.Enqueue(swapActions.swapActions);
  2977. return;
  2978. }
  2979. }
  2980. // try to return a wafer from PM
  2981. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2982. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2983. if (moveActions.pmWafers.Count > 0)
  2984. {
  2985. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2986. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  2987. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  2988. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  2989. if (pickAction != null)
  2990. {
  2991. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  2992. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  2993. }
  2994. _tmSchdActions.Enqueue(moveActions.swapAction);
  2995. }
  2996. }
  2997. else // robot arm is empty
  2998. {
  2999. // try return wafers from PM
  3000. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3001. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3002. if (moveActions.pmWafers.Count > 0)
  3003. {
  3004. int handIndex = 0;
  3005. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3006. foreach (var action in placeActions)
  3007. {
  3008. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3009. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3010. handIndex++;
  3011. }
  3012. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3013. foreach (var ac in pickActions)
  3014. {
  3015. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3016. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3017. }
  3018. _tmSchdActions.Enqueue(moveActions.swapAction);
  3019. }
  3020. if (_tmSchdActions.Count == 0)
  3021. {
  3022. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3023. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3024. {
  3025. RoutingTMSwapActions(swapActions.swapActions);
  3026. _tmSchdActions.Enqueue(swapActions.swapActions);
  3027. }
  3028. }
  3029. }
  3030. }
  3031. private void RoutingFixedSlotVacSystem()
  3032. {
  3033. var robotWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod));
  3034. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  3035. if (_LLASlotNumber == 2)
  3036. {
  3037. if (robotWafers.Count() == 1)
  3038. {
  3039. if(ModuleHelper.IsPm(robotWafers.First().destMod))
  3040. {
  3041. var destPM = robotWafers.First().destMod;
  3042. if(_dictModuleTask[destPM].TimeToReady <= 5)
  3043. {
  3044. if(_lstWaferTasks.Exists(wt => wt.currentMod == destPM))
  3045. {
  3046. var pickHand = SelectTMPickArm(destPM);
  3047. if(pickHand != Hand.None)
  3048. {
  3049. var pmSwap = new List<MoveItem>();
  3050. pmSwap.Add(new MoveItem(destPM, 0, ModuleName.TMRobot, (int)pickHand, pickHand));
  3051. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot));
  3052. _tmSchdActions.Enqueue(pmSwap);
  3053. return;
  3054. }
  3055. }
  3056. else
  3057. {
  3058. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot) });
  3059. return;
  3060. }
  3061. }
  3062. }
  3063. else
  3064. {
  3065. var readySwapLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3066. GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 &&
  3067. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3068. ll.Value.TimeToReady <= 10);
  3069. if (readySwapLL.Count() > 0)
  3070. {
  3071. var destLL = readySwapLL.First().Key;
  3072. Hand pickHand = SelectTMPickArm(destLL);
  3073. if (pickHand != Hand.None)
  3074. {
  3075. Hand placeHand = (Hand)robotWafers.First().currentSlot;
  3076. var llSwap = new List<MoveItem>();
  3077. var llSlots = GetLLFixedReadyInOutSlots(destLL);
  3078. llSwap.Add(new MoveItem(destLL, llSlots.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3079. llSwap.Add(new MoveItem(ModuleName.TMRobot, (int)placeHand, destLL, llSlots.tInSlot.First(), placeHand));
  3080. _tmSchdActions.Enqueue(llSwap);
  3081. return;
  3082. }
  3083. }
  3084. var emptyLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3085. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3086. ll.Value.TimeToReady <= 2);
  3087. if (emptyLL.Count() > 0)
  3088. {
  3089. var destLL = emptyLL.First().Key;
  3090. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem( ModuleName.TMRobot,
  3091. robotWafers.First().currentSlot,
  3092. destLL,
  3093. GetLLFixedReadyInOutSlots(destLL).tInSlot.First(),
  3094. (Hand)robotWafers.First().currentSlot) });
  3095. return;
  3096. }
  3097. }
  3098. // try to return a wafer
  3099. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3100. foreach(var pmWafer in readyReturnWafers)
  3101. {
  3102. 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);
  3103. if(readyLL.Count() > 0)
  3104. {
  3105. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3106. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3107. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand , readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3108. return;
  3109. }
  3110. }
  3111. // try to push in a wafer
  3112. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3113. foreach(var ll in readyInLL)
  3114. {
  3115. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3116. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3117. if( wafer != null &&
  3118. ModuleHelper.IsPm(wafer.destMod) &&
  3119. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3120. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3121. {
  3122. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3123. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3124. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3125. return;
  3126. }
  3127. }
  3128. }
  3129. else if (robotWafers.Count() == 0)
  3130. {
  3131. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  3132. if(readyReturnWafers.Count > 0)
  3133. {
  3134. // try to do a LL swap action
  3135. var readySwapLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 10);
  3136. foreach (var pmWafer in readyReturnWafers)
  3137. {
  3138. foreach (var ll in readySwapLL)
  3139. {
  3140. if (CanWaferGotoLL(pmWafer, ll.Key))
  3141. {
  3142. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3143. var pickHand = SelectTMPickArm(ll.Key);
  3144. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3145. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3146. var llSwapActions = new List<MoveItem>();
  3147. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, llWaferStatus.tInSlot.First(), returnHand));
  3148. llSwapActions.Add(new MoveItem(ll.Key, llWaferStatus.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3149. _tmSchdActions.Enqueue(llSwapActions);
  3150. return;
  3151. }
  3152. }
  3153. }
  3154. // just return to LL
  3155. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 5);
  3156. foreach(var pmWafer in readyReturnWafers)
  3157. {
  3158. foreach(var ll in readyInLL)
  3159. {
  3160. if(CanWaferGotoLL(pmWafer, ll.Key))
  3161. {
  3162. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3163. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3164. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, GetLLFixedReadyInOutSlots(ll.Key).tInSlot.First(), returnHand) });
  3165. return;
  3166. }
  3167. }
  3168. }
  3169. }
  3170. var readyPushInLLs = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && ll.Value.TimeToReady <= 2);
  3171. if(readyPushInLLs.Count() > 0)
  3172. {
  3173. var destLL = readyPushInLLs.First().Key;
  3174. if(readyPushInLLs.Count() == 2 && readyPushInLLs.First().Value.Scheduler.IsAtm && readyPushInLLs.Last().Value.Scheduler.IsVac)
  3175. {
  3176. destLL = readyPushInLLs.Last().Key;
  3177. }
  3178. var pickHand = SelectTMPickArm(destLL);
  3179. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(destLL, GetLLFixedReadyInOutSlots(destLL).tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand) });
  3180. return;
  3181. }
  3182. }
  3183. else
  3184. {
  3185. // should not go here
  3186. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Had better avoid picking two wafers on TM robot arms under Loadlock fixed slot pattern");
  3187. foreach(var wafer in robotWafers)
  3188. {
  3189. if(ModuleHelper.IsPm(wafer.destMod))
  3190. {
  3191. if(!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3192. {
  3193. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3194. return;
  3195. }
  3196. }
  3197. else
  3198. {
  3199. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 2);
  3200. if(readyInLL.Count() > 0)
  3201. {
  3202. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, readyInLL.First().Key, GetLLFixedReadyInOutSlots(readyInLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3203. return;
  3204. }
  3205. }
  3206. }
  3207. }
  3208. }
  3209. else // 4 slot Loadlock
  3210. {
  3211. if(robotWafers.Count() > 0)
  3212. {
  3213. if (robotWafers.Count() == 2)
  3214. {
  3215. if (robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)))
  3216. {
  3217. var destLL = lls.Where(ll => robotWafers.All(wt => CanWaferGotoLL(wt, ll.Key)) &&
  3218. ll.Value.TimeToReady <= 10 &&
  3219. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 2).
  3220. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3221. OrderBy(ll => ll.Value.TimeToReady);
  3222. if (destLL.Count() > 0)
  3223. {
  3224. var swapLL = destLL.First().Key;
  3225. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3226. var swapActions = new List<MoveItem>();
  3227. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafers.First().currentSlot));
  3228. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.Last().currentSlot, swapLL, llWaferStatus.tInSlot.Last(), (Hand)robotWafers.Last().currentSlot));
  3229. int pickCount = 0;
  3230. foreach (var slot in llWaferStatus.eOutSlot)
  3231. {
  3232. swapActions.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3233. }
  3234. _tmSchdActions.Enqueue(swapActions);
  3235. return;
  3236. }
  3237. }
  3238. foreach (var wafer in robotWafers)
  3239. {
  3240. if (ModuleHelper.IsPm(wafer.destMod))
  3241. {
  3242. if (!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 5)
  3243. {
  3244. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3245. return;
  3246. }
  3247. }
  3248. else
  3249. {
  3250. var placeLL = lls.Where(ll => CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 5 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).OrderBy(ll => ll.Value.TimeToReady);
  3251. if (placeLL.Count() > 0)
  3252. {
  3253. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, placeLL.First().Key, GetLLFixedReadyInOutSlots(placeLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3254. return;
  3255. }
  3256. }
  3257. }
  3258. }
  3259. else if (robotWafers.Count() == 1)
  3260. {
  3261. var robotWafer = robotWafers.First();
  3262. if (ModuleHelper.IsPm(robotWafer.destMod))
  3263. {
  3264. if (_dictModuleTask[robotWafer.destMod].TimeToReady <= 5)
  3265. {
  3266. if (_lstWaferTasks.Exists(wt => wt.currentMod == robotWafer.destMod))
  3267. {
  3268. var pmSwap = new List<MoveItem>();
  3269. pmSwap.Add(new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, 1 - robotWafer.currentSlot, (Hand)(1 - robotWafer.currentSlot)));
  3270. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot));
  3271. _tmSchdActions.Enqueue(pmSwap);
  3272. return;
  3273. }
  3274. else
  3275. {
  3276. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3277. return;
  3278. }
  3279. }
  3280. }
  3281. else
  3282. {
  3283. var destLL = lls.Where(ll => CanWaferGotoLL(robotWafer, ll.Key) &&
  3284. ll.Value.TimeToReady <= 10 &&
  3285. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).
  3286. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3287. OrderBy(ll => ll.Value.TimeToReady);
  3288. if (destLL.Count() > 0)
  3289. {
  3290. var swapLL = destLL.First().Key;
  3291. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3292. var llSwap = new List<MoveItem>();
  3293. llSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafer.currentSlot));
  3294. int pickCount = 0;
  3295. foreach (var slot in llWaferStatus.tOutSlot)
  3296. {
  3297. llSwap.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3298. pickCount++;
  3299. }
  3300. _tmSchdActions.Enqueue(llSwap);
  3301. return;
  3302. }
  3303. }
  3304. // try to return a wafer
  3305. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3306. foreach (var pmWafer in readyReturnWafers)
  3307. {
  3308. 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);
  3309. if (readyLL.Count() > 0)
  3310. {
  3311. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3312. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3313. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3314. return;
  3315. }
  3316. }
  3317. // try to push in a wafer
  3318. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3319. foreach (var ll in readyInLL)
  3320. {
  3321. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3322. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3323. if (wafer != null &&
  3324. ModuleHelper.IsPm(wafer.destMod) &&
  3325. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3326. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3327. {
  3328. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3329. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3330. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3331. return;
  3332. }
  3333. }
  3334. }
  3335. }
  3336. else // robot empty
  3337. {
  3338. 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();
  3339. var readyLL = lls.Where(ll => ll.Value.TimeToReady <= 10);
  3340. if(readyLL.Count() > 0)
  3341. {
  3342. var llPath = FindTheBestMovePathWithFixSlot(readyLL, nearlyReadyReturnWafers);
  3343. if(ModuleHelper.IsLoadLock(llPath))
  3344. {
  3345. int returnCount = 0;
  3346. var llWaferStatus = GetLLFixedReadyInOutSlots(llPath);
  3347. var llSwapActions = new List<MoveItem>();
  3348. foreach(var wafer in nearlyReadyReturnWafers)
  3349. {
  3350. if(CanWaferGotoLL(wafer, llPath) && returnCount < Math.Min(llWaferStatus.tInSlot.Count, 2))
  3351. {
  3352. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, 0, ModuleName.TMRobot, returnCount, (Hand)returnCount) });
  3353. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, returnCount, llPath, llWaferStatus.tInSlot[returnCount], (Hand)returnCount));
  3354. returnCount++;
  3355. }
  3356. }
  3357. int pickCount = 0;
  3358. foreach(var slot in llWaferStatus.tOutSlot)
  3359. {
  3360. if (pickCount < 2)
  3361. {
  3362. llSwapActions.Add(new MoveItem(llPath, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3363. pickCount++;
  3364. }
  3365. }
  3366. if(llSwapActions.Count > 0)
  3367. {
  3368. _tmSchdActions.Enqueue(llSwapActions);
  3369. }
  3370. return;
  3371. }
  3372. }
  3373. }
  3374. }
  3375. }
  3376. private bool IsTMRobotArmNotReserved(Hand hand)
  3377. {
  3378. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)hand) || _lstWaferTasks.Exists(wt => wt.currentMod == ModuleName.TMRobot && wt.currentSlot == (int)hand))
  3379. return false;
  3380. foreach(var acs in _tmSchdActions)
  3381. {
  3382. foreach(var ac in acs)
  3383. {
  3384. if ((ac.DestinationModule == ModuleName.TMRobot || ac.SourceModule == ModuleName.TMRobot) && ac.DestinationSlot == (int)hand)
  3385. return false;
  3386. }
  3387. }
  3388. return true;
  3389. }
  3390. private Hand SelectTMPickArm(ModuleName mod)
  3391. {
  3392. switch (_tmRobotSingleArmOption)
  3393. {
  3394. case 0:
  3395. {
  3396. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3397. return Hand.Blade1;
  3398. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3399. return Hand.Blade2;
  3400. }
  3401. break;
  3402. case 1:
  3403. {
  3404. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3405. return Hand.Blade1;
  3406. }
  3407. break;
  3408. case 2:
  3409. {
  3410. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3411. return Hand.Blade2;
  3412. }
  3413. break;
  3414. // Blade1 In Blade2 Out
  3415. case 3:
  3416. {
  3417. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3418. return Hand.Blade1;
  3419. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3420. return Hand.Blade2;
  3421. }
  3422. break;
  3423. // Blade2 In Blade1 Out
  3424. case 4:
  3425. {
  3426. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3427. return Hand.Blade2;
  3428. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3429. return Hand.Blade1;
  3430. }
  3431. break;
  3432. }
  3433. return Hand.None;
  3434. }
  3435. private List<Hand> GetTMFreeHand()
  3436. {
  3437. var lstHands = new List<Hand>();
  3438. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  3439. lstHands.Add(Hand.Blade1);
  3440. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  3441. lstHands.Add(Hand.Blade2);
  3442. return lstHands;
  3443. }
  3444. private List<Hand> GetEFEMFreeHand()
  3445. {
  3446. var lstHands = new List<Hand>();
  3447. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && _efemRobotSingleArmOption != 2)
  3448. lstHands.Add(Hand.Blade1);
  3449. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && _efemRobotSingleArmOption != 1)
  3450. lstHands.Add(Hand.Blade2);
  3451. return lstHands;
  3452. }
  3453. private bool CanWaferGotoLL(WaferTask task, ModuleName ll)
  3454. {
  3455. bool bVacWafer = ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod);
  3456. if (bVacWafer)
  3457. {
  3458. if (ModuleHelper.IsPm(task.destMod))
  3459. return false;
  3460. switch (task.llInOutPath)
  3461. {
  3462. case SequenceLLInOutPath.AInAOut:
  3463. case SequenceLLInOutPath.BInAOut:
  3464. return ll == ModuleName.LLA;
  3465. case SequenceLLInOutPath.AInBOut:
  3466. case SequenceLLInOutPath.BInBOut:
  3467. return ll == ModuleName.LLB;
  3468. case SequenceLLInOutPath.DInDOut:
  3469. return true;
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if (ModuleHelper.IsLoadPort(task.destMod))
  3475. return false;
  3476. switch (task.llInOutPath)
  3477. {
  3478. case SequenceLLInOutPath.AInAOut:
  3479. case SequenceLLInOutPath.AInBOut:
  3480. return ll == ModuleName.LLA;
  3481. case SequenceLLInOutPath.BInAOut:
  3482. case SequenceLLInOutPath.BInBOut:
  3483. return ll == ModuleName.LLB;
  3484. case SequenceLLInOutPath.DInDOut:
  3485. return true;
  3486. }
  3487. }
  3488. return false;
  3489. }
  3490. private (List<int> inSlot, List<int> outSlot, List<int> emptySlot) GetLLReadyInOutSlots(ModuleName ll)
  3491. {
  3492. var readInSlots = new List<int>();
  3493. var readyOutSlots = new List<int>();
  3494. var emptySlots = new List<int>();
  3495. for(int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3496. {
  3497. 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)))
  3498. {
  3499. emptySlots.Add(slot);
  3500. }
  3501. if(WaferManager.Instance.CheckHasWafer(ll, slot))
  3502. {
  3503. Guid waferID = WaferManager.Instance.GetWafer(ll, slot).InnerId;
  3504. var waferTask = _lstWaferTasks.Find(wafer => wafer.waferId == waferID);
  3505. if(waferTask != null && waferTask.movingStatus == RState.End)
  3506. {
  3507. if (ModuleHelper.IsPm(waferTask.destMod))
  3508. readInSlots.Add(slot);
  3509. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3510. readyOutSlots.Add(slot);
  3511. }
  3512. }
  3513. }
  3514. return (readInSlots, readyOutSlots, emptySlots);
  3515. }
  3516. private (List<int> eInSlot, List<int> eOutSlot, List<int> tInSlot, List<int> tOutSlot) GetLLFixedReadyInOutSlots(ModuleName ll)
  3517. {
  3518. var eInSlot = new List<int>();
  3519. var eOutSlot = new List<int>();
  3520. var tInSlot = new List<int>();
  3521. var tOutSlot = new List<int>();
  3522. int SlotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  3523. for (int slot = 0; slot < SlotNumber; slot++)
  3524. {
  3525. if (WaferManager.Instance.CheckNoWafer(ll, slot) && !_lstWaferTasks.Exists(wafer => (wafer.routedMod == ll && wafer.routedSlot == slot) || (wafer.currentMod == ll && wafer.currentSlot == slot) || (wafer.nextMod == ll && wafer.nextSlot == slot)))
  3526. {
  3527. if ((slot >= SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.UpperInLowerOut) ||
  3528. (slot < SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.LowerInUpperOut))
  3529. {
  3530. eInSlot.Add(slot);
  3531. }
  3532. else
  3533. {
  3534. tInSlot.Add(slot);
  3535. }
  3536. }
  3537. if (WaferManager.Instance.CheckHasWafer(ll, slot))
  3538. {
  3539. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3540. var waferTask = _lstWaferTasks.Find(wt => wt.waferId == wafer.InnerId && wt.currentMod == ll && wt.currentSlot == slot);
  3541. if(waferTask == null)
  3542. {
  3543. LOG.Write(eEvent.EV_ROUTER, ll, $"Routing trace: did not find inner task associated with {wafer.WaferOrigin} at {ll}.{slot + 1}");
  3544. }
  3545. else if (waferTask.movingStatus == RState.End)
  3546. {
  3547. if (ModuleHelper.IsPm(waferTask.destMod))
  3548. tOutSlot.Add(slot);
  3549. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3550. eOutSlot.Add(slot);
  3551. }
  3552. }
  3553. }
  3554. return (eInSlot, eOutSlot, tInSlot, tOutSlot);
  3555. }
  3556. private (List<WaferInfo> wafers, List<int> emptySlots) GetLLWaferExistance(ModuleName ll)
  3557. {
  3558. var lstWafers = new List<WaferInfo>();
  3559. var lstEmptySlots = new List<int>();
  3560. for (int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3561. {
  3562. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3563. if(wafer != null && !wafer.IsEmpty)
  3564. {
  3565. lstWafers.Add(wafer);
  3566. }
  3567. else
  3568. {
  3569. lstEmptySlots.Add(slot);
  3570. }
  3571. }
  3572. return (lstWafers, lstEmptySlots);
  3573. }
  3574. private void PrepareLLPressure()
  3575. {
  3576. if (RouteManager.IsATMMode)
  3577. return;
  3578. var preaparedLLs = new List<ModuleName>();
  3579. var lls = _efemSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3580. if (_curEfemAction.Count == 0 && _efemSchdActions.Count > 0 && ModuleHelper.IsLoadLock(_efemSchdActions.First().First().Module))
  3581. lls.Remove(_efemSchdActions.First().First().Module);
  3582. foreach(var ll in lls)
  3583. {
  3584. if(_dictModuleTask[ll].Scheduler.IsAvailable && _dictModuleTask[ll].Scheduler.IsVac && !preaparedLLs.Contains(ll))
  3585. {
  3586. (_dictModuleTask[ll].Scheduler as SchedulerLoadLock).PreVent();
  3587. preaparedLLs.Add(ll);
  3588. }
  3589. }
  3590. lls = _tmSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3591. if(_curTmAction.Count == 0 && _tmSchdActions.Count > 0 && ModuleHelper.IsLoadLock(_tmSchdActions.First().First().Module))
  3592. lls.Remove(_tmSchdActions.First().First().Module);
  3593. foreach (var ll in lls)
  3594. {
  3595. if (_dictModuleTask[ll].Scheduler.IsAvailable && _dictModuleTask[ll].Scheduler.IsAtm && !preaparedLLs.Contains(ll))
  3596. {
  3597. (_dictModuleTask[ll].Scheduler as SchedulerLoadLock).PrePump();
  3598. preaparedLLs.Add(ll);
  3599. }
  3600. }
  3601. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0 || _tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  3602. return;
  3603. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  3604. {
  3605. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  3606. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  3607. var inLLWaferCount = _lstWaferTasks.Where(wafer => wafer.currentMod == inLL).Count();
  3608. var outLLWaferCount = _lstWaferTasks.Where(wafer => wafer.currentMod == outLL).Count();
  3609. if (inLLWaferCount == 0 && !preaparedLLs.Contains(inLL))
  3610. {
  3611. (_dictModuleTask[inLL] as LoadlockTask).PreVent();
  3612. preaparedLLs.Add(inLL);
  3613. }
  3614. else if(inLLWaferCount == (LLInOutPath == SequenceLLInOutPath.AInBOut ? _LLASlotNumber : _LLBSlotNumber) && !preaparedLLs.Contains(inLL))
  3615. {
  3616. (_dictModuleTask[inLL] as LoadlockTask).PrePump();
  3617. preaparedLLs.Add(inLL);
  3618. }
  3619. if(outLLWaferCount == 0 && !preaparedLLs.Contains(outLL))
  3620. {
  3621. (_dictModuleTask[outLL] as LoadlockTask).PrePump();
  3622. preaparedLLs.Add(outLL);
  3623. }
  3624. else if(outLLWaferCount == (LLInOutPath == SequenceLLInOutPath.BInAOut ? _LLASlotNumber : _LLBSlotNumber) && !preaparedLLs.Contains(outLL))
  3625. {
  3626. (_dictModuleTask[outLL] as LoadlockTask).PreVent();
  3627. preaparedLLs.Add(outLL);
  3628. }
  3629. }
  3630. }
  3631. private void ReturnVacWafers()
  3632. {
  3633. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  3634. {
  3635. RunSchdTMReturnActions();
  3636. return;
  3637. }
  3638. if (_tmRobotStatus != RState.End)
  3639. return;
  3640. var hands = GetTMFreeHand();
  3641. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && !IsLLReservedByEFEM(mod.Key) && mod.Value.Scheduler.IsIdle && GetLLWaferExistance(mod.Key).emptySlots.Count > 0).OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).emptySlot.Count);
  3642. if(lls.Count() > 0)
  3643. {
  3644. // return robot wafers
  3645. int moveCount = 0;
  3646. var llActions = new List<MoveItem>();
  3647. var emptySlots = GetLLWaferExistance(lls.First().Key).emptySlots;
  3648. for(int arm = 0; arm < 2; arm++)
  3649. {
  3650. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, arm);
  3651. if(wafer != null && !wafer.IsEmpty && moveCount < emptySlots.Count)
  3652. {
  3653. llActions.Add(new MoveItem(ModuleName.TMRobot, arm, lls.First().Key, emptySlots[moveCount], (Hand)arm));
  3654. moveCount++;
  3655. }
  3656. }
  3657. if(moveCount > 0)
  3658. {
  3659. _tmSchdActions.Enqueue(llActions);
  3660. return;
  3661. }
  3662. // return PM wafers
  3663. var PickActions = new List<MoveItem>();
  3664. var hasWaferPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsIdle && WaferManager.Instance.CheckHasWafer(mod.Key, 0));
  3665. foreach(var pm in hasWaferPMs)
  3666. {
  3667. if (moveCount < hands.Count && moveCount < emptySlots.Count)
  3668. {
  3669. PickActions.Add(new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)hands[moveCount], hands[moveCount]));
  3670. llActions.Add(new MoveItem(ModuleName.TMRobot, (int)hands[moveCount], lls.First().Key, emptySlots[moveCount], hands[moveCount]));
  3671. moveCount++;
  3672. }
  3673. }
  3674. if(moveCount > 0)
  3675. {
  3676. foreach(var ac in PickActions)
  3677. {
  3678. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  3679. }
  3680. _tmSchdActions.Enqueue(llActions);
  3681. }
  3682. }
  3683. }
  3684. private void ReturnAtmWafers()
  3685. {
  3686. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  3687. {
  3688. RunSchdEFEMReturnActions();
  3689. return;
  3690. }
  3691. if (_efemRobotStatus != RState.End)
  3692. return;
  3693. // return Robot Wafer
  3694. for(int i = 0; i < 2; i++)
  3695. {
  3696. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  3697. if(wafer != null && !wafer.IsEmpty)
  3698. {
  3699. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  3700. }
  3701. }
  3702. if (_efemSchdActions.Count > 0)
  3703. return;
  3704. var hands = GetEFEMFreeHand();
  3705. // return Aligner wafer
  3706. var aligner = ModuleHelper.InstalledModules.Where(mod => ModuleHelper.IsAligner(mod)).ToList();
  3707. if(aligner.Count > 0 && WaferManager.Instance.CheckHasWafer(aligner.First(), 0) && hands.Count > 0)
  3708. {
  3709. var wafer = WaferManager.Instance.GetWafer(aligner.First(), 0);
  3710. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(aligner.First(), 0, ModuleName.EfemRobot, (int)hands.First(), hands.First()) });
  3711. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)hands.First(), (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands.First()) });
  3712. return;
  3713. }
  3714. // return Loadlock wafer
  3715. 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);
  3716. if(lls.Count() > 0)
  3717. {
  3718. int returnCount = 0;
  3719. var llActions = new List<MoveItem>();
  3720. var placActions = new List<MoveItem>();
  3721. foreach(var wafer in GetLLWaferExistance(lls.First().Key).wafers)
  3722. {
  3723. if(returnCount < hands.Count)
  3724. {
  3725. llActions.Add(new MoveItem(lls.First().Key, wafer.Slot, ModuleName.EfemRobot, (int)hands[returnCount], hands[returnCount]));
  3726. placActions.Add(new MoveItem(ModuleName.EfemRobot, (int)hands[returnCount], (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands[returnCount]));
  3727. returnCount++;
  3728. }
  3729. }
  3730. if (returnCount > 0)
  3731. {
  3732. _efemSchdActions.Enqueue(llActions);
  3733. foreach (var ac in placActions)
  3734. {
  3735. _efemSchdActions.Enqueue(new List<MoveItem> { ac });
  3736. }
  3737. }
  3738. }
  3739. }
  3740. private void RunSchdEFEMReturnActions()
  3741. {
  3742. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  3743. if (efemRobot == null || !efemRobot.IsAvailable)
  3744. return;
  3745. if (_efemSchdActions.Count > 0)
  3746. {
  3747. if (_curEfemAction.Count == 0 || isReturnActionsDone(_curEfemAction))
  3748. {
  3749. var nextActions = _efemSchdActions.First();
  3750. var nextModule = nextActions.First().Module;
  3751. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  3752. return;
  3753. _curEfemAction = _efemSchdActions.Dequeue();
  3754. efemRobot.PostMoveItems(_curEfemAction.ToArray());
  3755. }
  3756. }
  3757. else if (_curEfemAction.Count >= 0 && isReturnActionsDone(_curEfemAction)) // all scheduled actions done
  3758. {
  3759. _curEfemAction.Clear();
  3760. }
  3761. }
  3762. private void RunSchdTMReturnActions()
  3763. {
  3764. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerTMRobot;
  3765. if (tmRobot == null || !tmRobot.IsAvailable)
  3766. return;
  3767. if (_tmSchdActions.Count > 0)
  3768. {
  3769. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  3770. {
  3771. var nextActions = _tmSchdActions.First();
  3772. var nextModule = nextActions.First().Module;
  3773. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  3774. return;
  3775. _curTmAction = _tmSchdActions.Dequeue();
  3776. tmRobot.SendMoveItems(_curTmAction.ToArray());
  3777. }
  3778. }
  3779. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  3780. {
  3781. _curTmAction.Clear();
  3782. }
  3783. }
  3784. #endregion
  3785. #region sequence/recipe operation
  3786. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  3787. {
  3788. reason = "";
  3789. foreach(var pm in seq.PMs)
  3790. {
  3791. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  3792. return true;
  3793. }
  3794. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  3795. return false;
  3796. }
  3797. private bool CheckSequenceKepler2200TemperatureReady(SequenceInfo seq)
  3798. {
  3799. for (int i = 0; i < seq.Steps.Count; i++)
  3800. {
  3801. SequenceStepInfo stepInfo = seq.Steps[i];
  3802. foreach (var module in stepInfo.StepModules)
  3803. {
  3804. if (ModuleHelper.IsPm(module))
  3805. {
  3806. string attr = $"{module}Recipe";
  3807. if (stepInfo.StepParameter.ContainsKey(attr)
  3808. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3809. {
  3810. var recipeName = (string)stepInfo.StepParameter[attr];
  3811. var recipeContent =
  3812. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3813. var recipe = Recipe.Load(recipeContent);
  3814. float currentChamberTemperature;
  3815. switch (module)
  3816. {
  3817. case ModuleName.PMA:
  3818. currentChamberTemperature = Singleton<RouteManager>.Instance.PMA.ChamberTemperature;
  3819. break;
  3820. case ModuleName.PMB:
  3821. currentChamberTemperature = Singleton<RouteManager>.Instance.PMB.ChamberTemperature;
  3822. break;
  3823. case ModuleName.PMC:
  3824. currentChamberTemperature = Singleton<RouteManager>.Instance.PMC.ChamberTemperature;
  3825. break;
  3826. case ModuleName.PMD:
  3827. currentChamberTemperature = Singleton<RouteManager>.Instance.PMD.ChamberTemperature;
  3828. break;
  3829. default:
  3830. currentChamberTemperature = 0;
  3831. break;
  3832. }
  3833. if (recipe.Header.Temperature != null && recipe.Header.Temperature != "" && (currentChamberTemperature > Convert.ToSingle(recipe.Header.Temperature) + 10 || currentChamberTemperature < Convert.ToSingle(recipe.Header.Temperature) - 10))
  3834. {
  3835. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Start job失败,由于{module}腔体温度{currentChamberTemperature}与{recipeName} Recipe温度{recipe.Header.Temperature}不匹配");
  3836. return false;
  3837. }
  3838. }
  3839. }
  3840. }
  3841. }
  3842. return true;
  3843. }
  3844. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  3845. {
  3846. for (int i = 0; i < seq.Steps.Count; i++)
  3847. {
  3848. SequenceStepInfo stepInfo = seq.Steps[i];
  3849. foreach (var module in stepInfo.StepModules)
  3850. {
  3851. if (ModuleHelper.IsPm(module))
  3852. {
  3853. string attr = $"{module}Recipe";
  3854. if (stepInfo.StepParameter.ContainsKey(attr)
  3855. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3856. {
  3857. var recipeName = (string)stepInfo.StepParameter[attr];
  3858. if (!string.IsNullOrWhiteSpace(recipeName))
  3859. {
  3860. var recipeContent =
  3861. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3862. if (string.IsNullOrWhiteSpace(recipeContent))
  3863. {
  3864. reason = $"Can not find recipe file{recipeName}";
  3865. return false;
  3866. }
  3867. }
  3868. }
  3869. }
  3870. }
  3871. }
  3872. reason = "";
  3873. return true;
  3874. }
  3875. private void UpdateLLInOutPathProperty()
  3876. {
  3877. if (_lstControlJobs.Count == 0)
  3878. return;
  3879. var inOutPaths = new List<SequenceLLInOutPath>();
  3880. foreach(var wt in _lstWaferTasks)
  3881. {
  3882. if (!inOutPaths.Contains(wt.llInOutPath))
  3883. inOutPaths.Add(wt.llInOutPath);
  3884. }
  3885. if (inOutPaths.Count == 1)
  3886. {
  3887. _LLInOutPath = inOutPaths[0];
  3888. }
  3889. else
  3890. _LLInOutPath = SequenceLLInOutPath.DInDOut;
  3891. }
  3892. private bool GetAllJobRecipe(ControlJobInfo cj,SequenceInfo seq)
  3893. {
  3894. for (int i = 0; i < seq.Steps.Count; i++)
  3895. {
  3896. SequenceStepInfo stepInfo = seq.Steps[i];
  3897. foreach (var module in stepInfo.StepModules)
  3898. {
  3899. if (ModuleHelper.IsPm(module))
  3900. {
  3901. string attr = $"{module}Recipe";
  3902. if (stepInfo.StepParameter.ContainsKey(attr)
  3903. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3904. {
  3905. var recipeName = (string)stepInfo.StepParameter[attr];
  3906. var recipeContent =
  3907. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3908. var recipe = Recipe.Load(recipeContent);
  3909. if (recipe.Header.ChuckRecipe != null && recipe.Header.ChuckRecipe != "")
  3910. {
  3911. InUseRecipes.Add($"{module}.ChuckRecipe.{recipe.Header.ChuckRecipe}");
  3912. }
  3913. if (recipe.Header.DechuckRecipe != null && recipe.Header.DechuckRecipe != "")
  3914. {
  3915. InUseRecipes.Add($"{module}.DechuckRecipe.{recipe.Header.DechuckRecipe}");
  3916. }
  3917. InUseRecipes.Add($"{module}.Process.{recipeName}");
  3918. if (cj.PreJobClean != "")
  3919. {
  3920. InUseRecipes.Add($"{module}.Clean.{cj.PreJobClean}");
  3921. }
  3922. if (cj.PostJobClean != "")
  3923. {
  3924. InUseRecipes.Add($"{module}.Clean.{cj.PostJobClean}");
  3925. }
  3926. if (stepInfo.StepParameter["WTWClean"].ToString() != "")
  3927. {
  3928. InUseRecipes.Add($"{module}.Clean.{stepInfo.StepParameter["WTWClean"]}");
  3929. }
  3930. }
  3931. }
  3932. }
  3933. }
  3934. return true;
  3935. }
  3936. private bool IsSequenceNeedAlign(SequenceInfo sequence)
  3937. {
  3938. // check wether need align
  3939. foreach (var step in sequence.Steps)
  3940. {
  3941. foreach(var mod in step.StepModules)
  3942. {
  3943. if(ModuleHelper.IsAligner(mod))
  3944. return true;
  3945. }
  3946. }
  3947. return false;
  3948. }
  3949. #endregion
  3950. }
  3951. }