SystemDispatcher.cs 203 KB

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