SystemDispatcher.cs 212 KB

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