SystemDispatcher.cs 160 KB

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