SystemDispatcher.cs 215 KB

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