AutoCycle.cs 144 KB

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