SystemDispatcher.cs 202 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435
  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, bool needAlign)
  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 = !needAlign;
  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);
  1652. return;
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. private void CreateWaferTasks(WaferInfo wafer, ModuleName pm)
  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. wafer.ProcessJob.Sequence.LLDelayTime,
  1678. IsSequenceNeedAlign(wafer.ProcessJob.Sequence));
  1679. waferTask.OnWaferArrived += WaferArrived;
  1680. waferTask.OnWaferLeaved += WaferLeaved;
  1681. _lstWaferTasks.Add(waferTask);
  1682. }
  1683. private bool ForwardATMWafers(ModuleName ll)
  1684. {
  1685. var emptySlots = _LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut ? GetLLReadyInOutSlots(ll).emptySlot : GetLLFixedReadyInOutSlots(ll).eInSlot;
  1686. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End ||wafer.movingStatus == RState.Init) && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1687. var notAlignedWafer = atmWafers.Where(wafer => !wafer.IsAligned).ToList();
  1688. 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();
  1689. var freeHands = GetEFEMFreeHand();
  1690. if ((atmWafers.Count >= 2 && !atmWafers.Exists(wafer => !wafer.IsAligned)) || freeHands.Count == 0 || readyInWafers.Length == 0)
  1691. return false;
  1692. // force all wafer aligned
  1693. if (notAlignedWafer.Count > 0 && _lstWaferTasks.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 0)
  1694. {
  1695. notAlignedWafer.First().RouteTo(ModuleName.Aligner1, 0);
  1696. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(notAlignedWafer.First().currentMod, notAlignedWafer.First().currentSlot, ModuleName.Aligner1, 0, (Hand)notAlignedWafer.First().currentSlot) });
  1697. }
  1698. // forward one wafer
  1699. else if ((readyInWafers.Length > 0) && (atmWafers.Count == 0 || (atmWafers.Count == 1 && emptySlots.Count >= 2)))
  1700. {
  1701. if(readyInWafers[0].IsAligned)
  1702. {
  1703. // pick from LP
  1704. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyInWafers[0].currentMod, readyInWafers[0].currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1705. }
  1706. else if(!_lstWaferTasks.Exists(wt => ModuleHelper.IsAligner(wt.currentMod)))
  1707. {
  1708. readyInWafers[0].RouteTo(ModuleName.Aligner1, 0);
  1709. // pick from LP
  1710. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyInWafers[0].currentMod, readyInWafers[0].currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1711. // place to aligner
  1712. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ModuleName.Aligner1, 0, freeHands[0]) });
  1713. }
  1714. }
  1715. // forward aligner wafer
  1716. else if (atmWafers.Count == 1 && emptySlots.Count >= 2 && ModuleHelper.IsAligner(atmWafers.First().currentMod) && freeHands.Count > 1)
  1717. {
  1718. atmWafers.First().RouteTo(ModuleName.EfemRobot, (int)freeHands[1]);
  1719. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(atmWafers.First().currentMod, atmWafers.First().currentSlot, ModuleName.EfemRobot, (int)freeHands[1], freeHands[1]) });
  1720. }
  1721. return _efemSchdActions.Count > 0;
  1722. }
  1723. private bool ExchangeWaferWithLL(ModuleName ll)
  1724. {
  1725. if (IsLLReservedByTM(ll))
  1726. return false;
  1727. var waferStaus = GetLLReadyInOutSlots(ll);
  1728. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1729. var freeHands = GetEFEMFreeHand();
  1730. var swapActions = new List<MoveItem>();
  1731. var validHands = new List<Hand>();
  1732. int placeCount = 0;
  1733. if ( waferStaus.emptySlot.Count > 0 &&
  1734. freeHands.Count >= 1 &&
  1735. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  1736. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || waferStaus.emptySlot.Count >= 2))
  1737. {
  1738. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  1739. if (CanWaferGotoLL(alignerWafer, ll))
  1740. {
  1741. alignerWafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  1742. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1743. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, waferStaus.emptySlot[placeCount], freeHands[0]));
  1744. validHands.Add(freeHands[0]);
  1745. placeCount++;
  1746. }
  1747. }
  1748. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  1749. foreach(var wafer in armWafers)
  1750. {
  1751. if (CanWaferGotoLL(wafer, ll) && placeCount < waferStaus.emptySlot.Count)
  1752. {
  1753. wafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  1754. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, waferStaus.emptySlot[placeCount], (Hand)wafer.currentSlot));
  1755. if(!validHands.Contains((Hand)wafer.currentSlot))
  1756. validHands.Add((Hand)wafer.currentSlot);
  1757. placeCount++;
  1758. }
  1759. }
  1760. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  1761. validHands.Add(Hand.Blade1);
  1762. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  1763. validHands.Add(Hand.Blade2);
  1764. int pickCount = 0;
  1765. var returnActions = new List<MoveItem>();
  1766. foreach(var slot in waferStaus.outSlot)
  1767. {
  1768. if(pickCount < validHands.Count)
  1769. {
  1770. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  1771. if(outWafer != null)
  1772. {
  1773. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  1774. swapActions.Add(new MoveItem(ll, waferStaus.outSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  1775. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  1776. pickCount++;
  1777. }
  1778. }
  1779. }
  1780. if(swapActions.Count > 0)
  1781. {
  1782. _efemSchdActions.Enqueue(swapActions);
  1783. }
  1784. foreach(var action in returnActions)
  1785. {
  1786. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  1787. }
  1788. return _efemSchdActions.Count > 0;
  1789. }
  1790. private bool ExchangeWaferWithFixedSlotLL(ModuleName ll)
  1791. {
  1792. if (IsLLReservedByTM(ll))
  1793. return false;
  1794. var llWaferStatus = GetLLFixedReadyInOutSlots(ll);
  1795. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1796. var freeHands = GetEFEMFreeHand();
  1797. var swapActions = new List<MoveItem>();
  1798. var validHands = new List<Hand>();
  1799. int placeCount = 0;
  1800. if (llWaferStatus.eInSlot.Count > 0 &&
  1801. freeHands.Count >= 1 &&
  1802. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  1803. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || llWaferStatus.eInSlot.Count >= 2))
  1804. {
  1805. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  1806. if (CanWaferGotoLL(alignerWafer, ll))
  1807. {
  1808. alignerWafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  1809. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1810. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, llWaferStatus.eInSlot[placeCount], freeHands[0]));
  1811. validHands.Add(freeHands[0]);
  1812. placeCount++;
  1813. }
  1814. }
  1815. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  1816. foreach (var wafer in armWafers)
  1817. {
  1818. if (CanWaferGotoLL(wafer, ll) && placeCount < llWaferStatus.eInSlot.Count)
  1819. {
  1820. wafer.RouteTo(ll, llWaferStatus.eInSlot[placeCount]);
  1821. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, llWaferStatus.eInSlot[placeCount], (Hand)wafer.currentSlot));
  1822. if (!validHands.Contains((Hand)wafer.currentSlot))
  1823. validHands.Add((Hand)wafer.currentSlot);
  1824. placeCount++;
  1825. }
  1826. }
  1827. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  1828. validHands.Add(Hand.Blade1);
  1829. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  1830. validHands.Add(Hand.Blade2);
  1831. int pickCount = 0;
  1832. var returnActions = new List<MoveItem>();
  1833. foreach (var slot in llWaferStatus.eOutSlot)
  1834. {
  1835. if (pickCount < validHands.Count)
  1836. {
  1837. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  1838. if (outWafer != null)
  1839. {
  1840. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  1841. swapActions.Add(new MoveItem(ll, llWaferStatus.eOutSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  1842. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  1843. pickCount++;
  1844. }
  1845. }
  1846. }
  1847. if (swapActions.Count > 0)
  1848. {
  1849. _efemSchdActions.Enqueue(swapActions);
  1850. }
  1851. foreach (var action in returnActions)
  1852. {
  1853. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  1854. }
  1855. return _efemSchdActions.Count > 0;
  1856. }
  1857. private void RoutingATMWafers()
  1858. {
  1859. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  1860. {
  1861. RunSchdEFEMActions();
  1862. return;
  1863. }
  1864. if (_efemRobotStatus != RState.End)
  1865. return;
  1866. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  1867. {
  1868. if (_LLASlotNumber == 2)
  1869. {
  1870. Routing2SlotATMSystem();
  1871. }
  1872. else if (_LLASlotNumber == 4)
  1873. {
  1874. Routing4SlotATMSystem();
  1875. }
  1876. }
  1877. else
  1878. {
  1879. RoutingFixedSlotATMSystem();
  1880. }
  1881. }
  1882. private void Routing4SlotATMSystem()
  1883. {
  1884. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1885. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  1886. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  1887. {
  1888. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  1889. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  1890. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  1891. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  1892. if (efemRobotWafers.Count() >= 1)
  1893. {
  1894. if (inLLWaferStatus.emptySlot.Count >= 2 && !IsLLReservedByTM(inLL)) // wait for in loadlock ready
  1895. {
  1896. if (_dictModuleTask[inLL].TimeToReady < 2)
  1897. {
  1898. ExchangeWaferWithLL(inLL);
  1899. }
  1900. }
  1901. if ((inLLWaferStatus.emptySlot.Count == 0 || (outLLWaferStatus.outSlot.Count >= 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL)) // ready return wafer
  1902. {
  1903. ExchangeWaferWithLL(outLL);
  1904. }
  1905. }
  1906. else
  1907. {
  1908. if (((outLLWaferStatus.outSlot.Count >= 2 && _dictModuleTask[outLL].TimeToReady < 10) ||
  1909. (outLLWaferStatus.outSlot.Count == 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL))
  1910. {
  1911. ExchangeWaferWithLL(outLL);
  1912. }
  1913. else if (inLLWaferStatus.emptySlot.Count >= 2)
  1914. {
  1915. if (((_dictModuleTask[inLL].TimeToReady > 20 || _dictModuleTask[inLL].Scheduler.IsVac) && atmWaferCount < 2) || atmWaferCount == 0)
  1916. {
  1917. ForwardATMWafers(inLL);
  1918. }
  1919. else if (atmWaferCount >= 2 && !IsLLReservedByTM(inLL))
  1920. {
  1921. ExchangeWaferWithLL(inLL);
  1922. }
  1923. }
  1924. }
  1925. }
  1926. else
  1927. {
  1928. RoutingSameLLInOutATMSystem();
  1929. }
  1930. }
  1931. private void Routing2SlotATMSystem()
  1932. {
  1933. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1934. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  1935. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  1936. {
  1937. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  1938. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  1939. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  1940. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  1941. // whether can do double return in 5 second, single return with single arm option or LL under atm pressure
  1942. if ((outLLWaferStatus.outSlot.Count == 2 && _dictModuleTask[outLL].TimeToReady < 5 && (atmWaferCount < 2 || !_dictModuleTask[outLL].Scheduler.IsAtm)) ||
  1943. (outLLWaferStatus.outSlot.Count == 1 && ((_dictModuleTask[outLL].TimeToReady < 2 && _dictModuleTask[outLL].Scheduler.IsAtm)
  1944. || _efemRobotSingleArmOption != 0
  1945. || _lstWaferTasks.Where(wt => ModuleHelper.IsLoadPort(wt.destMod)).Count() == 1)))
  1946. {
  1947. if (ExchangeWaferWithLL(outLL))
  1948. return;
  1949. }
  1950. // 有两片processed wafer 时且, 不需要align wafer 时, 不要预期
  1951. if((atmWaferCount == 0 && (outLLWaferStatus.outSlot.Count() < 2 || _lstWaferTasks.Exists(wt => ModuleHelper.IsLoadPort(wt.currentMod) && !wt.IsAligned))) ||
  1952. (atmWaferCount == 1 && inLLWaferStatus.emptySlot.Count == 2 && _efemRobotSingleArmOption == 0 && (outLLWaferStatus.outSlot.Count < 2 || _dictModuleTask[outLL].TimeToReady > 20)))
  1953. {
  1954. if (ForwardATMWafers(inLL))
  1955. return;
  1956. }
  1957. if((inLLWaferStatus.emptySlot.Count == 2 || (inLLWaferStatus.emptySlot.Count == 1 && _efemRobotSingleArmOption != 0) && _dictModuleTask[inLL].TimeToReady < 2))
  1958. {
  1959. ExchangeWaferWithLL(inLL);
  1960. }
  1961. }
  1962. else
  1963. {
  1964. RoutingSameLLInOutATMSystem();
  1965. }
  1966. }
  1967. private void RoutingFixedSlotATMSystem()
  1968. {
  1969. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1970. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  1971. if ( atmWaferCount == 0 || (_efemRobotSingleArmOption == 0 && atmWaferCount == 1 ))
  1972. {
  1973. foreach(var ll in lls)
  1974. {
  1975. if (ForwardATMWafers(ll.Key))
  1976. return;
  1977. }
  1978. }
  1979. // try to match a ll swap action
  1980. var readyReturnLL = lls.Where(ll => (GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count > 0) && ll.Value.TimeToReady <= 10)
  1981. .OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).eInSlot.Count + GetLLFixedReadyInOutSlots(ll.Key).eOutSlot.Count)
  1982. .OrderBy(ll => ll.Value.TimeToReady);
  1983. foreach (var ll in readyReturnLL)
  1984. {
  1985. if (ExchangeWaferWithFixedSlotLL(ll.Key))
  1986. return;
  1987. }
  1988. }
  1989. private void RoutingSameLLInOutATMSystem()
  1990. {
  1991. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1992. var vacWaferCount = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod) || ModuleHelper.IsLoadLock(task.currentMod)).Count();
  1993. var preferWaferVacCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline).Count() +
  1994. (LLInOutPath == SequenceLLInOutPath.AInAOut ? _LLASlotNumber / 2 : (LLInOutPath == SequenceLLInOutPath.BInBOut ? _LLBSlotNumber / 2 : _LLASlotNumber));
  1995. var inOutIndicator = vacWaferCount - preferWaferVacCount;
  1996. if (inOutIndicator < 0)
  1997. {
  1998. // ready to push in
  1999. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2000. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2001. mod.Value.TimeToReady <= 10 &&
  2002. !IsLLReservedByTM(mod.Key) &&
  2003. GetLLReadyInOutSlots(mod.Key).emptySlot.Count >= 1).
  2004. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2005. if (atmWaferCount >= 1)
  2006. {
  2007. foreach(var ll in readyLLs)
  2008. {
  2009. if (ExchangeWaferWithLL(ll.Key))
  2010. return;
  2011. }
  2012. }
  2013. // forward wafer to system
  2014. if (atmWaferCount < 2)
  2015. {
  2016. var targetLL = readyLLs.Count > 0 ? readyLLs.First().Key : (LLInOutPath == SequenceLLInOutPath.BInBOut ? ModuleName.LLB : ModuleName.LLA);
  2017. ForwardATMWafers(targetLL);
  2018. }
  2019. if (_efemSchdActions.Count == 0)
  2020. {
  2021. var readyReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2022. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  2023. mod.Value.TimeToReady <= 5 &&
  2024. !IsLLReservedByTM(mod.Key) &&
  2025. GetLLReadyInOutSlots(mod.Key).outSlot.Count >= 1).
  2026. OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).outSlot.Count).ToList();
  2027. foreach(var ll in readyReturnLL)
  2028. {
  2029. if (ExchangeWaferWithLL(readyReturnLL.First().Key))
  2030. return;
  2031. }
  2032. }
  2033. }
  2034. else
  2035. {
  2036. // ready double return LL
  2037. var readyDoubleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2038. mod.Value.TimeToReady < 10 &&
  2039. !IsLLReservedByTM(mod.Key) &&
  2040. GetLLReadyInOutSlots(mod.Key).outSlot.Count > 1).
  2041. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2042. foreach(var ll in readyDoubleReturnLL)
  2043. {
  2044. if (ExchangeWaferWithLL(ll.Key))
  2045. return;
  2046. }
  2047. // ready single return LL
  2048. var readySingleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2049. mod.Value.TimeToReady < 2 &&
  2050. !IsLLReservedByTM(mod.Key) &&
  2051. GetLLReadyInOutSlots(mod.Key).outSlot.Count == 1).
  2052. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2053. foreach (var ll in readySingleReturnLL)
  2054. {
  2055. if (ExchangeWaferWithLL(ll.Key))
  2056. return;
  2057. }
  2058. if (atmWaferCount == 0)
  2059. {
  2060. // ready to push in
  2061. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  2062. ((mod.Key != ModuleName.LLA && LLInOutPath == SequenceLLInOutPath.BInBOut) || (mod.Key != ModuleName.LLB && LLInOutPath == SequenceLLInOutPath.AInAOut)) &&
  2063. mod.Value.TimeToReady <= 10 &&
  2064. !IsLLReservedByTM(mod.Key) &&
  2065. GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 1).
  2066. OrderBy(mod => mod.Value.TimeToReady).ToList();
  2067. foreach(var ll in readyLLs)
  2068. {
  2069. if (ForwardATMWafers(ll.Key))
  2070. return;
  2071. }
  2072. }
  2073. }
  2074. }
  2075. private bool isReturnActionsDone(List<MoveItem> items)
  2076. {
  2077. foreach(var item in items)
  2078. {
  2079. if (WaferManager.Instance.CheckHasWafer(item.SourceModule, item.SourceSlot) || WaferManager.Instance.CheckNoWafer(item.DestinationModule, item.DestinationSlot))
  2080. return false;
  2081. }
  2082. return true;
  2083. }
  2084. private bool IsMovingActionsDone(List<MoveItem> actions)
  2085. {
  2086. bool CheckWaferExistence(ModuleName mod, int slot)
  2087. {
  2088. return ModuleHelper.IsLoadPort(mod) ? WaferManager.Instance.CheckHasWafer(mod, slot) : _lstWaferTasks.Exists(wt => wt.currentMod == mod && wt.currentSlot == slot);
  2089. }
  2090. if(actions.Count == 1)
  2091. {
  2092. if ( CheckWaferExistence(actions.First().SourceModule, actions.First().SourceSlot) ||
  2093. !CheckWaferExistence(actions.First().DestinationModule, actions.First().DestinationSlot) )
  2094. return false;
  2095. }
  2096. else
  2097. {
  2098. // initialize all the wafer existance before move
  2099. var slotWafers = new Dictionary<KeyValuePair<ModuleName, int>, bool>();
  2100. foreach (var ac in actions)
  2101. {
  2102. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2103. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2104. if (!slotWafers.ContainsKey(scrSlot))
  2105. {
  2106. slotWafers[scrSlot] = true;
  2107. }
  2108. if (!slotWafers.ContainsKey(destSlot))
  2109. {
  2110. slotWafers[destSlot] = false;
  2111. }
  2112. }
  2113. // simulate moved result
  2114. foreach (var ac in actions)
  2115. {
  2116. var scrSlot = new KeyValuePair<ModuleName, int>(ac.SourceModule, ac.SourceSlot);
  2117. var destSlot = new KeyValuePair<ModuleName, int>(ac.DestinationModule, ac.DestinationSlot);
  2118. if (!slotWafers[scrSlot])
  2119. {
  2120. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[scrSlot]} do not has a wafer");
  2121. }
  2122. else
  2123. {
  2124. slotWafers[scrSlot] = false;
  2125. }
  2126. if (slotWafers[destSlot])
  2127. {
  2128. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{slotWafers[destSlot]} has a wafer");
  2129. }
  2130. else
  2131. {
  2132. slotWafers[destSlot] = true;
  2133. }
  2134. }
  2135. foreach (var slot in slotWafers)
  2136. {
  2137. if (slot.Value != CheckWaferExistence(slot.Key.Key, slot.Key.Value))
  2138. return false;
  2139. }
  2140. }
  2141. return true;
  2142. }
  2143. private bool IsLLReservedByTM(ModuleName ll)
  2144. {
  2145. foreach(var item in _curTmAction)
  2146. {
  2147. if (item.DestinationModule == ll || item.SourceModule == ll)
  2148. return true;
  2149. }
  2150. foreach(var action in _tmSchdActions)
  2151. {
  2152. foreach(var item in action)
  2153. {
  2154. if (item.DestinationModule == ll || item.SourceModule == ll)
  2155. return true;
  2156. }
  2157. }
  2158. return false;
  2159. }
  2160. private bool IsLLReservedByEFEM(ModuleName ll)
  2161. {
  2162. foreach (var item in _curEfemAction)
  2163. {
  2164. if (item.DestinationModule == ll || item.SourceModule == ll)
  2165. return true;
  2166. }
  2167. foreach (var action in _efemSchdActions)
  2168. {
  2169. foreach (var item in action)
  2170. {
  2171. if (item.DestinationModule == ll || item.SourceModule == ll)
  2172. return true;
  2173. }
  2174. }
  2175. return false;
  2176. }
  2177. private void RunSchdEFEMActions()
  2178. {
  2179. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  2180. if (efemRobot == null || !efemRobot.IsAvailable)
  2181. return;
  2182. if (_dictModuleTask[ModuleName.EfemRobot].IsIdle)
  2183. {
  2184. if(_efemSchdActions.Count > 0 )
  2185. {
  2186. if(_curEfemAction.Count == 0 || IsMovingActionsDone(_curEfemAction))
  2187. {
  2188. var nextActions = _efemSchdActions.First();
  2189. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2190. return;
  2191. var nextModule = nextActions.First().Module;
  2192. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  2193. return;
  2194. _curEfemAction = _efemSchdActions.Dequeue();
  2195. foreach (var action in _curEfemAction)
  2196. {
  2197. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2198. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2199. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  2200. if (ModuleHelper.IsLoadPort(action.SourceModule))
  2201. {
  2202. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.SourceModule);
  2203. if(currentControlJob!=null)
  2204. {
  2205. _faCallback.JobWaferStart(currentControlJob, action.SourceSlot);
  2206. }
  2207. }
  2208. if(ModuleHelper.IsLoadPort(action.DestinationModule))
  2209. {
  2210. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.DestinationModule);
  2211. if (currentControlJob != null)
  2212. {
  2213. _faCallback.JobWaferEnd(currentControlJob, action.SourceSlot);
  2214. }
  2215. }
  2216. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  2217. }
  2218. (_dictModuleTask[ModuleName.EfemRobot].Scheduler as SchedulerEfemRobot).PostMoveItems(_curEfemAction.ToArray());
  2219. }
  2220. }
  2221. else if(_curEfemAction.Count >= 0 && IsMovingActionsDone(_curEfemAction)) // all scheduled actions done
  2222. {
  2223. _curEfemAction.Clear();
  2224. }
  2225. }
  2226. }
  2227. private void RunSchdTMActions()
  2228. {
  2229. if (_dictModuleTask[ModuleName.TMRobot].IsIdle)
  2230. {
  2231. if (_tmSchdActions.Count > 0)
  2232. {
  2233. if (_curTmAction.Count == 0 || IsMovingActionsDone(_curTmAction))
  2234. {
  2235. var nextActions = _tmSchdActions.First();
  2236. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2237. return;
  2238. if (ModuleHelper.IsPm(nextActions.First().Module) && !_dictModuleTask[nextActions.First().Module].IsIdle) /// wait PMTask status update to idle
  2239. return;
  2240. _curTmAction = _tmSchdActions.Dequeue();
  2241. foreach(var action in _curTmAction)
  2242. {
  2243. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2244. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2245. }
  2246. (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerTMRobot).SendMoveItems(_curTmAction.ToArray());
  2247. }
  2248. }
  2249. else if (_curTmAction.Count >= 0 && IsMovingActionsDone(_curTmAction)) // all scheduled actions done
  2250. {
  2251. _curTmAction.Clear();
  2252. }
  2253. }
  2254. }
  2255. private int TimeForNextModuleReady(WaferTask task)
  2256. {
  2257. if (ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2258. return _dictModuleTask[task.destMod].TimeToReady;
  2259. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  2260. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  2261. if (ModuleHelper.IsLoadPort(task.destMod) && (ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2262. {
  2263. if (task.llInOutPath == SequenceLLInOutPath.AInBOut || task.llInOutPath == SequenceLLInOutPath.BInBOut)
  2264. {
  2265. if(llbWaferStatus.emptySlot.Count > 0)
  2266. {
  2267. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2268. }
  2269. }
  2270. else if(task.llInOutPath == SequenceLLInOutPath.BInAOut || task.llInOutPath == SequenceLLInOutPath.AInAOut)
  2271. {
  2272. if(llaWaferStatus.emptySlot.Count > 0)
  2273. {
  2274. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2275. }
  2276. }
  2277. else if(task.llInOutPath == SequenceLLInOutPath.DInDOut)
  2278. {
  2279. if(llaWaferStatus.emptySlot.Count > 0 && llbWaferStatus.emptySlot.Count > 0)
  2280. {
  2281. if (_dictModuleTask[ModuleName.LLA].TimeToReady == _dictModuleTask[ModuleName.LLB].TimeToReady)
  2282. {
  2283. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2284. }
  2285. else
  2286. {
  2287. return Math.Min(_dictModuleTask[ModuleName.LLA].TimeToReady, _dictModuleTask[ModuleName.LLB].TimeToReady);
  2288. }
  2289. }
  2290. else if(llaWaferStatus.emptySlot.Count > 0)
  2291. {
  2292. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2293. }
  2294. else if(llbWaferStatus.emptySlot.Count > 0)
  2295. {
  2296. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2297. }
  2298. }
  2299. }
  2300. else if(ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2301. {
  2302. if(_lstWaferTasks.Find(wafer => wafer.currentMod == task.destMod || wafer.routedMod == task.destMod) == null)
  2303. {
  2304. return _dictModuleTask[task.destMod].TimeToReady;
  2305. }
  2306. }
  2307. return int.MaxValue;
  2308. }
  2309. List<Hand> GetTMValidFreeHands(List<WaferTask> robotWafers, List<MoveItem> swapActions)
  2310. {
  2311. var hands = new List<Hand>();
  2312. for(int i = 0; i < 2; i++)
  2313. {
  2314. if(_tmRobotSingleArmOption == 0 || _tmRobotSingleArmOption == i + 1)
  2315. {
  2316. if ((!robotWafers.Exists(wafer => wafer.currentSlot == i) ||
  2317. ( robotWafers.Exists(wafer => wafer.currentSlot == i) &&
  2318. swapActions.Exists(item => item.SourceModule == ModuleName.TMRobot && item.SourceSlot == i))) &&
  2319. !swapActions.Exists(item => item.DestinationModule == ModuleName.TMRobot && item.DestinationSlot == i))
  2320. hands.Add((Hand)i);
  2321. }
  2322. }
  2323. return hands;
  2324. }
  2325. (ModuleName llPath, List<MoveItem> swapActions) FindBestLLSwapPlan(ModuleName ll, List<WaferTask> robotWafers)
  2326. {
  2327. ModuleName path = ll == ModuleName.System ? ModuleName.System : ll;
  2328. List<ModuleName> lls = ll == ModuleName.System ? new List<ModuleName> { ModuleName.LLA, ModuleName.LLB } : new List<ModuleName> { ll };
  2329. List<MoveItem> actions = new List<MoveItem>();
  2330. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2331. foreach (var loadlock in lls)
  2332. {
  2333. llSwapActions[loadlock] = new List<MoveItem>();
  2334. if (IsLLReservedByEFEM(loadlock))
  2335. continue;
  2336. var llWaferStatus = GetLLReadyInOutSlots(loadlock);
  2337. foreach(var wafer in robotWafers)
  2338. {
  2339. if(_dictModuleTask[loadlock].TimeToReady == 0 && !IsLLReservedByEFEM(loadlock) && CanWaferGotoLL(wafer,loadlock) && llWaferStatus.emptySlot.Count > llSwapActions[loadlock].Count)
  2340. {
  2341. llSwapActions[loadlock].Add(new MoveItem(ModuleName.TMRobot, wafer.currentSlot, loadlock, llWaferStatus.emptySlot[llSwapActions[loadlock].Count], (Hand)wafer.currentSlot));
  2342. }
  2343. }
  2344. int prePickTime = 20;
  2345. int prePickCount = 0;
  2346. var hands = GetTMValidFreeHands(robotWafers, llSwapActions[loadlock]);
  2347. foreach (var slot in llWaferStatus.inSlot)
  2348. {
  2349. var wafer = _lstWaferTasks.Find(task => task.currentMod == loadlock && task.currentSlot == slot);
  2350. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && hands.Count > prePickCount)
  2351. {
  2352. if(_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2353. {
  2354. 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))
  2355. {
  2356. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2357. prePickCount++;
  2358. break;
  2359. }
  2360. }
  2361. else
  2362. {
  2363. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2364. prePickCount++;
  2365. }
  2366. }
  2367. }
  2368. }
  2369. var validateActions = llSwapActions.Where(item => item.Value.Count > 0).ToDictionary(k => k.Key, v => v.Value);
  2370. if(validateActions.Count == 1)
  2371. {
  2372. (path, actions) = (validateActions.First().Key, validateActions.First().Value);
  2373. }
  2374. else if(validateActions.Count == 2)
  2375. {
  2376. var sortedActions = validateActions.OrderByDescending(item => item.Value.Count + (_dictModuleTask[item.Key].Scheduler.IsVac ? 2 : 0)).ToDictionary(k => k.Key, v => v.Value);
  2377. (path, actions) = (sortedActions.First().Key, sortedActions.First().Value);
  2378. }
  2379. return (path, actions);
  2380. }
  2381. (List<WaferTask> pmWafers, ModuleName destLL, List<MoveItem> swapAction) FindBestReturnWafersPlan(Hand[] freeHands)
  2382. {
  2383. Dictionary<ModuleName, List<WaferTask>> returnWafers = new Dictionary<ModuleName, List<WaferTask>>();
  2384. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2385. Dictionary<ModuleName, int> llValues = new Dictionary<ModuleName, int>();
  2386. foreach(var ll in new List<ModuleName> { ModuleName.LLA, ModuleName.LLB})
  2387. {
  2388. var llWaferStatus = GetLLReadyInOutSlots(ll);
  2389. returnWafers[ll] = new List<WaferTask>();
  2390. llSwapActions[ll] = new List<MoveItem>();
  2391. llValues[ll] = 0;
  2392. if (IsLLReservedByEFEM(ll))
  2393. continue;
  2394. var readyReturnWafers = _lstWaferTasks.Where( wafer => ModuleHelper.IsPm(wafer.currentMod) &&
  2395. ModuleHelper.IsLoadPort(wafer.destMod) &&
  2396. wafer.movingStatus == RState.End &&
  2397. _dictModuleTask[wafer.currentMod].TimeToReady <= 2 &&
  2398. CanWaferGotoLL(wafer, ll)).Take(Math.Min(freeHands.Length, llWaferStatus.emptySlot.Count)).ToList();
  2399. int prePickTime = 10 * llSwapActions[ll].Count;
  2400. int handIndex = 0;
  2401. if(_dictModuleTask[ll].TimeToReady <= prePickTime)
  2402. {
  2403. foreach (var wafer in readyReturnWafers)
  2404. {
  2405. if(handIndex < freeHands.Length)
  2406. {
  2407. returnWafers[ll].Add(wafer);
  2408. llSwapActions[ll].Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[handIndex], ll, llWaferStatus.emptySlot[handIndex], freeHands[handIndex]));
  2409. handIndex++;
  2410. }
  2411. }
  2412. int prePickCount = 0;
  2413. handIndex = 0;
  2414. foreach (var slot in llWaferStatus.inSlot)
  2415. {
  2416. var wafer = _lstWaferTasks.Find(task => task.currentMod == ll && task.currentSlot == slot);
  2417. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && freeHands.Length > prePickCount)
  2418. {
  2419. if (_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2420. {
  2421. 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))
  2422. {
  2423. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2424. prePickCount++;
  2425. break;
  2426. }
  2427. }
  2428. else
  2429. {
  2430. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2431. prePickCount++;
  2432. }
  2433. }
  2434. }
  2435. llValues[ll] = returnWafers[ll].Count * 2 + llSwapActions[ll].Count + (_dictModuleTask[ll].Scheduler.IsVac && returnWafers[ll].Count > 0 ? 2 : 0);
  2436. }
  2437. }
  2438. var preferLL = llValues.OrderByDescending(v => v.Value).First().Key;
  2439. return (returnWafers[preferLL], preferLL, llSwapActions[preferLL]);
  2440. }
  2441. ModuleName FindTheBestMovePathWithFixSlot(IEnumerable<KeyValuePair<ModuleName, ModuleTask>> lls, List<WaferTask> pmWafers)
  2442. {
  2443. Dictionary<ModuleName, int> moveValues = new Dictionary<ModuleName, int>();
  2444. foreach(var ll in lls)
  2445. {
  2446. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  2447. moveValues[ll.Key] = Math.Min(pmWafers.Where(wt => CanWaferGotoLL(wt, ll.Key)).Count(), GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count) + llWaferStatus.tOutSlot.Count;
  2448. }
  2449. var preferLL = moveValues.OrderByDescending(v => v.Value).First().Key;
  2450. return moveValues[preferLL] > 0 ? preferLL : ModuleName.System;
  2451. }
  2452. void RoutingTMSwapActions(List<MoveItem> actions)
  2453. {
  2454. foreach (var action in actions)
  2455. {
  2456. if (ModuleHelper.IsTMRobot(action.SourceModule))
  2457. {
  2458. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == ModuleName.TMRobot && wafer.currentSlot == action.SourceSlot);
  2459. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2460. }
  2461. else
  2462. {
  2463. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2464. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2465. }
  2466. }
  2467. }
  2468. private bool ManaulReturnPMWafer()
  2469. {
  2470. var mReturnWafer = _qeReturnWafers.Peek();
  2471. if (ModuleHelper.IsPm((ModuleName)mReturnWafer.Station))
  2472. {
  2473. var hands = GetTMValidFreeHands(_lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod)).ToList(), new List<MoveItem>());
  2474. var waferTask = _lstWaferTasks.Find(wt => wt.currentMod == (ModuleName)mReturnWafer.Station && wt.waferId == mReturnWafer.InnerId);
  2475. if (waferTask != null && hands.Count > 0)
  2476. {
  2477. waferTask.Return();
  2478. var outLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && CanWaferGotoLL(waferTask, mod.Key) && GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 0 && !IsLLReservedByEFEM(mod.Key));
  2479. if (outLL.Count() > 0)
  2480. {
  2481. var slot = GetLLReadyInOutSlots(outLL.First().Key).emptySlot.First();
  2482. waferTask.RouteTo(outLL.First().Key, slot);
  2483. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waferTask.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2484. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL.First().Key, slot, hands.First()) });
  2485. _qeReturnWafers.Dequeue();
  2486. return true;
  2487. }
  2488. }
  2489. }
  2490. return false;
  2491. }
  2492. private void RoutingVacWafers()
  2493. {
  2494. if(_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2495. {
  2496. RunSchdTMActions();
  2497. return;
  2498. }
  2499. if(_tmRobotStatus == RState.End)
  2500. {
  2501. // handle manual return wafer if exist
  2502. if(_qeReturnWafers.Count > 0)
  2503. {
  2504. if (ManaulReturnPMWafer())
  2505. return;
  2506. }
  2507. if(_LLSlotInOutOption == LLSlotInOutOpt.AllInAllOut)
  2508. {
  2509. if (_LLASlotNumber == 2)
  2510. {
  2511. Routing2SlotVacSystem();
  2512. }
  2513. else if (_LLASlotNumber == 4)
  2514. {
  2515. Routing4SlotVacSystem();
  2516. }
  2517. }
  2518. else
  2519. {
  2520. RoutingFixedSlotVacSystem();
  2521. }
  2522. }
  2523. }
  2524. private void Routing2SlotVacSystem()
  2525. {
  2526. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2527. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2528. {
  2529. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2530. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2531. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2532. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2533. if(robotWafers.Count == 2)
  2534. {
  2535. int returnCount = 0;
  2536. foreach (var wafer in robotWafers)
  2537. {
  2538. if (ModuleHelper.IsPm(wafer.destMod))
  2539. {
  2540. if (_dictModuleTask[wafer.destMod].TimeToReady <= 5 &&
  2541. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2542. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2543. {
  2544. wafer.RouteTo(wafer.destMod, 0);
  2545. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2546. }
  2547. }
  2548. else
  2549. {
  2550. if (_dictModuleTask[outLL].TimeToReady <= 5 && !IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > returnCount)
  2551. {
  2552. wafer.RouteTo(outLL, outLLWaferStatus.emptySlot[returnCount]);
  2553. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, outLL, outLLWaferStatus.emptySlot[returnCount], (Hand)wafer.currentSlot) });
  2554. returnCount++;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. else if(robotWafers.Count == 1)
  2560. {
  2561. int freeHand = 1 - robotWafers.First().currentSlot;
  2562. if (ModuleHelper.IsPm(robotWafers.First().destMod))
  2563. {
  2564. if(_dictModuleTask[robotWafers.First().destMod].TimeToReady <= 5)
  2565. {
  2566. if(_lstWaferTasks.Exists(waferT => waferT.currentMod == robotWafers.First().destMod))
  2567. {
  2568. var pmActions = new List<MoveItem>();
  2569. var pmWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == robotWafers.First().destMod);
  2570. pmWafer.RouteTo(ModuleName.TMRobot, freeHand);
  2571. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, freeHand, (Hand)freeHand));
  2572. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers.First().currentSlot));
  2573. _tmSchdActions.Enqueue(pmActions);
  2574. }
  2575. else
  2576. {
  2577. robotWafers.First().RouteTo(robotWafers.First().destMod, 0);
  2578. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, robotWafers.First().destMod, 0, (Hand)robotWafers.First().currentSlot) });
  2579. }
  2580. }
  2581. }
  2582. else
  2583. {
  2584. if (_dictModuleTask[outLL].TimeToReady <= 5 && !IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0)
  2585. {
  2586. robotWafers.First().RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2587. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)robotWafers.First().currentSlot) });
  2588. }
  2589. }
  2590. if (_tmSchdActions.Count == 0 && _tmRobotSingleArmOption == 0)
  2591. {
  2592. // try push in one wafer
  2593. if (!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].Scheduler.IsVac && inLLWaferStatus.inSlot.Count > 0)
  2594. {
  2595. foreach (var slot in inLLWaferStatus.inSlot)
  2596. {
  2597. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == inLL && wafer.currentSlot == slot);
  2598. if (llWafer != null && !_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].TimeToReady < 15)
  2599. {
  2600. llWafer.RouteTo(llWafer.destMod, 0);
  2601. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, slot, ModuleName.TMRobot, freeHand, (Hand)freeHand) });
  2602. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, freeHand, llWafer.destMod, 0, (Hand)freeHand) });
  2603. return;
  2604. }
  2605. }
  2606. }
  2607. // try to return one wafer
  2608. if (!IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0)
  2609. {
  2610. var reayReturnWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  2611. if (reayReturnWafer != null)
  2612. {
  2613. reayReturnWafer.RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2614. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(reayReturnWafer.currentMod, 0, ModuleName.TMRobot, freeHand, (Hand)freeHand) });
  2615. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, freeHand, outLL, outLLWaferStatus.emptySlot[0], (Hand)freeHand) });
  2616. return;
  2617. }
  2618. }
  2619. }
  2620. }
  2621. else // no wafer on robot arm
  2622. {
  2623. var readyInPms = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !_lstWaferTasks.Exists(wt => wt.currentMod == mod.Key) && mod.Value.Scheduler.IsOnline && mod.Value.TimeToReady <= 15);
  2624. var readyOutWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2).ToList() ;
  2625. if(_tmRobotSingleArmOption != 0)
  2626. {
  2627. var hands = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2628. if (hands.Count == 0)
  2629. return;
  2630. if(!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].TimeToReady <= 5 && inLLWaferStatus.inSlot.Count > 0 && readyInPms.Count() > 0)
  2631. {
  2632. foreach(var pm in readyInPms)
  2633. {
  2634. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && inLLWaferStatus.inSlot.Contains(wt.currentSlot) && wt.destMod == pm.Key);
  2635. if(llWafer != null)
  2636. {
  2637. llWafer.RouteTo(llWafer.destMod, 0);
  2638. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2639. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), llWafer.destMod, 0, hands.First()) });
  2640. return;
  2641. }
  2642. }
  2643. }
  2644. if(readyOutWafers.Count > 0 && !IsLLReservedByEFEM(outLL) && _dictModuleTask[outLL].TimeToReady < 50 && outLLWaferStatus.emptySlot.Count > 0)
  2645. {
  2646. var returnWafer = readyOutWafers.First();
  2647. returnWafer.RouteTo(outLL, outLLWaferStatus.emptySlot.First());
  2648. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(returnWafer.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2649. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL, outLLWaferStatus.emptySlot.First(), hands.First()) });
  2650. return;
  2651. }
  2652. return;
  2653. }
  2654. if(!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].TimeToReady <= 5 && inLLWaferStatus.inSlot.Count > 0)
  2655. {
  2656. if(inLLWaferStatus.inSlot.Count == 2)
  2657. {
  2658. if(readyInPms.Count() > 0) // double move from LL to PM
  2659. {
  2660. int pickCount = 0;
  2661. var swapActions = new List<MoveItem>();
  2662. var singleActions = new List<MoveItem>();
  2663. foreach(var pm in readyInPms)
  2664. {
  2665. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && inLLWaferStatus.inSlot.Contains(wt.currentSlot) && wt.destMod == pm.Key);
  2666. if(llWafer != null)
  2667. {
  2668. llWafer.RouteTo(pm.Key, 0);
  2669. swapActions.Add(new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  2670. singleActions.Add(new MoveItem(ModuleName.TMRobot, pickCount, pm.Key, 0, (Hand)pickCount));
  2671. pickCount++;
  2672. }
  2673. }
  2674. if(pickCount == 1)
  2675. {
  2676. int remainSlot = swapActions.First().SourceSlot == inLLWaferStatus.inSlot[0] ? inLLWaferStatus.inSlot[1] : inLLWaferStatus.inSlot[0];
  2677. var remainWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == remainSlot);
  2678. if (remainWafer != null)
  2679. {
  2680. remainWafer.RouteTo(ModuleName.TMRobot, 1);
  2681. swapActions.Add(new MoveItem(inLL, remainSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  2682. }
  2683. }
  2684. if(swapActions.Count > 0)
  2685. {
  2686. _tmSchdActions.Enqueue(swapActions);
  2687. foreach(var ac in singleActions)
  2688. {
  2689. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  2690. }
  2691. }
  2692. }
  2693. else
  2694. {
  2695. foreach(var slot in inLLWaferStatus.inSlot)
  2696. {
  2697. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == slot);
  2698. if (llWafer != null)
  2699. {
  2700. if(!_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].Scheduler.IsOnline)
  2701. {
  2702. var swapActions = new List<MoveItem>();
  2703. swapActions.Add(new MoveItem(inLL, slot, ModuleName.TMRobot, 0, Hand.Blade1));
  2704. int remainSlot = slot == inLLWaferStatus.inSlot[0] ? inLLWaferStatus.inSlot[1] : inLLWaferStatus.inSlot[0];
  2705. swapActions.Add(new MoveItem(inLL, remainSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  2706. _tmSchdActions.Enqueue(swapActions);
  2707. llWafer.RouteTo(ModuleName.TMRobot, 0);
  2708. if (_dictModuleTask[llWafer.destMod].TimeToReady <= 30)
  2709. {
  2710. llWafer.RouteTo(llWafer.destMod, 0);
  2711. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, 0, llWafer.destMod, 0, Hand.Blade1) });
  2712. }
  2713. return;
  2714. }
  2715. }
  2716. }
  2717. }
  2718. }
  2719. else
  2720. {
  2721. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == inLLWaferStatus.inSlot.First());
  2722. if (llWafer != null)
  2723. {
  2724. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inLLWaferStatus.inSlot.First(), ModuleName.TMRobot, 0, Hand.Blade1) });
  2725. if (!_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].TimeToReady < 15)
  2726. {
  2727. llWafer.RouteTo(llWafer.destMod, 0);
  2728. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, 0, llWafer.destMod, 0, Hand.Blade1) });
  2729. }
  2730. }
  2731. }
  2732. }
  2733. if (_tmSchdActions.Count > 0)
  2734. return;
  2735. if(!IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0 && readyOutWafers.Count > 0)
  2736. {
  2737. if(readyOutWafers.Count >= 2 && outLLWaferStatus.emptySlot.Count == 2)
  2738. {
  2739. readyOutWafers[0].RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2740. readyOutWafers[1].RouteTo(outLL, outLLWaferStatus.emptySlot[1]);
  2741. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[0].currentMod, readyOutWafers[0].currentSlot, ModuleName.TMRobot, 0, Hand.Blade1) });
  2742. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[1].currentMod, readyOutWafers[1].currentSlot, ModuleName.TMRobot, 1, Hand.Blade2) });
  2743. var swapActions = new List<MoveItem>();
  2744. swapActions.Add(new MoveItem(ModuleName.TMRobot, 0, outLL, outLLWaferStatus.emptySlot[0], Hand.Blade1));
  2745. swapActions.Add(new MoveItem(ModuleName.TMRobot, 1, outLL, outLLWaferStatus.emptySlot[1], Hand.Blade2));
  2746. _tmSchdActions.Enqueue(swapActions);
  2747. }
  2748. else
  2749. {
  2750. var freeHands = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2751. readyOutWafers[0].RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2752. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[0].currentMod, readyOutWafers[0].currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  2753. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot[0], freeHands[0]) });
  2754. }
  2755. }
  2756. }
  2757. }
  2758. else
  2759. {
  2760. if (robotWafers.Count == 2)
  2761. {
  2762. foreach (var wafer in robotWafers)
  2763. {
  2764. if (wafer.movingStatus == RState.End &&
  2765. ModuleHelper.IsPm(wafer.destMod) &&
  2766. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  2767. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2768. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2769. {
  2770. wafer.RouteTo(wafer.destMod, 0);
  2771. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2772. }
  2773. }
  2774. if (_tmSchdActions.Count == 0)
  2775. {
  2776. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2777. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2778. {
  2779. RoutingTMSwapActions(swapActions.swapActions);
  2780. _tmSchdActions.Enqueue(swapActions.swapActions);
  2781. }
  2782. }
  2783. }
  2784. else if (robotWafers.Count == 1)
  2785. {
  2786. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  2787. {
  2788. var pmActions = new List<MoveItem>();
  2789. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  2790. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  2791. {
  2792. int pickSlot = 1 - robotWafers[0].currentSlot;
  2793. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  2794. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  2795. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  2796. _tmSchdActions.Enqueue(pmActions);
  2797. return;
  2798. }
  2799. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  2800. {
  2801. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  2802. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  2803. _tmSchdActions.Enqueue(pmActions);
  2804. return;
  2805. }
  2806. }
  2807. // try to pick a wafer from LL
  2808. if (_tmSchdActions.Count == 0)
  2809. {
  2810. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2811. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2812. {
  2813. RoutingTMSwapActions(swapActions.swapActions);
  2814. _tmSchdActions.Enqueue(swapActions.swapActions);
  2815. return;
  2816. }
  2817. }
  2818. // try to return a wafer from PM
  2819. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2820. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2821. if (moveActions.pmWafers.Count > 0)
  2822. {
  2823. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2824. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  2825. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  2826. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  2827. if (pickAction != null)
  2828. {
  2829. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  2830. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  2831. }
  2832. _tmSchdActions.Enqueue(moveActions.swapAction);
  2833. }
  2834. }
  2835. else // robot arm is empty
  2836. {
  2837. // try return wafers from PM
  2838. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2839. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2840. if (moveActions.pmWafers.Count > 0)
  2841. {
  2842. int handIndex = 0;
  2843. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2844. foreach (var action in placeActions)
  2845. {
  2846. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  2847. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  2848. handIndex++;
  2849. }
  2850. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  2851. foreach (var ac in pickActions)
  2852. {
  2853. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  2854. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  2855. }
  2856. _tmSchdActions.Enqueue(moveActions.swapAction);
  2857. }
  2858. if (_tmSchdActions.Count == 0)
  2859. {
  2860. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2861. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2862. {
  2863. RoutingTMSwapActions(swapActions.swapActions);
  2864. _tmSchdActions.Enqueue(swapActions.swapActions);
  2865. }
  2866. }
  2867. }
  2868. }
  2869. }
  2870. private void Routing4SlotVacSystem()
  2871. {
  2872. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2873. if (robotWafers.Count == 2)
  2874. {
  2875. foreach (var wafer in robotWafers)
  2876. {
  2877. if (wafer.movingStatus == RState.End &&
  2878. ModuleHelper.IsPm(wafer.destMod) &&
  2879. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  2880. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2881. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2882. {
  2883. wafer.RouteTo(wafer.destMod, 0);
  2884. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2885. }
  2886. }
  2887. if (_tmSchdActions.Count == 0)
  2888. {
  2889. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2890. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2891. {
  2892. RoutingTMSwapActions(swapActions.swapActions);
  2893. _tmSchdActions.Enqueue(swapActions.swapActions);
  2894. }
  2895. }
  2896. }
  2897. else if (robotWafers.Count == 1)
  2898. {
  2899. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  2900. {
  2901. var pmActions = new List<MoveItem>();
  2902. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  2903. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  2904. {
  2905. int pickSlot = 1 - robotWafers[0].currentSlot;
  2906. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  2907. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  2908. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  2909. _tmSchdActions.Enqueue(pmActions);
  2910. return;
  2911. }
  2912. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  2913. {
  2914. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  2915. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  2916. _tmSchdActions.Enqueue(pmActions);
  2917. return;
  2918. }
  2919. }
  2920. // try to pick a wafer from LL
  2921. if (_tmSchdActions.Count == 0)
  2922. {
  2923. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2924. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2925. {
  2926. RoutingTMSwapActions(swapActions.swapActions);
  2927. _tmSchdActions.Enqueue(swapActions.swapActions);
  2928. return;
  2929. }
  2930. }
  2931. // try to return a wafer from PM
  2932. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2933. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2934. if (moveActions.pmWafers.Count > 0)
  2935. {
  2936. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2937. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  2938. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  2939. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  2940. if (pickAction != null)
  2941. {
  2942. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  2943. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  2944. }
  2945. _tmSchdActions.Enqueue(moveActions.swapAction);
  2946. }
  2947. }
  2948. else // robot arm is empty
  2949. {
  2950. // try return wafers from PM
  2951. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2952. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2953. if (moveActions.pmWafers.Count > 0)
  2954. {
  2955. int handIndex = 0;
  2956. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2957. foreach (var action in placeActions)
  2958. {
  2959. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  2960. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  2961. handIndex++;
  2962. }
  2963. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  2964. foreach (var ac in pickActions)
  2965. {
  2966. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  2967. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  2968. }
  2969. _tmSchdActions.Enqueue(moveActions.swapAction);
  2970. }
  2971. if (_tmSchdActions.Count == 0)
  2972. {
  2973. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2974. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2975. {
  2976. RoutingTMSwapActions(swapActions.swapActions);
  2977. _tmSchdActions.Enqueue(swapActions.swapActions);
  2978. }
  2979. }
  2980. }
  2981. }
  2982. private void RoutingFixedSlotVacSystem()
  2983. {
  2984. var robotWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod));
  2985. var lls = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && mod.Value.Scheduler.IsOnline);
  2986. if (_LLASlotNumber == 2)
  2987. {
  2988. if (robotWafers.Count() == 1)
  2989. {
  2990. if(ModuleHelper.IsPm(robotWafers.First().destMod))
  2991. {
  2992. var destPM = robotWafers.First().destMod;
  2993. if(_dictModuleTask[destPM].TimeToReady <= 5)
  2994. {
  2995. if(_lstWaferTasks.Exists(wt => wt.currentMod == destPM))
  2996. {
  2997. var pickHand = SelectTMPickArm(destPM);
  2998. if(pickHand != Hand.None)
  2999. {
  3000. var pmSwap = new List<MoveItem>();
  3001. pmSwap.Add(new MoveItem(destPM, 0, ModuleName.TMRobot, (int)pickHand, pickHand));
  3002. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot));
  3003. _tmSchdActions.Enqueue(pmSwap);
  3004. return;
  3005. }
  3006. }
  3007. else
  3008. {
  3009. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, destPM, 0, (Hand)robotWafers.First().currentSlot) });
  3010. return;
  3011. }
  3012. }
  3013. }
  3014. else
  3015. {
  3016. var readySwapLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3017. GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 &&
  3018. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3019. ll.Value.TimeToReady <= 10);
  3020. if (readySwapLL.Count() > 0)
  3021. {
  3022. var destLL = readySwapLL.First().Key;
  3023. Hand pickHand = SelectTMPickArm(destLL);
  3024. if (pickHand != Hand.None)
  3025. {
  3026. Hand placeHand = (Hand)robotWafers.First().currentSlot;
  3027. var llSwap = new List<MoveItem>();
  3028. var llSlots = GetLLFixedReadyInOutSlots(destLL);
  3029. llSwap.Add(new MoveItem(destLL, llSlots.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3030. llSwap.Add(new MoveItem(ModuleName.TMRobot, (int)placeHand, destLL, llSlots.tInSlot.First(), placeHand));
  3031. _tmSchdActions.Enqueue(llSwap);
  3032. return;
  3033. }
  3034. }
  3035. var emptyLL = lls.Where(ll => CanWaferGotoLL(robotWafers.First(), ll.Key) &&
  3036. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 &&
  3037. ll.Value.TimeToReady <= 2);
  3038. if (emptyLL.Count() > 0)
  3039. {
  3040. var destLL = emptyLL.First().Key;
  3041. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem( ModuleName.TMRobot,
  3042. robotWafers.First().currentSlot,
  3043. destLL,
  3044. GetLLFixedReadyInOutSlots(destLL).tInSlot.First(),
  3045. (Hand)robotWafers.First().currentSlot) });
  3046. return;
  3047. }
  3048. }
  3049. // try to return a wafer
  3050. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3051. foreach(var pmWafer in readyReturnWafers)
  3052. {
  3053. 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);
  3054. if(readyLL.Count() > 0)
  3055. {
  3056. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3057. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3058. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand , readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3059. return;
  3060. }
  3061. }
  3062. // try to push in a wafer
  3063. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3064. foreach(var ll in readyInLL)
  3065. {
  3066. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3067. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3068. if( wafer != null &&
  3069. ModuleHelper.IsPm(wafer.destMod) &&
  3070. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3071. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3072. {
  3073. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3074. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3075. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3076. return;
  3077. }
  3078. }
  3079. }
  3080. else if (robotWafers.Count() == 0)
  3081. {
  3082. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod)).ToList();
  3083. if(readyReturnWafers.Count > 0)
  3084. {
  3085. // try to do a LL swap action
  3086. var readySwapLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 10);
  3087. foreach (var pmWafer in readyReturnWafers)
  3088. {
  3089. foreach (var ll in readySwapLL)
  3090. {
  3091. if (CanWaferGotoLL(pmWafer, ll.Key))
  3092. {
  3093. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3094. var pickHand = SelectTMPickArm(ll.Key);
  3095. var llWaferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3096. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3097. var llSwapActions = new List<MoveItem>();
  3098. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, llWaferStatus.tInSlot.First(), returnHand));
  3099. llSwapActions.Add(new MoveItem(ll.Key, llWaferStatus.tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand));
  3100. _tmSchdActions.Enqueue(llSwapActions);
  3101. return;
  3102. }
  3103. }
  3104. }
  3105. // just return to LL
  3106. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && ll.Value.TimeToReady <= 5);
  3107. foreach(var pmWafer in readyReturnWafers)
  3108. {
  3109. foreach(var ll in readyInLL)
  3110. {
  3111. if(CanWaferGotoLL(pmWafer, ll.Key))
  3112. {
  3113. var returnHand = SelectTMPickArm(pmWafer.currentMod);
  3114. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, pmWafer.currentSlot, ModuleName.TMRobot, (int)returnHand, returnHand) });
  3115. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)returnHand, ll.Key, GetLLFixedReadyInOutSlots(ll.Key).tInSlot.First(), returnHand) });
  3116. return;
  3117. }
  3118. }
  3119. }
  3120. }
  3121. var readyPushInLLs = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count == 1 && ll.Value.TimeToReady <= 2);
  3122. if(readyPushInLLs.Count() > 0)
  3123. {
  3124. var destLL = readyPushInLLs.First().Key;
  3125. if(readyPushInLLs.Count() == 2 && readyPushInLLs.First().Value.Scheduler.IsAtm && readyPushInLLs.Last().Value.Scheduler.IsVac)
  3126. {
  3127. destLL = readyPushInLLs.Last().Key;
  3128. }
  3129. var pickHand = SelectTMPickArm(destLL);
  3130. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(destLL, GetLLFixedReadyInOutSlots(destLL).tOutSlot.First(), ModuleName.TMRobot, (int)pickHand, pickHand) });
  3131. return;
  3132. }
  3133. }
  3134. else
  3135. {
  3136. // should not go here
  3137. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, "Had better avoid picking two wafers on TM robot arms under Loadlock fixed slot pattern");
  3138. foreach(var wafer in robotWafers)
  3139. {
  3140. if(ModuleHelper.IsPm(wafer.destMod))
  3141. {
  3142. if(!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3143. {
  3144. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3145. return;
  3146. }
  3147. }
  3148. else
  3149. {
  3150. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 1 && CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 2);
  3151. if(readyInLL.Count() > 0)
  3152. {
  3153. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, readyInLL.First().Key, GetLLFixedReadyInOutSlots(readyInLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3154. return;
  3155. }
  3156. }
  3157. }
  3158. }
  3159. }
  3160. else // 4 slot Loadlock
  3161. {
  3162. if(robotWafers.Count() > 0)
  3163. {
  3164. if (robotWafers.Count() == 2)
  3165. {
  3166. if (robotWafers.All(wt => ModuleHelper.IsLoadPort(wt.destMod)))
  3167. {
  3168. var destLL = lls.Where(ll => robotWafers.All(wt => CanWaferGotoLL(wt, ll.Key)) &&
  3169. ll.Value.TimeToReady <= 10 &&
  3170. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count == 2).
  3171. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3172. OrderBy(ll => ll.Value.TimeToReady);
  3173. if (destLL.Count() > 0)
  3174. {
  3175. var swapLL = destLL.First().Key;
  3176. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3177. var swapActions = new List<MoveItem>();
  3178. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafers.First().currentSlot));
  3179. swapActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.Last().currentSlot, swapLL, llWaferStatus.tInSlot.Last(), (Hand)robotWafers.Last().currentSlot));
  3180. int pickCount = 0;
  3181. foreach (var slot in llWaferStatus.eOutSlot)
  3182. {
  3183. swapActions.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3184. }
  3185. _tmSchdActions.Enqueue(swapActions);
  3186. return;
  3187. }
  3188. }
  3189. foreach (var wafer in robotWafers)
  3190. {
  3191. if (ModuleHelper.IsPm(wafer.destMod))
  3192. {
  3193. if (!_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) && _dictModuleTask[wafer.destMod].TimeToReady <= 5)
  3194. {
  3195. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  3196. return;
  3197. }
  3198. }
  3199. else
  3200. {
  3201. var placeLL = lls.Where(ll => CanWaferGotoLL(wafer, ll.Key) && ll.Value.TimeToReady <= 5 && GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).OrderBy(ll => ll.Value.TimeToReady);
  3202. if (placeLL.Count() > 0)
  3203. {
  3204. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, placeLL.First().Key, GetLLFixedReadyInOutSlots(placeLL.First().Key).tInSlot.First(), (Hand)wafer.currentSlot) });
  3205. return;
  3206. }
  3207. }
  3208. }
  3209. }
  3210. else if (robotWafers.Count() == 1)
  3211. {
  3212. var robotWafer = robotWafers.First();
  3213. if (ModuleHelper.IsPm(robotWafer.destMod))
  3214. {
  3215. if (_dictModuleTask[robotWafer.destMod].TimeToReady <= 5)
  3216. {
  3217. if (_lstWaferTasks.Exists(wt => wt.currentMod == robotWafer.destMod))
  3218. {
  3219. var pmSwap = new List<MoveItem>();
  3220. pmSwap.Add(new MoveItem(robotWafer.destMod, 0, ModuleName.TMRobot, 1 - robotWafer.currentSlot, (Hand)(1 - robotWafer.currentSlot)));
  3221. pmSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot));
  3222. _tmSchdActions.Enqueue(pmSwap);
  3223. return;
  3224. }
  3225. else
  3226. {
  3227. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, robotWafer.destMod, 0, (Hand)robotWafer.currentSlot) });
  3228. return;
  3229. }
  3230. }
  3231. }
  3232. else
  3233. {
  3234. var destLL = lls.Where(ll => CanWaferGotoLL(robotWafer, ll.Key) &&
  3235. ll.Value.TimeToReady <= 10 &&
  3236. GetLLFixedReadyInOutSlots(ll.Key).tInSlot.Count > 0).
  3237. OrderByDescending(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count).
  3238. OrderBy(ll => ll.Value.TimeToReady);
  3239. if (destLL.Count() > 0)
  3240. {
  3241. var swapLL = destLL.First().Key;
  3242. var llWaferStatus = GetLLFixedReadyInOutSlots(swapLL);
  3243. var llSwap = new List<MoveItem>();
  3244. llSwap.Add(new MoveItem(ModuleName.TMRobot, robotWafer.currentSlot, swapLL, llWaferStatus.tInSlot.First(), (Hand)robotWafer.currentSlot));
  3245. int pickCount = 0;
  3246. foreach (var slot in llWaferStatus.tOutSlot)
  3247. {
  3248. llSwap.Add(new MoveItem(swapLL, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3249. pickCount++;
  3250. }
  3251. _tmSchdActions.Enqueue(llSwap);
  3252. return;
  3253. }
  3254. }
  3255. // try to return a wafer
  3256. var readyReturnWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  3257. foreach (var pmWafer in readyReturnWafers)
  3258. {
  3259. 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);
  3260. if (readyLL.Count() > 0)
  3261. {
  3262. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3263. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, (int)validHand, validHand) });
  3264. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, readyLL.First().Key, GetLLFixedReadyInOutSlots(readyLL.First().Key).tInSlot.First(), validHand) });
  3265. return;
  3266. }
  3267. }
  3268. // try to push in a wafer
  3269. var readyInLL = lls.Where(ll => GetLLFixedReadyInOutSlots(ll.Key).tOutSlot.Count > 0 && ll.Value.TimeToReady <= 2).OrderBy(ll => ll.Value.Scheduler.IsVac ? 0 : 1);
  3270. foreach (var ll in readyInLL)
  3271. {
  3272. var waferStatus = GetLLFixedReadyInOutSlots(ll.Key);
  3273. var wafer = _lstWaferTasks.Find(wt => wt.currentMod == ll.Key && wt.currentSlot == waferStatus.tOutSlot.First());
  3274. if (wafer != null &&
  3275. ModuleHelper.IsPm(wafer.destMod) &&
  3276. !_lstWaferTasks.Exists(wt => wt.currentMod == wafer.destMod) &&
  3277. _dictModuleTask[wafer.destMod].TimeToReady <= 2)
  3278. {
  3279. var validHand = (Hand)(1 - robotWafers.First().currentSlot);
  3280. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, wafer.currentSlot, ModuleName.TMRobot, (int)validHand, validHand) });
  3281. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)validHand, wafer.destMod, 0, validHand) });
  3282. return;
  3283. }
  3284. }
  3285. }
  3286. }
  3287. else // robot empty
  3288. {
  3289. 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();
  3290. var readyLL = lls.Where(ll => ll.Value.TimeToReady <= 10);
  3291. if(readyLL.Count() > 0)
  3292. {
  3293. var llPath = FindTheBestMovePathWithFixSlot(readyLL, nearlyReadyReturnWafers);
  3294. if(ModuleHelper.IsLoadLock(llPath))
  3295. {
  3296. int returnCount = 0;
  3297. var llWaferStatus = GetLLFixedReadyInOutSlots(llPath);
  3298. var llSwapActions = new List<MoveItem>();
  3299. foreach(var wafer in nearlyReadyReturnWafers)
  3300. {
  3301. if(CanWaferGotoLL(wafer, llPath) && returnCount < Math.Min(llWaferStatus.tInSlot.Count, 2))
  3302. {
  3303. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(wafer.currentMod, 0, ModuleName.TMRobot, returnCount, (Hand)returnCount) });
  3304. llSwapActions.Add(new MoveItem(ModuleName.TMRobot, returnCount, llPath, llWaferStatus.tInSlot[returnCount], (Hand)returnCount));
  3305. returnCount++;
  3306. }
  3307. }
  3308. int pickCount = 0;
  3309. foreach(var slot in llWaferStatus.tOutSlot)
  3310. {
  3311. if (pickCount < 2)
  3312. {
  3313. llSwapActions.Add(new MoveItem(llPath, slot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  3314. pickCount++;
  3315. }
  3316. }
  3317. if(llSwapActions.Count > 0)
  3318. {
  3319. _tmSchdActions.Enqueue(llSwapActions);
  3320. }
  3321. return;
  3322. }
  3323. }
  3324. }
  3325. }
  3326. }
  3327. private bool IsTMRobotArmNotReserved(Hand hand)
  3328. {
  3329. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)hand) || _lstWaferTasks.Exists(wt => wt.currentMod == ModuleName.TMRobot && wt.currentSlot == (int)hand))
  3330. return false;
  3331. foreach(var acs in _tmSchdActions)
  3332. {
  3333. foreach(var ac in acs)
  3334. {
  3335. if ((ac.DestinationModule == ModuleName.TMRobot || ac.SourceModule == ModuleName.TMRobot) && ac.DestinationSlot == (int)hand)
  3336. return false;
  3337. }
  3338. }
  3339. return true;
  3340. }
  3341. private Hand SelectTMPickArm(ModuleName mod)
  3342. {
  3343. switch (_tmRobotSingleArmOption)
  3344. {
  3345. case 0:
  3346. {
  3347. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3348. return Hand.Blade1;
  3349. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3350. return Hand.Blade2;
  3351. }
  3352. break;
  3353. case 1:
  3354. {
  3355. if (IsTMRobotArmNotReserved(Hand.Blade1))
  3356. return Hand.Blade1;
  3357. }
  3358. break;
  3359. case 2:
  3360. {
  3361. if (IsTMRobotArmNotReserved(Hand.Blade2))
  3362. return Hand.Blade2;
  3363. }
  3364. break;
  3365. // Blade1 In Blade2 Out
  3366. case 3:
  3367. {
  3368. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3369. return Hand.Blade1;
  3370. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3371. return Hand.Blade2;
  3372. }
  3373. break;
  3374. // Blade2 In Blade1 Out
  3375. case 4:
  3376. {
  3377. if (ModuleHelper.IsLoadLock(mod) && IsTMRobotArmNotReserved(Hand.Blade2))
  3378. return Hand.Blade2;
  3379. if (ModuleHelper.IsPm(mod) && IsTMRobotArmNotReserved(Hand.Blade1))
  3380. return Hand.Blade1;
  3381. }
  3382. break;
  3383. }
  3384. return Hand.None;
  3385. }
  3386. private List<Hand> GetTMFreeHand()
  3387. {
  3388. var lstHands = new List<Hand>();
  3389. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  3390. lstHands.Add(Hand.Blade1);
  3391. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  3392. lstHands.Add(Hand.Blade2);
  3393. return lstHands;
  3394. }
  3395. private List<Hand> GetEFEMFreeHand()
  3396. {
  3397. var lstHands = new List<Hand>();
  3398. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && _efemRobotSingleArmOption != 2)
  3399. lstHands.Add(Hand.Blade1);
  3400. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && _efemRobotSingleArmOption != 1)
  3401. lstHands.Add(Hand.Blade2);
  3402. return lstHands;
  3403. }
  3404. private bool CanWaferGotoLL(WaferTask task, ModuleName ll)
  3405. {
  3406. bool bVacWafer = ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod);
  3407. if (bVacWafer)
  3408. {
  3409. if (ModuleHelper.IsPm(task.destMod))
  3410. return false;
  3411. switch (task.llInOutPath)
  3412. {
  3413. case SequenceLLInOutPath.AInAOut:
  3414. case SequenceLLInOutPath.BInAOut:
  3415. return ll == ModuleName.LLA;
  3416. case SequenceLLInOutPath.AInBOut:
  3417. case SequenceLLInOutPath.BInBOut:
  3418. return ll == ModuleName.LLB;
  3419. case SequenceLLInOutPath.DInDOut:
  3420. return true;
  3421. }
  3422. }
  3423. else
  3424. {
  3425. if (ModuleHelper.IsLoadPort(task.destMod))
  3426. return false;
  3427. switch (task.llInOutPath)
  3428. {
  3429. case SequenceLLInOutPath.AInAOut:
  3430. case SequenceLLInOutPath.AInBOut:
  3431. return ll == ModuleName.LLA;
  3432. case SequenceLLInOutPath.BInAOut:
  3433. case SequenceLLInOutPath.BInBOut:
  3434. return ll == ModuleName.LLB;
  3435. case SequenceLLInOutPath.DInDOut:
  3436. return true;
  3437. }
  3438. }
  3439. return false;
  3440. }
  3441. private (List<int> inSlot, List<int> outSlot, List<int> emptySlot) GetLLReadyInOutSlots(ModuleName ll)
  3442. {
  3443. var readInSlots = new List<int>();
  3444. var readyOutSlots = new List<int>();
  3445. var emptySlots = new List<int>();
  3446. for(int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3447. {
  3448. 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)))
  3449. {
  3450. emptySlots.Add(slot);
  3451. }
  3452. if(WaferManager.Instance.CheckHasWafer(ll, slot))
  3453. {
  3454. Guid waferID = WaferManager.Instance.GetWafer(ll, slot).InnerId;
  3455. var waferTask = _lstWaferTasks.Find(wafer => wafer.waferId == waferID);
  3456. if(waferTask != null && waferTask.movingStatus == RState.End)
  3457. {
  3458. if (ModuleHelper.IsPm(waferTask.destMod))
  3459. readInSlots.Add(slot);
  3460. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3461. readyOutSlots.Add(slot);
  3462. }
  3463. }
  3464. }
  3465. return (readInSlots, readyOutSlots, emptySlots);
  3466. }
  3467. private (List<int> eInSlot, List<int> eOutSlot, List<int> tInSlot, List<int> tOutSlot) GetLLFixedReadyInOutSlots(ModuleName ll)
  3468. {
  3469. var eInSlot = new List<int>();
  3470. var eOutSlot = new List<int>();
  3471. var tInSlot = new List<int>();
  3472. var tOutSlot = new List<int>();
  3473. int SlotNumber = ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber;
  3474. for (int slot = 0; slot < SlotNumber; slot++)
  3475. {
  3476. 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)))
  3477. {
  3478. if ((slot >= SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.UpperInLowerOut) ||
  3479. (slot < SlotNumber / 2 && _LLSlotInOutOption == LLSlotInOutOpt.LowerInUpperOut))
  3480. {
  3481. eInSlot.Add(slot);
  3482. }
  3483. else
  3484. {
  3485. tInSlot.Add(slot);
  3486. }
  3487. }
  3488. if (WaferManager.Instance.CheckHasWafer(ll, slot))
  3489. {
  3490. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3491. var waferTask = _lstWaferTasks.Find(wt => wt.waferId == wafer.InnerId && wt.currentMod == ll && wt.currentSlot == slot);
  3492. if(waferTask == null)
  3493. {
  3494. LOG.Write(eEvent.EV_ROUTER, ll, $"Routing trace: did not find inner task associated with {wafer.WaferOrigin} at {ll}.{slot + 1}");
  3495. }
  3496. else if (waferTask.movingStatus == RState.End)
  3497. {
  3498. if (ModuleHelper.IsPm(waferTask.destMod))
  3499. tOutSlot.Add(slot);
  3500. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  3501. eOutSlot.Add(slot);
  3502. }
  3503. }
  3504. }
  3505. return (eInSlot, eOutSlot, tInSlot, tOutSlot);
  3506. }
  3507. private (List<WaferInfo> wafers, List<int> emptySlots) GetLLWaferExistance(ModuleName ll)
  3508. {
  3509. var lstWafers = new List<WaferInfo>();
  3510. var lstEmptySlots = new List<int>();
  3511. for (int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  3512. {
  3513. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  3514. if(wafer != null && !wafer.IsEmpty)
  3515. {
  3516. lstWafers.Add(wafer);
  3517. }
  3518. else
  3519. {
  3520. lstEmptySlots.Add(slot);
  3521. }
  3522. }
  3523. return (lstWafers, lstEmptySlots);
  3524. }
  3525. private void PrepareLLPressure()
  3526. {
  3527. var preaparedLLs = new List<ModuleName>();
  3528. var lls = _efemSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3529. if (_curEfemAction.Count == 0 && _efemSchdActions.Count > 0 && ModuleHelper.IsLoadLock(_efemSchdActions.First().First().Module))
  3530. lls.Remove(_efemSchdActions.First().First().Module);
  3531. foreach(var ll in lls)
  3532. {
  3533. if(_dictModuleTask[ll].Scheduler.IsAvailable && _dictModuleTask[ll].Scheduler.IsVac && !preaparedLLs.Contains(ll))
  3534. {
  3535. (_dictModuleTask[ll].Scheduler as SchedulerLoadLock).PreVent();
  3536. preaparedLLs.Add(ll);
  3537. }
  3538. }
  3539. lls = _tmSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  3540. if(_curTmAction.Count == 0 && _tmSchdActions.Count > 0 && ModuleHelper.IsLoadLock(_tmSchdActions.First().First().Module))
  3541. lls.Remove(_tmSchdActions.First().First().Module);
  3542. foreach (var ll in lls)
  3543. {
  3544. if (_dictModuleTask[ll].Scheduler.IsAvailable && _dictModuleTask[ll].Scheduler.IsAtm && !preaparedLLs.Contains(ll))
  3545. {
  3546. (_dictModuleTask[ll].Scheduler as SchedulerLoadLock).PrePump();
  3547. preaparedLLs.Add(ll);
  3548. }
  3549. }
  3550. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0 || _tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  3551. return;
  3552. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  3553. {
  3554. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  3555. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  3556. var inLLWaferCount = _lstWaferTasks.Where(wafer => wafer.currentMod == inLL).Count();
  3557. var outLLWaferCount = _lstWaferTasks.Where(wafer => wafer.currentMod == outLL).Count();
  3558. if (inLLWaferCount == 0 && !preaparedLLs.Contains(inLL))
  3559. {
  3560. (_dictModuleTask[inLL] as LoadlockTask).PreVent();
  3561. preaparedLLs.Add(inLL);
  3562. }
  3563. else if(inLLWaferCount == (LLInOutPath == SequenceLLInOutPath.AInBOut ? _LLASlotNumber : _LLBSlotNumber) && !preaparedLLs.Contains(inLL))
  3564. {
  3565. (_dictModuleTask[inLL] as LoadlockTask).PrePump();
  3566. preaparedLLs.Add(inLL);
  3567. }
  3568. if(outLLWaferCount == 0 && !preaparedLLs.Contains(outLL))
  3569. {
  3570. (_dictModuleTask[outLL] as LoadlockTask).PrePump();
  3571. preaparedLLs.Add(outLL);
  3572. }
  3573. else if(outLLWaferCount == (LLInOutPath == SequenceLLInOutPath.BInAOut ? _LLASlotNumber : _LLBSlotNumber) && !preaparedLLs.Contains(outLL))
  3574. {
  3575. (_dictModuleTask[outLL] as LoadlockTask).PreVent();
  3576. preaparedLLs.Add(outLL);
  3577. }
  3578. }
  3579. }
  3580. private void ReturnVacWafers()
  3581. {
  3582. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  3583. {
  3584. RunSchdTMReturnActions();
  3585. return;
  3586. }
  3587. if (_tmRobotStatus != RState.End)
  3588. return;
  3589. var hands = GetTMFreeHand();
  3590. 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);
  3591. if(lls.Count() > 0)
  3592. {
  3593. // return robot wafers
  3594. int moveCount = 0;
  3595. var llActions = new List<MoveItem>();
  3596. var emptySlots = GetLLWaferExistance(lls.First().Key).emptySlots;
  3597. for(int arm = 0; arm < 2; arm++)
  3598. {
  3599. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, arm);
  3600. if(wafer != null && !wafer.IsEmpty && moveCount < emptySlots.Count)
  3601. {
  3602. llActions.Add(new MoveItem(ModuleName.TMRobot, arm, lls.First().Key, emptySlots[moveCount], (Hand)arm));
  3603. moveCount++;
  3604. }
  3605. }
  3606. if(moveCount > 0)
  3607. {
  3608. _tmSchdActions.Enqueue(llActions);
  3609. return;
  3610. }
  3611. // return PM wafers
  3612. var PickActions = new List<MoveItem>();
  3613. var hasWaferPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsIdle && WaferManager.Instance.CheckHasWafer(mod.Key, 0));
  3614. foreach(var pm in hasWaferPMs)
  3615. {
  3616. if (moveCount < hands.Count && moveCount < emptySlots.Count)
  3617. {
  3618. PickActions.Add(new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)hands[moveCount], hands[moveCount]));
  3619. llActions.Add(new MoveItem(ModuleName.TMRobot, (int)hands[moveCount], lls.First().Key, emptySlots[moveCount], hands[moveCount]));
  3620. moveCount++;
  3621. }
  3622. }
  3623. if(moveCount > 0)
  3624. {
  3625. foreach(var ac in PickActions)
  3626. {
  3627. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  3628. }
  3629. _tmSchdActions.Enqueue(llActions);
  3630. }
  3631. }
  3632. }
  3633. private void ReturnAtmWafers()
  3634. {
  3635. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  3636. {
  3637. RunSchdEFEMReturnActions();
  3638. return;
  3639. }
  3640. if (_efemRobotStatus != RState.End)
  3641. return;
  3642. // return Robot Wafer
  3643. for(int i = 0; i < 2; i++)
  3644. {
  3645. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  3646. if(wafer != null && !wafer.IsEmpty)
  3647. {
  3648. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  3649. }
  3650. }
  3651. if (_efemSchdActions.Count > 0)
  3652. return;
  3653. var hands = GetEFEMFreeHand();
  3654. // return Aligner wafer
  3655. var aligner = ModuleHelper.InstalledModules.Where(mod => ModuleHelper.IsAligner(mod)).ToList();
  3656. if(aligner.Count > 0 && WaferManager.Instance.CheckHasWafer(aligner.First(), 0) && hands.Count > 0)
  3657. {
  3658. var wafer = WaferManager.Instance.GetWafer(aligner.First(), 0);
  3659. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(aligner.First(), 0, ModuleName.EfemRobot, (int)hands.First(), hands.First()) });
  3660. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)hands.First(), (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands.First()) });
  3661. return;
  3662. }
  3663. // return Loadlock wafer
  3664. 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);
  3665. if(lls.Count() > 0)
  3666. {
  3667. int returnCount = 0;
  3668. var llActions = new List<MoveItem>();
  3669. var placActions = new List<MoveItem>();
  3670. foreach(var wafer in GetLLWaferExistance(lls.First().Key).wafers)
  3671. {
  3672. if(returnCount < hands.Count)
  3673. {
  3674. llActions.Add(new MoveItem(lls.First().Key, wafer.Slot, ModuleName.EfemRobot, (int)hands[returnCount], hands[returnCount]));
  3675. placActions.Add(new MoveItem(ModuleName.EfemRobot, (int)hands[returnCount], (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands[returnCount]));
  3676. returnCount++;
  3677. }
  3678. }
  3679. if (returnCount > 0)
  3680. {
  3681. _efemSchdActions.Enqueue(llActions);
  3682. foreach (var ac in placActions)
  3683. {
  3684. _efemSchdActions.Enqueue(new List<MoveItem> { ac });
  3685. }
  3686. }
  3687. }
  3688. }
  3689. private void RunSchdEFEMReturnActions()
  3690. {
  3691. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  3692. if (efemRobot == null || !efemRobot.IsAvailable)
  3693. return;
  3694. if (_efemSchdActions.Count > 0)
  3695. {
  3696. if (_curEfemAction.Count == 0 || isReturnActionsDone(_curEfemAction))
  3697. {
  3698. var nextActions = _efemSchdActions.First();
  3699. var nextModule = nextActions.First().Module;
  3700. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  3701. return;
  3702. _curEfemAction = _efemSchdActions.Dequeue();
  3703. efemRobot.PostMoveItems(_curEfemAction.ToArray());
  3704. }
  3705. }
  3706. else if (_curEfemAction.Count >= 0 && isReturnActionsDone(_curEfemAction)) // all scheduled actions done
  3707. {
  3708. _curEfemAction.Clear();
  3709. }
  3710. }
  3711. private void RunSchdTMReturnActions()
  3712. {
  3713. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerTMRobot;
  3714. if (tmRobot == null || !tmRobot.IsAvailable)
  3715. return;
  3716. if (_tmSchdActions.Count > 0)
  3717. {
  3718. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  3719. {
  3720. var nextActions = _tmSchdActions.First();
  3721. var nextModule = nextActions.First().Module;
  3722. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  3723. return;
  3724. _curTmAction = _tmSchdActions.Dequeue();
  3725. tmRobot.SendMoveItems(_curTmAction.ToArray());
  3726. }
  3727. }
  3728. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  3729. {
  3730. _curTmAction.Clear();
  3731. }
  3732. }
  3733. #endregion
  3734. #region sequence/recipe operation
  3735. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  3736. {
  3737. reason = "";
  3738. foreach(var pm in seq.PMs)
  3739. {
  3740. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  3741. return true;
  3742. }
  3743. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  3744. return false;
  3745. }
  3746. private bool CheckSequenceKepler2200TemperatureReady(SequenceInfo seq)
  3747. {
  3748. for (int i = 0; i < seq.Steps.Count; i++)
  3749. {
  3750. SequenceStepInfo stepInfo = seq.Steps[i];
  3751. foreach (var module in stepInfo.StepModules)
  3752. {
  3753. if (ModuleHelper.IsPm(module))
  3754. {
  3755. string attr = $"{module}Recipe";
  3756. if (stepInfo.StepParameter.ContainsKey(attr)
  3757. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3758. {
  3759. var recipeName = (string)stepInfo.StepParameter[attr];
  3760. var recipeContent =
  3761. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3762. var recipe = Recipe.Load(recipeContent);
  3763. float currentChamberTemperature;
  3764. switch (module)
  3765. {
  3766. case ModuleName.PMA:
  3767. currentChamberTemperature = Singleton<RouteManager>.Instance.PMA.ChamberTemperature;
  3768. break;
  3769. case ModuleName.PMB:
  3770. currentChamberTemperature = Singleton<RouteManager>.Instance.PMB.ChamberTemperature;
  3771. break;
  3772. case ModuleName.PMC:
  3773. currentChamberTemperature = Singleton<RouteManager>.Instance.PMC.ChamberTemperature;
  3774. break;
  3775. case ModuleName.PMD:
  3776. currentChamberTemperature = Singleton<RouteManager>.Instance.PMD.ChamberTemperature;
  3777. break;
  3778. default:
  3779. currentChamberTemperature = 0;
  3780. break;
  3781. }
  3782. if (recipe.Header.Temperature != null && recipe.Header.Temperature != "" && (currentChamberTemperature > Convert.ToSingle(recipe.Header.Temperature) + 10 || currentChamberTemperature < Convert.ToSingle(recipe.Header.Temperature) - 10))
  3783. {
  3784. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Start job失败,由于{module}腔体温度{currentChamberTemperature}与{recipeName} Recipe温度{recipe.Header.Temperature}不匹配");
  3785. return false;
  3786. }
  3787. }
  3788. }
  3789. }
  3790. }
  3791. return true;
  3792. }
  3793. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  3794. {
  3795. for (int i = 0; i < seq.Steps.Count; i++)
  3796. {
  3797. SequenceStepInfo stepInfo = seq.Steps[i];
  3798. foreach (var module in stepInfo.StepModules)
  3799. {
  3800. if (ModuleHelper.IsPm(module))
  3801. {
  3802. string attr = $"{module}Recipe";
  3803. if (stepInfo.StepParameter.ContainsKey(attr)
  3804. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3805. {
  3806. var recipeName = (string)stepInfo.StepParameter[attr];
  3807. if (!string.IsNullOrWhiteSpace(recipeName))
  3808. {
  3809. var recipeContent =
  3810. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3811. if (string.IsNullOrWhiteSpace(recipeContent))
  3812. {
  3813. reason = $"Can not find recipe file{recipeName}";
  3814. return false;
  3815. }
  3816. }
  3817. }
  3818. }
  3819. }
  3820. }
  3821. reason = "";
  3822. return true;
  3823. }
  3824. private void UpdateLLInOutPathProperty()
  3825. {
  3826. if (_lstControlJobs.Count == 0)
  3827. return;
  3828. var inOutPaths = new List<SequenceLLInOutPath>();
  3829. foreach(var wt in _lstWaferTasks)
  3830. {
  3831. if (!inOutPaths.Contains(wt.llInOutPath))
  3832. inOutPaths.Add(wt.llInOutPath);
  3833. }
  3834. if (inOutPaths.Count == 1)
  3835. {
  3836. _LLInOutPath = inOutPaths[0];
  3837. }
  3838. else
  3839. _LLInOutPath = SequenceLLInOutPath.DInDOut;
  3840. }
  3841. private bool GetAllJobRecipe(ControlJobInfo cj,SequenceInfo seq)
  3842. {
  3843. for (int i = 0; i < seq.Steps.Count; i++)
  3844. {
  3845. SequenceStepInfo stepInfo = seq.Steps[i];
  3846. foreach (var module in stepInfo.StepModules)
  3847. {
  3848. if (ModuleHelper.IsPm(module))
  3849. {
  3850. string attr = $"{module}Recipe";
  3851. if (stepInfo.StepParameter.ContainsKey(attr)
  3852. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3853. {
  3854. var recipeName = (string)stepInfo.StepParameter[attr];
  3855. var recipeContent =
  3856. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3857. var recipe = Recipe.Load(recipeContent);
  3858. if (recipe.Header.ChuckRecipe != null && recipe.Header.ChuckRecipe != "")
  3859. {
  3860. InUseRecipes.Add($"{module}.ChuckRecipe.{recipe.Header.ChuckRecipe}");
  3861. }
  3862. if (recipe.Header.DechuckRecipe != null && recipe.Header.DechuckRecipe != "")
  3863. {
  3864. InUseRecipes.Add($"{module}.DechuckRecipe.{recipe.Header.DechuckRecipe}");
  3865. }
  3866. InUseRecipes.Add($"{module}.Process.{recipeName}");
  3867. if (cj.PreJobClean != "")
  3868. {
  3869. InUseRecipes.Add($"{module}.Clean.{cj.PreJobClean}");
  3870. }
  3871. if (cj.PostJobClean != "")
  3872. {
  3873. InUseRecipes.Add($"{module}.Clean.{cj.PostJobClean}");
  3874. }
  3875. if (stepInfo.StepParameter["WTWClean"].ToString() != "")
  3876. {
  3877. InUseRecipes.Add($"{module}.Clean.{stepInfo.StepParameter["WTWClean"]}");
  3878. }
  3879. }
  3880. }
  3881. }
  3882. }
  3883. return true;
  3884. }
  3885. private bool IsSequenceNeedAlign(SequenceInfo sequence)
  3886. {
  3887. // check wether need align
  3888. foreach (var step in sequence.Steps)
  3889. {
  3890. foreach(var mod in step.StepModules)
  3891. {
  3892. if(ModuleHelper.IsAligner(mod))
  3893. return true;
  3894. }
  3895. }
  3896. return false;
  3897. }
  3898. #endregion
  3899. }
  3900. }