SystemDispatcher.cs 209 KB

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