SystemDispatcher.cs 220 KB

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