SystemDispatcher.cs 228 KB

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