SystemDispatcher.cs 234 KB

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