SystemDispatcher.cs 199 KB

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