SystemDispatcher.cs 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668
  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. foreach (var item in _lstProcessJobs)
  1016. {
  1017. if (item.ControlJobName == cj.Name && !CheckSequenceKepler2200TemperatureReady(item.Sequence))
  1018. {
  1019. return false;
  1020. }
  1021. }
  1022. }
  1023. if (cj.State == EnumControlJobState.WaitingForStart)
  1024. {
  1025. cj.SetState(EnumControlJobState.Executing);
  1026. //PreJobClean(cj);
  1027. cj.JetState = EnumJetCtrlJobState.Quequed;
  1028. cj.StartTime = DateTime.Now;
  1029. _dbCallback.LotCreated(cj);
  1030. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  1031. //if (!_blockingWatcher.IsRunning)
  1032. // _blockingWatcher.Restart();
  1033. //ResetTraceFlag();
  1034. }
  1035. if (!_cycleWatch.IsRunning)
  1036. {
  1037. _cycleWatch.Restart();
  1038. }
  1039. if (!_lpCycleWafer.Keys.Contains(ModuleHelper.Converter(cj.Module)))
  1040. {
  1041. _lpCycleCount.Add(ModuleHelper.Converter(cj.Module), 0);
  1042. _lpCycleWafer.Add(ModuleHelper.Converter(cj.Module), 0);
  1043. }
  1044. _cycleState = RState.Running;
  1045. return true;
  1046. }
  1047. public void Clear()
  1048. {
  1049. foreach (var module in _dictModuleTask)
  1050. {
  1051. module.Value.Status = ModuleStatus.Idle;
  1052. module.Value.Scheduler.ResetTask();
  1053. }
  1054. List<string> keys = _loadportControlJobDic.Keys.ToList();
  1055. foreach (var key in keys)
  1056. {
  1057. _loadportControlJobDic[key] = null;
  1058. }
  1059. _lstWaferTasks.Clear();
  1060. _tmSchdActions.Clear();
  1061. _curTmAction.Clear();
  1062. _efemSchdActions.Clear();
  1063. _curEfemAction.Clear();
  1064. _lstControlJobs.Clear();
  1065. _lstProcessJobs.Clear();
  1066. _cycleState = RState.End;
  1067. }
  1068. // manual return one wafer while system is auto running
  1069. public bool ManualReturnWafer(object[] objs)
  1070. {
  1071. ModuleName SourceModule = (ModuleName)objs[0];
  1072. int SourceSlot = (int)objs[1];
  1073. if (!_dictModuleTask.Keys.Contains(SourceModule))
  1074. {
  1075. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Invalid source module {SourceModule} for manual return wafer");
  1076. return false;
  1077. }
  1078. if (WaferManager.Instance.CheckNoWafer(SourceModule, SourceSlot))
  1079. {
  1080. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"Can not return wafer as {SourceModule} {SourceSlot} has no wafer");
  1081. return false;
  1082. }
  1083. if (!_dictModuleTask[SourceModule].Scheduler.IsIdle)
  1084. {
  1085. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"The module: {SourceModule} is not ready for return wafer");
  1086. return false;
  1087. }
  1088. var wafer = WaferManager.Instance.GetWafer(SourceModule, SourceSlot);
  1089. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Manual return wafer: {wafer.WaferOrigin} at {SourceModule} {SourceSlot} while system is auto running");
  1090. _qeReturnWafers.Enqueue(wafer);
  1091. return true;
  1092. }
  1093. public RState CheckManualReturnWafer()
  1094. {
  1095. var pmWaferCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && WaferManager.Instance.CheckHasWafer(mod.Key, 0)).Count();
  1096. var tmRobotWaferCount = (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 1 : 0) + (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) ? 1 : 0);
  1097. if (!_dictModuleTask[ModuleName.TMRobot].Scheduler.IsIdle && (pmWaferCount > 0 || tmRobotWaferCount > 0))
  1098. {
  1099. LOG.Write(eEvent.ERR_ROUTER, ModuleName.TMRobot, $"The TM Robot is not ready for return wafer.");
  1100. return RState.Failed;
  1101. }
  1102. if (!_dictModuleTask[ModuleName.EfemRobot].Scheduler.IsIdle)
  1103. {
  1104. LOG.Write(eEvent.ERR_ROUTER, ModuleName.EfemRobot, $"The EFEM Robot is not ready for return wafer.");
  1105. return RState.Failed;
  1106. }
  1107. foreach (var mod in _dictModuleTask)
  1108. {
  1109. if (ModuleHelper.IsLoadPort(mod.Key))
  1110. continue;
  1111. if (!mod.Value.Scheduler.IsIdle)
  1112. {
  1113. LOG.Write(eEvent.ERR_ROUTER, mod.Key, $"{mod.Key} is not ready for return wafer.");
  1114. return RState.Failed;
  1115. }
  1116. int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
  1117. for (int slot = 0; slot < nSlotNumber; slot++)
  1118. {
  1119. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  1120. if (wafer.IsEmpty)
  1121. continue;
  1122. var destLP = (ModuleName)wafer.OriginStation;
  1123. if (!_dictModuleTask[destLP].Scheduler.IsAvailable)
  1124. {
  1125. LOG.Write(eEvent.ERR_ROUTER, destLP, $"The destination Loadport {destLP} is not ready for return wafer.");
  1126. return RState.Failed;
  1127. }
  1128. if(!ModuleHelper.IsLoadPort(destLP))
  1129. {
  1130. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"The wafer {wafer.WaferOrigin} cannot be return, please manually drag it.");
  1131. return RState.Failed;
  1132. }
  1133. }
  1134. }
  1135. Clear();
  1136. return RState.Running;
  1137. }
  1138. public RState ReturnAllWafers()
  1139. {
  1140. int systemWaferCount = 0;
  1141. foreach (var mod in _dictModuleTask)
  1142. {
  1143. if (ModuleHelper.IsLoadPort(mod.Key))
  1144. continue;
  1145. int nSlotNumber = ModuleHelper.IsLoadLock(mod.Key) ? (mod.Key == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber) : (ModuleHelper.IsTMRobot(mod.Key) || ModuleHelper.IsEFEMRobot(mod.Key) ? 2 : 1);
  1146. for (int slot = 0; slot < nSlotNumber; slot++)
  1147. {
  1148. var wafer = WaferManager.Instance.GetWafer(mod.Key, slot);
  1149. if (!wafer.IsEmpty)
  1150. systemWaferCount++;
  1151. }
  1152. }
  1153. if (systemWaferCount == 0)
  1154. return RState.End;
  1155. ReturnVacWafers();
  1156. ReturnAtmWafers();
  1157. return RState.Running;
  1158. }
  1159. #endregion
  1160. #region internal implementation
  1161. private void InitModules()
  1162. {
  1163. foreach (var module in ModuleHelper.InstalledModules)
  1164. {
  1165. if (ModuleHelper.IsInstalled(module))
  1166. {
  1167. if(ModuleHelper.IsPm(module))
  1168. {
  1169. _dictModuleTask[module] = new PMTask(module);
  1170. }
  1171. else if (ModuleHelper.IsLoadLock(module))
  1172. {
  1173. _dictModuleTask[module] = new LoadlockTask(module);
  1174. }
  1175. else if(ModuleHelper.IsLoadPort(module))
  1176. {
  1177. _dictModuleTask[module] = new LoadPortTask(module);
  1178. }
  1179. else if(ModuleHelper.IsTMRobot(module))
  1180. {
  1181. _dictModuleTask[module] = new TMRobotTask(module);
  1182. }
  1183. else if(ModuleHelper.IsEFEMRobot(module))
  1184. {
  1185. _dictModuleTask[module] = new EFEMRobotTask(module);
  1186. }
  1187. else if(ModuleHelper.IsAligner(module))
  1188. {
  1189. _dictModuleTask[module] = new AlignerTask(module);
  1190. }
  1191. }
  1192. }
  1193. }
  1194. private void prelude()
  1195. {
  1196. }
  1197. private void epilogue()
  1198. {
  1199. UpdateProcessJobStatus();
  1200. UpdateControlJobStatus();
  1201. UpdateLLInOutPathProperty();
  1202. PrepareLLPressure();
  1203. CreateNewWaferTask();
  1204. _lstWaferTasks.RemoveAll(item => ModuleHelper.IsLoadPort(item.destMod) && ModuleHelper.IsLoadPort(item.currentMod) && item.pressureStatus == RState.End);
  1205. }
  1206. private void RunWaferTask()
  1207. {
  1208. foreach (var task in _lstWaferTasks)
  1209. {
  1210. task.Run();
  1211. }
  1212. }
  1213. private void RunModuleTasks()
  1214. {
  1215. foreach (var task in _dictModuleTask)
  1216. {
  1217. task.Value.Run();
  1218. }
  1219. }
  1220. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1221. {
  1222. bool allWaferReturn = true;
  1223. foreach (var slot in pj.SlotWafers)
  1224. {
  1225. var wafer = WaferManager.Instance.GetWafer(slot.Item1, slot.Item2);
  1226. if(wafer.IsEmpty || (wafer.ProcessState != EnumWaferProcessStatus.Completed && checkAllProcessed))
  1227. {
  1228. allWaferReturn = false;
  1229. break;
  1230. }
  1231. }
  1232. return allWaferReturn;
  1233. }
  1234. private void UpdateProcessJobStatus()
  1235. {
  1236. if (_efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1237. return;
  1238. foreach (var pj in _lstProcessJobs)
  1239. {
  1240. if (CheckAllWaferReturned(pj, pj.State != EnumProcessJobState.Stopping))
  1241. {
  1242. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1243. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1244. }
  1245. }
  1246. }
  1247. private void UpdateControlJobStatus()
  1248. {
  1249. if (_lstControlJobs.Count == 0 || _efemRobotStatus == RState.Running || _tmRobotStatus == RState.Running)
  1250. return;
  1251. bool allControlJobComplete = true;
  1252. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1253. foreach (var cj in _lstControlJobs)
  1254. {
  1255. if (cj.JetState == EnumJetCtrlJobState.Quequed) // active quequed control job: need prejob clean or don need prejob clean
  1256. {
  1257. var runingJobs = _lstControlJobs.FindAll(job => IsCtrlJobRuning(job));
  1258. if (runingJobs.Count == 0 || (runingJobs.Count == 1 && IsCtrlJobEndingState(runingJobs.First())))
  1259. {
  1260. var quequedJobs = _lstControlJobs.FindAll(job => job.JetState == EnumJetCtrlJobState.Quequed);
  1261. var firstQuequeJob = quequedJobs.OrderBy(job => job.StartTime).First();
  1262. if (firstQuequeJob.InnerId == cj.InnerId)
  1263. {
  1264. if (IsCtrlJobNeedPreClean(cj))
  1265. {
  1266. cj.JetState = EnumJetCtrlJobState.PreJobClean;
  1267. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1268. foreach (var pm in PMs)
  1269. {
  1270. var pmTask = _dictModuleTask[pm] as PMTask;
  1271. if(pmTask != null && pmTask.Scheduler.IsOnline)
  1272. {
  1273. pmTask.InvokePreJobClean(cj.PreJobClean);
  1274. }
  1275. }
  1276. }
  1277. else
  1278. {
  1279. ActiveControlJob(cj);
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else if (IsCtrlJobRuning(cj))
  1285. {
  1286. if (cj.JetState == EnumJetCtrlJobState.PreJobClean)
  1287. {
  1288. if (IsPreJobCleanDone(cj))
  1289. {
  1290. ActiveControlJob(cj);
  1291. }
  1292. }
  1293. else
  1294. {
  1295. if (cj.JetState == EnumJetCtrlJobState.Processing && IsCtrlJobNeedPostClean(cj)) // active post job clean
  1296. {
  1297. if (IsAllJobWaferProcessedOrProcessing(cj))
  1298. {
  1299. cj.JetState = EnumJetCtrlJobState.PostJobClean;
  1300. var PMs = GetWaitPreCleanPMsByCtrlJob(cj);
  1301. foreach (var pm in PMs)
  1302. {
  1303. var pmTask = _dictModuleTask[pm] as PMTask;
  1304. if (pmTask != null && pmTask.Scheduler.IsOnline)
  1305. {
  1306. pmTask.InvokePostJobClean(cj.PostJobClean);
  1307. }
  1308. }
  1309. }
  1310. }
  1311. // control job complete
  1312. if (IsAllProcessJobComplete(cj) && (!IsCtrlJobNeedPostClean(cj) || cj.JetState == EnumJetCtrlJobState.PostJobClean && IsPostJobCleanDone(cj)))
  1313. {
  1314. cj.JetState = EnumJetCtrlJobState.Completed;
  1315. cj.SetState(EnumControlJobState.Completed);
  1316. cj.EndTime = DateTime.Now;
  1317. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1318. _dbCallback.LotFinished(cj);
  1319. if (!(_isCycleMode && _cycledCount < _cycleSetPoint))
  1320. (Singleton<TransferModule>.Instance.GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
  1321. _lpCycleCount[ModuleHelper.Converter(cj.Module)]++;
  1322. }
  1323. }
  1324. int countProcessed = 0;
  1325. foreach (var pjName in cj.ProcessJobNameList)
  1326. {
  1327. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1328. if (pj == null)
  1329. {
  1330. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1331. continue;
  1332. }
  1333. // caculate process wafer by process
  1334. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1335. {
  1336. foreach (var pjSlotWafer in pj.SlotWafers)
  1337. {
  1338. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1339. if (!wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  1340. countProcessed++;
  1341. }
  1342. }
  1343. }
  1344. int lpCycleWafer = _lpCycleCount[ModuleHelper.Converter(cj.Module)] * cj.LotWafers.Count + (cj.JetState == EnumJetCtrlJobState.Completed && cj.LotWafers.Count == countProcessed ? 0 : countProcessed);
  1345. if (_lpCycleCount[ModuleHelper.Converter(cj.Module)] != _cycledCount || lpCycleWafer != _lpCycleWafer[ModuleHelper.Converter(cj.Module)])
  1346. {
  1347. _lpCycleWafer[ModuleHelper.Converter(cj.Module)] = lpCycleWafer;
  1348. }
  1349. }
  1350. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1351. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal && cj.JetState == EnumJetCtrlJobState.Completed)
  1352. {
  1353. cjRemoveList.Add(cj);
  1354. }
  1355. allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
  1356. }
  1357. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1358. {
  1359. int totolCycleWafer = _lpCycleWafer.Sum(item => item.Value);
  1360. if (totolCycleWafer != _cycledWafer || _lpCycleCount.Sum(item => item.Value) > 0 && _throughput < 0.01) // refresh _throughput in time
  1361. {
  1362. _cycledWafer = totolCycleWafer;
  1363. if (_cycledCount > 0 || allControlJobComplete)
  1364. {
  1365. _throughput = (float)(_cycledWafer / _cycleWatch.Elapsed.TotalHours);
  1366. }
  1367. else
  1368. {
  1369. _throughput = 0;
  1370. }
  1371. }
  1372. if (allControlJobComplete)
  1373. {
  1374. _cycledCount++;
  1375. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Cycle Count: {_cycledCount}, Total Processed Wafer: {_cycledWafer}, Throughput: {_throughput}");
  1376. if (_cycledCount < _cycleSetPoint)
  1377. {
  1378. foreach (var cj in _lstControlJobs)
  1379. {
  1380. cj.SetState(EnumControlJobState.Executing);
  1381. cj.JetState = EnumJetCtrlJobState.Quequed;
  1382. cj.LotInnerId = Guid.NewGuid();
  1383. _dbCallback.LotCreated(cj);
  1384. }
  1385. foreach (var pj in _lstProcessJobs)
  1386. {
  1387. pj.SetState(EnumProcessJobState.Queued);
  1388. pj.InnerId = Guid.NewGuid();
  1389. foreach (var pjSlotWafer in pj.SlotWafers)
  1390. {
  1391. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1392. wafer.ProcessJob = null;
  1393. wafer.NextSequenceStep = 0;
  1394. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1395. }
  1396. }
  1397. _lstWaferTasks.Clear();
  1398. }
  1399. else
  1400. _cycleState = RState.End;
  1401. }
  1402. }
  1403. foreach (var cj in cjRemoveList)
  1404. {
  1405. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1406. foreach (var pj in _lstProcessJobs)
  1407. {
  1408. if (pj.ControlJobName == cj.Name)
  1409. pjRemoveList.Add(pj);
  1410. }
  1411. foreach (var pj in pjRemoveList)
  1412. {
  1413. _lstProcessJobs.Remove(pj);
  1414. }
  1415. _lstControlJobs.Remove(cj);
  1416. }
  1417. }
  1418. private bool ActiveProcessJob(ProcessJobInfo pj)
  1419. {
  1420. foreach (var pjSlotWafer in pj.SlotWafers)
  1421. {
  1422. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1423. wafer.ProcessJob = pj;
  1424. wafer.NextSequenceStep = 0;
  1425. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1426. }
  1427. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1428. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1429. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1430. pj.SetState(EnumProcessJobState.Processing);
  1431. return true;
  1432. }
  1433. private bool ActiveControlJob(ControlJobInfo cj)
  1434. {
  1435. cj.JetState = EnumJetCtrlJobState.Processing;
  1436. foreach (var pjName in cj.ProcessJobNameList)
  1437. {
  1438. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1439. if (pj == null)
  1440. {
  1441. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Not find pj named {pjName} in {cj.Name}");
  1442. continue;
  1443. }
  1444. if (pj.State == EnumProcessJobState.Queued)
  1445. {
  1446. ActiveProcessJob(pj);
  1447. }
  1448. }
  1449. return true;
  1450. }
  1451. private bool IsAllJobWaferProcessedOrProcessing(ControlJobInfo cj)
  1452. {
  1453. List<ModuleName> allModules = _dictModuleTask.Keys.ToList();
  1454. int original = (int)ModuleHelper.Converter(cj.Module);
  1455. foreach (var mod in allModules)
  1456. {
  1457. if (ModuleHelper.IsLoadPort(mod) && (int)mod != original)
  1458. continue;
  1459. var wafers = WaferManager.Instance.GetWafers(mod);
  1460. foreach (var wafer in wafers)
  1461. {
  1462. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.ControlJobName != cj.Name)
  1463. continue;
  1464. if (wafer.ProcessState != EnumWaferProcessStatus.Completed && wafer.ProcessState != EnumWaferProcessStatus.InProcess)
  1465. return false; ;
  1466. }
  1467. }
  1468. return true;
  1469. }
  1470. private bool IsAllProcessJobComplete(ControlJobInfo cj)
  1471. {
  1472. foreach (var pj in _lstProcessJobs)
  1473. {
  1474. if (pj.ControlJobName == cj.Name && pj.State != EnumProcessJobState.ProcessingComplete)
  1475. {
  1476. return false;
  1477. }
  1478. }
  1479. return true;
  1480. }
  1481. private bool IsCtrlJobRuning(ControlJobInfo cj)
  1482. {
  1483. return cj.JetState == EnumJetCtrlJobState.PreJobClean ||
  1484. cj.JetState == EnumJetCtrlJobState.Processing ||
  1485. cj.JetState == EnumJetCtrlJobState.PostJobClean;
  1486. }
  1487. private bool IsCtrlJobEndingState(ControlJobInfo cj)
  1488. {
  1489. return cj.JetState == EnumJetCtrlJobState.PostJobClean ||
  1490. (cj.JetState == EnumJetCtrlJobState.Processing
  1491. && IsAllJobWaferProcessedOrProcessing(cj)
  1492. && !IsCtrlJobNeedPostClean(cj));
  1493. }
  1494. private bool IsCtrlJobNeedPreClean(ControlJobInfo cj)
  1495. {
  1496. return !string.IsNullOrWhiteSpace(cj.PreJobClean);
  1497. }
  1498. private bool IsCtrlJobNeedPostClean(ControlJobInfo cj)
  1499. {
  1500. return !string.IsNullOrWhiteSpace(cj.PostJobClean.Trim());
  1501. }
  1502. private List<ModuleName> GetWaitPreCleanPMsByCtrlJob(ControlJobInfo cj)
  1503. {
  1504. var pmlist = new List<ModuleName>();
  1505. foreach (var pj in _lstProcessJobs)
  1506. {
  1507. if (pj.ControlJobName == cj.Name)
  1508. {
  1509. foreach (var pm in pj.Sequence.PMs)
  1510. {
  1511. if (!pmlist.Contains(pm))
  1512. pmlist.Add(pm);
  1513. }
  1514. }
  1515. }
  1516. return pmlist;
  1517. }
  1518. private bool IsPreJobCleanDone(ControlJobInfo cj)
  1519. {
  1520. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1521. foreach(var pm in pms)
  1522. {
  1523. var pmTask = _dictModuleTask[pm] as PMTask;
  1524. if (pmTask.Scheduler.IsOnline && !pmTask.IsPreJobCleanDone())
  1525. return false;
  1526. }
  1527. return true;
  1528. }
  1529. private bool IsPostJobCleanDone(ControlJobInfo cj)
  1530. {
  1531. var pms = GetWaitPreCleanPMsByCtrlJob(cj);
  1532. foreach (var pm in pms)
  1533. {
  1534. var pmTask = _dictModuleTask[pm] as PMTask;
  1535. if (pmTask.Scheduler.IsOnline && !pmTask.IsPostJobCleanDone())
  1536. return false;
  1537. }
  1538. return true;
  1539. }
  1540. private void WaferArrived(WaferTask wafer, MoveItem item)
  1541. {
  1542. _dictModuleTask[item.DestinationModule].WaferArrived(wafer, item.DestinationSlot);
  1543. //--2024-03-21 增加了PortJobWaferEnd 上报事件 start--
  1544. if (ModuleHelper.IsLoadPort(item.DestinationModule))
  1545. {
  1546. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.DestinationModule);
  1547. if (currentControlJob != null)
  1548. {
  1549. _faCallback.JobWaferEnd(currentControlJob, item.SourceSlot);
  1550. }
  1551. }
  1552. //--2024-03-21 增加了PortJobWaferEnd 上报事件 end--
  1553. }
  1554. private void WaferLeaved(WaferTask wafer, MoveItem item)
  1555. {
  1556. _dictModuleTask[item.SourceModule].WaferLeaved(wafer, item.DestinationSlot);
  1557. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  1558. if (ModuleHelper.IsLoadPort(item.SourceModule))
  1559. {
  1560. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(item.SourceModule);
  1561. if (currentControlJob != null)
  1562. {
  1563. _faCallback.JobWaferStart(currentControlJob, item.SourceSlot);
  1564. }
  1565. }
  1566. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  1567. }
  1568. private ModuleName GetComingAvailablePM(ControlJobInfo cj)
  1569. {
  1570. var lstInProcessPMs = new List<ModuleName>();
  1571. foreach (var wafer in cj.LotWafers)
  1572. {
  1573. if(!wafer.IsEmpty && wafer.NextSequenceStep == 0 && wafer.ProcessJob != null)
  1574. {
  1575. foreach(var pm in wafer.ProcessJob.Sequence.PMs)
  1576. {
  1577. if (!lstInProcessPMs.Contains(pm) && _dictModuleTask[pm].Scheduler.IsOnline)
  1578. lstInProcessPMs.Add(pm);
  1579. }
  1580. }
  1581. }
  1582. // blocking check while only one loadlock in out
  1583. if (LLInOutPath == SequenceLLInOutPath.AInAOut ||
  1584. LLInOutPath == SequenceLLInOutPath.BInBOut ||
  1585. !_dictModuleTask[ModuleName.LLA].Scheduler.IsOnline ||
  1586. !_dictModuleTask[ModuleName.LLB].Scheduler.IsOnline)
  1587. {
  1588. if (_lstWaferTasks.Count >= lstInProcessPMs.Count + _LLASlotNumber / 2)
  1589. return ModuleName.System;
  1590. }
  1591. Dictionary<ModuleName, int> pmAssociatedWaferCount = new Dictionary<ModuleName, int>();
  1592. foreach (var mod in _dictModuleTask)
  1593. {
  1594. if (ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline && lstInProcessPMs.Contains(mod.Key))
  1595. {
  1596. pmAssociatedWaferCount[mod.Key] = 0;
  1597. }
  1598. }
  1599. var unprocessedWafer = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.destMod));
  1600. foreach (var wafer in unprocessedWafer)
  1601. {
  1602. if (ModuleHelper.IsPm(wafer.destMod) && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && lstInProcessPMs.Contains(wafer.destMod))
  1603. {
  1604. pmAssociatedWaferCount[wafer.destMod]++;
  1605. }
  1606. }
  1607. var oderedPMCount = pmAssociatedWaferCount.OrderBy(p => p.Value).ToDictionary(p => p.Key, o => o.Value);
  1608. if (oderedPMCount.Count > 0 && oderedPMCount.First().Value < 2)
  1609. return oderedPMCount.First().Key;
  1610. return ModuleName.System;
  1611. }
  1612. private void CreateNewWaferTask()
  1613. {
  1614. var cj = _lstControlJobs.Find(c => c.JetState == EnumJetCtrlJobState.PreJobClean || c.JetState == EnumJetCtrlJobState.Processing);
  1615. if (cj != null)
  1616. {
  1617. var pm = GetComingAvailablePM(cj);
  1618. if (pm != ModuleName.System)
  1619. {
  1620. foreach (var wafer in cj.LotWafers)
  1621. {
  1622. if (wafer.IsEmpty || wafer.ProcessJob == null)
  1623. continue;
  1624. if (wafer.ProcessJob.Sequence.PMs.Contains(pm) && wafer.NextSequenceStep == 0 && !_lstWaferTasks.Exists(task => task.sourceMod == (ModuleName)wafer.OriginStation && task.sourceSlot == wafer.OriginSlot))
  1625. {
  1626. CreateWaferTasks(wafer, pm, wafer.ProcessJob.Sequence.LLDelayTime);
  1627. return;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. private void CreateWaferTasks(WaferInfo wafer, ModuleName pm, int LLDeayTime)
  1634. {
  1635. var recipeName = wafer.ProcessJob.Sequence.GetRecipe(pm);
  1636. var recipeContent = RecipeFileManager.Instance.LoadRecipe(pm.ToString(), recipeName, false, RecipeType.Process.ToString());
  1637. Recipe recipe = Recipe.Load(recipeContent);
  1638. int temperature = 0;
  1639. if(int.TryParse(recipe.Header.Temperature, out int temp))
  1640. {
  1641. temperature = temp;
  1642. }
  1643. var waferTask = new WaferTask((ModuleName)wafer.OriginStation,
  1644. wafer.OriginSlot,
  1645. pm,
  1646. 0,
  1647. temperature,
  1648. wafer.InnerId,
  1649. recipeName,
  1650. wafer.ProcessJob.Sequence.WTWCleanRecipe,
  1651. wafer.ProcessJob.Sequence.LLInOutPath,
  1652. LLDeayTime);
  1653. waferTask.OnWaferArrived += WaferArrived;
  1654. waferTask.OnWaferLeaved += WaferLeaved;
  1655. _lstWaferTasks.Add(waferTask);
  1656. }
  1657. private bool ForwardATMWafers(ModuleName ll)
  1658. {
  1659. var waferStaus = GetLLReadyInOutSlots(ll);
  1660. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End ||wafer.movingStatus == RState.Init) && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1661. var notAlignedWafer = atmWafers.Where(wafer => !wafer.IsAligned).ToList();
  1662. var readyInWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsLoadPort(wafer.currentMod) && wafer.movingStatus == RState.Init && wafer.pressureStatus == RState.Init).OrderBy(wafer => wafer.currentSlot).ToArray();
  1663. var freeHands = GetEFEMFreeHand();
  1664. if ((atmWafers.Count >= 2 && atmWafers.Count(wafer => !wafer.IsAligned) == 0) || freeHands.Count == 0 || readyInWafers.Length == 0)
  1665. return false;
  1666. // force all wafer aligned
  1667. if (notAlignedWafer.Count > 0 && _lstWaferTasks.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 0)
  1668. {
  1669. notAlignedWafer.First().RouteTo(ModuleName.Aligner1, 0);
  1670. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(notAlignedWafer.First().currentMod, notAlignedWafer.First().currentSlot, ModuleName.Aligner1, 0, (Hand)notAlignedWafer.First().currentSlot) });
  1671. }
  1672. // forward one wafer
  1673. else if ((readyInWafers.Length > 0) && (atmWafers.Count == 0 || (atmWafers.Count == 1 && _lstWaferTasks.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 0 && waferStaus.emptySlot.Count >= 2)))
  1674. {
  1675. readyInWafers[0].RouteTo(ModuleName.Aligner1, 0);
  1676. // pick from LP
  1677. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyInWafers[0].currentMod, readyInWafers[0].currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1678. // place to aligner
  1679. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ModuleName.Aligner1, 0, freeHands[0]) });
  1680. }
  1681. // forward aligner wafer
  1682. else if (atmWafers.Count == 1 && waferStaus.emptySlot.Count >= 2 && ModuleHelper.IsAligner(atmWafers.First().currentMod) && freeHands.Count > 1)
  1683. {
  1684. atmWafers.First().RouteTo(ModuleName.EfemRobot, (int)freeHands[1]);
  1685. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(atmWafers.First().currentMod, atmWafers.First().currentSlot, ModuleName.EfemRobot, (int)freeHands[1], freeHands[1]) });
  1686. }
  1687. return _efemSchdActions.Count > 0;
  1688. }
  1689. private bool ExchangeWaferWithLL(ModuleName ll)
  1690. {
  1691. if (IsLLReservedByTM(ll))
  1692. return false;
  1693. var waferStaus = GetLLReadyInOutSlots(ll);
  1694. var atmWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.IsAligned && (ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod))).ToList();
  1695. var freeHands = GetEFEMFreeHand();
  1696. var swapActions = new List<MoveItem>();
  1697. var validHands = new List<Hand>();
  1698. int placeCount = 0;
  1699. if ( waferStaus.emptySlot.Count > 0 &&
  1700. freeHands.Count >= 1 &&
  1701. atmWafers.Count(wafer => ModuleHelper.IsAligner(wafer.currentMod)) == 1 &&
  1702. (atmWafers.Count(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)) == 0 || waferStaus.emptySlot.Count >= 2))
  1703. {
  1704. var alignerWafer = atmWafers.Where(wafer => ModuleHelper.IsAligner(wafer.currentMod)).First();
  1705. if(CanWaferGotoLL(alignerWafer, ll))
  1706. {
  1707. alignerWafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  1708. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(alignerWafer.currentMod, alignerWafer.currentSlot, ModuleName.EfemRobot, (int)freeHands[0], freeHands[0]) });
  1709. swapActions.Add(new MoveItem(ModuleName.EfemRobot, (int)freeHands[0], ll, waferStaus.emptySlot[placeCount], freeHands[0]));
  1710. validHands.Add(freeHands[0]);
  1711. placeCount++;
  1712. }
  1713. }
  1714. var armWafers = atmWafers.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToArray();
  1715. foreach(var wafer in armWafers)
  1716. {
  1717. if(CanWaferGotoLL(wafer, ll) && placeCount < waferStaus.emptySlot.Count)
  1718. {
  1719. wafer.RouteTo(ll, waferStaus.emptySlot[placeCount]);
  1720. swapActions.Add(new MoveItem(wafer.currentMod, wafer.currentSlot, ll, waferStaus.emptySlot[placeCount], (Hand)wafer.currentSlot));
  1721. if(!validHands.Contains((Hand)wafer.currentSlot))
  1722. validHands.Add((Hand)wafer.currentSlot);
  1723. placeCount++;
  1724. }
  1725. }
  1726. if (!validHands.Contains(Hand.Blade1) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade1) && _efemRobotSingleArmOption != 2)
  1727. validHands.Add(Hand.Blade1);
  1728. if (!validHands.Contains(Hand.Blade2) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)Hand.Blade2) && _efemRobotSingleArmOption != 1)
  1729. validHands.Add(Hand.Blade2);
  1730. int pickCount = 0;
  1731. var returnActions = new List<MoveItem>();
  1732. foreach(var slot in waferStaus.outSlot)
  1733. {
  1734. if(pickCount < validHands.Count)
  1735. {
  1736. var outWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == ll && wafer.currentSlot == slot);
  1737. if(outWafer != null)
  1738. {
  1739. outWafer.RouteTo(outWafer.destMod, outWafer.destSlot);
  1740. swapActions.Add(new MoveItem(ll, waferStaus.outSlot[pickCount], ModuleName.EfemRobot, (int)validHands[pickCount], validHands[pickCount]));
  1741. returnActions.Add(new MoveItem(ModuleName.EfemRobot, (int)validHands[pickCount], outWafer.destMod, outWafer.destSlot, validHands[pickCount]));
  1742. pickCount++;
  1743. }
  1744. }
  1745. }
  1746. if(swapActions.Count > 0)
  1747. {
  1748. _efemSchdActions.Enqueue(swapActions);
  1749. }
  1750. foreach(var action in returnActions)
  1751. {
  1752. _efemSchdActions.Enqueue(new List<MoveItem> { action });
  1753. }
  1754. return _efemSchdActions.Count > 0;
  1755. }
  1756. private void RoutingATMWafers()
  1757. {
  1758. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  1759. {
  1760. RunSchdEFEMActions();
  1761. return;
  1762. }
  1763. if (_efemRobotStatus != RState.End)
  1764. return;
  1765. if(_LLASlotNumber == 2)
  1766. {
  1767. Routing2SlotATMSystem();
  1768. }
  1769. else if(_LLASlotNumber == 4)
  1770. {
  1771. Routing4SlotATMSystem();
  1772. }
  1773. }
  1774. private void Routing4SlotATMSystem()
  1775. {
  1776. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1777. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  1778. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  1779. {
  1780. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  1781. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  1782. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  1783. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  1784. if (efemRobotWafers.Count() >= 1)
  1785. {
  1786. if (inLLWaferStatus.emptySlot.Count >= 2 && !IsLLReservedByTM(inLL)) // wait for in loadlock ready
  1787. {
  1788. if (_dictModuleTask[inLL].TimeToReady < 2)
  1789. {
  1790. ExchangeWaferWithLL(inLL);
  1791. }
  1792. }
  1793. if ((inLLWaferStatus.emptySlot.Count == 0 || (outLLWaferStatus.outSlot.Count >= 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL)) // ready return wafer
  1794. {
  1795. ExchangeWaferWithLL(outLL);
  1796. }
  1797. }
  1798. else
  1799. {
  1800. if (((outLLWaferStatus.outSlot.Count >= 2 && _dictModuleTask[outLL].TimeToReady < 10) ||
  1801. (outLLWaferStatus.outSlot.Count == 1 && _dictModuleTask[outLL].TimeToReady < 2)) && !IsLLReservedByTM(outLL))
  1802. {
  1803. ExchangeWaferWithLL(outLL);
  1804. }
  1805. else if (inLLWaferStatus.emptySlot.Count >= 2)
  1806. {
  1807. if (((_dictModuleTask[inLL].TimeToReady > 20 || _dictModuleTask[inLL].Scheduler.IsVac) && atmWaferCount < 2) || atmWaferCount == 0)
  1808. {
  1809. ForwardATMWafers(inLL);
  1810. }
  1811. else if (atmWaferCount >= 2 && !IsLLReservedByTM(inLL))
  1812. {
  1813. ExchangeWaferWithLL(inLL);
  1814. }
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. RoutingSameLLInOutATMSystem();
  1821. }
  1822. }
  1823. private void Routing2SlotATMSystem()
  1824. {
  1825. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1826. var efemRobotWafers = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod)).ToList();
  1827. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut) // don need check system wafer existence as no blocking risk
  1828. {
  1829. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  1830. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  1831. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  1832. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  1833. // whether can do double return in 5 second, single return with single arm option or LL under atm pressure
  1834. if ((outLLWaferStatus.outSlot.Count == 2 && _dictModuleTask[outLL].TimeToReady < 5 && (atmWaferCount < 2 || !_dictModuleTask[outLL].Scheduler.IsAtm)) ||
  1835. (outLLWaferStatus.outSlot.Count == 1 && ((_dictModuleTask[outLL].TimeToReady < 2 && _dictModuleTask[outLL].Scheduler.IsAtm)
  1836. || _efemRobotSingleArmOption != 0
  1837. || _lstWaferTasks.Where(wt => ModuleHelper.IsLoadPort(wt.destMod)).Count() == 1)))
  1838. {
  1839. if (ExchangeWaferWithLL(outLL))
  1840. return;
  1841. }
  1842. if(atmWaferCount == 0 || (atmWaferCount == 1 && inLLWaferStatus.emptySlot.Count == 2 && _efemRobotSingleArmOption == 0 && (outLLWaferStatus.outSlot.Count < 2 || _dictModuleTask[outLL].TimeToReady > 20)))
  1843. {
  1844. if (ForwardATMWafers(inLL))
  1845. return;
  1846. }
  1847. if((inLLWaferStatus.emptySlot.Count == 2 || (inLLWaferStatus.emptySlot.Count == 1 && _efemRobotSingleArmOption != 0) && _dictModuleTask[inLL].TimeToReady < 2))
  1848. {
  1849. ExchangeWaferWithLL(inLL);
  1850. }
  1851. }
  1852. else
  1853. {
  1854. RoutingSameLLInOutATMSystem();
  1855. }
  1856. }
  1857. private void RoutingSameLLInOutATMSystem()
  1858. {
  1859. var atmWaferCount = _lstWaferTasks.Where(wafer => ModuleHelper.IsEFEMRobot(wafer.currentMod) || ModuleHelper.IsAligner(wafer.currentMod)).Count();
  1860. var vacWaferCount = _lstWaferTasks.Where(task => ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod) || ModuleHelper.IsLoadLock(task.currentMod)).Count();
  1861. var preferWaferVacCount = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsOnline).Count() +
  1862. (LLInOutPath == SequenceLLInOutPath.AInAOut ? _LLASlotNumber / 2 : (LLInOutPath == SequenceLLInOutPath.BInBOut ? _LLBSlotNumber / 2 : _LLASlotNumber));
  1863. var inOutIndicator = vacWaferCount - preferWaferVacCount;
  1864. if (inOutIndicator < 0)
  1865. {
  1866. // ready to push in
  1867. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  1868. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  1869. mod.Value.TimeToReady <= 10 &&
  1870. !IsLLReservedByTM(mod.Key) &&
  1871. GetLLReadyInOutSlots(mod.Key).emptySlot.Count >= 1).
  1872. OrderBy(mod => mod.Value.TimeToReady).ToList();
  1873. if (atmWaferCount >= 1)
  1874. {
  1875. foreach(var ll in readyLLs)
  1876. {
  1877. if (ExchangeWaferWithLL(ll.Key))
  1878. return;
  1879. }
  1880. }
  1881. // forward wafer to system
  1882. if (atmWaferCount < 2)
  1883. {
  1884. var targetLL = readyLLs.Count > 0 ? readyLLs.First().Key : (LLInOutPath == SequenceLLInOutPath.BInBOut ? ModuleName.LLB : ModuleName.LLA);
  1885. ForwardATMWafers(targetLL);
  1886. }
  1887. if (_efemSchdActions.Count == 0)
  1888. {
  1889. var readyReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  1890. ((mod.Key == ModuleName.LLA && LLInOutPath != SequenceLLInOutPath.BInBOut) || (mod.Key == ModuleName.LLB && LLInOutPath != SequenceLLInOutPath.AInAOut)) &&
  1891. mod.Value.TimeToReady <= 5 &&
  1892. !IsLLReservedByTM(mod.Key) &&
  1893. GetLLReadyInOutSlots(mod.Key).outSlot.Count >= 1).
  1894. OrderByDescending(mod => GetLLReadyInOutSlots(mod.Key).outSlot.Count).ToList();
  1895. foreach(var ll in readyReturnLL)
  1896. {
  1897. if (ExchangeWaferWithLL(readyReturnLL.First().Key))
  1898. return;
  1899. }
  1900. }
  1901. }
  1902. else
  1903. {
  1904. // ready double return LL
  1905. var readyDoubleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  1906. mod.Value.TimeToReady < 10 &&
  1907. !IsLLReservedByTM(mod.Key) &&
  1908. GetLLReadyInOutSlots(mod.Key).outSlot.Count > 1).
  1909. OrderBy(mod => mod.Value.TimeToReady).ToList();
  1910. foreach(var ll in readyDoubleReturnLL)
  1911. {
  1912. if (ExchangeWaferWithLL(ll.Key))
  1913. return;
  1914. }
  1915. // ready single return LL
  1916. var readySingleReturnLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  1917. mod.Value.TimeToReady < 2 &&
  1918. !IsLLReservedByTM(mod.Key) &&
  1919. GetLLReadyInOutSlots(mod.Key).outSlot.Count == 1).
  1920. OrderBy(mod => mod.Value.TimeToReady).ToList();
  1921. foreach (var ll in readySingleReturnLL)
  1922. {
  1923. if (ExchangeWaferWithLL(ll.Key))
  1924. return;
  1925. }
  1926. if (atmWaferCount == 0)
  1927. {
  1928. // ready to push in
  1929. var readyLLs = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) &&
  1930. ((mod.Key != ModuleName.LLA && LLInOutPath == SequenceLLInOutPath.BInBOut) || (mod.Key != ModuleName.LLB && LLInOutPath == SequenceLLInOutPath.AInAOut)) &&
  1931. mod.Value.TimeToReady <= 10 &&
  1932. !IsLLReservedByTM(mod.Key) &&
  1933. GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 1).
  1934. OrderBy(mod => mod.Value.TimeToReady).ToList();
  1935. foreach(var ll in readyLLs)
  1936. {
  1937. if (ForwardATMWafers(ll.Key))
  1938. return;
  1939. }
  1940. }
  1941. }
  1942. }
  1943. private bool isReturnActionsDone(List<MoveItem> items)
  1944. {
  1945. foreach(var item in items)
  1946. {
  1947. if (WaferManager.Instance.CheckHasWafer(item.SourceModule, item.SourceSlot) || WaferManager.Instance.CheckNoWafer(item.DestinationModule, item.DestinationSlot))
  1948. return false;
  1949. }
  1950. return true;
  1951. }
  1952. private bool IsMovingActionsDone(List<MoveItem> actions)
  1953. {
  1954. foreach(var ac in actions)
  1955. {
  1956. var task = _lstWaferTasks.Find(wafer => (wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot) || (wafer.currentMod == ac.DestinationModule && wafer.currentSlot == ac.DestinationSlot));
  1957. if (task != null && task.movingStatus == RState.Running)
  1958. return false; ;
  1959. }
  1960. return true;
  1961. }
  1962. private bool IsLLReservedByTM(ModuleName ll)
  1963. {
  1964. foreach(var item in _curTmAction)
  1965. {
  1966. if (item.DestinationModule == ll || item.SourceModule == ll)
  1967. return true;
  1968. }
  1969. foreach(var action in _tmSchdActions)
  1970. {
  1971. foreach(var item in action)
  1972. {
  1973. if (item.DestinationModule == ll || item.SourceModule == ll)
  1974. return true;
  1975. }
  1976. }
  1977. return false;
  1978. }
  1979. private bool IsLLReservedByEFEM(ModuleName ll)
  1980. {
  1981. foreach (var item in _curEfemAction)
  1982. {
  1983. if (item.DestinationModule == ll || item.SourceModule == ll)
  1984. return true;
  1985. }
  1986. foreach (var action in _efemSchdActions)
  1987. {
  1988. foreach (var item in action)
  1989. {
  1990. if (item.DestinationModule == ll || item.SourceModule == ll)
  1991. return true;
  1992. }
  1993. }
  1994. return false;
  1995. }
  1996. private void RunSchdEFEMActions()
  1997. {
  1998. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  1999. if (efemRobot == null || !efemRobot.IsAvailable)
  2000. return;
  2001. if (_dictModuleTask[ModuleName.EfemRobot].IsIdle)
  2002. {
  2003. if(_efemSchdActions.Count > 0 )
  2004. {
  2005. if(_curEfemAction.Count == 0 || IsMovingActionsDone(_curEfemAction))
  2006. {
  2007. var nextActions = _efemSchdActions.First();
  2008. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2009. return;
  2010. var nextModule = nextActions.First().Module;
  2011. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  2012. return;
  2013. _curEfemAction = _efemSchdActions.Dequeue();
  2014. foreach (var action in _curEfemAction)
  2015. {
  2016. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2017. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2018. //--2024-03-21 增加了PortJobWaferStart 上报事件 start--
  2019. if (ModuleHelper.IsLoadPort(action.SourceModule))
  2020. {
  2021. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.SourceModule);
  2022. if(currentControlJob!=null)
  2023. {
  2024. _faCallback.JobWaferStart(currentControlJob, action.SourceSlot);
  2025. }
  2026. }
  2027. if(ModuleHelper.IsLoadPort(action.DestinationModule))
  2028. {
  2029. ControlJobInfo currentControlJob = GetLoadPortCurrentControlJob(action.DestinationModule);
  2030. if (currentControlJob != null)
  2031. {
  2032. _faCallback.JobWaferEnd(currentControlJob, action.SourceSlot);
  2033. }
  2034. }
  2035. //--2024-03-21 增加了PortJobWaferStart 上报事件 end--
  2036. }
  2037. (_dictModuleTask[ModuleName.EfemRobot].Scheduler as SchedulerEfemRobot).PostMoveItems(_curEfemAction.ToArray());
  2038. }
  2039. }
  2040. else if(_curEfemAction.Count >= 0 && IsMovingActionsDone(_curEfemAction)) // all scheduled actions done
  2041. {
  2042. _curEfemAction.Clear();
  2043. }
  2044. }
  2045. }
  2046. private void RunSchdTMActions()
  2047. {
  2048. if (_dictModuleTask[ModuleName.TMRobot].IsIdle)
  2049. {
  2050. if (_tmSchdActions.Count > 0)
  2051. {
  2052. if (_curTmAction.Count == 0 || IsMovingActionsDone(_curTmAction))
  2053. {
  2054. var nextActions = _tmSchdActions.First();
  2055. if (nextActions.Exists(action => !_lstWaferTasks.Exists(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot)))
  2056. return;
  2057. if (ModuleHelper.IsPm(nextActions.First().Module) && !_dictModuleTask[nextActions.First().Module].IsIdle) /// wait PMTask status update to idle
  2058. return;
  2059. _curTmAction = _tmSchdActions.Dequeue();
  2060. foreach(var action in _curTmAction)
  2061. {
  2062. var waferTask = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2063. waferTask.MoveTo(action.DestinationModule, action.DestinationSlot);
  2064. }
  2065. (_dictModuleTask[ModuleName.TMRobot].Scheduler as SchedulerTMRobot).SendMoveItems(_curTmAction.ToArray());
  2066. }
  2067. }
  2068. else if (_curTmAction.Count >= 0 && IsMovingActionsDone(_curTmAction)) // all scheduled actions done
  2069. {
  2070. _curTmAction.Clear();
  2071. }
  2072. }
  2073. }
  2074. private int TimeForNextModuleReady(WaferTask task)
  2075. {
  2076. if (ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2077. return _dictModuleTask[task.destMod].TimeToReady;
  2078. var llbWaferStatus = GetLLReadyInOutSlots(ModuleName.LLB);
  2079. var llaWaferStatus = GetLLReadyInOutSlots(ModuleName.LLA);
  2080. if (ModuleHelper.IsLoadPort(task.destMod) && (ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2081. {
  2082. if (task.llInOutPath == SequenceLLInOutPath.AInBOut || task.llInOutPath == SequenceLLInOutPath.BInBOut)
  2083. {
  2084. if(llbWaferStatus.emptySlot.Count > 0)
  2085. {
  2086. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2087. }
  2088. }
  2089. else if(task.llInOutPath == SequenceLLInOutPath.BInAOut || task.llInOutPath == SequenceLLInOutPath.AInAOut)
  2090. {
  2091. if(llaWaferStatus.emptySlot.Count > 0)
  2092. {
  2093. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2094. }
  2095. }
  2096. else if(task.llInOutPath == SequenceLLInOutPath.DInDOut)
  2097. {
  2098. if(llaWaferStatus.emptySlot.Count > 0 && llbWaferStatus.emptySlot.Count > 0)
  2099. {
  2100. if (_dictModuleTask[ModuleName.LLA].TimeToReady == _dictModuleTask[ModuleName.LLB].TimeToReady)
  2101. {
  2102. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2103. }
  2104. else
  2105. {
  2106. return Math.Min(_dictModuleTask[ModuleName.LLA].TimeToReady, _dictModuleTask[ModuleName.LLB].TimeToReady);
  2107. }
  2108. }
  2109. else if(llaWaferStatus.emptySlot.Count > 0)
  2110. {
  2111. return _dictModuleTask[ModuleName.LLA].TimeToReady;
  2112. }
  2113. else if(llbWaferStatus.emptySlot.Count > 0)
  2114. {
  2115. return _dictModuleTask[ModuleName.LLB].TimeToReady;
  2116. }
  2117. }
  2118. }
  2119. else if(ModuleHelper.IsPm(task.destMod) && (ModuleHelper.IsLoadLock(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod)))
  2120. {
  2121. if(_lstWaferTasks.Find(wafer => wafer.currentMod == task.destMod || wafer.routedMod == task.destMod) == null)
  2122. {
  2123. return _dictModuleTask[task.destMod].TimeToReady;
  2124. }
  2125. }
  2126. return int.MaxValue;
  2127. }
  2128. List<Hand> GetTMValidFreeHands(List<WaferTask> robotWafers, List<MoveItem> swapActions)
  2129. {
  2130. var hands = new List<Hand>();
  2131. for(int i = 0; i < 2; i++)
  2132. {
  2133. if(_tmRobotSingleArmOption == 0 || _tmRobotSingleArmOption == i + 1)
  2134. {
  2135. if ((!robotWafers.Exists(wafer => wafer.currentSlot == i) ||
  2136. ( robotWafers.Exists(wafer => wafer.currentSlot == i) &&
  2137. swapActions.Exists(item => item.SourceModule == ModuleName.TMRobot && item.SourceSlot == i))) &&
  2138. !swapActions.Exists(item => item.DestinationModule == ModuleName.TMRobot && item.DestinationSlot == i))
  2139. hands.Add((Hand)i);
  2140. }
  2141. }
  2142. return hands;
  2143. }
  2144. (ModuleName llPath, List<MoveItem> swapActions) FindBestLLSwapPlan(ModuleName ll, List<WaferTask> robotWafers)
  2145. {
  2146. ModuleName path = ll == ModuleName.System ? ModuleName.System : ll;
  2147. List<ModuleName> lls = ll == ModuleName.System ? new List<ModuleName> { ModuleName.LLA, ModuleName.LLB } : new List<ModuleName> { ll };
  2148. List<MoveItem> actions = new List<MoveItem>();
  2149. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2150. foreach (var loadlock in lls)
  2151. {
  2152. llSwapActions[loadlock] = new List<MoveItem>();
  2153. if (IsLLReservedByEFEM(loadlock))
  2154. continue;
  2155. var llWaferStatus = GetLLReadyInOutSlots(loadlock);
  2156. foreach(var wafer in robotWafers)
  2157. {
  2158. if(_dictModuleTask[loadlock].TimeToReady == 0 && !IsLLReservedByEFEM(loadlock) && CanWaferGotoLL(wafer,loadlock) && llWaferStatus.emptySlot.Count > llSwapActions[loadlock].Count)
  2159. {
  2160. llSwapActions[loadlock].Add(new MoveItem(ModuleName.TMRobot, wafer.currentSlot, loadlock, llWaferStatus.emptySlot[llSwapActions[loadlock].Count], (Hand)wafer.currentSlot));
  2161. }
  2162. }
  2163. int prePickTime = 20;
  2164. int prePickCount = 0;
  2165. var hands = GetTMValidFreeHands(robotWafers, llSwapActions[loadlock]);
  2166. foreach (var slot in llWaferStatus.inSlot)
  2167. {
  2168. var wafer = _lstWaferTasks.Find(task => task.currentMod == loadlock && task.currentSlot == slot);
  2169. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && hands.Count > prePickCount)
  2170. {
  2171. if(_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2172. {
  2173. 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))
  2174. {
  2175. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2176. prePickCount++;
  2177. break;
  2178. }
  2179. }
  2180. else
  2181. {
  2182. llSwapActions[loadlock].Add(new MoveItem(loadlock, slot, ModuleName.TMRobot, (int)hands[prePickCount], hands[prePickCount]));
  2183. prePickCount++;
  2184. }
  2185. }
  2186. }
  2187. }
  2188. var validateActions = llSwapActions.Where(item => item.Value.Count > 0).ToDictionary(k => k.Key, v => v.Value);
  2189. if(validateActions.Count == 1)
  2190. {
  2191. (path, actions) = (validateActions.First().Key, validateActions.First().Value);
  2192. }
  2193. else if(validateActions.Count == 2)
  2194. {
  2195. var sortedActions = validateActions.OrderByDescending(item => item.Value.Count + (_dictModuleTask[item.Key].Scheduler.IsVac ? 2 : 0)).ToDictionary(k => k.Key, v => v.Value);
  2196. (path, actions) = (sortedActions.First().Key, sortedActions.First().Value);
  2197. }
  2198. return (path, actions);
  2199. }
  2200. (List<WaferTask> pmWafers, ModuleName destLL, List<MoveItem> swapAction) FindBestReturnWafersPlan(Hand[] freeHands)
  2201. {
  2202. Dictionary<ModuleName, List<WaferTask>> returnWafers = new Dictionary<ModuleName, List<WaferTask>>();
  2203. Dictionary<ModuleName, List<MoveItem>> llSwapActions = new Dictionary<ModuleName, List<MoveItem>>();
  2204. Dictionary<ModuleName, int> llValues = new Dictionary<ModuleName, int>();
  2205. foreach(var ll in new List<ModuleName> { ModuleName.LLA, ModuleName.LLB})
  2206. {
  2207. var llWaferStatus = GetLLReadyInOutSlots(ll);
  2208. returnWafers[ll] = new List<WaferTask>();
  2209. llSwapActions[ll] = new List<MoveItem>();
  2210. llValues[ll] = 0;
  2211. if (IsLLReservedByEFEM(ll))
  2212. continue;
  2213. var readyReturnWafers = _lstWaferTasks.Where( wafer => ModuleHelper.IsPm(wafer.currentMod) &&
  2214. ModuleHelper.IsLoadPort(wafer.destMod) &&
  2215. wafer.movingStatus == RState.End &&
  2216. _dictModuleTask[wafer.currentMod].TimeToReady <= 2 &&
  2217. CanWaferGotoLL(wafer, ll)).Take(Math.Min(freeHands.Length, llWaferStatus.emptySlot.Count)).ToList();
  2218. int prePickTime = 10 * llSwapActions[ll].Count;
  2219. int handIndex = 0;
  2220. if(_dictModuleTask[ll].TimeToReady <= prePickTime)
  2221. {
  2222. foreach (var wafer in readyReturnWafers)
  2223. {
  2224. if(handIndex < freeHands.Length)
  2225. {
  2226. returnWafers[ll].Add(wafer);
  2227. llSwapActions[ll].Add(new MoveItem(ModuleName.TMRobot, (int)freeHands[handIndex], ll, llWaferStatus.emptySlot[handIndex], freeHands[handIndex]));
  2228. handIndex++;
  2229. }
  2230. }
  2231. int prePickCount = 0;
  2232. handIndex = 0;
  2233. foreach (var slot in llWaferStatus.inSlot)
  2234. {
  2235. var wafer = _lstWaferTasks.Find(task => task.currentMod == ll && task.currentSlot == slot);
  2236. if (wafer != null && _dictModuleTask[wafer.destMod].TimeToReady <= prePickTime && _dictModuleTask[wafer.destMod].Scheduler.IsOnline && freeHands.Length > prePickCount)
  2237. {
  2238. if (_lstWaferTasks.Exists(task => task.currentMod == wafer.destMod))
  2239. {
  2240. 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))
  2241. {
  2242. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2243. prePickCount++;
  2244. break;
  2245. }
  2246. }
  2247. else
  2248. {
  2249. llSwapActions[ll].Add(new MoveItem(ll, slot, ModuleName.TMRobot, (int)freeHands[prePickCount], freeHands[prePickCount]));
  2250. prePickCount++;
  2251. }
  2252. }
  2253. }
  2254. llValues[ll] = returnWafers[ll].Count * 2 + llSwapActions[ll].Count + (_dictModuleTask[ll].Scheduler.IsVac && returnWafers[ll].Count > 0 ? 2 : 0);
  2255. }
  2256. }
  2257. var preferLL = llValues.OrderByDescending(v => v.Value).First().Key;
  2258. return (returnWafers[preferLL], preferLL, llSwapActions[preferLL]);
  2259. }
  2260. void RoutingTMSwapActions(List<MoveItem> actions)
  2261. {
  2262. foreach (var action in actions)
  2263. {
  2264. if (ModuleHelper.IsTMRobot(action.SourceModule))
  2265. {
  2266. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == ModuleName.TMRobot && wafer.currentSlot == action.SourceSlot);
  2267. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2268. }
  2269. else
  2270. {
  2271. var waferTask = _lstWaferTasks.Find(wafer => wafer.currentMod == action.SourceModule && wafer.currentSlot == action.SourceSlot);
  2272. waferTask.RouteTo(action.DestinationModule, action.DestinationSlot);
  2273. }
  2274. }
  2275. }
  2276. private bool ManaulReturnPMWafer()
  2277. {
  2278. var mReturnWafer = _qeReturnWafers.Peek();
  2279. if (ModuleHelper.IsPm((ModuleName)mReturnWafer.Station))
  2280. {
  2281. var hands = GetTMValidFreeHands(_lstWaferTasks.Where(wt => ModuleHelper.IsTMRobot(wt.currentMod)).ToList(), new List<MoveItem>());
  2282. var waferTask = _lstWaferTasks.Find(wt => wt.currentMod == (ModuleName)mReturnWafer.Station && wt.waferId == mReturnWafer.InnerId);
  2283. if (waferTask != null && hands.Count > 0)
  2284. {
  2285. waferTask.Return();
  2286. var outLL = _dictModuleTask.Where(mod => ModuleHelper.IsLoadLock(mod.Key) && CanWaferGotoLL(waferTask, mod.Key) && GetLLReadyInOutSlots(mod.Key).emptySlot.Count > 0 && !IsLLReservedByEFEM(mod.Key));
  2287. if (outLL.Count() > 0)
  2288. {
  2289. var slot = GetLLReadyInOutSlots(outLL.First().Key).emptySlot.First();
  2290. waferTask.RouteTo(outLL.First().Key, slot);
  2291. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(waferTask.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2292. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL.First().Key, slot, hands.First()) });
  2293. _qeReturnWafers.Dequeue();
  2294. return true;
  2295. }
  2296. }
  2297. }
  2298. return false;
  2299. }
  2300. private void RoutingVacWafers()
  2301. {
  2302. if(_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2303. {
  2304. RunSchdTMActions();
  2305. return;
  2306. }
  2307. if(_tmRobotStatus == RState.End)
  2308. {
  2309. // handle manual return wafer if exist
  2310. if(_qeReturnWafers.Count > 0)
  2311. {
  2312. if (ManaulReturnPMWafer())
  2313. return;
  2314. }
  2315. if(_LLASlotNumber == 2)
  2316. {
  2317. Routing2SlotVacSystem();
  2318. }
  2319. else if(_LLASlotNumber == 4)
  2320. {
  2321. Routing4SlotVacSystem();
  2322. }
  2323. }
  2324. }
  2325. private void Routing2SlotVacSystem()
  2326. {
  2327. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2328. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2329. {
  2330. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2331. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2332. var inLLWaferStatus = GetLLReadyInOutSlots(inLL);
  2333. var outLLWaferStatus = GetLLReadyInOutSlots(outLL);
  2334. if(robotWafers.Count == 2)
  2335. {
  2336. int returnCount = 0;
  2337. foreach (var wafer in robotWafers)
  2338. {
  2339. if (ModuleHelper.IsPm(wafer.destMod))
  2340. {
  2341. if (_dictModuleTask[wafer.destMod].TimeToReady <= 5 &&
  2342. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2343. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2344. {
  2345. wafer.RouteTo(wafer.destMod, 0);
  2346. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2347. }
  2348. }
  2349. else
  2350. {
  2351. if (_dictModuleTask[outLL].TimeToReady <= 5 && !IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > returnCount)
  2352. {
  2353. wafer.RouteTo(outLL, outLLWaferStatus.emptySlot[returnCount]);
  2354. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, outLL, outLLWaferStatus.emptySlot[returnCount], (Hand)wafer.currentSlot) });
  2355. returnCount++;
  2356. }
  2357. }
  2358. }
  2359. }
  2360. else if(robotWafers.Count == 1)
  2361. {
  2362. int freeHand = 1 - robotWafers.First().currentSlot;
  2363. if (ModuleHelper.IsPm(robotWafers.First().destMod))
  2364. {
  2365. if(_dictModuleTask[robotWafers.First().destMod].TimeToReady <= 5)
  2366. {
  2367. if(_lstWaferTasks.Exists(waferT => waferT.currentMod == robotWafers.First().destMod))
  2368. {
  2369. var pmActions = new List<MoveItem>();
  2370. var pmWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == robotWafers.First().destMod);
  2371. pmWafer.RouteTo(ModuleName.TMRobot, freeHand);
  2372. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, freeHand, (Hand)freeHand));
  2373. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers.First().currentSlot));
  2374. _tmSchdActions.Enqueue(pmActions);
  2375. }
  2376. else
  2377. {
  2378. robotWafers.First().RouteTo(robotWafers.First().destMod, 0);
  2379. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, robotWafers.First().destMod, 0, (Hand)robotWafers.First().currentSlot) });
  2380. }
  2381. }
  2382. }
  2383. else
  2384. {
  2385. if (_dictModuleTask[outLL].TimeToReady <= 5 && !IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0)
  2386. {
  2387. robotWafers.First().RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2388. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, robotWafers.First().currentSlot, outLL, outLLWaferStatus.emptySlot[0], (Hand)robotWafers.First().currentSlot) });
  2389. }
  2390. }
  2391. if (_tmSchdActions.Count == 0 && _tmRobotSingleArmOption == 0)
  2392. {
  2393. // try push in one wafer
  2394. if (!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].Scheduler.IsVac && inLLWaferStatus.inSlot.Count > 0)
  2395. {
  2396. foreach (var slot in inLLWaferStatus.inSlot)
  2397. {
  2398. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == inLL && wafer.currentSlot == slot);
  2399. if (llWafer != null && !_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].TimeToReady < 15)
  2400. {
  2401. llWafer.RouteTo(llWafer.destMod, 0);
  2402. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, slot, ModuleName.TMRobot, freeHand, (Hand)freeHand) });
  2403. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, freeHand, llWafer.destMod, 0, (Hand)freeHand) });
  2404. return;
  2405. }
  2406. }
  2407. }
  2408. // try to return one wafer
  2409. if (!IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0)
  2410. {
  2411. var reayReturnWafer = _lstWaferTasks.Find(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2);
  2412. if (reayReturnWafer != null)
  2413. {
  2414. reayReturnWafer.RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2415. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(reayReturnWafer.currentMod, 0, ModuleName.TMRobot, freeHand, (Hand)freeHand) });
  2416. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, freeHand, outLL, outLLWaferStatus.emptySlot[0], (Hand)freeHand) });
  2417. return;
  2418. }
  2419. }
  2420. }
  2421. }
  2422. else // no wafer on robot arm
  2423. {
  2424. var readyInPms = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && !_lstWaferTasks.Exists(wt => wt.currentMod == mod.Key) && mod.Value.Scheduler.IsOnline && mod.Value.TimeToReady <= 15);
  2425. var readyOutWafers = _lstWaferTasks.Where(wt => ModuleHelper.IsPm(wt.currentMod) && ModuleHelper.IsLoadPort(wt.destMod) && _dictModuleTask[wt.currentMod].TimeToReady <= 2).ToList() ;
  2426. if(_tmRobotSingleArmOption != 0)
  2427. {
  2428. var hands = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2429. if (hands.Count == 0)
  2430. return;
  2431. if(!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].TimeToReady <= 5 && inLLWaferStatus.inSlot.Count > 0 && readyInPms.Count() > 0)
  2432. {
  2433. foreach(var pm in readyInPms)
  2434. {
  2435. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && inLLWaferStatus.inSlot.Contains(wt.currentSlot) && wt.destMod == pm.Key);
  2436. if(llWafer != null)
  2437. {
  2438. llWafer.RouteTo(llWafer.destMod, 0);
  2439. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2440. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), llWafer.destMod, 0, hands.First()) });
  2441. return;
  2442. }
  2443. }
  2444. }
  2445. if(readyOutWafers.Count > 0 && !IsLLReservedByEFEM(outLL) && _dictModuleTask[outLL].TimeToReady < 50 && outLLWaferStatus.emptySlot.Count > 0)
  2446. {
  2447. var returnWafer = readyOutWafers.First();
  2448. returnWafer.RouteTo(outLL, outLLWaferStatus.emptySlot.First());
  2449. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(returnWafer.currentMod, 0, ModuleName.TMRobot, (int)hands.First(), hands.First()) });
  2450. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)hands.First(), outLL, outLLWaferStatus.emptySlot.First(), hands.First()) });
  2451. return;
  2452. }
  2453. return;
  2454. }
  2455. if(!IsLLReservedByEFEM(inLL) && _dictModuleTask[inLL].TimeToReady <= 5 && inLLWaferStatus.inSlot.Count > 0)
  2456. {
  2457. if(inLLWaferStatus.inSlot.Count == 2)
  2458. {
  2459. if(readyInPms.Count() > 0) // double move from LL to PM
  2460. {
  2461. int pickCount = 0;
  2462. var swapActions = new List<MoveItem>();
  2463. var singleActions = new List<MoveItem>();
  2464. foreach(var pm in readyInPms)
  2465. {
  2466. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && inLLWaferStatus.inSlot.Contains(wt.currentSlot) && wt.destMod == pm.Key);
  2467. if(llWafer != null)
  2468. {
  2469. llWafer.RouteTo(pm.Key, 0);
  2470. swapActions.Add(new MoveItem(inLL, llWafer.currentSlot, ModuleName.TMRobot, pickCount, (Hand)pickCount));
  2471. singleActions.Add(new MoveItem(ModuleName.TMRobot, pickCount, pm.Key, 0, (Hand)pickCount));
  2472. pickCount++;
  2473. }
  2474. }
  2475. if(pickCount == 1)
  2476. {
  2477. int remainSlot = swapActions.First().SourceSlot == inLLWaferStatus.inSlot[0] ? inLLWaferStatus.inSlot[1] : inLLWaferStatus.inSlot[0];
  2478. var remainWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == remainSlot);
  2479. if (remainWafer != null)
  2480. {
  2481. remainWafer.RouteTo(ModuleName.TMRobot, 1);
  2482. swapActions.Add(new MoveItem(inLL, remainSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  2483. }
  2484. }
  2485. if(swapActions.Count > 0)
  2486. {
  2487. _tmSchdActions.Enqueue(swapActions);
  2488. foreach(var ac in singleActions)
  2489. {
  2490. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  2491. }
  2492. }
  2493. }
  2494. else
  2495. {
  2496. foreach(var slot in inLLWaferStatus.inSlot)
  2497. {
  2498. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == slot);
  2499. if (llWafer != null)
  2500. {
  2501. if(!_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].Scheduler.IsOnline)
  2502. {
  2503. var swapActions = new List<MoveItem>();
  2504. swapActions.Add(new MoveItem(inLL, slot, ModuleName.TMRobot, 0, Hand.Blade1));
  2505. int remainSlot = slot == inLLWaferStatus.inSlot[0] ? inLLWaferStatus.inSlot[1] : inLLWaferStatus.inSlot[0];
  2506. swapActions.Add(new MoveItem(inLL, remainSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  2507. _tmSchdActions.Enqueue(swapActions);
  2508. llWafer.RouteTo(ModuleName.TMRobot, 0);
  2509. if (_dictModuleTask[llWafer.destMod].TimeToReady <= 30)
  2510. {
  2511. llWafer.RouteTo(llWafer.destMod, 0);
  2512. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, 0, llWafer.destMod, 0, Hand.Blade1) });
  2513. }
  2514. return;
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. else
  2521. {
  2522. var llWafer = _lstWaferTasks.Find(wt => wt.currentMod == inLL && wt.currentSlot == inLLWaferStatus.inSlot.First());
  2523. if (llWafer != null)
  2524. {
  2525. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(inLL, inLLWaferStatus.inSlot.First(), ModuleName.TMRobot, 0, Hand.Blade1) });
  2526. if (!_lstWaferTasks.Exists(wt => wt.currentMod == llWafer.destMod) && _dictModuleTask[llWafer.destMod].TimeToReady < 15)
  2527. {
  2528. llWafer.RouteTo(llWafer.destMod, 0);
  2529. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, 0, llWafer.destMod, 0, Hand.Blade1) });
  2530. }
  2531. }
  2532. }
  2533. }
  2534. if (_tmSchdActions.Count > 0)
  2535. return;
  2536. if(!IsLLReservedByEFEM(outLL) && outLLWaferStatus.emptySlot.Count > 0 && readyOutWafers.Count > 0)
  2537. {
  2538. if(readyOutWafers.Count >= 2 && outLLWaferStatus.emptySlot.Count == 2)
  2539. {
  2540. readyOutWafers[0].RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2541. readyOutWafers[1].RouteTo(outLL, outLLWaferStatus.emptySlot[1]);
  2542. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[0].currentMod, readyOutWafers[0].currentSlot, ModuleName.TMRobot, 0, Hand.Blade1) });
  2543. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[1].currentMod, readyOutWafers[1].currentSlot, ModuleName.TMRobot, 1, Hand.Blade2) });
  2544. var swapActions = new List<MoveItem>();
  2545. swapActions.Add(new MoveItem(ModuleName.TMRobot, 0, outLL, outLLWaferStatus.emptySlot[0], Hand.Blade1));
  2546. swapActions.Add(new MoveItem(ModuleName.TMRobot, 1, outLL, outLLWaferStatus.emptySlot[1], Hand.Blade2));
  2547. _tmSchdActions.Enqueue(swapActions);
  2548. }
  2549. else
  2550. {
  2551. var freeHands = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2552. readyOutWafers[0].RouteTo(outLL, outLLWaferStatus.emptySlot[0]);
  2553. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(readyOutWafers[0].currentMod, readyOutWafers[0].currentSlot, ModuleName.TMRobot, (int)freeHands[0], freeHands[0]) });
  2554. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, (int)freeHands[0], outLL, outLLWaferStatus.emptySlot[0], freeHands[0]) });
  2555. }
  2556. }
  2557. }
  2558. }
  2559. else
  2560. {
  2561. if (robotWafers.Count == 2)
  2562. {
  2563. foreach (var wafer in robotWafers)
  2564. {
  2565. if (wafer.movingStatus == RState.End &&
  2566. ModuleHelper.IsPm(wafer.destMod) &&
  2567. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  2568. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2569. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2570. {
  2571. wafer.RouteTo(wafer.destMod, 0);
  2572. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2573. }
  2574. }
  2575. if (_tmSchdActions.Count == 0)
  2576. {
  2577. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2578. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2579. {
  2580. RoutingTMSwapActions(swapActions.swapActions);
  2581. _tmSchdActions.Enqueue(swapActions.swapActions);
  2582. }
  2583. }
  2584. }
  2585. else if (robotWafers.Count == 1)
  2586. {
  2587. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  2588. {
  2589. var pmActions = new List<MoveItem>();
  2590. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  2591. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  2592. {
  2593. int pickSlot = 1 - robotWafers[0].currentSlot;
  2594. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  2595. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  2596. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  2597. _tmSchdActions.Enqueue(pmActions);
  2598. return;
  2599. }
  2600. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  2601. {
  2602. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  2603. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  2604. _tmSchdActions.Enqueue(pmActions);
  2605. return;
  2606. }
  2607. }
  2608. // try to pick a wafer from LL
  2609. if (_tmSchdActions.Count == 0)
  2610. {
  2611. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2612. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2613. {
  2614. RoutingTMSwapActions(swapActions.swapActions);
  2615. _tmSchdActions.Enqueue(swapActions.swapActions);
  2616. return;
  2617. }
  2618. }
  2619. // try to return a wafer from PM
  2620. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2621. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2622. if (moveActions.pmWafers.Count > 0)
  2623. {
  2624. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2625. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  2626. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  2627. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  2628. if (pickAction != null)
  2629. {
  2630. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  2631. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  2632. }
  2633. _tmSchdActions.Enqueue(moveActions.swapAction);
  2634. }
  2635. }
  2636. else // robot arm is empty
  2637. {
  2638. // try return wafers from PM
  2639. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2640. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2641. if (moveActions.pmWafers.Count > 0)
  2642. {
  2643. int handIndex = 0;
  2644. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2645. foreach (var action in placeActions)
  2646. {
  2647. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  2648. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  2649. handIndex++;
  2650. }
  2651. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  2652. foreach (var ac in pickActions)
  2653. {
  2654. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  2655. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  2656. }
  2657. _tmSchdActions.Enqueue(moveActions.swapAction);
  2658. }
  2659. if (_tmSchdActions.Count == 0)
  2660. {
  2661. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2662. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2663. {
  2664. RoutingTMSwapActions(swapActions.swapActions);
  2665. _tmSchdActions.Enqueue(swapActions.swapActions);
  2666. }
  2667. }
  2668. }
  2669. }
  2670. }
  2671. private void Routing4SlotVacSystem()
  2672. {
  2673. var robotWafers = _lstWaferTasks.Where(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && ModuleHelper.IsTMRobot(wafer.currentMod)).OrderBy(wafer => TimeForNextModuleReady(wafer)).ToList();
  2674. if (robotWafers.Count == 2)
  2675. {
  2676. foreach (var wafer in robotWafers)
  2677. {
  2678. if (wafer.movingStatus == RState.End &&
  2679. ModuleHelper.IsPm(wafer.destMod) &&
  2680. _dictModuleTask[wafer.destMod].TimeToReady == 0 &&
  2681. !_lstWaferTasks.Exists(waferT => waferT.currentMod == wafer.destMod) &&
  2682. !_lstWaferTasks.Exists(waferT => waferT.routedMod == wafer.destMod))
  2683. {
  2684. wafer.RouteTo(wafer.destMod, 0);
  2685. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.TMRobot, wafer.currentSlot, wafer.destMod, 0, (Hand)wafer.currentSlot) });
  2686. }
  2687. }
  2688. if (_tmSchdActions.Count == 0)
  2689. {
  2690. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2691. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2692. {
  2693. RoutingTMSwapActions(swapActions.swapActions);
  2694. _tmSchdActions.Enqueue(swapActions.swapActions);
  2695. }
  2696. }
  2697. }
  2698. else if (robotWafers.Count == 1)
  2699. {
  2700. if (ModuleHelper.IsPm(robotWafers[0].destMod) && _dictModuleTask[robotWafers[0].destMod].TimeToReady == 0)
  2701. {
  2702. var pmActions = new List<MoveItem>();
  2703. var pmWafer = _lstWaferTasks.Find(wafer => (wafer.movingStatus == RState.End || wafer.movingStatus == RState.Init) && wafer.currentMod == robotWafers[0].destMod && ModuleHelper.IsLoadPort(wafer.destMod));
  2704. if (pmWafer != null && string.IsNullOrWhiteSpace(pmWafer.wtwCleanRecipe))
  2705. {
  2706. int pickSlot = 1 - robotWafers[0].currentSlot;
  2707. pmWafer.RouteTo(ModuleName.TMRobot, pickSlot);
  2708. pmActions.Add(new MoveItem(pmWafer.currentMod, 0, ModuleName.TMRobot, pickSlot, (Hand)pickSlot));
  2709. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, pmWafer.currentMod, 0, (Hand)robotWafers[0].currentSlot));
  2710. _tmSchdActions.Enqueue(pmActions);
  2711. return;
  2712. }
  2713. if (!_lstWaferTasks.Exists(wafer => wafer.currentMod == robotWafers[0].destMod))
  2714. {
  2715. robotWafers[0].RouteTo(robotWafers[0].destMod, 0);
  2716. pmActions.Add(new MoveItem(ModuleName.TMRobot, robotWafers[0].currentSlot, robotWafers[0].destMod, 0, (Hand)robotWafers[0].currentSlot));
  2717. _tmSchdActions.Enqueue(pmActions);
  2718. return;
  2719. }
  2720. }
  2721. // try to pick a wafer from LL
  2722. if (_tmSchdActions.Count == 0)
  2723. {
  2724. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2725. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2726. {
  2727. RoutingTMSwapActions(swapActions.swapActions);
  2728. _tmSchdActions.Enqueue(swapActions.swapActions);
  2729. return;
  2730. }
  2731. }
  2732. // try to return a wafer from PM
  2733. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2734. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2735. if (moveActions.pmWafers.Count > 0)
  2736. {
  2737. MoveItem placeAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2738. moveActions.pmWafers.First().RouteTo(placeAction.DestinationModule, placeAction.DestinationSlot);
  2739. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers.First().currentMod, 0, ModuleName.TMRobot, (int)freeHand[0], freeHand[0]) });
  2740. MoveItem pickAction = moveActions.swapAction.Find(ac => ModuleHelper.IsLoadLock(ac.SourceModule));
  2741. if (pickAction != null)
  2742. {
  2743. var pickWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == pickAction.SourceModule && wafer.currentSlot == pickAction.SourceSlot);
  2744. pickWafer.RouteTo(pickAction.DestinationModule, pickAction.DestinationSlot);
  2745. }
  2746. _tmSchdActions.Enqueue(moveActions.swapAction);
  2747. }
  2748. }
  2749. else // robot arm is empty
  2750. {
  2751. // try return wafers from PM
  2752. var freeHand = GetTMValidFreeHands(robotWafers, new List<MoveItem>());
  2753. var moveActions = FindBestReturnWafersPlan(freeHand.ToArray());
  2754. if (moveActions.pmWafers.Count > 0)
  2755. {
  2756. int handIndex = 0;
  2757. var placeActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.DestinationModule));
  2758. foreach (var action in placeActions)
  2759. {
  2760. moveActions.pmWafers[handIndex].RouteTo(action.DestinationModule, action.DestinationSlot);
  2761. _tmSchdActions.Enqueue(new List<MoveItem> { new MoveItem(moveActions.pmWafers[handIndex].currentMod, 0, ModuleName.TMRobot, (int)freeHand[handIndex], freeHand[handIndex]) });
  2762. handIndex++;
  2763. }
  2764. var pickActions = moveActions.swapAction.Where(ac => ModuleHelper.IsLoadLock(ac.SourceModule)).ToList();
  2765. foreach (var ac in pickActions)
  2766. {
  2767. var llWafer = _lstWaferTasks.Find(wafer => wafer.currentMod == ac.SourceModule && wafer.currentSlot == ac.SourceSlot);
  2768. llWafer.RouteTo(ac.DestinationModule, ac.DestinationSlot);
  2769. }
  2770. _tmSchdActions.Enqueue(moveActions.swapAction);
  2771. }
  2772. if (_tmSchdActions.Count == 0)
  2773. {
  2774. var swapActions = FindBestLLSwapPlan(ModuleName.System, robotWafers);
  2775. if (swapActions.llPath != ModuleName.System && swapActions.swapActions.Count > 0)
  2776. {
  2777. RoutingTMSwapActions(swapActions.swapActions);
  2778. _tmSchdActions.Enqueue(swapActions.swapActions);
  2779. }
  2780. }
  2781. }
  2782. }
  2783. private List<Hand> GetTMFreeHand()
  2784. {
  2785. var lstHands = new List<Hand>();
  2786. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _tmRobotSingleArmOption != 2)
  2787. lstHands.Add(Hand.Blade1);
  2788. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _tmRobotSingleArmOption != 1)
  2789. lstHands.Add(Hand.Blade2);
  2790. return lstHands;
  2791. }
  2792. private List<Hand> GetEFEMFreeHand()
  2793. {
  2794. var lstHands = new List<Hand>();
  2795. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && _efemRobotSingleArmOption != 2)
  2796. lstHands.Add(Hand.Blade1);
  2797. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && _efemRobotSingleArmOption != 1)
  2798. lstHands.Add(Hand.Blade2);
  2799. return lstHands;
  2800. }
  2801. private bool CanWaferGotoLL(WaferTask task, ModuleName ll)
  2802. {
  2803. bool bVacWafer = ModuleHelper.IsPm(task.currentMod) || ModuleHelper.IsTMRobot(task.currentMod);
  2804. if (bVacWafer)
  2805. {
  2806. if (ModuleHelper.IsPm(task.destMod))
  2807. return false;
  2808. switch (task.llInOutPath)
  2809. {
  2810. case SequenceLLInOutPath.AInAOut:
  2811. case SequenceLLInOutPath.BInAOut:
  2812. return ll == ModuleName.LLA;
  2813. case SequenceLLInOutPath.AInBOut:
  2814. case SequenceLLInOutPath.BInBOut:
  2815. return ll == ModuleName.LLB;
  2816. case SequenceLLInOutPath.DInDOut:
  2817. return true;
  2818. }
  2819. }
  2820. else
  2821. {
  2822. if (ModuleHelper.IsLoadPort(task.destMod))
  2823. return false;
  2824. switch (task.llInOutPath)
  2825. {
  2826. case SequenceLLInOutPath.AInAOut:
  2827. case SequenceLLInOutPath.AInBOut:
  2828. return ll == ModuleName.LLA;
  2829. case SequenceLLInOutPath.BInAOut:
  2830. case SequenceLLInOutPath.BInBOut:
  2831. return ll == ModuleName.LLB;
  2832. case SequenceLLInOutPath.DInDOut:
  2833. return true;
  2834. }
  2835. }
  2836. return false;
  2837. }
  2838. private (List<int> inSlot, List<int> outSlot, List<int> emptySlot) GetLLReadyInOutSlots(ModuleName ll)
  2839. {
  2840. var readInSlots = new List<int>();
  2841. var readyOutSlots = new List<int>();
  2842. var emptySlots = new List<int>();
  2843. for(int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  2844. {
  2845. 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)))
  2846. {
  2847. emptySlots.Add(slot);
  2848. }
  2849. if(WaferManager.Instance.CheckHasWafer(ll, slot))
  2850. {
  2851. Guid waferID = WaferManager.Instance.GetWafer(ll, slot).InnerId;
  2852. var waferTask = _lstWaferTasks.Find(wafer => wafer.waferId == waferID);
  2853. if(waferTask != null && waferTask.movingStatus == RState.End)
  2854. {
  2855. if (ModuleHelper.IsPm(waferTask.destMod))
  2856. readInSlots.Add(slot);
  2857. else if (_dictModuleTask[ll].Scheduler.WaferArrivedTicks(slot) > waferTask.llDelayTime * 1000)
  2858. readyOutSlots.Add(slot);
  2859. }
  2860. }
  2861. }
  2862. return (readInSlots, readyOutSlots, emptySlots);
  2863. }
  2864. private (List<WaferInfo> wafers, List<int> emptySlots) GetLLWaferExistance(ModuleName ll)
  2865. {
  2866. var lstWafers = new List<WaferInfo>();
  2867. var lstEmptySlots = new List<int>();
  2868. for (int slot = 0; slot < (ll == ModuleName.LLA ? _LLASlotNumber : _LLBSlotNumber); slot++)
  2869. {
  2870. var wafer = WaferManager.Instance.GetWafer(ll, slot);
  2871. if(wafer != null && !wafer.IsEmpty)
  2872. {
  2873. lstWafers.Add(wafer);
  2874. }
  2875. else
  2876. {
  2877. lstEmptySlots.Add(slot);
  2878. }
  2879. }
  2880. return (lstWafers, lstEmptySlots);
  2881. }
  2882. private void PrepareLLPressure()
  2883. {
  2884. var preaparedLLs = new List<ModuleName>();
  2885. var lls = _efemSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  2886. if (_curEfemAction.Count == 0 && _efemSchdActions.Count > 0 && ModuleHelper.IsLoadLock(_efemSchdActions.First().First().Module))
  2887. lls.Remove(_efemSchdActions.First().First().Module);
  2888. foreach(var ll in lls)
  2889. {
  2890. if(_dictModuleTask[ll].Scheduler.IsAvailable && _dictModuleTask[ll].Scheduler.IsVac && !preaparedLLs.Contains(ll))
  2891. {
  2892. (_dictModuleTask[ll].Scheduler as SchedulerLoadLock).PreVent();
  2893. preaparedLLs.Add(ll);
  2894. }
  2895. }
  2896. lls = _tmSchdActions.Where(acs => ModuleHelper.IsLoadLock(acs.First().Module)).Select(item => item.First().Module).ToList();
  2897. if(_curTmAction.Count == 0 && _tmSchdActions.Count > 0 && ModuleHelper.IsLoadLock(_tmSchdActions.First().First().Module))
  2898. lls.Remove(_tmSchdActions.First().First().Module);
  2899. foreach (var ll in lls)
  2900. {
  2901. if (_dictModuleTask[ll].Scheduler.IsAvailable && _dictModuleTask[ll].Scheduler.IsAtm && !preaparedLLs.Contains(ll))
  2902. {
  2903. (_dictModuleTask[ll].Scheduler as SchedulerLoadLock).PrePump();
  2904. preaparedLLs.Add(ll);
  2905. }
  2906. }
  2907. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0 || _tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2908. return;
  2909. if (LLInOutPath == SequenceLLInOutPath.AInBOut || LLInOutPath == SequenceLLInOutPath.BInAOut)
  2910. {
  2911. var inLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLA : ModuleName.LLB;
  2912. var outLL = LLInOutPath == SequenceLLInOutPath.AInBOut ? ModuleName.LLB : ModuleName.LLA;
  2913. var inLLWaferCount = _lstWaferTasks.Where(wafer => wafer.currentMod == inLL).Count();
  2914. var outLLWaferCount = _lstWaferTasks.Where(wafer => wafer.currentMod == outLL).Count();
  2915. if (inLLWaferCount == 0 && !preaparedLLs.Contains(inLL))
  2916. {
  2917. (_dictModuleTask[inLL] as LoadlockTask).PreVent();
  2918. preaparedLLs.Add(inLL);
  2919. }
  2920. else if(inLLWaferCount == (LLInOutPath == SequenceLLInOutPath.AInBOut ? _LLASlotNumber : _LLBSlotNumber) && !preaparedLLs.Contains(inLL))
  2921. {
  2922. (_dictModuleTask[inLL] as LoadlockTask).PrePump();
  2923. preaparedLLs.Add(inLL);
  2924. }
  2925. if(outLLWaferCount == 0 && !preaparedLLs.Contains(outLL))
  2926. {
  2927. (_dictModuleTask[outLL] as LoadlockTask).PrePump();
  2928. preaparedLLs.Add(outLL);
  2929. }
  2930. else if(outLLWaferCount == (LLInOutPath == SequenceLLInOutPath.BInAOut ? _LLASlotNumber : _LLBSlotNumber) && !preaparedLLs.Contains(outLL))
  2931. {
  2932. (_dictModuleTask[outLL] as LoadlockTask).PreVent();
  2933. preaparedLLs.Add(outLL);
  2934. }
  2935. }
  2936. }
  2937. private void ReturnVacWafers()
  2938. {
  2939. if (_tmSchdActions.Count > 0 || _curTmAction.Count > 0)
  2940. {
  2941. RunSchdTMReturnActions();
  2942. return;
  2943. }
  2944. if (_tmRobotStatus != RState.End)
  2945. return;
  2946. var hands = GetTMFreeHand();
  2947. 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);
  2948. if(lls.Count() > 0)
  2949. {
  2950. // return robot wafers
  2951. int moveCount = 0;
  2952. var llActions = new List<MoveItem>();
  2953. var emptySlots = GetLLWaferExistance(lls.First().Key).emptySlots;
  2954. for(int arm = 0; arm < 2; arm++)
  2955. {
  2956. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, arm);
  2957. if(wafer != null && !wafer.IsEmpty && moveCount < emptySlots.Count)
  2958. {
  2959. llActions.Add(new MoveItem(ModuleName.TMRobot, arm, lls.First().Key, emptySlots[moveCount], (Hand)arm));
  2960. moveCount++;
  2961. }
  2962. }
  2963. if(moveCount > 0)
  2964. {
  2965. _tmSchdActions.Enqueue(llActions);
  2966. return;
  2967. }
  2968. // return PM wafers
  2969. var PickActions = new List<MoveItem>();
  2970. var hasWaferPMs = _dictModuleTask.Where(mod => ModuleHelper.IsPm(mod.Key) && mod.Value.Scheduler.IsIdle && WaferManager.Instance.CheckHasWafer(mod.Key, 0));
  2971. foreach(var pm in hasWaferPMs)
  2972. {
  2973. if (moveCount < hands.Count && moveCount < emptySlots.Count)
  2974. {
  2975. PickActions.Add(new MoveItem(pm.Key, 0, ModuleName.TMRobot, (int)hands[moveCount], hands[moveCount]));
  2976. llActions.Add(new MoveItem(ModuleName.TMRobot, (int)hands[moveCount], lls.First().Key, emptySlots[moveCount], hands[moveCount]));
  2977. moveCount++;
  2978. }
  2979. }
  2980. if(moveCount > 0)
  2981. {
  2982. foreach(var ac in PickActions)
  2983. {
  2984. _tmSchdActions.Enqueue(new List<MoveItem> { ac });
  2985. }
  2986. _tmSchdActions.Enqueue(llActions);
  2987. }
  2988. }
  2989. }
  2990. private void ReturnAtmWafers()
  2991. {
  2992. if (_efemSchdActions.Count > 0 || _curEfemAction.Count > 0)
  2993. {
  2994. RunSchdEFEMReturnActions();
  2995. return;
  2996. }
  2997. if (_efemRobotStatus != RState.End)
  2998. return;
  2999. // return Robot Wafer
  3000. for(int i = 0; i < 2; i++)
  3001. {
  3002. var wafer = WaferManager.Instance.GetWafer(ModuleName.EfemRobot, i);
  3003. if(wafer != null && !wafer.IsEmpty)
  3004. {
  3005. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, i, (ModuleName)wafer.OriginStation, wafer.OriginSlot, (Hand)i) });
  3006. }
  3007. }
  3008. if (_efemSchdActions.Count > 0)
  3009. return;
  3010. var hands = GetEFEMFreeHand();
  3011. // return Aligner wafer
  3012. var aligner = ModuleHelper.InstalledModules.Where(mod => ModuleHelper.IsAligner(mod)).ToList();
  3013. if(aligner.Count > 0 && WaferManager.Instance.CheckHasWafer(aligner.First(), 0) && hands.Count > 0)
  3014. {
  3015. var wafer = WaferManager.Instance.GetWafer(aligner.First(), 0);
  3016. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(aligner.First(), 0, ModuleName.EfemRobot, (int)hands.First(), hands.First()) });
  3017. _efemSchdActions.Enqueue(new List<MoveItem> { new MoveItem(ModuleName.EfemRobot, (int)hands.First(), (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands.First()) });
  3018. return;
  3019. }
  3020. // return Loadlock wafer
  3021. 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);
  3022. if(lls.Count() > 0)
  3023. {
  3024. int returnCount = 0;
  3025. var llActions = new List<MoveItem>();
  3026. var placActions = new List<MoveItem>();
  3027. foreach(var wafer in GetLLWaferExistance(lls.First().Key).wafers)
  3028. {
  3029. if(returnCount < hands.Count)
  3030. {
  3031. llActions.Add(new MoveItem(lls.First().Key, wafer.Slot, ModuleName.EfemRobot, (int)hands[returnCount], hands[returnCount]));
  3032. placActions.Add(new MoveItem(ModuleName.EfemRobot, (int)hands[returnCount], (ModuleName)wafer.OriginStation, wafer.OriginSlot, hands[returnCount]));
  3033. returnCount++;
  3034. }
  3035. }
  3036. if (returnCount > 0)
  3037. {
  3038. _efemSchdActions.Enqueue(llActions);
  3039. foreach (var ac in placActions)
  3040. {
  3041. _efemSchdActions.Enqueue(new List<MoveItem> { ac });
  3042. }
  3043. }
  3044. }
  3045. }
  3046. private void RunSchdEFEMReturnActions()
  3047. {
  3048. var efemRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.EfemRobot) as SchedulerEfemRobot;
  3049. if (efemRobot == null || !efemRobot.IsAvailable)
  3050. return;
  3051. if (_efemSchdActions.Count > 0)
  3052. {
  3053. if (_curEfemAction.Count == 0 || isReturnActionsDone(_curEfemAction))
  3054. {
  3055. var nextActions = _efemSchdActions.First();
  3056. var nextModule = nextActions.First().Module;
  3057. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  3058. return;
  3059. _curEfemAction = _efemSchdActions.Dequeue();
  3060. efemRobot.PostMoveItems(_curEfemAction.ToArray());
  3061. }
  3062. }
  3063. else if (_curEfemAction.Count >= 0 && isReturnActionsDone(_curEfemAction)) // all scheduled actions done
  3064. {
  3065. _curEfemAction.Clear();
  3066. }
  3067. }
  3068. private void RunSchdTMReturnActions()
  3069. {
  3070. var tmRobot = Singleton<TransferModule>.Instance.GetScheduler(ModuleName.TMRobot) as SchedulerTMRobot;
  3071. if (tmRobot == null || !tmRobot.IsAvailable)
  3072. return;
  3073. if (_tmSchdActions.Count > 0)
  3074. {
  3075. if (_curTmAction.Count == 0 || isReturnActionsDone(_curTmAction))
  3076. {
  3077. var nextActions = _tmSchdActions.First();
  3078. var nextModule = nextActions.First().Module;
  3079. if (ModuleHelper.IsLoadLock(nextModule) && !_dictModuleTask[nextModule].IsIdle)
  3080. return;
  3081. _curTmAction = _tmSchdActions.Dequeue();
  3082. tmRobot.SendMoveItems(_curTmAction.ToArray());
  3083. }
  3084. }
  3085. else if (_curTmAction.Count >= 0 && isReturnActionsDone(_curTmAction)) // all scheduled actions done
  3086. {
  3087. _curTmAction.Clear();
  3088. }
  3089. }
  3090. #endregion
  3091. #region sequence/recipe operation
  3092. private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  3093. {
  3094. reason = "";
  3095. foreach(var pm in seq.PMs)
  3096. {
  3097. if (ModuleHelper.IsInstalled(pm) && (_dictModuleTask[pm].Scheduler.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode))
  3098. return true;
  3099. }
  3100. reason = $"Sequence {seq.Name} no valid PM, " + string.Join("|", seq.PMs);
  3101. return false;
  3102. }
  3103. private bool CheckSequenceKepler2200TemperatureReady(SequenceInfo seq)
  3104. {
  3105. for (int i = 0; i < seq.Steps.Count; i++)
  3106. {
  3107. SequenceStepInfo stepInfo = seq.Steps[i];
  3108. foreach (var module in stepInfo.StepModules)
  3109. {
  3110. if (ModuleHelper.IsPm(module))
  3111. {
  3112. string attr = $"{module}Recipe";
  3113. if (stepInfo.StepParameter.ContainsKey(attr)
  3114. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3115. {
  3116. var recipeName = (string)stepInfo.StepParameter[attr];
  3117. var recipeContent =
  3118. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3119. var recipe = Recipe.Load(recipeContent);
  3120. float currentChamberTemperature;
  3121. switch (module)
  3122. {
  3123. case ModuleName.PMA:
  3124. currentChamberTemperature = Singleton<RouteManager>.Instance.PMA.ChamberTemperature;
  3125. break;
  3126. case ModuleName.PMB:
  3127. currentChamberTemperature = Singleton<RouteManager>.Instance.PMB.ChamberTemperature;
  3128. break;
  3129. case ModuleName.PMC:
  3130. currentChamberTemperature = Singleton<RouteManager>.Instance.PMC.ChamberTemperature;
  3131. break;
  3132. case ModuleName.PMD:
  3133. currentChamberTemperature = Singleton<RouteManager>.Instance.PMD.ChamberTemperature;
  3134. break;
  3135. default:
  3136. currentChamberTemperature = 0;
  3137. break;
  3138. }
  3139. if (recipe.Header.Temperature != null && recipe.Header.Temperature != "" && (currentChamberTemperature > Convert.ToSingle(recipe.Header.Temperature) + 10 || currentChamberTemperature < Convert.ToSingle(recipe.Header.Temperature) - 10))
  3140. {
  3141. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Start job失败,由于{seq.Name}里{module}腔体温度{currentChamberTemperature}与{recipeName} Recipe温度{recipe.Header.Temperature}不匹配");
  3142. return false;
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. return true;
  3149. }
  3150. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  3151. {
  3152. for (int i = 0; i < seq.Steps.Count; i++)
  3153. {
  3154. SequenceStepInfo stepInfo = seq.Steps[i];
  3155. foreach (var module in stepInfo.StepModules)
  3156. {
  3157. if (ModuleHelper.IsPm(module))
  3158. {
  3159. string attr = $"{module}Recipe";
  3160. if (stepInfo.StepParameter.ContainsKey(attr)
  3161. && !string.IsNullOrWhiteSpace((string)stepInfo.StepParameter[attr]))
  3162. {
  3163. var recipeName = (string)stepInfo.StepParameter[attr];
  3164. if (!string.IsNullOrWhiteSpace(recipeName))
  3165. {
  3166. var recipeContent =
  3167. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  3168. if (string.IsNullOrWhiteSpace(recipeContent))
  3169. {
  3170. reason = $"Can not find recipe file{recipeName}";
  3171. return false;
  3172. }
  3173. }
  3174. }
  3175. }
  3176. }
  3177. }
  3178. reason = "";
  3179. return true;
  3180. }
  3181. private void UpdateLLInOutPathProperty()
  3182. {
  3183. if (_lstControlJobs.Count == 0)
  3184. return;
  3185. var inOutPaths = new List<SequenceLLInOutPath>();
  3186. foreach(var wt in _lstWaferTasks)
  3187. {
  3188. if (!inOutPaths.Contains(wt.llInOutPath))
  3189. inOutPaths.Add(wt.llInOutPath);
  3190. }
  3191. if (inOutPaths.Count == 1)
  3192. {
  3193. _LLInOutPath = inOutPaths[0];
  3194. }
  3195. else
  3196. _LLInOutPath = SequenceLLInOutPath.DInDOut;
  3197. }
  3198. #endregion
  3199. }
  3200. }