SystemDispatcher.cs 198 KB

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