SystemDispatcher.cs 201 KB

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