SystemDispatcher.cs 228 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107
  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 ((RouteManager.IsATMMode ? Status == ModuleStatus.AtmReady : 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. //if (ModuleHelper.IsLoadLock(mod.Key) && _dictModuleTask[mod.Key].HasWafer)
  1418. //{
  1419. // (_dictModuleTask[mod.Key] as LoadlockTask).Cooling();
  1420. //}
  1421. }
  1422. if (systemWaferCount == 0)
  1423. return RState.End;
  1424. ReturnVacWafers();
  1425. ReturnAtmWafers();
  1426. return RState.Running;
  1427. }
  1428. #endregion
  1429. #region internal implementation
  1430. private void InitModules()
  1431. {
  1432. foreach (var module in ModuleHelper.InstalledModules)
  1433. {
  1434. if (ModuleHelper.IsInstalled(module))
  1435. {
  1436. if(ModuleHelper.IsPm(module))
  1437. {
  1438. _dictModuleTask[module] = new PMTask(module);
  1439. _preLotCleanMarks[module] = new List<Guid>();
  1440. _postLotCleanMarks[module] = new List<Guid>();
  1441. }
  1442. else if (ModuleHelper.IsLoadLock(module))
  1443. {
  1444. _dictModuleTask[module] = new LoadlockTask(module);
  1445. }
  1446. else if(ModuleHelper.IsLoadPort(module))
  1447. {
  1448. _dictModuleTask[module] = new LoadPortTask(module);
  1449. }
  1450. else if(ModuleHelper.IsTMRobot(module))
  1451. {
  1452. _dictModuleTask[module] = new TMRobotTask(module);
  1453. }
  1454. else if(ModuleHelper.IsEFEMRobot(module))
  1455. {
  1456. _dictModuleTask[module] = new EFEMRobotTask(module);
  1457. }
  1458. else if(ModuleHelper.IsAligner(module))
  1459. {
  1460. _dictModuleTask[module] = new AlignerTask(module);
  1461. }
  1462. }
  1463. }
  1464. }
  1465. private void prelude()
  1466. {
  1467. bool available = true;
  1468. foreach(var mod in _dictModuleTask)
  1469. {
  1470. available = mod.Value.Scheduler.IsAvailable; // force scheduler update
  1471. }
  1472. }
  1473. private void epilogue()
  1474. {
  1475. UpdateProcessJobStatus();
  1476. UpdateControlJobStatus();
  1477. UpdateLLInOutPathProperty();
  1478. PrepareLLPressure();
  1479. RunLotCleanTasks();
  1480. CreateNewWaferTask();
  1481. _lstWaferTasks.RemoveAll(item => ModuleHelper.IsLoadPort(item.destMod) && ModuleHelper.IsLoadPort(item.currentMod) && item.pressureStatus == RState.End);
  1482. ReDispatchBlockingWafers();
  1483. }
  1484. private void RunWaferTask()
  1485. {
  1486. foreach (var task in _lstWaferTasks)
  1487. {
  1488. task.Run();
  1489. }
  1490. }
  1491. private void RunModuleTasks()
  1492. {
  1493. foreach (var task in _dictModuleTask)
  1494. {
  1495. task.Value.Run();
  1496. }
  1497. }
  1498. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1499. {
  1500. bool allWaferReturn = true;
  1501. foreach (var slot in pj.SlotWafers)
  1502. {
  1503. var wafer = WaferManager.Instance.GetWafer(slot.Item1, slot.Item2);
  1504. if(wafer.IsEmpty || (wafer.ProcessState != EnumWaferProcessStatus.Completed && checkAllProcessed))
  1505. {
  1506. allWaferReturn = false;
  1507. break;
  1508. }
  1509. }
  1510. return allWaferReturn;
  1511. }
  1512. private void UpdateProcessJobStatus()
  1513. {
  1514. if (_efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1515. return;
  1516. foreach (var pj in _lstProcessJobs)
  1517. {
  1518. if (CheckAllWaferReturned(pj, pj.State != EnumProcessJobState.Stopping))
  1519. {
  1520. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1521. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1522. }
  1523. }
  1524. }
  1525. private bool IsControlJobIntersect(ControlJobInfo cj1, ControlJobInfo cj2)
  1526. {
  1527. var cj1Pms = GetWaitPreCleanPMsByCtrlJob(cj1);
  1528. var cj2Pms = GetWaitPreCleanPMsByCtrlJob(cj2);
  1529. return cj1Pms.Intersect(cj2Pms).Count() > 0;
  1530. }
  1531. private void UpdateControlJobStatus()
  1532. {
  1533. if (_lstControlJobs.Count == 0 || _efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1534. return;
  1535. var runningJobs = _lstControlJobs.FindAll(cj => IsCtrlJobRuning(cj));
  1536. var queueJobs = _lstControlJobs.FindAll(cj => cj.JetState == EnumJetCtrlJobState.Quequed).OrderBy(cj => cj.StartTime);
  1537. if (runningJobs.Count == 0)
  1538. {
  1539. if(queueJobs.Count() > 0)
  1540. {
  1541. // start the first waiting job
  1542. RunControlJob(queueJobs.First());
  1543. }
  1544. }
  1545. else
  1546. {
  1547. foreach(var runningjob in runningJobs)
  1548. {
  1549. // update the running job
  1550. RunControlJob(runningjob);
  1551. }
  1552. foreach(var queueJob in queueJobs)
  1553. {
  1554. if(!runningJobs.Exists(cj => IsControlJobIntersect(cj, queueJob)))
  1555. {
  1556. // parallelly start the not intersect job
  1557. RunControlJob(queueJob);
  1558. }
  1559. else
  1560. {
  1561. foreach(var cj in runningJobs)
  1562. {
  1563. if(!_qePollingJobs.Contains(cj))
  1564. _qePollingJobs.Enqueue(cj);
  1565. }
  1566. RunControlJob(queueJob);
  1567. if (!_qePollingJobs.Contains(queueJob))
  1568. _qePollingJobs.Enqueue(queueJob);
  1569. }
  1570. }
  1571. }
  1572. // update system cycle status
  1573. if (_lstControlJobs.All(cj => cj.State == EnumControlJobState.Completed))
  1574. _cycleState = RState.End;
  1575. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1576. foreach (var cj in _lstControlJobs)
  1577. {
  1578. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1579. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  1580. {
  1581. cjRemoveList.Add(cj);
  1582. }
  1583. }
  1584. foreach (var cj in cjRemoveList)
  1585. {
  1586. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1587. foreach (var pj in _lstProcessJobs)
  1588. {
  1589. if (pj.ControlJobName == cj.Name)
  1590. pjRemoveList.Add(pj);
  1591. }
  1592. foreach (var pj in pjRemoveList)
  1593. {
  1594. _lstProcessJobs.Remove(pj);
  1595. }
  1596. _lstControlJobs.Remove(cj);
  1597. }
  1598. }
  1599. private bool ActiveProcessJob(ProcessJobInfo pj)
  1600. {
  1601. foreach (var pjSlotWafer in pj.SlotWafers)
  1602. {
  1603. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1604. wafer.ProcessJob = pj;
  1605. wafer.NextSequenceStep = 0;
  1606. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1607. }
  1608. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1609. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1610. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1611. pj.SetState(EnumProcessJobState.Processing);
  1612. return true;
  1613. }
  1614. private bool ActiveControlJob(ControlJobInfo cj)
  1615. {
  1616. cj.JetState = EnumJetCtrlJobState.Processing;
  1617. foreach (var pjName in cj.ProcessJobNameList)
  1618. {
  1619. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1620. if (pj == null)
  1621. {
  1622. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1623. continue;
  1624. }
  1625. if (pj.State == EnumProcessJobState.Queued)
  1626. {
  1627. ActiveProcessJob(pj);
  1628. }
  1629. }
  1630. return true;
  1631. }
  1632. private bool RunControlJob(ControlJobInfo cj)
  1633. {
  1634. // polling the sequencial jobs
  1635. if (_qePollingJobs.Contains(cj))
  1636. {
  1637. if (_qePollingJobs.First() == cj)
  1638. {
  1639. if ( !cj.LotWafers.Exists(wafer => !wafer.IsEmpty && wafer.NextSequenceStep == 0) && (IsAllJobWaferProcessedOrProcessing(cj) || IsAllProcessJobComplete(cj)))
  1640. {
  1641. _qePollingJobs.Dequeue();
  1642. _qePollingJobs.Enqueue(cj);
  1643. }
  1644. }
  1645. }
  1646. switch (cj.JetState)
  1647. {
  1648. case EnumJetCtrlJobState.Quequed:
  1649. {
  1650. ActiveControlJob(cj);
  1651. }
  1652. break;
  1653. case EnumJetCtrlJobState.Processing:
  1654. {
  1655. if (IsAllProcessJobComplete(cj))
  1656. {
  1657. cj.JetState = EnumJetCtrlJobState.Completed;
  1658. }
  1659. }
  1660. break;
  1661. }
  1662. // caculate processed wafer by control job
  1663. var lp = ModuleHelper.Converter(cj.Module);
  1664. int countProcessed = 0;
  1665. foreach (var pjName in cj.ProcessJobNameList)
  1666. {
  1667. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1668. if (pj == null)
  1669. {
  1670. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1671. continue;
  1672. }
  1673. // caculate process wafer by process
  1674. if (_lpCycleCount[lp] < cj.CycleNumber)
  1675. {
  1676. foreach (var pjSlotWafer in pj.SlotWafers)
  1677. {
  1678. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1679. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  1680. countProcessed++;
  1681. }
  1682. }
  1683. }
  1684. int lpCycleWafer = 0;
  1685. if (cj.JetState == EnumJetCtrlJobState.Completed)
  1686. {
  1687. cj.EndTime = DateTime.Now;
  1688. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1689. _dbCallback.LotFinished(cj);
  1690. if (_lpCycleCount[lp] >= cj.CycleNumber)
  1691. (Singleton<TransferModule>.Instance.GetScheduler(lp) as SchedulerLoadPort).NoteJobComplete();
  1692. _lpCycleCount[lp]++;
  1693. lpCycleWafer = _lpCycleCount[lp] * cj.LotWafers.Count;
  1694. _lpThroughput[lp] = (float)(lpCycleWafer / (DateTime.Now - cj.StartTime).TotalHours);
  1695. LOG.Write(eEvent.EV_ROUTER, lp, $"Cycle Count: {_lpCycleCount[lp]}, Total Processed Wafer: {lpCycleWafer}, Throughput: {_lpThroughput[lp]}");
  1696. if (_lpCycleCount[lp] < cj.CycleNumber)
  1697. {
  1698. cj.SetState(EnumControlJobState.Executing);
  1699. cj.JetState = EnumJetCtrlJobState.Quequed;
  1700. cj.LotInnerId = Guid.NewGuid();
  1701. _dbCallback.LotCreated(cj);
  1702. foreach (var pj in _lstProcessJobs)
  1703. {
  1704. if(pj.ControlJobName == cj.Name)
  1705. {
  1706. foreach(var marks in _preLotCleanMarks)
  1707. {
  1708. if (marks.Value.Contains(pj.InnerId))
  1709. marks.Value.Remove(pj.InnerId);
  1710. }
  1711. foreach(var marks in _postLotCleanMarks)
  1712. {
  1713. if (marks.Value.Contains(pj.InnerId))
  1714. marks.Value.Remove(pj.InnerId);
  1715. }
  1716. pj.SetState(EnumProcessJobState.Queued);
  1717. pj.InnerId = Guid.NewGuid();
  1718. foreach (var pjSlotWafer in pj.SlotWafers)
  1719. {
  1720. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1721. wafer.ProcessJob = null;
  1722. wafer.NextSequenceStep = 0;
  1723. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1724. }
  1725. }
  1726. }
  1727. _lstWaferTasks.RemoveAll(wt => wt.currentMod == lp);
  1728. }
  1729. else
  1730. {
  1731. cj.SetState(EnumControlJobState.Completed);
  1732. if (_qePollingJobs.Contains(cj))
  1733. {
  1734. Queue<ControlJobInfo> removedPolingJobs = new Queue<ControlJobInfo>();
  1735. foreach (var pj in _qePollingJobs)
  1736. {
  1737. if (pj != cj)
  1738. removedPolingJobs.Enqueue(pj);
  1739. }
  1740. if(removedPolingJobs.Count > 1)
  1741. _qePollingJobs = removedPolingJobs;
  1742. else
  1743. _qePollingJobs.Clear();
  1744. }
  1745. }
  1746. }
  1747. else
  1748. {
  1749. lpCycleWafer = _lpCycleCount[lp] * cj.LotWafers.Count + countProcessed;
  1750. }
  1751. if (lpCycleWafer != _lpCycleWafer[lp])
  1752. {
  1753. _lpCycleWafer[lp] = lpCycleWafer;
  1754. RefreshThroughput();
  1755. }
  1756. return cj.State == EnumControlJobState.Completed;
  1757. }
  1758. void RefreshThroughput()
  1759. {
  1760. foreach(var cj in _lstControlJobs)
  1761. {
  1762. if(cj.State == EnumControlJobState.Executing)
  1763. {
  1764. var lp = ModuleHelper.Converter(cj.Module);
  1765. if (_lpCycleCount[lp] > 0)
  1766. {
  1767. _lpThroughput[lp] = (float)((_lpCycleWafer[lp] - 2) / _lpCycleWatch[lp].Elapsed.TotalHours);
  1768. }
  1769. }
  1770. }
  1771. }
  1772. private bool IsAllJobWaferProcessedOrProcessing(ControlJobInfo cj)
  1773. {
  1774. List<ModuleName> allModules = _dictModuleTask.Keys.ToList();
  1775. int original = (int)ModuleHelper.Converter(cj.Module);
  1776. foreach (var mod in allModules)
  1777. {
  1778. if (ModuleHelper.IsLoadPort(mod) && (int)mod != original)
  1779. continue;
  1780. var wafers = WaferManager.Instance.GetWafers(mod);
  1781. foreach (var wafer in wafers)
  1782. {
  1783. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.ControlJobName != cj.Name)
  1784. continue;
  1785. if (wafer.ProcessState != EnumWaferProcessStatus.Completed && wafer.ProcessState != EnumWaferProcessStatus.InProcess)
  1786. return false; ;
  1787. }
  1788. }
  1789. return true;
  1790. }
  1791. private bool IsAllProcessJobComplete(ControlJobInfo cj)
  1792. {
  1793. foreach (var pj in _lstProcessJobs)
  1794. {
  1795. if (pj.ControlJobName == cj.Name && pj.State != EnumProcessJobState.ProcessingComplete)
  1796. {
  1797. return false;
  1798. }
  1799. }
  1800. return true;
  1801. }
  1802. private bool IsCtrlJobExecuting(ModuleName lp)
  1803. {
  1804. var cJob = _lstControlJobs.Find(cj => ModuleHelper.Converter(cj.Module) == lp);
  1805. if (cJob != null && cJob.State == EnumControlJobState.Executing)
  1806. return true;
  1807. return false;
  1808. }
  1809. private bool IsCtrlJobRuning(ControlJobInfo cj)
  1810. {
  1811. return cj.JetState == EnumJetCtrlJobState.PreJobClean ||
  1812. cj.JetState == EnumJetCtrlJobState.Processing ||
  1813. cj.JetState == EnumJetCtrlJobState.PostJobClean;
  1814. }
  1815. private bool IsCtrlJobNeedPreClean(ControlJobInfo cj)
  1816. {
  1817. return !string.IsNullOrWhiteSpace(cj.PreJobClean);
  1818. }
  1819. private bool IsCtrlJobNeedPostClean(ControlJobInfo cj)
  1820. {
  1821. return !string.IsNullOrWhiteSpace(cj.PostJobClean.Trim());
  1822. }
  1823. private List<ModuleName> GetWaitPreCleanPMsByCtrlJob(ControlJobInfo cj)
  1824. {
  1825. var pmlist = new List<ModuleName>();
  1826. foreach (var pj in _lstProcessJobs)
  1827. {
  1828. if (pj.ControlJobName == cj.Name)
  1829. {
  1830. foreach (var pm in pj.Sequence.PMs)
  1831. {
  1832. if (!pmlist.Contains(pm))
  1833. pmlist.Add(pm);
  1834. }
  1835. }
  1836. }
  1837. return pmlist;
  1838. }
  1839. private bool IsPreJobCleanDone(ControlJobInfo cj)
  1840. {
  1841. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1842. foreach(var pm in pms)
  1843. {
  1844. var pmTask = _dictModuleTask[pm] as PMTask;
  1845. if (pmTask.Scheduler.IsOnline && !pmTask.IsPreJobCleanDone())
  1846. return false;
  1847. }
  1848. return true;
  1849. }
  1850. private bool IsPostJobCleanDone(ControlJobInfo cj)
  1851. {
  1852. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1853. foreach (var pm in pms)
  1854. {
  1855. var pmTask = _dictModuleTask[pm] as PMTask;
  1856. if (pmTask.Scheduler.IsOnline && !pmTask.IsPostJobCleanDone())
  1857. return false;
  1858. }
  1859. return true;
  1860. }
  1861. private void WaferArrived(WaferTask wafer, MoveItem item)
  1862. {
  1863. _dictModuleTask[item.DestinationModule].WaferArrived(wafer, item.DestinationSlot);
  1864. //--2024-03-21 增加了PortJobWaferEnd 上报事件 start--
  1865. if (ModuleHelper.IsLoadPort(item.DestinationModule))
  1866. {
  1867. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.DestinationModule);
  1868. if (currentControlJob != null)
  1869. {
  1870. _faCallback.JobWaferEnd(currentControlJob, item.SourceSlot);
  1871. }
  1872. }
  1873. if(ModuleHelper.IsLoadPort(item.DestinationModule))
  1874. {
  1875. if (!_lpCycleWatch[wafer.sourceMod].IsRunning)
  1876. _lpCycleWatch[wafer.sourceMod].Start();
  1877. }
  1878. //--2024-03-21 增加了PortJobWaferEnd 上报事件 end--
  1879. }
  1880. private void WaferLeaved(WaferTask wafer, MoveItem item)
  1881. {
  1882. _dictModuleTask[item.SourceModule].WaferLeaved(wafer, item.DestinationSlot);
  1883. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  1884. if (ModuleHelper.IsLoadPort(item.SourceModule))
  1885. {
  1886. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.SourceModule);
  1887. if (currentControlJob != null)
  1888. {
  1889. _faCallback.JobWaferStart(currentControlJob, item.SourceSlot);
  1890. }
  1891. }
  1892. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  1893. }
  1894. private ModuleName GetComingAvailablePM(ControlJobInfo cj)
  1895. {
  1896. var lstInProcessPMs = new List<ModuleName>();
  1897. foreach (var wafer in cj.LotWafers)
  1898. {
  1899. if(!wafer.IsEmpty && wafer.NextSequenceStep == 0 && wafer.ProcessJob != null)
  1900. {
  1901. foreach(var pm in wafer.ProcessJob.Sequence.PMs)
  1902. {
  1903. if (!lstInProcessPMs.Contains(pm) && _dictModuleTask[pm].Scheduler.IsOnline)
  1904. lstInProcessPMs.Add(pm);
  1905. }
  1906. }
  1907. }
  1908. // blocking check while only one loadlock in out
  1909. if (LLInOutPath == SequenceLLInOutPath.AInAOut ||
  1910. LLInOutPath == SequenceLLInOutPath.BInBOut ||
  1911. !_dictModuleTask[ModuleName.LLA].Scheduler.IsOnline ||
  1912. !_dictModuleTask[ModuleName.LLB].Scheduler.IsOnline)
  1913. {
  1914. if (_lstWaferTasks.Count >= lstInProcessPMs.Count + _LLASlotNumber / 2)
  1915. return ModuleName.System;
  1916. }
  1917. Dictionary<ModuleName, int> pmAssociatedWaferCount = new Dictionary<ModuleName, int>();
  1918. foreach (var mod in _dictModuleTask)
  1919. {
  1920. if (ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline && lstInProcessPMs.Contains(mod.Key))
  1921. {
  1922. pmAssociatedWaferCount[mod.Key] = 0;
  1923. }
  1924. }
  1925. var unprocessedWafer = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.destMod));
  1926. foreach (var wafer in unprocessedWafer)
  1927. {
  1928. if (ModuleHelper.IsPm(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && lstInProcessPMs.Contains(wafer.destMod))
  1929. {
  1930. pmAssociatedWaferCount[wafer.destMod]++;
  1931. }
  1932. }
  1933. var oderedPMCount = pmAssociatedWaferCount.OrderBy(p => p.Value).ToDictionary(p => p.Key, o => o.Value);
  1934. if (oderedPMCount.Count > 0 && oderedPMCount.First().Value < 2)
  1935. return oderedPMCount.First().Key;
  1936. return ModuleName.System;
  1937. }
  1938. private void CreateNewWaferTask()
  1939. {
  1940. var runningJobs = _lstControlJobs.FindAll(cj => cj.JetState == EnumJetCtrlJobState.PreJobClean || cj.JetState == EnumJetCtrlJobState.Processing);
  1941. var onDutyPms = new Dictionary<ModuleName, int>();
  1942. foreach (var job in runningJobs)
  1943. {
  1944. var pms = GetWaitPreCleanPMsByCtrlJob(job);
  1945. foreach(var pm in pms)
  1946. {
  1947. if (_dictModuleTask[pm].Scheduler.IsOnline && !onDutyPms.ContainsKey(pm))
  1948. {
  1949. onDutyPms[pm] = _lstWaferTasks.Where(wt => wt.destMod == pm || wt.currentMod == pm).Count();
  1950. }
  1951. }
  1952. }
  1953. if (runningJobs.Count == 0 || onDutyPms.Count == 0)
  1954. return;
  1955. var oderedPMs = onDutyPms.OrderBy(kv => kv.Value).OrderBy(kv => _dictModuleTask[kv.Key].TimeToReady);
  1956. if (oderedPMs.First().Value < 1)
  1957. {
  1958. foreach(var runningJob in runningJobs)
  1959. {
  1960. if (_qePollingJobs.Contains(runningJob) && _qePollingJobs.First() != runningJob)
  1961. continue;
  1962. foreach (var wafer in runningJob.LotWafers)
  1963. {
  1964. if (wafer.IsEmpty || wafer.ProcessJob == null)
  1965. continue;
  1966. if (wafer.ProcessJob.Sequence.PMs.Contains(oderedPMs.First().Key) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  1967. {
  1968. CreateWaferTasks(wafer, oderedPMs.First().Key);
  1969. return;
  1970. }
  1971. }
  1972. }
  1973. }
  1974. if (_tmRobotStatus == RState.Running)
  1975. return;
  1976. // keep two raw atm wafer, try match a double place to LL
  1977. 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)));
  1978. if (atmWaferCount < 2)
  1979. {
  1980. var busyPMs = oderedPMs.Where(pv => pv.Value == 1 && _dictModuleTask[pv.Key].HasWafer).OrderBy(pv => _dictModuleTask[pv.Key].TimeToReady);
  1981. if (busyPMs.Count() == 0)
  1982. return;
  1983. ModuleName nextPM = busyPMs.First().Key;
  1984. if (_lpCycleWafer.Sum(kv => kv.Value) == 0)
  1985. {
  1986. if (busyPMs.ToList().Exists(kv => _dictModuleTask[kv.Key].TimeToReady > 36000) && busyPMs.ToList().Exists(pv => _dictModuleTask[pv.Key].TimeToReady < 3600))
  1987. {
  1988. foreach (var pm in busyPMs)
  1989. {
  1990. if (_dictModuleTask[pm.Key].TimeToReady > 36000)
  1991. {
  1992. nextPM = pm.Key;
  1993. break;
  1994. }
  1995. }
  1996. }
  1997. }
  1998. foreach (var runningJob in runningJobs)
  1999. {
  2000. if (_qePollingJobs.Contains(runningJob) && _qePollingJobs.First() != runningJob)
  2001. continue;
  2002. foreach (var wafer in runningJob.LotWafers)
  2003. {
  2004. if (wafer.IsEmpty || wafer.ProcessJob == null)
  2005. continue;
  2006. if (wafer.ProcessJob.Sequence.PMs.Contains(nextPM) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  2007. {
  2008. CreateWaferTasks(wafer, nextPM);
  2009. return;
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. private void CreateWaferTasks(WaferInfo wafer, ModuleName pm)
  2016. {
  2017. var recipeName = wafer.ProcessJob.Sequence.GetRecipe(pm);
  2018. var recipeContent = RecipeFileManager.Instance.LoadRecipe(pm.ToString(), recipeName, false, RecipeType.Process.ToString());
  2019. Recipe recipe = Recipe.Load(recipeContent);
  2020. int temperature = 0;
  2021. if(int.TryParse(recipe.Header.Temperature, out int temp))
  2022. {
  2023. temperature = temp;
  2024. }
  2025. var waferTask = new WaferTask((ModuleName)wafer.OriginStation,
  2026. wafer.OriginSlot,
  2027. pm,
  2028. 0,
  2029. temperature,
  2030. wafer.InnerId,
  2031. wafer.ProcessJob.InnerId,
  2032. recipeName,
  2033. wafer.ProcessJob.Sequence.GetWTWCleanRecipe(pm),
  2034. wafer.ProcessJob.Sequence.LLInOutPath,
  2035. wafer.ProcessJob.Sequence.LLDelayTime,
  2036. IsSequenceNeedAlign(wafer.ProcessJob.Sequence));
  2037. waferTask.OnWaferArrived += WaferArrived;
  2038. waferTask.OnWaferLeaved += WaferLeaved;
  2039. _lstWaferTasks.Add(waferTask);
  2040. _qeWaitInWafers.Enqueue(wafer.InnerId);
  2041. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, waferTask.sourceMod, $"Routing wafer: {waferTask.sourceMod}.{waferTask.sourceSlot + 1} to {pm}");
  2042. }
  2043. private void ReDispatchBlockingWafers()
  2044. {
  2045. foreach (var wt in _lstWaferTasks)
  2046. {
  2047. if (ModuleHelper.IsPm(wt.destMod) && !ModuleHelper.IsPm(wt.currentMod) && !ModuleHelper.IsLoadPort(wt.currentMod))
  2048. {
  2049. if (!_dictModuleTask[wt.destMod].Scheduler.IsOnline && wt.elapseTime > 120)
  2050. {
  2051. var wafer = WaferManager.Instance.GetWafer(wt.currentMod, wt.currentSlot);
  2052. 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();
  2053. if(otherPMs.Count > 0)
  2054. {
  2055. LOG.Write(eEvent.WARN_ROUTER, wt.currentMod, $"Re-assign process chamber {otherPMs.First().Key} for {wafer.WaferOrigin} as {wt.destMod} unexpected offline");
  2056. wt.ReAssignPM(otherPMs.First().Key, 0);
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. private bool ForwardATMWafers(ModuleName ll)
  2063. {
  2064. if (_qeWaitInWafers.Count == 0)
  2065. return false;
  2066. var emptySlots = GetLLReadyInOutSlots(ll).emptySlot;
  2067. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End ||wafer.movingStatus == RState.Init) && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  2068. var notAlignedWafer = atmWafers.Where(wafer => !wafer.IsAligned).ToList();
  2069. var freeHands = GetEFEMFreeHand();
  2070. var waitInWafer = _lstWaferTasks.Find(wt => wt.waferId == _qeWaitInWafers.First());
  2071. if (atmWafers.Count >= 2 && freeHands.Count == 0 || waitInWafer == null)
  2072. return false;
  2073. // do not need pass by aligner
  2074. if (waitInWafer.IsAligned)
  2075. {
  2076. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafer.currentMod, waitInWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2077. _qeWaitInWafers.Dequeue();
  2078. }
  2079. else
  2080. {
  2081. if (atmWafers.Count == 0)
  2082. {
  2083. // push one wafer to aligner
  2084. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafer.currentMod, waitInWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2085. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ModuleName.Aligner1, 0, freeHands[0]) });
  2086. _qeWaitInWafers.Dequeue();
  2087. }
  2088. else if (_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)) && freeHands.Count == 2)
  2089. {
  2090. // forward another wafer to aligner
  2091. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waitInWafer.currentMod, waitInWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[1], freeHands[1]) });
  2092. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.Aligner1, 0, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2093. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[1], ModuleName.Aligner1, 0, freeHands[1]) });
  2094. _qeWaitInWafers.Dequeue();
  2095. }
  2096. }
  2097. return _efemSchdActions.Count > 0;
  2098. }
  2099. private bool ExchangeWaferWithLL(ModuleName ll)
  2100. {
  2101. if (IsLLReservedByTM(ll))
  2102. return false;
  2103. var waferStaus = GetLLReadyInOutSlots(ll);
  2104. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  2105. var freeHands = GetEFEMFreeHand();
  2106. var swapActions = new List<MoveItem>();
  2107. var validHands = new List<Hand>();
  2108. int placeCount = 0;
  2109. if ( waferStaus.emptySlot.Count > 0 &&
  2110. freeHands.Count >= 1 &&
  2111. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  2112. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || waferStaus.emptySlot.Count >= 2))
  2113. {
  2114. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  2115. if (CanWaferGotoLL(alignerWafer, ll))
  2116. {
  2117. alignerWafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  2118. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2119. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, waferStaus.emptySlot[placeCount], freeHands[0]));
  2120. validHands.Add(freeHands[0]);
  2121. placeCount++;
  2122. }
  2123. }
  2124. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  2125. foreach(var wafer in armWafers)
  2126. {
  2127. if (CanWaferGotoLL(wafer, ll) && placeCount < waferStaus.emptySlot.Count)
  2128. {
  2129. wafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  2130. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, waferStaus.emptySlot[placeCount], (Hand)wafer.currentSlot));
  2131. if(!validHands.Contains((Hand)wafer.currentSlot))
  2132. validHands.Add((Hand)wafer.currentSlot);
  2133. placeCount++;
  2134. }
  2135. }
  2136. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  2137. validHands.Add(Hand.Blade1);
  2138. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  2139. validHands.Add(Hand.Blade2);
  2140. int pickCount = 0;
  2141. var returnActions = new List<MoveItem>();
  2142. foreach(var slot in waferStaus.outSlot)
  2143. {
  2144. if(pickCount < validHands.Count)
  2145. {
  2146. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  2147. if(outWafer != null)
  2148. {
  2149. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  2150. swapActions.Add(new MoveItem(ll, waferStaus.outSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  2151. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  2152. pickCount++;
  2153. }
  2154. }
  2155. }
  2156. if(swapActions.Count > 0)
  2157. {
  2158. _efemSchdActions.Enqueue(swapActions);
  2159. }
  2160. foreach(var action in returnActions)
  2161. {
  2162. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  2163. }
  2164. return _efemSchdActions.Count > 0;
  2165. }
  2166. private bool ExchangeWaferWithFixedSlotLL(ModuleName ll)
  2167. {
  2168. if (IsLLReservedByTM(ll))
  2169. return false;
  2170. var llWaferStatus = GetLLFixedReadyInOutSlots(ll);
  2171. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  2172. var freeHands = GetEFEMFreeHand();
  2173. var swapActions = new List<MoveItem>();
  2174. var validHands = new List<Hand>();
  2175. int placeCount = 0;
  2176. if (llWaferStatus.eInSlot.Count > 0 &&
  2177. freeHands.Count >= 1 &&
  2178. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  2179. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || llWaferStatus.eInSlot.Count >= 2))
  2180. {
  2181. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  2182. if (CanWaferGotoLL(alignerWafer, ll))
  2183. {
  2184. alignerWafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  2185. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  2186. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, llWaferStatus.eInSlot[placeCount], freeHands[0]));
  2187. validHands.Add(freeHands[0]);
  2188. placeCount++;
  2189. }
  2190. }
  2191. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  2192. foreach (var wafer in armWafers)
  2193. {
  2194. if (CanWaferGotoLL(wafer, ll) && placeCount < llWaferStatus.eInSlot.Count)
  2195. {
  2196. wafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  2197. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, llWaferStatus.eInSlot[placeCount], (Hand)wafer.currentSlot));
  2198. if (!validHands.Contains((Hand)wafer.currentSlot))
  2199. validHands.Add((Hand)wafer.currentSlot);
  2200. placeCount++;
  2201. }
  2202. }
  2203. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  2204. validHands.Add(Hand.Blade1);
  2205. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  2206. validHands.Add(Hand.Blade2);
  2207. int pickCount = 0;
  2208. var returnActions = new List<MoveItem>();
  2209. foreach (var slot in llWaferStatus.eOutSlot)
  2210. {
  2211. if (pickCount < validHands.Count)
  2212. {
  2213. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  2214. if (outWafer != null)
  2215. {
  2216. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  2217. swapActions.Add(new MoveItem(ll, llWaferStatus.eOutSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  2218. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  2219. pickCount++;
  2220. }
  2221. }
  2222. }
  2223. if (swapActions.Count > 0)
  2224. {
  2225. _efemSchdActions.Enqueue(swapActions);
  2226. }
  2227. foreach (var action in returnActions)
  2228. {
  2229. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  2230. }
  2231. return _efemSchdActions.Count > 0;
  2232. }
  2233. private void RoutingATMWafers()
  2234. {
  2235. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  2236. {
  2237. RunSchdEFEMActions();
  2238. return;
  2239. }
  2240. if (_efemRobotStatus != RState.End)
  2241. return;
  2242. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2243. {
  2244. if (_LLASlotNumber == 2)
  2245. {
  2246. Routing2SlotATMSystem();
  2247. }
  2248. else if (_LLASlotNumber == 4)
  2249. {
  2250. Routing4SlotATMSystem();
  2251. }
  2252. }
  2253. else
  2254. {
  2255. RoutingFixedSlotATMSystem();
  2256. }
  2257. }
  2258. private void Routing4SlotATMSystem()
  2259. {
  2260. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2261. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  2262. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  2263. {
  2264. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2265. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2266. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2267. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2268. if (efemRobotWafers.Count() >= 1)
  2269. {
  2270. if (inLLWaferStatus.emptySlot.Count >= 2 && !IsLLReservedByTM(inLL)) // wait for in loadlock ready
  2271. {
  2272. if (_dictModuleTask[inLL].TimeToReady < 2)
  2273. {
  2274. ExchangeWaferWithLL(inLL);
  2275. }
  2276. }
  2277. if ((inLLWaferStatus.emptySlot.Count == 0 || (outLLWaferStatus.outSlot.Count >= 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL)) // ready return wafer
  2278. {
  2279. ExchangeWaferWithLL(outLL);
  2280. }
  2281. }
  2282. else
  2283. {
  2284. if (((outLLWaferStatus.outSlot.Count >= 2 && _dictModuleTask[outLL].TimeToReady < 10) ||
  2285. (outLLWaferStatus.outSlot.Count == 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL))
  2286. {
  2287. ExchangeWaferWithLL(outLL);
  2288. }
  2289. else if (inLLWaferStatus.emptySlot.Count >= 2)
  2290. {
  2291. if (((_dictModuleTask[inLL].TimeToReady > 20 || _dictModuleTask[inLL].Scheduler.IsVac) && atmWaferCount < 2) || atmWaferCount == 0)
  2292. {
  2293. ForwardATMWafers(inLL);
  2294. }
  2295. else if (atmWaferCount >= 2 && !IsLLReservedByTM(inLL))
  2296. {
  2297. ExchangeWaferWithLL(inLL);
  2298. }
  2299. }
  2300. }
  2301. }
  2302. else
  2303. {
  2304. RoutingSameLLInOutATMSystem();
  2305. }
  2306. }
  2307. private void Routing2SlotATMSystem()
  2308. {
  2309. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2310. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  2311. var validHands = (_efemRobotSingleArmOption == 0 ? 2 : 1);
  2312. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  2313. {
  2314. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2315. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2316. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2317. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2318. var inLLModule = _dictModuleTask[inLL] as LoadlockTask;
  2319. var outLLModule = _dictModuleTask[outLL] as LoadlockTask;
  2320. var needAlign = _lstProcessJobs.Exists(pj => pj.State == EnumProcessJobState.Processing && IsSequenceNeedAlign(pj.Sequence));
  2321. // return wafer while out LL ready or cooling state
  2322. //if ((outLLWaferStatus.outSlot.Count > 0 && outLLWaferStatus.outSlot.Count <= (validHands - efemRobotWafers.Count)) && outLLModule.ReayForEfemInTime(10))
  2323. if (outLLWaferStatus.outSlot.Count > 0 && outLLModule.ReayForEfemInTime(10))
  2324. {
  2325. if (ExchangeWaferWithLL(outLL))
  2326. {
  2327. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady}");
  2328. return;
  2329. }
  2330. }
  2331. if (needAlign)
  2332. {
  2333. if (atmWaferCount == 0 ||
  2334. (inLLModule.ReayForEfemInTime(20) && Math.Min(validHands, inLLWaferStatus.emptySlot.Count) > atmWaferCount))
  2335. {
  2336. if (ForwardATMWafers(inLL))
  2337. {
  2338. ////LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady}");
  2339. return;
  2340. }
  2341. }
  2342. }
  2343. else
  2344. {
  2345. if (inLLModule.ReayForEfemInTime(20) && inLLWaferStatus.emptySlot.Count > efemRobotWafers.Count && ((outLLModule.TimeToReady - inLLModule.TimeToReady > 10) || !outLLModule.ReayForEfemInTime(30) || outLLWaferStatus.emptySlot.Count < efemRobotWafers.Count))
  2346. {
  2347. if (ForwardATMWafers(inLL))
  2348. {
  2349. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady}");
  2350. return;
  2351. }
  2352. }
  2353. }
  2354. if (inLLModule.ReayForEfemInTime(5) &&
  2355. (Math.Min(validHands, inLLWaferStatus.emptySlot.Count) == atmWaferCount || _qeWaitInWafers.Count == 0))
  2356. {
  2357. if (ExchangeWaferWithLL(inLL))
  2358. {
  2359. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady}");
  2360. return;
  2361. }
  2362. }
  2363. }
  2364. else
  2365. {
  2366. RoutingSameLLInOutATMSystem();
  2367. }
  2368. }
  2369. private void RoutingFixedSlotATMSystem()
  2370. {
  2371. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2372. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  2373. if ( atmWaferCount == 0 || (_efemRobotSingleArmOption == 0 && atmWaferCount == 1 ))
  2374. {
  2375. foreach(var ll in lls)
  2376. {
  2377. if (ForwardATMWafers(ll.Key))
  2378. return;
  2379. }
  2380. }
  2381. // try to match a ll swap action
  2382. var readyReturnLL = lls.Where(ll => (GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count > 0) && ll.Value.TimeToReady <= 10)
  2383. .OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count)
  2384. .OrderBy(ll => ll.Value.TimeToReady);
  2385. foreach (var ll in readyReturnLL)
  2386. {
  2387. if (ExchangeWaferWithFixedSlotLL(ll.Key))
  2388. return;
  2389. }
  2390. }
  2391. private void RoutingSameLLInOutATMSystem()
  2392. {
  2393. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  2394. var vacWaferCount = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod) || ModuleHelper.IsLoadLock(task.currentMod)).Count();
  2395. var preferWaferVacCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline).Count() +
  2396. (LLInOutPath == SequenceLLInOutPath.AInAOut ? _LLASlotNumber / 2 : (LLInOutPath == SequenceLLInOutPath.BInBOut ? _LLBSlotNumber / 2 : _LLASlotNumber));
  2397. var inOutIndicator = vacWaferCount - preferWaferVacCount;
  2398. if (inOutIndicator < 0)
  2399. {
  2400. // ready to push in
  2401. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2402. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2403. mod.Value.TimeToReady <= 10 &&
  2404. !IsLLReservedByTM(mod.Key) &&
  2405. GetLLReadyInOutSlots(mod.Key).emptySlot.Count >= 1).
  2406. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2407. if (atmWaferCount >= 1)
  2408. {
  2409. foreach(var ll in readyLLs)
  2410. {
  2411. if (ExchangeWaferWithLL(ll.Key))
  2412. return;
  2413. }
  2414. }
  2415. // forward wafer to system
  2416. if (atmWaferCount < 2)
  2417. {
  2418. var targetLL = readyLLs.Count > 0 ? readyLLs.First().Key : (LLInOutPath == SequenceLLInOutPath.BInBOut ? ModuleName.LLB : ModuleName.LLA);
  2419. ForwardATMWafers(targetLL);
  2420. }
  2421. if (_efemSchdActions.Count == 0)
  2422. {
  2423. var readyReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2424. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2425. mod.Value.TimeToReady <= 5 &&
  2426. !IsLLReservedByTM(mod.Key) &&
  2427. GetLLReadyInOutSlots(mod.Key).outSlot.Count >= 1).
  2428. OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).outSlot.Count).ToList();
  2429. foreach(var ll in readyReturnLL)
  2430. {
  2431. if (ExchangeWaferWithLL(readyReturnLL.First().Key))
  2432. return;
  2433. }
  2434. }
  2435. }
  2436. else
  2437. {
  2438. // ready double return LL
  2439. var readyDoubleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2440. mod.Value.TimeToReady < 10 &&
  2441. !IsLLReservedByTM(mod.Key) &&
  2442. GetLLReadyInOutSlots(mod.Key).outSlot.Count > 1).
  2443. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2444. foreach(var ll in readyDoubleReturnLL)
  2445. {
  2446. if (ExchangeWaferWithLL(ll.Key))
  2447. return;
  2448. }
  2449. // ready single return LL
  2450. var readySingleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2451. mod.Value.TimeToReady < 2 &&
  2452. !IsLLReservedByTM(mod.Key) &&
  2453. GetLLReadyInOutSlots(mod.Key).outSlot.Count == 1).
  2454. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2455. foreach (var ll in readySingleReturnLL)
  2456. {
  2457. if (ExchangeWaferWithLL(ll.Key))
  2458. return;
  2459. }
  2460. if (atmWaferCount == 0)
  2461. {
  2462. // ready to push in
  2463. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2464. ((mod.Key != ModuleName.LLA && LLInOutPath == SequenceLLInOutPath.BInBOut) || (mod.Key != ModuleName.LLB && LLInOutPath == SequenceLLInOutPath.AInAOut)) &&
  2465. mod.Value.TimeToReady <= 10 &&
  2466. !IsLLReservedByTM(mod.Key) &&
  2467. GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 1).
  2468. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2469. foreach(var ll in readyLLs)
  2470. {
  2471. if (ForwardATMWafers(ll.Key))
  2472. return;
  2473. }
  2474. }
  2475. }
  2476. }
  2477. private bool isReturnActionsDone(List<MoveItem> items)
  2478. {
  2479. foreach(var item in items)
  2480. {
  2481. if (WaferManager.Instance.CheckHasWafer(item.SourceModule, item.SourceSlot) || WaferManager.Instance.CheckNoWafer(item.DestinationModule, item.DestinationSlot))
  2482. return false;
  2483. }
  2484. return true;
  2485. }
  2486. private bool IsMovingActionsDone(List<MoveItem> actions)
  2487. {
  2488. bool CheckWaferExistence(ModuleName mod, int slot)
  2489. {
  2490. return ModuleHelper.IsLoadPort(mod) ? WaferManager.Instance.CheckHasWafer(mod, slot) : _lstWaferTasks.Exists(wt => wt.currentMod == mod && wt.currentSlot == slot);
  2491. }
  2492. if(actions.Count == 1)
  2493. {
  2494. if ( CheckWaferExistence(actions.First().SourceModule, actions.First().SourceSlot) ||
  2495. !CheckWaferExistence(actions.First().DestinationModule, actions.First().DestinationSlot) )
  2496. return false;
  2497. }
  2498. else
  2499. {
  2500. // initialize all the wafer existance before move
  2501. var slotWafers = new Dictionary<KeyValuePair<ModuleName, int>, bool>();
  2502. foreach (var ac in actions)
  2503. {
  2504. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2505. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2506. if (!slotWafers.ContainsKey(scrSlot))
  2507. {
  2508. slotWafers[scrSlot] = true;
  2509. }
  2510. if (!slotWafers.ContainsKey(destSlot))
  2511. {
  2512. slotWafers[destSlot] = false;
  2513. }
  2514. }
  2515. // simulate moved result
  2516. foreach (var ac in actions)
  2517. {
  2518. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2519. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2520. if (!slotWafers[scrSlot])
  2521. {
  2522. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[scrSlot]} do not has a wafer");
  2523. }
  2524. else
  2525. {
  2526. slotWafers[scrSlot] = false;
  2527. }
  2528. if (slotWafers[destSlot])
  2529. {
  2530. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[destSlot]} has a wafer");
  2531. }
  2532. else
  2533. {
  2534. slotWafers[destSlot] = true;
  2535. }
  2536. }
  2537. foreach (var slot in slotWafers)
  2538. {
  2539. if (slot.Value != CheckWaferExistence(slot.Key.Key, slot.Key.Value))
  2540. return false;
  2541. }
  2542. }
  2543. return true;
  2544. }
  2545. private bool IsLLReservedByTM(ModuleName ll)
  2546. {
  2547. foreach(var item in _curTmAction)
  2548. {
  2549. if (item.DestinationModule == ll || item.SourceModule == ll)
  2550. return true;
  2551. }
  2552. foreach(var action in _tmSchdActions)
  2553. {
  2554. foreach(var item in action)
  2555. {
  2556. if (item.DestinationModule == ll || item.SourceModule == ll)
  2557. return true;
  2558. }
  2559. }
  2560. return false;
  2561. }
  2562. private bool IsLLReservedByEFEM(ModuleName ll)
  2563. {
  2564. foreach (var item in _curEfemAction)
  2565. {
  2566. if (item.DestinationModule == ll || item.SourceModule == ll)
  2567. return true;
  2568. }
  2569. foreach (var action in _efemSchdActions)
  2570. {
  2571. foreach (var item in action)
  2572. {
  2573. if (item.DestinationModule == ll || item.SourceModule == ll)
  2574. return true;
  2575. }
  2576. }
  2577. return false;
  2578. }
  2579. private void RunSchdEFEMActions()
  2580. {
  2581. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  2582. if (efemRobot == null || !efemRobot.IsAvailable)
  2583. return;
  2584. if (_dictModuleTask[ModuleName.EfemRobot].IsIdle)
  2585. {
  2586. if(_efemSchdActions.Count > 0 )
  2587. {
  2588. if(_curEfemAction.Count == 0 || IsMovingActionsDone(_curEfemAction))
  2589. {
  2590. var nextActions = _efemSchdActions.First();
  2591. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2592. return;
  2593. var nextModule = nextActions.First().Module;
  2594. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].Scheduler.IsAvailable)
  2595. return;
  2596. _curEfemAction = _efemSchdActions.Dequeue();
  2597. foreach (var action in _curEfemAction)
  2598. {
  2599. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2600. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2601. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  2602. if (ModuleHelper.IsLoadPort(action.SourceModule))
  2603. {
  2604. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.SourceModule);
  2605. if(currentControlJob!=null)
  2606. {
  2607. _faCallback.JobWaferStart(currentControlJob, action.SourceSlot);
  2608. }
  2609. }
  2610. if(ModuleHelper.IsLoadPort(action.DestinationModule))
  2611. {
  2612. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.DestinationModule);
  2613. if (currentControlJob != null)
  2614. {
  2615. _faCallback.JobWaferEnd(currentControlJob, action.SourceSlot);
  2616. }
  2617. }
  2618. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  2619. }
  2620. (_dictModuleTask[ModuleName.EfemRobot].Scheduler as SchedulerEfemRobot).PostMoveItems(_curEfemAction.ToArray());
  2621. }
  2622. }
  2623. else if(_curEfemAction.Count >= 0 && IsMovingActionsDone(_curEfemAction)) // all scheduled actions done
  2624. {
  2625. _curEfemAction.Clear();
  2626. }
  2627. }
  2628. }
  2629. private void RunSchdTMActions()
  2630. {
  2631. if (_dictModuleTask[ModuleName.TMRobot].IsIdle)
  2632. {
  2633. if (_tmSchdActions.Count > 0)
  2634. {
  2635. if (_curTmAction.Count == 0 || IsMovingActionsDone(_curTmAction))
  2636. {
  2637. var nextActions = _tmSchdActions.First();
  2638. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2639. return;
  2640. if (ModuleHelper.IsPm(nextActions.First().Module) && !_dictModuleTask[nextActions.First().Module].IsIdle) /// wait PMTask status update to idle
  2641. return;
  2642. _curTmAction = _tmSchdActions.Dequeue();
  2643. foreach(var action in _curTmAction)
  2644. {
  2645. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2646. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2647. }
  2648. (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerTMRobot).SendMoveItems(_curTmAction.ToArray());
  2649. }
  2650. }
  2651. else if (_curTmAction.Count >= 0 && IsMovingActionsDone(_curTmAction)) // all scheduled actions done
  2652. {
  2653. _curTmAction.Clear();
  2654. }
  2655. }
  2656. }
  2657. private int TimeForNextModuleReady(WaferTask task)
  2658. {
  2659. if (ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2660. return _dictModuleTask[task.destMod].TimeToReady;
  2661. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  2662. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  2663. if (ModuleHelper.IsLoadPort(task.destMod) && (ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2664. {
  2665. if (task.llInOutPath == SequenceLLInOutPath.AInBOut || task.llInOutPath == SequenceLLInOutPath.BInBOut)
  2666. {
  2667. if(llbWaferStatus.emptySlot.Count > 0)
  2668. {
  2669. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2670. }
  2671. }
  2672. else if(task.llInOutPath == SequenceLLInOutPath.BInAOut || task.llInOutPath == SequenceLLInOutPath.AInAOut)
  2673. {
  2674. if(llaWaferStatus.emptySlot.Count > 0)
  2675. {
  2676. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2677. }
  2678. }
  2679. else if(task.llInOutPath == SequenceLLInOutPath.DInDOut)
  2680. {
  2681. if(llaWaferStatus.emptySlot.Count > 0 && llbWaferStatus.emptySlot.Count > 0)
  2682. {
  2683. if (_dictModuleTask[ModuleName.LLA].TimeToReady == _dictModuleTask[ModuleName.LLB].TimeToReady)
  2684. {
  2685. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2686. }
  2687. else
  2688. {
  2689. return Math.Min(_dictModuleTask[ModuleName.LLA].TimeToReady, _dictModuleTask[ModuleName.LLB].TimeToReady);
  2690. }
  2691. }
  2692. else if(llaWaferStatus.emptySlot.Count > 0)
  2693. {
  2694. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2695. }
  2696. else if(llbWaferStatus.emptySlot.Count > 0)
  2697. {
  2698. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2699. }
  2700. }
  2701. }
  2702. else if(ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2703. {
  2704. if(_lstWaferTasks.Find(wafer => wafer.currentMod == task.destMod || wafer.routedMod == task.destMod) == null)
  2705. {
  2706. return _dictModuleTask[task.destMod].TimeToReady;
  2707. }
  2708. }
  2709. return int.MaxValue / 2;
  2710. }
  2711. List<Hand> GetTMValidFreeHands(List<WaferTask> robotWafers, List<MoveItem> swapActions)
  2712. {
  2713. var hands = new List<Hand>();
  2714. for(int i = 0; i < 2; i++)
  2715. {
  2716. if(_tmRobotSingleArmOption == 0 || _tmRobotSingleArmOption == i + 1)
  2717. {
  2718. if ((!robotWafers.Exists(wafer => wafer.currentSlot == i) ||
  2719. ( robotWafers.Exists(wafer => wafer.currentSlot == i) &&
  2720. swapActions.Exists(item => item.SourceModule == ModuleName.TMRobot && item.SourceSlot == i))) &&
  2721. !swapActions.Exists(item => item.DestinationModule == ModuleName.TMRobot && item.DestinationSlot == i))
  2722. hands.Add((Hand)i);
  2723. }
  2724. }
  2725. return hands;
  2726. }
  2727. (ModuleName llPath, List<MoveItem> swapActions) FindBestLLSwapPlan(ModuleName ll, List<WaferTask> robotWafers)
  2728. {
  2729. ModuleName path = ll == ModuleName.System ? ModuleName.System : ll;
  2730. List<ModuleName> lls = ll == ModuleName.System ? new List<ModuleName> { ModuleName.LLA, ModuleName.LLB } : new List<ModuleName> { ll };
  2731. List<MoveItem> actions = new List<MoveItem>();
  2732. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2733. foreach (var loadlock in lls)
  2734. {
  2735. llSwapActions[loadlock] = new List<MoveItem>();
  2736. if (IsLLReservedByEFEM(loadlock))
  2737. continue;
  2738. var llWaferStatus = GetLLReadyInOutSlots(loadlock);
  2739. foreach(var wafer in robotWafers)
  2740. {
  2741. if(_dictModuleTask[loadlock].TimeToReady == 0 && !IsLLReservedByEFEM(loadlock) && CanWaferGotoLL(wafer,loadlock) && llWaferStatus.emptySlot.Count > llSwapActions[loadlock].Count)
  2742. {
  2743. llSwapActions[loadlock].Add(new MoveItem(ModuleName.TMRobot, wafer.currentSlot, loadlock, llWaferStatus.emptySlot[llSwapActions[loadlock].Count], (Hand)wafer.currentSlot));
  2744. }
  2745. }
  2746. int prePickTime = 20;
  2747. int prePickCount = 0;
  2748. var hands = GetTMValidFreeHands(robotWafers, llSwapActions[loadlock]);
  2749. foreach (var slot in llWaferStatus.inSlot)
  2750. {
  2751. var wafer = _lstWaferTasks.Find(task => task.currentMod == loadlock && task.currentSlot == slot);
  2752. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && hands.Count > prePickCount)
  2753. {
  2754. if(_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2755. {
  2756. 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))
  2757. {
  2758. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2759. prePickCount++;
  2760. break;
  2761. }
  2762. }
  2763. else
  2764. {
  2765. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2766. prePickCount++;
  2767. }
  2768. }
  2769. }
  2770. }
  2771. var validateActions = llSwapActions.Where(item => item.Value.Count > 0).ToDictionary(k => k.Key, v => v.Value);
  2772. if(validateActions.Count == 1)
  2773. {
  2774. (path, actions) = (validateActions.First().Key, validateActions.First().Value);
  2775. }
  2776. else if(validateActions.Count == 2)
  2777. {
  2778. var sortedActions = validateActions.OrderByDescending(item => item.Value.Count + (_dictModuleTask[item.Key].Scheduler.IsVac ? 2 : 0)).ToDictionary(k => k.Key, v => v.Value);
  2779. (path, actions) = (sortedActions.First().Key, sortedActions.First().Value);
  2780. }
  2781. return (path, actions);
  2782. }
  2783. (List<WaferTask> pmWafers, ModuleName destLL, List<MoveItem> swapAction) FindBestReturnWafersPlan(Hand[] freeHands)
  2784. {
  2785. Dictionary<ModuleName, List<WaferTask>> returnWafers = new Dictionary<ModuleName, List<WaferTask>>();
  2786. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2787. Dictionary<ModuleName, int> llValues = new Dictionary<ModuleName, int>();
  2788. foreach(var ll in new List<ModuleName> { ModuleName.LLA, ModuleName.LLB})
  2789. {
  2790. var llWaferStatus = GetLLReadyInOutSlots(ll);
  2791. returnWafers[ll] = new List<WaferTask>();
  2792. llSwapActions[ll] = new List<MoveItem>();
  2793. llValues[ll] = 0;
  2794. if (IsLLReservedByEFEM(ll))
  2795. continue;
  2796. var readyReturnWafers = _lstWaferTasks.Where( wafer => ModuleHelper.IsPm(wafer.currentMod) &&
  2797. ModuleHelper.IsLoadPort(wafer.destMod) &&
  2798. wafer.movingStatus == RState.End &&
  2799. _dictModuleTask[wafer.currentMod].TimeToReady <= 2 &&
  2800. CanWaferGotoLL(wafer, ll)).Take(Math.Min(freeHands.Length, llWaferStatus.emptySlot.Count)).ToList();
  2801. int prePickTime = 10 * llSwapActions[ll].Count;
  2802. int handIndex = 0;
  2803. if(_dictModuleTask[ll].TimeToReady <= prePickTime)
  2804. {
  2805. foreach (var wafer in readyReturnWafers)
  2806. {
  2807. if(handIndex < freeHands.Length)
  2808. {
  2809. returnWafers[ll].Add(wafer);
  2810. llSwapActions[ll].Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[handIndex], ll, llWaferStatus.emptySlot[handIndex], freeHands[handIndex]));
  2811. handIndex++;
  2812. }
  2813. }
  2814. int prePickCount = 0;
  2815. handIndex = 0;
  2816. foreach (var slot in llWaferStatus.inSlot)
  2817. {
  2818. var wafer = _lstWaferTasks.Find(task => task.currentMod == ll && task.currentSlot == slot);
  2819. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && freeHands.Length > prePickCount)
  2820. {
  2821. if (_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2822. {
  2823. 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))
  2824. {
  2825. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2826. prePickCount++;
  2827. break;
  2828. }
  2829. }
  2830. else
  2831. {
  2832. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2833. prePickCount++;
  2834. }
  2835. }
  2836. }
  2837. llValues[ll] = returnWafers[ll].Count * 2 + llSwapActions[ll].Count + (_dictModuleTask[ll].Scheduler.IsVac && returnWafers[ll].Count > 0 ? 2 : 0);
  2838. }
  2839. }
  2840. var preferLL = llValues.OrderByDescending(v => v.Value).First().Key;
  2841. return (returnWafers[preferLL], preferLL, llSwapActions[preferLL]);
  2842. }
  2843. ModuleName FindTheBestMovePathWithFixSlot(IEnumerable<KeyValuePair<ModuleName, ModuleTask>> lls, List<WaferTask> pmWafers)
  2844. {
  2845. Dictionary<ModuleName, int> moveValues = new Dictionary<ModuleName, int>();
  2846. foreach(var ll in lls)
  2847. {
  2848. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  2849. moveValues[ll.Key] = Math.Min(pmWafers.Where(wt => CanWaferGotoLL(wt, ll.Key)).Count(), GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count) + llWaferStatus.tOutSlot.Count;
  2850. }
  2851. var preferLL = moveValues.OrderByDescending(v => v.Value).First().Key;
  2852. return moveValues[preferLL] > 0 ? preferLL : ModuleName.System;
  2853. }
  2854. void RoutingTMSwapActions(List<MoveItem> actions)
  2855. {
  2856. foreach (var action in actions)
  2857. {
  2858. if (ModuleHelper.IsTMRobot(action.SourceModule))
  2859. {
  2860. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == ModuleName.TMRobot && wafer.currentSlot == action.SourceSlot);
  2861. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2862. }
  2863. else
  2864. {
  2865. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2866. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2867. }
  2868. }
  2869. }
  2870. private bool ManaulReturnPMWafer()
  2871. {
  2872. var mReturnWafer = _qeReturnWafers.Peek();
  2873. if (ModuleHelper.IsPm((ModuleName)mReturnWafer.Station) && _lstWaferTasks.Count(wt => ModuleHelper.IsTMRobot(wt.currentMod)) == 0)
  2874. {
  2875. var hands = GetTMValidFreeHands(_lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod)).ToList(), new List<MoveItem>());
  2876. var waferTask = _lstWaferTasks.Find(wt => wt.currentMod == (ModuleName)mReturnWafer.Station && wt.waferId == mReturnWafer.InnerId);
  2877. if (waferTask != null && hands.Count > 0)
  2878. {
  2879. waferTask.Return();
  2880. var outLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && CanWaferGotoLL(waferTask, mod.Key) && GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 0 && !IsLLReservedByEFEM(mod.Key));
  2881. if (outLL.Count() > 0)
  2882. {
  2883. var slot = GetLLReadyInOutSlots(outLL.First().Key).emptySlot.First();
  2884. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waferTask.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2885. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL.First().Key, slot, hands.First()) });
  2886. _qeReturnWafers.Dequeue();
  2887. return true;
  2888. }
  2889. }
  2890. }
  2891. return false;
  2892. }
  2893. private void RoutingVacWafers()
  2894. {
  2895. if(_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2896. {
  2897. RunSchdTMActions();
  2898. return;
  2899. }
  2900. if(_tmRobotStatus == RState.End)
  2901. {
  2902. // handle manual return wafer if exist
  2903. if(_qeReturnWafers.Count > 0)
  2904. {
  2905. if (ManaulReturnPMWafer())
  2906. return;
  2907. }
  2908. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2909. {
  2910. if (_LLASlotNumber == 2)
  2911. {
  2912. Routing2SlotVacSystem();
  2913. }
  2914. else if (_LLASlotNumber == 4)
  2915. {
  2916. Routing4SlotVacSystem();
  2917. }
  2918. }
  2919. else
  2920. {
  2921. RoutingFixedSlotVacSystem();
  2922. }
  2923. }
  2924. }
  2925. private bool HasPendingCleanTask()
  2926. {
  2927. foreach( var mod in _dictModuleTask)
  2928. {
  2929. if(ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline)
  2930. {
  2931. if ((mod.Value as PMTask).HasPendingCleanTask)
  2932. return true;
  2933. }
  2934. }
  2935. return false;
  2936. }
  2937. private void Routing2SlotVacSystem()
  2938. {
  2939. var robotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2940. var freeHands = GetTMFreeHand();
  2941. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2942. {
  2943. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2944. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2945. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2946. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2947. var inLLModule = _dictModuleTask[inLL] as LoadlockTask;
  2948. var outLLModule = _dictModuleTask[outLL] as LoadlockTask;
  2949. if(robotWafers.Count == 0)
  2950. {
  2951. #region special routing pattern
  2952. if (_specialRoutingPattern != SpecialRoutingPattern.Disable)
  2953. {
  2954. if(_specialRoutingPattern == SpecialRoutingPattern.LongTimeRecipe && freeHands.Count == 2 && !HasPendingCleanTask())
  2955. {
  2956. if(_dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).Count() == 0 && inLLWaferStatus.inSlot.Count > 0)
  2957. {
  2958. var readyOutPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 25).OrderBy(mod => mod.Value.TimeToReady).ToList();
  2959. if(readyOutPMs.Count > 0 && inLLModule.ReayForTMInTime(5) && _lstWaferTasks.Exists(wt => wt.currentMod == inLL && readyOutPMs.Exists(kv => kv.Key == wt.destMod)))
  2960. {
  2961. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.destMod == readyOutPMs.First().Key);
  2962. if(llWafer == null)
  2963. {
  2964. llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && readyOutPMs.Exists( pm => pm.Key == wt.destMod && pm.Value.TimeToReady < 5));
  2965. }
  2966. if(llWafer != null)
  2967. {
  2968. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  2969. var pmSwap = new List<MoveItem>
  2970. { new MoveItem(readyOutPMs.First().Key, 0, ModuleName.TMRobot, (int)freeHands[1], freeHands[1]),
  2971. new MoveItem(ModuleName.TMRobot, (int)freeHands[0], readyOutPMs.First().Key, 0, freeHands[0])
  2972. };
  2973. _tmSchdActions.Enqueue(pmSwap);
  2974. if(outLLModule.ReayForTMInTime(25) && outLLWaferStatus.emptySlot.Count > 0)
  2975. {
  2976. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[1], outLL, outLLWaferStatus.emptySlot[0], freeHands[1]) });
  2977. }
  2978. }
  2979. }
  2980. return;
  2981. }
  2982. }
  2983. }
  2984. #endregion
  2985. if (_dictModuleTask.Count(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 5) > 0 && outLLModule.ReayForTMInTime(30) && outLLWaferStatus.emptySlot.Count > 0)
  2986. {
  2987. var readyOutPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 25).OrderBy(mod => mod.Value.TimeToReady).ToList();
  2988. var placeActions = new List<MoveItem>();
  2989. int pickCount = 0;
  2990. foreach (var pm in readyOutPMs)
  2991. {
  2992. var pmWafer = _lstWaferTasks.Find(wt => wt.currentMod == pm.Key);
  2993. if (pmWafer != null && pickCount < freeHands.Count && pickCount < outLLWaferStatus.emptySlot.Count)
  2994. {
  2995. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)freeHands[pickCount], freeHands[pickCount]) });
  2996. placeActions.Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[pickCount], outLL, outLLWaferStatus.emptySlot[pickCount], freeHands[pickCount]));
  2997. pickCount++;
  2998. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, pm.Key, $"{pm.Key} will be ready in {pm.Value.TimeToReady} seconds");
  2999. }
  3000. }
  3001. if (pickCount > 0)
  3002. {
  3003. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3004. _tmSchdActions.Enqueue(placeActions);
  3005. return;
  3006. }
  3007. }
  3008. // push wafer from LL to PM and avoid blocking two robot arms
  3009. if (inLLModule.ReayForTMInTime(10) && inLLWaferStatus.inSlot.Count > 0)
  3010. {
  3011. var pickActions = new List<MoveItem>();
  3012. var inLLWafers = _lstWaferTasks.FindAll(wt => wt.currentMod == inLL).ToList();
  3013. if (inLLWaferStatus.inSlot.Count < 2 || inLLWafers.Exists(wt => !_dictModuleTask[wt.destMod].HasWafer && _dictModuleTask[wt.destMod].TimeToReady < 20))
  3014. {
  3015. for (int i = 0; i < Math.Min(inLLWaferStatus.inSlot.Count, freeHands.Count); i++)
  3016. {
  3017. pickActions.Add(new MoveItem(inLL, inLLWaferStatus.inSlot[i], ModuleName.TMRobot, (int)freeHands[i], freeHands[i]));
  3018. }
  3019. }
  3020. if(pickActions.Count > 0)
  3021. {
  3022. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3023. _tmSchdActions.Enqueue(pickActions);
  3024. return;
  3025. }
  3026. }
  3027. }
  3028. else
  3029. {
  3030. #region special routing pattern
  3031. if (_specialRoutingPattern != SpecialRoutingPattern.Disable)
  3032. {
  3033. if (_specialRoutingPattern == SpecialRoutingPattern.LongTimeRecipe && _tmRobotSingleArmOption == 0 && !HasPendingCleanTask())
  3034. {
  3035. if(_dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).Count() == 0 && ModuleHelper.IsLoadPort(robotWafers[0].destMod))
  3036. {
  3037. if (outLLModule.ReayForTMInTime(10) && outLLWaferStatus.emptySlot.Count > 0)
  3038. {
  3039. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)(robotWafers[0].currentSlot)) });
  3040. }
  3041. return;
  3042. }
  3043. }
  3044. }
  3045. #endregion
  3046. foreach (var robotWafer in robotWafers)
  3047. {
  3048. if (ModuleHelper.IsPm(robotWafer.destMod))
  3049. {
  3050. if (_dictModuleTask[robotWafer.destMod].TimeToReady < 5)
  3051. {
  3052. var pmWafer = _lstWaferTasks.Find(wt => wt.currentMod == robotWafer.destMod);
  3053. if (_dictModuleTask[robotWafer.destMod].HasWafer && pmWafer != null)
  3054. {
  3055. // PM Swap
  3056. if (freeHands.Count > 0)
  3057. {
  3058. if (string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe) && !(_dictModuleTask[pmWafer.currentMod] as PMTask).HasPendingCleanTask)
  3059. {
  3060. var pmActions = new List<MoveItem>
  3061. {
  3062. new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]),
  3063. new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot)
  3064. };
  3065. _tmSchdActions.Enqueue(pmActions);
  3066. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, robotWafer.destMod, $"{robotWafer.destMod} will be ready in {_dictModuleTask[robotWafer.destMod].TimeToReady} seconds");
  3067. return;
  3068. }
  3069. else
  3070. {
  3071. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3072. return;
  3073. }
  3074. }
  3075. }
  3076. else
  3077. {
  3078. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, robotWafer.destMod, $"{robotWafer.destMod} will be ready in {_dictModuleTask[robotWafer.destMod].TimeToReady} seconds");
  3079. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3080. return;
  3081. }
  3082. }
  3083. else if (_dictModuleTask[robotWafer.destMod].TimeToReady > 20 && freeHands.Count > 0)
  3084. {
  3085. if (outLLWaferStatus.emptySlot.Count > 0 && outLLModule.ReayForTMInTime(10) && _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)) > 0)
  3086. {
  3087. // try to return one wafer from PM to LL
  3088. var readyOutWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod));
  3089. if (readyOutWafer != null && _dictModuleTask[readyOutWafer.currentMod].TimeToReady < 5)
  3090. {
  3091. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, readyOutWafer.currentMod, $"{readyOutWafer.currentMod} will be ready in {_dictModuleTask[readyOutWafer.currentMod].TimeToReady} seconds");
  3092. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3093. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafer.currentMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3094. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot[0], freeHands[0]) });
  3095. return;
  3096. }
  3097. }
  3098. if (inLLModule.ReayForTMInTime(5) && inLLWaferStatus.inSlot.Count > 0)
  3099. {
  3100. var inLLWafers = _lstWaferTasks.FindAll(wt => wt.currentMod == inLL).OrderBy(wt => _dictModuleTask[wt.destMod].TimeToReady);
  3101. foreach (var inWafer in inLLWafers)
  3102. {
  3103. if (!_dictModuleTask[inWafer.destMod].HasWafer && _dictModuleTask[inWafer.destMod].TimeToReady < 10)
  3104. {
  3105. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inWafer.destMod, $"{inWafer.destMod} will be ready in {_dictModuleTask[inWafer.destMod].TimeToReady} seconds");
  3106. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3107. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inWafer.currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3108. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], inWafer.destMod, 0, freeHands[0]) });
  3109. return;
  3110. }
  3111. }
  3112. }
  3113. }
  3114. }
  3115. else
  3116. {
  3117. if (freeHands.Count > 0 &&
  3118. outLLWaferStatus.emptySlot.Count == 2 &&
  3119. outLLModule.ReayForTMInTime(10) &&
  3120. _lstWaferTasks.Count(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)) > 0 )
  3121. {
  3122. // try to get one wafer from PM, and match a double place next time
  3123. var readyOutWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod));
  3124. if(readyOutWafer != null && _dictModuleTask[readyOutWafer.currentMod].TimeToReady < 5)
  3125. {
  3126. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafer.currentMod, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3127. return;
  3128. }
  3129. }
  3130. if (outLLModule.ReayForTMInTime(5))
  3131. {
  3132. // try match a double place
  3133. if (robotWafers.Count == 2 && robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)) && outLLWaferStatus.emptySlot.Count == 2)
  3134. {
  3135. var doublePlace = new List<MoveItem>
  3136. {
  3137. new MoveItem(ModuleName.TMRobot, 0, outLL, 0, Hand.Blade1),
  3138. new MoveItem(ModuleName.TMRobot, 1, outLL, 1, Hand.Blade2)
  3139. };
  3140. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3141. _tmSchdActions.Enqueue(doublePlace);
  3142. return;
  3143. }
  3144. if(outLLWaferStatus.emptySlot.Count > 0)
  3145. {
  3146. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3147. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)robotWafer.currentSlot) });
  3148. return;
  3149. }
  3150. }
  3151. }
  3152. }
  3153. if (freeHands.Count == 0)
  3154. return;
  3155. // try to push one wafer in pm
  3156. if(inLLWaferStatus.inSlot.Count == 1 && inLLModule.ReayForTMInTime(5))
  3157. {
  3158. var inWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == inLLWaferStatus.inSlot.First());
  3159. if(inWafer != null && !_dictModuleTask[inWafer.destMod].HasWafer && _dictModuleTask[inWafer.destMod].TimeToReady < 20)
  3160. {
  3161. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inWafer.destMod, $"{inWafer.destMod} will be ready in {_dictModuleTask[inWafer.destMod].TimeToReady} seconds");
  3162. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, inLL, $"{inLL} will be ready in {inLLModule.TimeToReady} seconds");
  3163. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inLLWaferStatus.inSlot.First(), ModuleName.TMRobot, (int)freeHands[0], freeHands[0])});
  3164. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], inWafer.destMod, 0, freeHands[0]) });
  3165. return;
  3166. }
  3167. }
  3168. // try to return one wafer
  3169. if(outLLModule.ReayForTMInTime(15) && outLLWaferStatus.emptySlot.Count > 0)
  3170. {
  3171. var readyReturnPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.TimeToReady < 5).OrderBy(mod => mod.Value.TimeToReady).ToList();
  3172. if(readyReturnPMs.Count > 0)
  3173. {
  3174. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, readyReturnPMs.First().Key, $"{readyReturnPMs.First().Key} will be ready in {readyReturnPMs.First().Value.TimeToReady} seconds");
  3175. //LOG.Write(eEvent.INFO_TROUGHPUT_ENHANCE_TRACE, outLL, $"{outLL} will be ready in {outLLModule.TimeToReady} seconds");
  3176. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyReturnPMs.First().Key, 0, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  3177. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot.First(), freeHands[0]) });
  3178. return;
  3179. }
  3180. }
  3181. }
  3182. }
  3183. else
  3184. {
  3185. if (robotWafers.Count == 2)
  3186. {
  3187. foreach (var wafer in robotWafers)
  3188. {
  3189. if (wafer.movingStatus == RState.End &&
  3190. ModuleHelper.IsPm(wafer.destMod) &&
  3191. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  3192. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  3193. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  3194. {
  3195. wafer.RouteTo(wafer.destMod, 0);
  3196. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3197. }
  3198. }
  3199. if (_tmSchdActions.Count == 0)
  3200. {
  3201. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3202. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3203. {
  3204. RoutingTMSwapActions(swapActions.swapActions);
  3205. _tmSchdActions.Enqueue(swapActions.swapActions);
  3206. }
  3207. }
  3208. }
  3209. else if (robotWafers.Count == 1)
  3210. {
  3211. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  3212. {
  3213. var pmActions = new List<MoveItem>();
  3214. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  3215. if (pmWafer != null)
  3216. {
  3217. int pickSlot = 1 - robotWafers[0].currentSlot;
  3218. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  3219. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  3220. if (string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe) && !(_dictModuleTask[robotWafers[0].destMod] as PMTask).HasPendingCleanTask)
  3221. {
  3222. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  3223. }
  3224. _tmSchdActions.Enqueue(pmActions);
  3225. return;
  3226. }
  3227. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  3228. {
  3229. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  3230. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  3231. _tmSchdActions.Enqueue(pmActions);
  3232. return;
  3233. }
  3234. }
  3235. // try to pick a wafer from LL
  3236. if (_tmSchdActions.Count == 0)
  3237. {
  3238. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3239. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3240. {
  3241. RoutingTMSwapActions(swapActions.swapActions);
  3242. _tmSchdActions.Enqueue(swapActions.swapActions);
  3243. return;
  3244. }
  3245. }
  3246. // try to return a wafer from PM
  3247. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3248. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3249. if (moveActions.pmWafers.Count > 0)
  3250. {
  3251. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3252. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  3253. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  3254. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  3255. if (pickAction != null)
  3256. {
  3257. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  3258. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  3259. }
  3260. _tmSchdActions.Enqueue(moveActions.swapAction);
  3261. }
  3262. }
  3263. else // robot arm is empty
  3264. {
  3265. // try return wafers from PM
  3266. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3267. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3268. if (moveActions.pmWafers.Count > 0)
  3269. {
  3270. int handIndex = 0;
  3271. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3272. foreach (var action in placeActions)
  3273. {
  3274. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3275. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3276. handIndex++;
  3277. }
  3278. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3279. foreach (var ac in pickActions)
  3280. {
  3281. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3282. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3283. }
  3284. _tmSchdActions.Enqueue(moveActions.swapAction);
  3285. }
  3286. if (_tmSchdActions.Count == 0)
  3287. {
  3288. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3289. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3290. {
  3291. RoutingTMSwapActions(swapActions.swapActions);
  3292. _tmSchdActions.Enqueue(swapActions.swapActions);
  3293. }
  3294. }
  3295. }
  3296. }
  3297. }
  3298. private void Routing4SlotVacSystem()
  3299. {
  3300. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  3301. if (robotWafers.Count == 2)
  3302. {
  3303. foreach (var wafer in robotWafers)
  3304. {
  3305. if (wafer.movingStatus == RState.End &&
  3306. ModuleHelper.IsPm(wafer.destMod) &&
  3307. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  3308. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  3309. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  3310. {
  3311. wafer.RouteTo(wafer.destMod, 0);
  3312. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3313. }
  3314. }
  3315. if (_tmSchdActions.Count == 0)
  3316. {
  3317. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3318. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3319. {
  3320. RoutingTMSwapActions(swapActions.swapActions);
  3321. _tmSchdActions.Enqueue(swapActions.swapActions);
  3322. }
  3323. }
  3324. }
  3325. else if (robotWafers.Count == 1)
  3326. {
  3327. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  3328. {
  3329. var pmActions = new List<MoveItem>();
  3330. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  3331. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  3332. {
  3333. int pickSlot = 1 - robotWafers[0].currentSlot;
  3334. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  3335. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  3336. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  3337. _tmSchdActions.Enqueue(pmActions);
  3338. return;
  3339. }
  3340. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  3341. {
  3342. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  3343. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  3344. _tmSchdActions.Enqueue(pmActions);
  3345. return;
  3346. }
  3347. }
  3348. // try to pick a wafer from LL
  3349. if (_tmSchdActions.Count == 0)
  3350. {
  3351. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3352. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3353. {
  3354. RoutingTMSwapActions(swapActions.swapActions);
  3355. _tmSchdActions.Enqueue(swapActions.swapActions);
  3356. return;
  3357. }
  3358. }
  3359. // try to return a wafer from PM
  3360. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3361. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3362. if (moveActions.pmWafers.Count > 0)
  3363. {
  3364. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3365. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  3366. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  3367. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  3368. if (pickAction != null)
  3369. {
  3370. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  3371. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  3372. }
  3373. _tmSchdActions.Enqueue(moveActions.swapAction);
  3374. }
  3375. }
  3376. else // robot arm is empty
  3377. {
  3378. // try return wafers from PM
  3379. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  3380. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  3381. if (moveActions.pmWafers.Count > 0)
  3382. {
  3383. int handIndex = 0;
  3384. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  3385. foreach (var action in placeActions)
  3386. {
  3387. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  3388. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  3389. handIndex++;
  3390. }
  3391. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  3392. foreach (var ac in pickActions)
  3393. {
  3394. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  3395. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  3396. }
  3397. _tmSchdActions.Enqueue(moveActions.swapAction);
  3398. }
  3399. if (_tmSchdActions.Count == 0)
  3400. {
  3401. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  3402. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  3403. {
  3404. RoutingTMSwapActions(swapActions.swapActions);
  3405. _tmSchdActions.Enqueue(swapActions.swapActions);
  3406. }
  3407. }
  3408. }
  3409. }
  3410. private void RoutingFixedSlotVacSystem()
  3411. {
  3412. var robotWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod));
  3413. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  3414. if (_LLASlotNumber == 2)
  3415. {
  3416. if (robotWafers.Count() == 1)
  3417. {
  3418. if(ModuleHelper.IsPm(robotWafers.First().destMod))
  3419. {
  3420. var destPM = robotWafers.First().destMod;
  3421. if(_dictModuleTask[destPM].TimeToReady <= 5)
  3422. {
  3423. if(_lstWaferTasks.Exists(wt => wt.currentMod == destPM))
  3424. {
  3425. var pickHand = SelectTMPickArm(destPM);
  3426. if(pickHand != Hand.None)
  3427. {
  3428. var pmSwap = new List<MoveItem>
  3429. {
  3430. new MoveItem(destPM, 0, ModuleName.TMRobot, (int)pickHand, pickHand),
  3431. new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot)
  3432. };
  3433. _tmSchdActions.Enqueue(pmSwap);
  3434. return;
  3435. }
  3436. }
  3437. else
  3438. {
  3439. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot) });
  3440. return;
  3441. }
  3442. }
  3443. }
  3444. else
  3445. {
  3446. var readySwapLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3447. GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 &&
  3448. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3449. ll.Value.TimeToReady <= 10);
  3450. if (readySwapLL.Count() > 0)
  3451. {
  3452. var destLL = readySwapLL.First().Key;
  3453. Hand pickHand = SelectTMPickArm(destLL);
  3454. if (pickHand != Hand.None)
  3455. {
  3456. Hand placeHand = (Hand)robotWafers.First().currentSlot;
  3457. var llSwap = new List<MoveItem>();
  3458. var llSlots = GetLLFixedReadyInOutSlots(destLL);
  3459. llSwap.Add(new MoveItem(destLL, llSlots.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3460. llSwap.Add(new MoveItem(ModuleName.TMRobot, (int)placeHand, destLL, llSlots.tInSlot.First(), placeHand));
  3461. _tmSchdActions.Enqueue(llSwap);
  3462. return;
  3463. }
  3464. }
  3465. var emptyLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3466. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3467. ll.Value.TimeToReady <= 2);
  3468. if (emptyLL.Count() > 0)
  3469. {
  3470. var destLL = emptyLL.First().Key;
  3471. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem( ModuleName.TMRobot,
  3472. robotWafers.First().currentSlot,
  3473. destLL,
  3474. GetLLFixedReadyInOutSlots(destLL).tInSlot.First(),
  3475. (Hand)robotWafers.First().currentSlot) });
  3476. return;
  3477. }
  3478. }
  3479. // try to return a wafer
  3480. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3481. foreach(var pmWafer in readyReturnWafers)
  3482. {
  3483. 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);
  3484. if(readyLL.Count() > 0)
  3485. {
  3486. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3487. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3488. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand , readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3489. return;
  3490. }
  3491. }
  3492. // try to push in a wafer
  3493. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3494. foreach(var ll in readyInLL)
  3495. {
  3496. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3497. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3498. if( wafer != null &&
  3499. ModuleHelper.IsPm(wafer.destMod) &&
  3500. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3501. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3502. {
  3503. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3504. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3505. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3506. return;
  3507. }
  3508. }
  3509. }
  3510. else if (robotWafers.Count() == 0)
  3511. {
  3512. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  3513. if(readyReturnWafers.Count > 0)
  3514. {
  3515. // try to do a LL swap action
  3516. var readySwapLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 10);
  3517. foreach (var pmWafer in readyReturnWafers)
  3518. {
  3519. foreach (var ll in readySwapLL)
  3520. {
  3521. if (CanWaferGotoLL(pmWafer, ll.Key))
  3522. {
  3523. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3524. var pickHand = SelectTMPickArm(ll.Key);
  3525. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3526. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3527. var llSwapActions = new List<MoveItem>();
  3528. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, llWaferStatus.tInSlot.First(), returnHand));
  3529. llSwapActions.Add(new MoveItem(ll.Key, llWaferStatus.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3530. _tmSchdActions.Enqueue(llSwapActions);
  3531. return;
  3532. }
  3533. }
  3534. }
  3535. // just return to LL
  3536. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 5);
  3537. foreach(var pmWafer in readyReturnWafers)
  3538. {
  3539. foreach(var ll in readyInLL)
  3540. {
  3541. if(CanWaferGotoLL(pmWafer, ll.Key))
  3542. {
  3543. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3544. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3545. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, GetLLFixedReadyInOutSlots(ll.Key).tInSlot.First(), returnHand) });
  3546. return;
  3547. }
  3548. }
  3549. }
  3550. }
  3551. var readyPushInLLs = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && ll.Value.TimeToReady <= 2);
  3552. if(readyPushInLLs.Count() > 0)
  3553. {
  3554. var destLL = readyPushInLLs.First().Key;
  3555. if(readyPushInLLs.Count() == 2 && readyPushInLLs.First().Value.Scheduler.IsAtm && readyPushInLLs.Last().Value.Scheduler.IsVac)
  3556. {
  3557. destLL = readyPushInLLs.Last().Key;
  3558. }
  3559. var pickHand = SelectTMPickArm(destLL);
  3560. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(destLL, GetLLFixedReadyInOutSlots(destLL).tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand) });
  3561. return;
  3562. }
  3563. }
  3564. else
  3565. {
  3566. // should not go here
  3567. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Had better avoid picking two wafers on TM robot arms under Loadlock fixed slot pattern");
  3568. foreach(var wafer in robotWafers)
  3569. {
  3570. if(ModuleHelper.IsPm(wafer.destMod))
  3571. {
  3572. if(!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3573. {
  3574. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3575. return;
  3576. }
  3577. }
  3578. else
  3579. {
  3580. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 2);
  3581. if(readyInLL.Count() > 0)
  3582. {
  3583. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, readyInLL.First().Key, GetLLFixedReadyInOutSlots(readyInLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3584. return;
  3585. }
  3586. }
  3587. }
  3588. }
  3589. }
  3590. else // 4 slot Loadlock
  3591. {
  3592. if(robotWafers.Count() > 0)
  3593. {
  3594. if (robotWafers.Count() == 2)
  3595. {
  3596. if (robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)))
  3597. {
  3598. var destLL = lls.Where(ll => robotWafers.All(wt => CanWaferGotoLL(wt, ll.Key)) &&
  3599. ll.Value.TimeToReady <= 10 &&
  3600. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 2).
  3601. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3602. OrderBy(ll => ll.Value.TimeToReady);
  3603. if (destLL.Count() > 0)
  3604. {
  3605. var swapLL = destLL.First().Key;
  3606. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3607. var swapActions = new List<MoveItem>();
  3608. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafers.First().currentSlot));
  3609. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.Last().currentSlot, swapLL, llWaferStatus.tInSlot.Last(), (Hand)robotWafers.Last().currentSlot));
  3610. int pickCount = 0;
  3611. foreach (var slot in llWaferStatus.eOutSlot)
  3612. {
  3613. swapActions.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3614. }
  3615. _tmSchdActions.Enqueue(swapActions);
  3616. return;
  3617. }
  3618. }
  3619. foreach (var wafer in robotWafers)
  3620. {
  3621. if (ModuleHelper.IsPm(wafer.destMod))
  3622. {
  3623. if (!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 5)
  3624. {
  3625. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3626. return;
  3627. }
  3628. }
  3629. else
  3630. {
  3631. var placeLL = lls.Where(ll => CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 5 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).OrderBy(ll => ll.Value.TimeToReady);
  3632. if (placeLL.Count() > 0)
  3633. {
  3634. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, placeLL.First().Key, GetLLFixedReadyInOutSlots(placeLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3635. return;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. else if (robotWafers.Count() == 1)
  3641. {
  3642. var robotWafer = robotWafers.First();
  3643. if (ModuleHelper.IsPm(robotWafer.destMod))
  3644. {
  3645. if (_dictModuleTask[robotWafer.destMod].TimeToReady <= 5)
  3646. {
  3647. if (_lstWaferTasks.Exists(wt => wt.currentMod == robotWafer.destMod))
  3648. {
  3649. var pmSwap = new List<MoveItem>();
  3650. pmSwap.Add(new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, 1 - robotWafer.currentSlot, (Hand)(1 - robotWafer.currentSlot)));
  3651. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot));
  3652. _tmSchdActions.Enqueue(pmSwap);
  3653. return;
  3654. }
  3655. else
  3656. {
  3657. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3658. return;
  3659. }
  3660. }
  3661. }
  3662. else
  3663. {
  3664. var destLL = lls.Where(ll => CanWaferGotoLL(robotWafer, ll.Key) &&
  3665. ll.Value.TimeToReady <= 10 &&
  3666. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).
  3667. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3668. OrderBy(ll => ll.Value.TimeToReady);
  3669. if (destLL.Count() > 0)
  3670. {
  3671. var swapLL = destLL.First().Key;
  3672. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3673. var llSwap = new List<MoveItem>();
  3674. llSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafer.currentSlot));
  3675. int pickCount = 0;
  3676. foreach (var slot in llWaferStatus.tOutSlot)
  3677. {
  3678. llSwap.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3679. pickCount++;
  3680. }
  3681. _tmSchdActions.Enqueue(llSwap);
  3682. return;
  3683. }
  3684. }
  3685. // try to return a wafer
  3686. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3687. foreach (var pmWafer in readyReturnWafers)
  3688. {
  3689. 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);
  3690. if (readyLL.Count() > 0)
  3691. {
  3692. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3693. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3694. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3695. return;
  3696. }
  3697. }
  3698. // try to push in a wafer
  3699. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3700. foreach (var ll in readyInLL)
  3701. {
  3702. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3703. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3704. if (wafer != null &&
  3705. ModuleHelper.IsPm(wafer.destMod) &&
  3706. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3707. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3708. {
  3709. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3710. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3711. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3712. return;
  3713. }
  3714. }
  3715. }
  3716. }
  3717. else // robot empty
  3718. {
  3719. 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();
  3720. var readyLL = lls.Where(ll => ll.Value.TimeToReady <= 10);
  3721. if(readyLL.Count() > 0)
  3722. {
  3723. var llPath = FindTheBestMovePathWithFixSlot(readyLL, nearlyReadyReturnWafers);
  3724. if(ModuleHelper.IsLoadLock(llPath))
  3725. {
  3726. int returnCount = 0;
  3727. var llWaferStatus = GetLLFixedReadyInOutSlots(llPath);
  3728. var llSwapActions = new List<MoveItem>();
  3729. foreach(var wafer in nearlyReadyReturnWafers)
  3730. {
  3731. if(CanWaferGotoLL(wafer, llPath) && returnCount < Math.Min(llWaferStatus.tInSlot.Count, 2))
  3732. {
  3733. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, 0, ModuleName.TMRobot, returnCount, (Hand)returnCount) });
  3734. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, returnCount, llPath, llWaferStatus.tInSlot[returnCount], (Hand)returnCount));
  3735. returnCount++;
  3736. }
  3737. }
  3738. int pickCount = 0;
  3739. foreach(var slot in llWaferStatus.tOutSlot)
  3740. {
  3741. if (pickCount < 2)
  3742. {
  3743. llSwapActions.Add(new MoveItem(llPath, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3744. pickCount++;
  3745. }
  3746. }
  3747. if(llSwapActions.Count > 0)
  3748. {
  3749. _tmSchdActions.Enqueue(llSwapActions);
  3750. }
  3751. return;
  3752. }
  3753. }
  3754. }
  3755. }
  3756. }
  3757. private bool IsTMRobotArmNotReserved(Hand hand)
  3758. {
  3759. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)hand) || _lstWaferTasks.Exists(wt => wt.currentMod == ModuleName.TMRobot && wt.currentSlot == (int)hand))
  3760. return false;
  3761. foreach(var acs in _tmSchdActions)
  3762. {
  3763. foreach(var ac in acs)
  3764. {
  3765. if ((ac.DestinationModule == ModuleName.TMRobot || ac.SourceModule == ModuleName.TMRobot) && ac.DestinationSlot == (int)hand)
  3766. return false;
  3767. }
  3768. }
  3769. return true;
  3770. }
  3771. private Hand SelectTMPickArm(ModuleName mod)
  3772. {
  3773. switch (_tmRobotSingleArmOption)
  3774. {
  3775. case 0:
  3776. {
  3777. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3778. return Hand.Blade1;
  3779. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3780. return Hand.Blade2;
  3781. }
  3782. break;
  3783. case 1:
  3784. {
  3785. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3786. return Hand.Blade1;
  3787. }
  3788. break;
  3789. case 2:
  3790. {
  3791. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3792. return Hand.Blade2;
  3793. }
  3794. break;
  3795. // Blade1 In Blade2 Out
  3796. case 3:
  3797. {
  3798. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3799. return Hand.Blade1;
  3800. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3801. return Hand.Blade2;
  3802. }
  3803. break;
  3804. // Blade2 In Blade1 Out
  3805. case 4:
  3806. {
  3807. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3808. return Hand.Blade2;
  3809. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3810. return Hand.Blade1;
  3811. }
  3812. break;
  3813. }
  3814. return Hand.None;
  3815. }
  3816. private List<Hand> GetTMFreeHand()
  3817. {
  3818. var lstHands = new List<Hand>();
  3819. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  3820. lstHands.Add(Hand.Blade1);
  3821. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  3822. lstHands.Add(Hand.Blade2);
  3823. return lstHands;
  3824. }
  3825. private List<Hand> GetEFEMFreeHand()
  3826. {
  3827. var lstHands = new List<Hand>();
  3828. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && _efemRobotSingleArmOption != 2)
  3829. lstHands.Add(Hand.Blade1);
  3830. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && _efemRobotSingleArmOption != 1)
  3831. lstHands.Add(Hand.Blade2);
  3832. return lstHands;
  3833. }
  3834. private bool CanWaferGotoLL(WaferTask task, ModuleName ll)
  3835. {
  3836. bool bVacWafer = ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod);
  3837. if (bVacWafer)
  3838. {
  3839. if (ModuleHelper.IsPm(task.destMod))
  3840. return false;
  3841. switch (task.llInOutPath)
  3842. {
  3843. case SequenceLLInOutPath.AInAOut:
  3844. case SequenceLLInOutPath.BInAOut:
  3845. return ll == ModuleName.LLA;
  3846. case SequenceLLInOutPath.AInBOut:
  3847. case SequenceLLInOutPath.BInBOut:
  3848. return ll == ModuleName.LLB;
  3849. case SequenceLLInOutPath.DInDOut:
  3850. return true;
  3851. }
  3852. }
  3853. else
  3854. {
  3855. if (ModuleHelper.IsLoadPort(task.destMod))
  3856. return false;
  3857. switch (task.llInOutPath)
  3858. {
  3859. case SequenceLLInOutPath.AInAOut:
  3860. case SequenceLLInOutPath.AInBOut:
  3861. return ll == ModuleName.LLA;
  3862. case SequenceLLInOutPath.BInAOut:
  3863. case SequenceLLInOutPath.BInBOut:
  3864. return ll == ModuleName.LLB;
  3865. case SequenceLLInOutPath.DInDOut:
  3866. return true;
  3867. }
  3868. }
  3869. return false;
  3870. }
  3871. private (List<int> inSlot, List<int> outSlot, List<int> emptySlot) GetLLReadyInOutSlots(ModuleName ll)
  3872. {
  3873. var readInSlots = new List<int>();
  3874. var readyOutSlots = new List<int>();
  3875. var emptySlots = new List<int>();
  3876. for(int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3877. {
  3878. 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)))
  3879. {
  3880. emptySlots.Add(slot);
  3881. }
  3882. if(WaferManager.Instance.CheckHasWafer(ll, slot))
  3883. {
  3884. Guid waferID = WaferManager.Instance.GetWafer(ll, slot).InnerId;
  3885. var waferTask = _lstWaferTasks.Find(wafer => wafer.waferId == waferID);
  3886. if(waferTask != null && waferTask.movingStatus == RState.End)
  3887. {
  3888. if (ModuleHelper.IsPm(waferTask.destMod))
  3889. readInSlots.Add(slot);
  3890. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3891. readyOutSlots.Add(slot);
  3892. }
  3893. }
  3894. }
  3895. return (readInSlots, readyOutSlots, emptySlots);
  3896. }
  3897. private (List<int> eInSlot, List<int> eOutSlot, List<int> tInSlot, List<int> tOutSlot) GetLLFixedReadyInOutSlots(ModuleName ll)
  3898. {
  3899. var eInSlot = new List<int>();
  3900. var eOutSlot = new List<int>();
  3901. var tInSlot = new List<int>();
  3902. var tOutSlot = new List<int>();
  3903. int SlotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  3904. for (int slot = 0; slot < SlotNumber; slot++)
  3905. {
  3906. 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)))
  3907. {
  3908. if ((slot >= SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.UpperInLowerOut) ||
  3909. (slot < SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.LowerInUpperOut))
  3910. {
  3911. eInSlot.Add(slot);
  3912. }
  3913. else
  3914. {
  3915. tInSlot.Add(slot);
  3916. }
  3917. }
  3918. if (WaferManager.Instance.CheckHasWafer(ll, slot))
  3919. {
  3920. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3921. var waferTask = _lstWaferTasks.Find(wt => wt.waferId == wafer.InnerId && wt.currentMod == ll && wt.currentSlot == slot);
  3922. if(waferTask == null)
  3923. {
  3924. LOG.Write(eEvent.EV_ROUTER, ll, $"Routing trace: did not find inner task associated with {wafer.WaferOrigin} at {ll}.{slot + 1}");
  3925. }
  3926. else if (waferTask.movingStatus == RState.End)
  3927. {
  3928. if (ModuleHelper.IsPm(waferTask.destMod))
  3929. tOutSlot.Add(slot);
  3930. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3931. eOutSlot.Add(slot);
  3932. }
  3933. }
  3934. }
  3935. return (eInSlot, eOutSlot, tInSlot, tOutSlot);
  3936. }
  3937. private (List<WaferInfo> wafers, List<int> emptySlots) GetLLWaferExistance(ModuleName ll)
  3938. {
  3939. var lstWafers = new List<WaferInfo>();
  3940. var lstEmptySlots = new List<int>();
  3941. for (int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3942. {
  3943. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3944. if(wafer != null && !wafer.IsEmpty)
  3945. {
  3946. lstWafers.Add(wafer);
  3947. }
  3948. else
  3949. {
  3950. lstEmptySlots.Add(slot);
  3951. }
  3952. }
  3953. return (lstWafers, lstEmptySlots);
  3954. }
  3955. private bool NeedPairingForNexWafer()
  3956. {
  3957. if (_lstWaferTasks.Exists(wt => ModuleHelper.IsLoadPort(wt.destMod) && (ModuleHelper.IsPm(wt.currentMod) || ModuleHelper.IsTMRobot(wt.currentMod))))
  3958. return true;
  3959. var processingPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.HasWafer && mod.Value.Scheduler.IsOnline).OrderBy(wt => wt.Value.TimeToReady);
  3960. if(processingPMs.Count() > 0)
  3961. {
  3962. int maxWaitingTime = SC.GetValue<int>("TM.MaxWaitTimePairingOutWafer");
  3963. return processingPMs.First().Value.TimeToReady < maxWaitingTime;
  3964. }
  3965. return false;
  3966. }
  3967. private void PrepareLLPressure()
  3968. {
  3969. if (RouteManager.IsATMMode)
  3970. return;
  3971. var schdPumpingLLs = new List<ModuleName>();
  3972. var schdVentingLLs = new List<ModuleName>();
  3973. var schdCoolingLLs = new List<ModuleName>();
  3974. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  3975. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  3976. // pre pumping/venting for schedule actions
  3977. if (_efemSchdActions.Count > 0)
  3978. {
  3979. var ventLLs = _efemSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3980. foreach(var ll in ventLLs)
  3981. {
  3982. if (!schdVentingLLs.Contains(ll))
  3983. schdVentingLLs.Add(ll);
  3984. }
  3985. }
  3986. if(_tmSchdActions.Count > 0)
  3987. {
  3988. var pumpLLs = _tmSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3989. foreach(var ll in pumpLLs)
  3990. {
  3991. if (!schdPumpingLLs.Contains(ll))
  3992. schdPumpingLLs.Add(ll);
  3993. }
  3994. }
  3995. // loadlock in out path advance check
  3996. if (_LLInOutPath == SequenceLLInOutPath.AInBOut)
  3997. {
  3998. if(llaWaferStatus.emptySlot.Count == _LLASlotNumber)
  3999. {
  4000. if (!schdVentingLLs.Contains(ModuleName.LLA))
  4001. schdVentingLLs.Add(ModuleName.LLA);
  4002. }
  4003. else if ((llaWaferStatus.inSlot.Count == _LLASlotNumber) ||
  4004. (llaWaferStatus.inSlot.Count > 0 && llaWaferStatus.inSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  4005. {
  4006. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  4007. schdPumpingLLs.Add(ModuleName.LLA);
  4008. }
  4009. if(llbWaferStatus.emptySlot.Count == _LLBSlotNumber)
  4010. {
  4011. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  4012. schdPumpingLLs.Add(ModuleName.LLB);
  4013. }
  4014. else if ((llbWaferStatus.outSlot.Count == _LLBSlotNumber) ||
  4015. (llbWaferStatus.outSlot.Count > 0 && llbWaferStatus.outSlot.Count < _LLBSlotNumber && !NeedPairingForNexWafer()))
  4016. {
  4017. schdCoolingLLs.Add(ModuleName.LLB);
  4018. }
  4019. }
  4020. else if(_LLInOutPath == SequenceLLInOutPath.BInAOut)
  4021. {
  4022. if (llbWaferStatus.emptySlot.Count == _LLBSlotNumber)
  4023. {
  4024. if (!schdVentingLLs.Contains(ModuleName.LLA))
  4025. schdVentingLLs.Add(ModuleName.LLB);
  4026. }
  4027. else if ((llbWaferStatus.inSlot.Count == _LLBSlotNumber) ||
  4028. (llbWaferStatus.inSlot.Count > 0 && llbWaferStatus.inSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  4029. {
  4030. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  4031. schdPumpingLLs.Add(ModuleName.LLB);
  4032. }
  4033. if (llaWaferStatus.emptySlot.Count == _LLASlotNumber)
  4034. {
  4035. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  4036. schdPumpingLLs.Add(ModuleName.LLA);
  4037. }
  4038. else if ((llaWaferStatus.outSlot.Count == _LLASlotNumber) ||
  4039. (llaWaferStatus.outSlot.Count > 0 && llaWaferStatus.outSlot.Count < _LLASlotNumber && !NeedPairingForNexWafer()))
  4040. {
  4041. schdCoolingLLs.Add(ModuleName.LLA);
  4042. }
  4043. }
  4044. else
  4045. {
  4046. if ((llaWaferStatus.inSlot.Count == _LLASlotNumber) ||
  4047. (llaWaferStatus.inSlot.Count > 0 && llaWaferStatus.inSlot.Count < _LLASlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  4048. {
  4049. if (!schdPumpingLLs.Contains(ModuleName.LLA))
  4050. schdPumpingLLs.Add(ModuleName.LLA);
  4051. }
  4052. else if ((llaWaferStatus.outSlot.Count == _LLASlotNumber) ||
  4053. (llaWaferStatus.outSlot.Count > 0 && llaWaferStatus.outSlot.Count < _LLASlotNumber && !NeedPairingForNexWafer()))
  4054. {
  4055. if (!schdVentingLLs.Contains(ModuleName.LLA))
  4056. schdCoolingLLs.Add(ModuleName.LLA);
  4057. }
  4058. if ((llbWaferStatus.inSlot.Count == _LLBSlotNumber) ||
  4059. (llbWaferStatus.inSlot.Count > 0 && llbWaferStatus.inSlot.Count < _LLBSlotNumber && _lstWaferTasks.Count(wt => ModuleHelper.IsLoadPort(wt.currentMod) && ModuleHelper.IsPm(wt.destMod)) == 0))
  4060. {
  4061. if (!schdPumpingLLs.Contains(ModuleName.LLB))
  4062. schdPumpingLLs.Add(ModuleName.LLB);
  4063. }
  4064. else if ((llbWaferStatus.outSlot.Count == _LLBSlotNumber) ||
  4065. (llbWaferStatus.outSlot.Count > 0 && llbWaferStatus.outSlot.Count < _LLBSlotNumber && !NeedPairingForNexWafer()))
  4066. {
  4067. if (!schdVentingLLs.Contains(ModuleName.LLB))
  4068. schdCoolingLLs.Add(ModuleName.LLB);
  4069. }
  4070. }
  4071. foreach (var ventLL in schdVentingLLs)
  4072. {
  4073. if (_dictModuleTask[ventLL].Scheduler.IsAvailable && !_dictModuleTask[ventLL].Scheduler.IsAtm && !schdCoolingLLs.Contains(ventLL))
  4074. (_dictModuleTask[ventLL] as LoadlockTask).PreVent();
  4075. }
  4076. foreach (var pumpLL in schdPumpingLLs)
  4077. {
  4078. if (_dictModuleTask[pumpLL].Scheduler.IsAvailable && !_dictModuleTask[pumpLL].Scheduler.IsVac && !schdVentingLLs.Contains(pumpLL))
  4079. (_dictModuleTask[pumpLL] as LoadlockTask).PrePump();
  4080. }
  4081. foreach (var coolLL in schdCoolingLLs)
  4082. {
  4083. if (_dictModuleTask[coolLL].Scheduler.IsOnline && !_dictModuleTask[coolLL].Scheduler.IsAtm)
  4084. (_dictModuleTask[coolLL] as LoadlockTask).Cooling();
  4085. }
  4086. }
  4087. private void RunLotCleanTasks()
  4088. {
  4089. foreach(var pm in _dictModuleTask)
  4090. {
  4091. if (!ModuleHelper.IsPm(pm.Key))
  4092. continue;
  4093. var pmTask = pm.Value as PMTask;
  4094. if(pmTask.HasWafer)
  4095. {
  4096. var pmWafer = _lstWaferTasks.Find(wt => wt.currentMod == pm.Key);
  4097. if (pmWafer != null && IsProcessJobEnding(pmWafer.lotId, pm.Key) && !_postLotCleanMarks[pm.Key].Contains(pmWafer.lotId))
  4098. {
  4099. var pj = _lstProcessJobs.Find(process => process.InnerId == pmWafer.lotId);
  4100. if (pj != null)
  4101. {
  4102. var postClean = pj.Sequence.GetPostCleanRecipe(pm.Key);
  4103. if (!string.IsNullOrWhiteSpace(postClean))
  4104. {
  4105. pmTask.InvokePostJobClean(postClean);
  4106. _postLotCleanMarks[pm.Key].Add(pmWafer.lotId);
  4107. }
  4108. }
  4109. }
  4110. }
  4111. // pre clean
  4112. var waitInWafer = GetFirstWaitInWafer(pm.Key);
  4113. if (waitInWafer != null && !_preLotCleanMarks[pm.Key].Contains(waitInWafer.lotId))
  4114. {
  4115. var pj = _lstProcessJobs.Find(process => process.InnerId == waitInWafer.lotId);
  4116. if (pj != null)
  4117. {
  4118. var preClean = pj.Sequence.GetPreCleanRecipe(pm.Key);
  4119. if (!string.IsNullOrWhiteSpace(preClean))
  4120. {
  4121. pmTask.InvokePreJobClean(preClean);
  4122. _preLotCleanMarks[pm.Key].Add(waitInWafer.lotId);
  4123. }
  4124. }
  4125. }
  4126. }
  4127. }
  4128. bool IsProcessJobEnding(Guid pjId, ModuleName pm)
  4129. {
  4130. if(!_lstWaferTasks.Exists(wt => wt.lotId == pjId && wt.destMod == pm && !ModuleHelper.IsPm(wt.currentMod)))
  4131. {
  4132. var processJob = _lstProcessJobs.Find(pj => pj.InnerId == pjId);
  4133. if (processJob == null)
  4134. return false;
  4135. foreach(var slot in processJob.SlotWafers)
  4136. {
  4137. if(WaferManager.Instance.CheckHasWafer(slot.Item1, slot.Item2))
  4138. {
  4139. if (WaferManager.Instance.GetWafer(slot.Item1, slot.Item2).NextSequenceStep == 0)
  4140. return false;
  4141. }
  4142. }
  4143. return true;
  4144. }
  4145. return false;
  4146. }
  4147. WaferTask GetFirstWaitInWafer(ModuleName pm)
  4148. {
  4149. int distance(WaferTask wafer)
  4150. {
  4151. if (ModuleHelper.IsTMRobot(wafer.currentMod))
  4152. return 0;
  4153. else if (ModuleHelper.IsLoadLock(wafer.currentMod))
  4154. {
  4155. return (_dictModuleTask[wafer.currentMod] as LoadlockTask).Distance;
  4156. }
  4157. else if(ModuleHelper.IsEFEMRobot(wafer.currentMod))
  4158. {
  4159. if (wafer.IsAligned)
  4160. return 15;
  4161. else
  4162. return 19;
  4163. }
  4164. return 17;
  4165. }
  4166. var waitInWafers = _lstWaferTasks.Where(wt => (wt.destMod == pm) && !ModuleHelper.IsPm(wt.currentMod) && !ModuleHelper.IsLoadPort(wt.currentMod)).OrderBy(wt => distance(wt));
  4167. if (waitInWafers.Count() > 0)
  4168. return waitInWafers.First();
  4169. return null;
  4170. }
  4171. private void ReturnVacWafers()
  4172. {
  4173. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  4174. {
  4175. RunSchdTMReturnActions();
  4176. return;
  4177. }
  4178. if (_tmRobotStatus != RState.End)
  4179. return;
  4180. var hands = GetTMFreeHand();
  4181. 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);
  4182. if(lls.Count() > 0)
  4183. {
  4184. // return robot wafers
  4185. int moveCount = 0;
  4186. var llActions = new List<MoveItem>();
  4187. var emptySlots = GetLLWaferExistance(lls.First().Key).emptySlots;
  4188. for(int arm = 0; arm < 2; arm++)
  4189. {
  4190. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, arm);
  4191. if(wafer != null && !wafer.IsEmpty && moveCount < emptySlots.Count)
  4192. {
  4193. llActions.Add(new MoveItem(ModuleName.TMRobot, arm, lls.First().Key, emptySlots[moveCount], (Hand)arm));
  4194. moveCount++;
  4195. }
  4196. }
  4197. if(moveCount > 0)
  4198. {
  4199. _tmSchdActions.Enqueue(llActions);
  4200. return;
  4201. }
  4202. // return PM wafers
  4203. var PickActions = new List<MoveItem>();
  4204. var hasWaferPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsIdle && mod.Value.Scheduler.IsInclude && WaferManager.Instance.CheckHasWafer(mod.Key, 0));
  4205. foreach(var pm in hasWaferPMs)
  4206. {
  4207. if (moveCount < hands.Count && moveCount < emptySlots.Count)
  4208. {
  4209. PickActions.Add(new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)hands[moveCount], hands[moveCount]));
  4210. llActions.Add(new MoveItem(ModuleName.TMRobot, (int)hands[moveCount], lls.First().Key, emptySlots[moveCount], hands[moveCount]));
  4211. moveCount++;
  4212. }
  4213. }
  4214. if(moveCount > 0)
  4215. {
  4216. foreach(var ac in PickActions)
  4217. {
  4218. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  4219. }
  4220. _tmSchdActions.Enqueue(llActions);
  4221. }
  4222. }
  4223. }
  4224. private void ReturnAtmWafers()
  4225. {
  4226. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  4227. {
  4228. RunSchdEFEMReturnActions();
  4229. return;
  4230. }
  4231. if (_efemRobotStatus != RState.End)
  4232. return;
  4233. // return Robot Wafer
  4234. for(int i = 0; i < 2; i++)
  4235. {
  4236. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  4237. if(wafer != null && !wafer.IsEmpty)
  4238. {
  4239. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  4240. }
  4241. }
  4242. if (_efemSchdActions.Count > 0)
  4243. return;
  4244. var hands = GetEFEMFreeHand();
  4245. // return Aligner wafer
  4246. var aligner = ModuleHelper.InstalledModules.Where(mod => ModuleHelper.IsAligner(mod)).ToList();
  4247. if(aligner.Count > 0 && WaferManager.Instance.CheckHasWafer(aligner.First(), 0) && hands.Count > 0)
  4248. {
  4249. var wafer = WaferManager.Instance.GetWafer(aligner.First(), 0);
  4250. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(aligner.First(), 0, ModuleName.EfemRobot, (int)hands.First(), hands.First()) });
  4251. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)hands.First(), (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands.First()) });
  4252. return;
  4253. }
  4254. // return Loadlock wafer
  4255. 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);
  4256. if(lls.Count() > 0)
  4257. {
  4258. int returnCount = 0;
  4259. var llActions = new List<MoveItem>();
  4260. var placActions = new List<MoveItem>();
  4261. foreach(var wafer in GetLLWaferExistance(lls.First().Key).wafers)
  4262. {
  4263. if(returnCount < hands.Count)
  4264. {
  4265. llActions.Add(new MoveItem(lls.First().Key, wafer.Slot, ModuleName.EfemRobot, (int)hands[returnCount], hands[returnCount]));
  4266. placActions.Add(new MoveItem(ModuleName.EfemRobot, (int)hands[returnCount], (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands[returnCount]));
  4267. returnCount++;
  4268. }
  4269. }
  4270. if (returnCount > 0)
  4271. {
  4272. _efemSchdActions.Enqueue(llActions);
  4273. foreach (var ac in placActions)
  4274. {
  4275. _efemSchdActions.Enqueue(new List<MoveItem> { ac });
  4276. }
  4277. }
  4278. }
  4279. }
  4280. private void RunSchdEFEMReturnActions()
  4281. {
  4282. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  4283. if (efemRobot == null || !efemRobot.IsAvailable)
  4284. return;
  4285. if (_efemSchdActions.Count > 0)
  4286. {
  4287. if (_curEfemAction.Count == 0 || isReturnActionsDone(_curEfemAction))
  4288. {
  4289. var nextActions = _efemSchdActions.First();
  4290. var nextModule = nextActions.First().Module;
  4291. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle && _dictModuleTask[nextModule].Status!=ModuleStatus.StartCooling)
  4292. return;
  4293. _curEfemAction = _efemSchdActions.Dequeue();
  4294. efemRobot.PostMoveItems(_curEfemAction.ToArray());
  4295. }
  4296. }
  4297. else if (_curEfemAction.Count >= 0 && isReturnActionsDone(_curEfemAction)) // all scheduled actions done
  4298. {
  4299. _curEfemAction.Clear();
  4300. }
  4301. }
  4302. private void RunSchdTMReturnActions()
  4303. {
  4304. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerTMRobot;
  4305. if (tmRobot == null || !tmRobot.IsAvailable)
  4306. return;
  4307. if (_tmSchdActions.Count > 0)
  4308. {
  4309. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  4310. {
  4311. var nextActions = _tmSchdActions.First();
  4312. var nextModule = nextActions.First().Module;
  4313. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle && _dictModuleTask[nextModule].Status != ModuleStatus.StartCooling)
  4314. return;
  4315. _curTmAction = _tmSchdActions.Dequeue();
  4316. tmRobot.SendMoveItems(_curTmAction.ToArray());
  4317. }
  4318. }
  4319. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  4320. {
  4321. _curTmAction.Clear();
  4322. }
  4323. }
  4324. #endregion
  4325. #region sequence/recipe operation
  4326. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  4327. {
  4328. reason = "";
  4329. foreach(var pm in seq.PMs)
  4330. {
  4331. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  4332. return true;
  4333. }
  4334. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  4335. return false;
  4336. }
  4337. private bool CheckSequenceKepler2200TemperatureReady(SequenceInfo seq)
  4338. {
  4339. for (int i = 0; i < seq.Steps.Count; i++)
  4340. {
  4341. SequenceStepInfo stepInfo = seq.Steps[i];
  4342. foreach (var module in stepInfo.StepModules)
  4343. {
  4344. if (ModuleHelper.IsPm(module))
  4345. {
  4346. string attr = $"{module}Recipe";
  4347. if (stepInfo.StepParameter.ContainsKey(attr)
  4348. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4349. {
  4350. var recipeName =seq.GetRecipe(module);
  4351. var recipeContent =
  4352. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4353. var recipe = Recipe.Load(recipeContent);
  4354. float currentChamberTemperature;
  4355. switch (module)
  4356. {
  4357. case ModuleName.PMA:
  4358. currentChamberTemperature = Singleton<RouteManager>.Instance.PMA.ChamberTemperature;
  4359. break;
  4360. case ModuleName.PMB:
  4361. currentChamberTemperature = Singleton<RouteManager>.Instance.PMB.ChamberTemperature;
  4362. break;
  4363. case ModuleName.PMC:
  4364. currentChamberTemperature = Singleton<RouteManager>.Instance.PMC.ChamberTemperature;
  4365. break;
  4366. case ModuleName.PMD:
  4367. currentChamberTemperature = Singleton<RouteManager>.Instance.PMD.ChamberTemperature;
  4368. break;
  4369. default:
  4370. currentChamberTemperature = 0;
  4371. break;
  4372. }
  4373. if (recipe.Header.Temperature != null && recipe.Header.Temperature != "" && (currentChamberTemperature > Convert.ToSingle(recipe.Header.Temperature) + 10 || currentChamberTemperature < Convert.ToSingle(recipe.Header.Temperature) - 10))
  4374. {
  4375. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Start job失败,由于{module}腔体温度{currentChamberTemperature}与{recipeName} Recipe温度{recipe.Header.Temperature}不匹配");
  4376. return false;
  4377. }
  4378. }
  4379. }
  4380. }
  4381. }
  4382. return true;
  4383. }
  4384. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  4385. {
  4386. for (int i = 0; i < seq.Steps.Count; i++)
  4387. {
  4388. SequenceStepInfo stepInfo = seq.Steps[i];
  4389. foreach (var module in stepInfo.StepModules)
  4390. {
  4391. if (ModuleHelper.IsPm(module))
  4392. {
  4393. string attr = $"{module}Recipe";
  4394. if (stepInfo.StepParameter.ContainsKey(attr)
  4395. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4396. {
  4397. var recipeName = (string)stepInfo.StepParameter[attr];
  4398. if (!string.IsNullOrWhiteSpace(recipeName))
  4399. {
  4400. var recipeContent =
  4401. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4402. if (string.IsNullOrWhiteSpace(recipeContent))
  4403. {
  4404. reason = $"Can not find recipe file{recipeName}";
  4405. return false;
  4406. }
  4407. }
  4408. }
  4409. }
  4410. }
  4411. }
  4412. reason = "";
  4413. return true;
  4414. }
  4415. private void UpdateLLInOutPathProperty()
  4416. {
  4417. if (_lstControlJobs.Count == 0)
  4418. return;
  4419. var inOutPaths = new List<SequenceLLInOutPath>();
  4420. foreach(var wt in _lstWaferTasks)
  4421. {
  4422. if (!inOutPaths.Contains(wt.llInOutPath))
  4423. inOutPaths.Add(wt.llInOutPath);
  4424. }
  4425. if (inOutPaths.Count == 1)
  4426. {
  4427. _LLInOutPath = inOutPaths[0];
  4428. }
  4429. else
  4430. _LLInOutPath = SequenceLLInOutPath.DInDOut;
  4431. }
  4432. private bool GetAllJobRecipe(List<string> InUseRecipes, ControlJobInfo cj,SequenceInfo seq)
  4433. {
  4434. for (int i = 0; i < seq.Steps.Count; i++)
  4435. {
  4436. SequenceStepInfo stepInfo = seq.Steps[i];
  4437. foreach (var module in stepInfo.StepModules)
  4438. {
  4439. if (ModuleHelper.IsPm(module))
  4440. {
  4441. string attr = $"{module}Recipe";
  4442. if (stepInfo.StepParameter.ContainsKey(attr)
  4443. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  4444. {
  4445. var recipeName =seq.GetRecipe(module);
  4446. var recipeContent =
  4447. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  4448. var recipe = Recipe.Load(recipeContent);
  4449. if (recipe.Header.ChuckRecipe != null && recipe.Header.ChuckRecipe != "")
  4450. {
  4451. InUseRecipes.Add($"{module}.ChuckRecipe.{recipe.Header.ChuckRecipe}");
  4452. }
  4453. if (recipe.Header.DechuckRecipe != null && recipe.Header.DechuckRecipe != "")
  4454. {
  4455. InUseRecipes.Add($"{module}.DechuckRecipe.{recipe.Header.DechuckRecipe}");
  4456. }
  4457. InUseRecipes.Add($"{module}.Process.{recipeName}");
  4458. if (cj.PreJobClean != "")
  4459. {
  4460. InUseRecipes.Add($"{module}.Clean.{cj.PreJobClean}");
  4461. }
  4462. if (cj.PostJobClean != "")
  4463. {
  4464. InUseRecipes.Add($"{module}.Clean.{cj.PostJobClean}");
  4465. }
  4466. if (stepInfo.StepParameter["WTWClean"].ToString() != "")
  4467. {
  4468. InUseRecipes.Add($"{module}.Clean.{stepInfo.StepParameter["WTWClean"]}");
  4469. }
  4470. }
  4471. }
  4472. }
  4473. }
  4474. return true;
  4475. }
  4476. private bool IsSequenceNeedAlign(SequenceInfo sequence)
  4477. {
  4478. // check wether need align
  4479. foreach (var step in sequence.Steps)
  4480. {
  4481. foreach(var mod in step.StepModules)
  4482. {
  4483. if(ModuleHelper.IsAligner(mod))
  4484. return true;
  4485. }
  4486. }
  4487. return false;
  4488. }
  4489. #endregion
  4490. }
  4491. }