SystemDispatcher.cs 232 KB

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