SystemDispatcher.cs 191 KB

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