SystemDispatcher.cs 204 KB

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