SystemDispatcher.cs 158 KB

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