AutoTransfer_T.cs 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Xml;
  5. using System.Diagnostics;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using VirgoRT.Modules.Schedulers;
  9. using VirgoRT.Scheduler;
  10. using MECF.Framework.Common.DBCore;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.Common.Jobs;
  13. using MECF.Framework.Common.Schedulers;
  14. using MECF.Framework.Common.SubstrateTrackings;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  16. using Aitex.Core.RT.SCCore;
  17. using Aitex.Sorter.Common;
  18. using Aitex.Core.Common;
  19. using Aitex.Core.RT.Routine;
  20. using Aitex.Core.RT.Event;
  21. using Aitex.Core.RT.Device;
  22. using Aitex.Core.RT.Log;
  23. using Aitex.Core.RT.RecipeCenter;
  24. using Aitex.Core.RT.DataCenter;
  25. using Aitex.Core.Util;
  26. namespace VirgoRT.Modules
  27. {
  28. enum RobotFreeHand
  29. {
  30. Blade1 = 0, //Lower arm
  31. Blade2 = 1, //Upper arm
  32. Both = 2,
  33. None = 3,
  34. }
  35. enum ActionState
  36. {
  37. Init = 0,
  38. Prepare,
  39. Run,
  40. Post,
  41. Done,
  42. }
  43. struct MoveAction
  44. {
  45. public EnumTransferType eType;
  46. public ModuleName targetModule;
  47. public int targetSlot;
  48. public int robotSlot1;
  49. public int robotSlot2;
  50. public ActionState state;
  51. public MoveAction(EnumTransferType type, ModuleName module, int tSlot = 0, int Slot1 = 0, int Slot2 = 0)
  52. {
  53. eType = type;
  54. targetModule = module;
  55. targetSlot = tSlot;
  56. robotSlot1 = Slot1;
  57. robotSlot2 = Slot2;
  58. state = ActionState.Init;
  59. }
  60. }
  61. enum ModulePriority
  62. {
  63. High,
  64. Middle,
  65. Low,
  66. Stop,
  67. }
  68. class ModuleFlag
  69. {
  70. public ModulePriority priority;
  71. public ModuleFlag(ModulePriority _priority)
  72. {
  73. priority = _priority;
  74. }
  75. }
  76. enum RtTraceState
  77. {
  78. Init,
  79. Pumping,
  80. WaitEfemRobotReady,
  81. WaitPenddingActionsFinish,
  82. WaitModuleReady,
  83. WaitPMReadyForPlace,
  84. WaitPMReadyForPick,
  85. WaitModuleReadyForPlace,
  86. WaitModuleReadyForPick,
  87. WaitPMReadyForTemperature,
  88. VerifyTransferAction,
  89. }
  90. public class AutoTransfer_T : TransferModule, IAutoTransfer
  91. {
  92. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  93. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  94. Dictionary<ModuleName, SchedulerModule> dictSchedulers = new Dictionary<ModuleName, SchedulerModule>();
  95. Dictionary<ModuleName, ModuleFlag> dictModules = new Dictionary<ModuleName, ModuleFlag>();
  96. Dictionary<Guid, ModuleName> dictWaferProcessPM = new Dictionary<Guid, ModuleName>();
  97. Dictionary<ModuleName, ModuleName> dictLPAssociatedPM = new Dictionary<ModuleName, ModuleName>();
  98. Queue<MoveAction> queMoveAction = new Queue<MoveAction>();
  99. private List<ModuleName> _mapTarget = new List<ModuleName>();
  100. private const string LogSource = "Scheduler";
  101. private bool _isCycleMode;
  102. private int _cycleSetPoint = 0;
  103. private int _cycledCount = 0;
  104. private int _cycledWafer = 0;
  105. private bool _isInited;
  106. private Stopwatch _blockingWatcher = new Stopwatch();
  107. private RtTraceState _lastTraceState;
  108. private RtTraceState _currentTraceState;
  109. public bool HasJobRunning => _lstControlJobs.Count > 0;
  110. public bool IsEfemRobotAvavilable => _efemRobot.IsAvailable;
  111. public static int SystemInternalWaferCount => SC.GetValue<int>($"System.MaxInternalWaferCount");
  112. private static int _maxBufferWaferCount = 1;
  113. private int _bufferSlotNumber = 0;
  114. private bool IsModuleAvailable(ModuleName module) => dictSchedulers.Keys.Contains(module) && dictSchedulers[module].IsAvailable;
  115. private SchedulerModule GetScheduler(ModuleName module) => dictSchedulers.Keys.Contains(module) ? dictSchedulers[module] : null;
  116. private SchedulerFACallback _faCallback;
  117. private SchedulerDBCallback _dbCallback;
  118. MoveAction _curAction = new MoveAction();
  119. public AutoTransfer_T()
  120. {
  121. _faCallback = new SchedulerFACallback();
  122. _dbCallback = new SchedulerDBCallback();
  123. InitModules();
  124. _curAction.state = ActionState.Done;
  125. DATA.Subscribe("Scheduler.CycledCount", () => _cycledCount);
  126. DATA.Subscribe("Scheduler.CycledWafer", () => _cycledWafer);
  127. DATA.Subscribe("Scheduler.CycleSetPoint", () => _cycleSetPoint);
  128. DATA.Subscribe("Scheduler.PjIdList", () => Array.ConvertAll(_lstProcessJobs.ToArray(), x => x.InnerId.ToString()).ToList());
  129. foreach (var lp in dictSchedulers)
  130. {
  131. if (ModuleHelper.IsLoadPort(lp.Key))
  132. {
  133. DATA.Subscribe($"{lp.Key}.LocalJobName", () => {
  134. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Key.ToString());
  135. if (cj != null)
  136. return cj.Name;
  137. return "";
  138. });
  139. DATA.Subscribe($"{lp.Key}.JobLotName", () => {
  140. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Key.ToString());
  141. if (cj != null)
  142. return cj.LotName;
  143. return "";
  144. });
  145. DATA.Subscribe($"{lp.Key}.LocalJobStatus", () => {
  146. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == lp.Key.ToString());
  147. if (cj != null)
  148. return cj.State.ToString();
  149. return "";
  150. });
  151. DATA.Subscribe($"{lp.Key}.CurrentRecipeList", () => {
  152. var local = lp;
  153. List<string> result = Enumerable.Repeat("", SC.GetValue<int>("EFEM.LoadPort.SlotNumber")).ToList();
  154. for (int i = 0; i < _lstProcessJobs.Count; i++)
  155. {
  156. foreach (var wafers in _lstProcessJobs[i].SlotWafers)
  157. {
  158. if (wafers.Item1 == local.Key)
  159. {
  160. result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
  161. }
  162. }
  163. }
  164. return result;
  165. });
  166. }
  167. }
  168. _maxBufferWaferCount = SC.GetValue<int>("EFEM.Buffer.SlotNumber") / 2;
  169. }
  170. private void InitModules()
  171. {
  172. void _initMoudle(ModuleName name, SchedulerModule sche, ModulePriority prio)
  173. {
  174. if (ModuleHelper.IsInstalled(name))
  175. {
  176. dictSchedulers[name] = sche;
  177. dictModules[name] = new ModuleFlag(prio);
  178. }
  179. }
  180. _initMoudle(ModuleName.PMA, _pma, ModulePriority.Middle);
  181. _initMoudle(ModuleName.PMB, _pmb, ModulePriority.Middle);
  182. _initMoudle(ModuleName.LP1, _lp1, ModulePriority.Middle);
  183. _initMoudle(ModuleName.LP2, _lp2, ModulePriority.Middle);
  184. _initMoudle(ModuleName.Aligner1, _aligner1, ModulePriority.Middle);
  185. _initMoudle(ModuleName.Aligner2, _aligner2, ModulePriority.Middle);
  186. _initMoudle(ModuleName.Cooling1, _cooling1, ModulePriority.Middle);
  187. _initMoudle(ModuleName.Cooling2, _cooling2, ModulePriority.Middle);
  188. _initMoudle(ModuleName.Flipper, _flipper, ModulePriority.Middle);
  189. _initMoudle(ModuleName.Buffer, _buffer, ModulePriority.Middle);
  190. }
  191. #region transfer routine
  192. private bool HasCrossSequence()
  193. {
  194. List<ModuleName> lstStepModules = new List<ModuleName>();
  195. foreach (var pj in _lstProcessJobs)
  196. {
  197. lstStepModules.Clear();
  198. foreach (var step in pj.Sequence.Steps)
  199. {
  200. foreach (var module in step.StepModules)
  201. {
  202. if (lstStepModules.Contains(module))
  203. return true;
  204. else
  205. lstStepModules.Add(module);
  206. }
  207. }
  208. }
  209. return false;
  210. }
  211. private void dumpMoveAction(string prefix, MoveAction action)
  212. {
  213. EV.PostInfoLog("System", $"{prefix} : {action.state}, {action.eType}, {action.targetModule}, {action.targetSlot}");
  214. }
  215. private void blockingChecking()
  216. {
  217. if (CheckAllJobDone())
  218. return;
  219. if (_currentTraceState != _lastTraceState)
  220. {
  221. _lastTraceState = _currentTraceState;
  222. _blockingWatcher.Restart();
  223. }
  224. if (_blockingWatcher.ElapsedMilliseconds >= 120 * 1000)
  225. {
  226. EV.PostInfoLog("", $"Router Blocking State: {_currentTraceState}");
  227. dumpMoveAction("Current Action", _curAction);
  228. for (int i = 0; i < queMoveAction.Count; i++)
  229. {
  230. dumpMoveAction(i.ToString(), queMoveAction.ElementAt(i));
  231. }
  232. foreach (var module in dictSchedulers)
  233. {
  234. string moduleStatus = module.Value.IsAvailable ? "Idle" : (module.Value.IsError ? "Error" : "Busy");
  235. EV.PostInfoLog("", $"Module State: {module.Key} is {moduleStatus}");
  236. }
  237. if (_curAction.state != ActionState.Done && dictSchedulers[_curAction.targetModule].IsError)
  238. {
  239. _curAction.state = ActionState.Done;
  240. queMoveAction.Clear();
  241. }
  242. _blockingWatcher.Restart();
  243. ResetTraceFlag();
  244. }
  245. }
  246. private bool prelude()
  247. {
  248. MonitorEfemRobotMapTask();
  249. return true;
  250. }
  251. private bool epilogue()
  252. {
  253. UpdateProcessJobStatus();
  254. UpdateControlJobStatus();
  255. StartNewJob();
  256. MonitorCleanTasks();
  257. blockingChecking();
  258. return true;
  259. }
  260. private bool Pump()
  261. {
  262. if (queMoveAction.Count > 0 || _curAction.state != ActionState.Done)
  263. return false;
  264. // move remaining wafers in robot arms
  265. for(int slot = 0; slot < 2; slot++)
  266. {
  267. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, slot))
  268. {
  269. var nextSlot = GetWaferNextReadySlot(new SlotItem(ModuleName.EfemRobot, slot));
  270. if (nextSlot.Module != ModuleName.System)
  271. {
  272. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, nextSlot.Module, nextSlot.Slot, slot));
  273. PreparePMTemp(ModuleName.EfemRobot, slot, nextSlot.Module, EnumTransferType.Place);
  274. return true;
  275. }
  276. var swapSlot = GetWaferNextReadySlot(new SlotItem(ModuleName.EfemRobot, slot), true);
  277. if (swapSlot.Module != ModuleName.System)
  278. {
  279. int peerSlot = slot == 0 ? 1 : 0;
  280. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, peerSlot))
  281. {
  282. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, swapSlot.Module, swapSlot.Slot, peerSlot /* Pick Blade */, slot /* Place Blade */));
  283. PreparePMTemp(ModuleName.EfemRobot, slot, swapSlot.Module, EnumTransferType.Pick);
  284. return true;
  285. }
  286. }
  287. }
  288. }
  289. ModulePriority[] prioritys = new ModulePriority[] { ModulePriority.High, ModulePriority.Middle, ModulePriority.Low };
  290. foreach (var prio in prioritys)
  291. {
  292. foreach (var module in dictModules)
  293. {
  294. if (module.Value.priority != prio)
  295. continue;
  296. var outSlot = GetReadyOutSlot(module.Key);
  297. if (outSlot.Module != ModuleName.System && IsWaferCtrlJobRuning(outSlot))
  298. {
  299. var nextSlot = GetWaferNextReadySlot(outSlot);
  300. if (nextSlot.Module != ModuleName.System)
  301. {
  302. var waitInSlot = GetWaitInWaferSlot(outSlot);
  303. if (waitInSlot.Module != ModuleName.System && GetRobotFreeHand() == RobotFreeHand.Both)
  304. {
  305. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, waitInSlot.Module, waitInSlot.Slot, (int)Hand.Blade1));
  306. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, module.Key, outSlot.Slot, (int)Hand.Blade2 /* Pick Blade */, (int)Hand.Blade1 /* Place Blade */));
  307. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, nextSlot.Module, nextSlot.Slot, (int)Hand.Blade2));
  308. PreparePMTemp(waitInSlot.Module, waitInSlot.Slot, module.Key, EnumTransferType.Pick);
  309. PreparePMTemp(module.Key, outSlot.Slot, nextSlot.Module, EnumTransferType.Place);
  310. return true;
  311. }
  312. else
  313. {
  314. int nFreeHand = (int)SelectRobotFreeHand();
  315. if (nFreeHand != (int)RobotFreeHand.None)
  316. {
  317. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, module.Key, outSlot.Slot, nFreeHand));
  318. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, nextSlot.Module, nextSlot.Slot, nFreeHand));
  319. PreparePMTemp(module.Key, outSlot.Slot, nextSlot.Module, EnumTransferType.Place);
  320. return true;
  321. }
  322. }
  323. }
  324. else
  325. {
  326. var swapSlot = GetCanSwapSlot(outSlot);
  327. if (swapSlot.Module != ModuleName.System && GetRobotFreeHand() == RobotFreeHand.Both)
  328. {
  329. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, swapSlot.Module, swapSlot.Slot, (int)Hand.Blade1));
  330. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, module.Key, outSlot.Slot, (int)Hand.Blade2 /* Pick Blade */, (int)Hand.Blade1 /* Place Blade */));
  331. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Place, swapSlot.Module, swapSlot.Slot, (int)Hand.Blade2));
  332. PreparePMTemp(swapSlot.Module, swapSlot.Slot, module.Key, EnumTransferType.Pick);
  333. PreparePMTemp(module.Key, outSlot.Slot, swapSlot.Module, EnumTransferType.Pick);
  334. return true;
  335. }
  336. }
  337. }
  338. }
  339. }
  340. // pick the wafer to robot arm while the next module is not ready
  341. if (HasCrossSequence() == false && GetRobotFreeHand() == RobotFreeHand.Both)
  342. {
  343. foreach (var module in dictModules)
  344. {
  345. var outSlot = GetReadyOutSlot(module.Key);
  346. if (outSlot.Module != ModuleName.System && IsWaferCtrlJobRuning(outSlot))
  347. {
  348. var swapSlot = GetWaferNextReadySlot(outSlot, true);
  349. if (swapSlot.Module != ModuleName.System)
  350. {
  351. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Pick, outSlot.Module, outSlot.Slot, (int)Hand.Blade1));
  352. queMoveAction.Enqueue(new MoveAction(EnumTransferType.Swap, swapSlot.Module, swapSlot.Slot, (int)Hand.Blade2 /* Pick Blade */, (int)Hand.Blade1 /* Place Blade */));
  353. PreparePMTemp(outSlot.Module, outSlot.Slot, swapSlot.Module, EnumTransferType.Pick);
  354. return true;
  355. }
  356. }
  357. }
  358. }
  359. _currentTraceState = RtTraceState.Pumping;
  360. return false;
  361. }
  362. private void Pop()
  363. {
  364. if (!_efemRobot.IsAvailable)
  365. {
  366. _currentTraceState = RtTraceState.WaitEfemRobotReady;
  367. return;
  368. }
  369. if (queMoveAction.Count == 0 && _curAction.state == ActionState.Done)
  370. return;
  371. switch (_curAction.state)
  372. {
  373. case ActionState.Init:
  374. {
  375. if (IsModuleAvailable(_curAction.targetModule))
  376. {
  377. if (PrepareCurrentAction())
  378. {
  379. _curAction.state = ActionState.Prepare;
  380. if (RunCurrentAction())
  381. {
  382. _curAction.state = ActionState.Run;
  383. }
  384. }
  385. }
  386. else
  387. {
  388. _currentTraceState = RtTraceState.WaitModuleReady;
  389. }
  390. }
  391. break;
  392. case ActionState.Prepare:
  393. {
  394. if (RunCurrentAction())
  395. {
  396. _curAction.state = ActionState.Run;
  397. }
  398. }
  399. break;
  400. case ActionState.Run:
  401. {
  402. if (dictSchedulers[_curAction.targetModule].IsWaitTransfer(ModuleName.EfemRobot))
  403. {
  404. NotifyFaWaferEnd();
  405. dictSchedulers[_curAction.targetModule].PostTransfer(ModuleName.EfemRobot);
  406. _curAction.state = ActionState.Post;
  407. }
  408. else
  409. {
  410. _currentTraceState = RtTraceState.VerifyTransferAction;
  411. }
  412. }
  413. break;
  414. case ActionState.Post:
  415. {
  416. if (IsModuleAvailable(_curAction.targetModule))
  417. {
  418. PostProcessCurrentAction();
  419. _curAction.state = ActionState.Done;
  420. }
  421. else
  422. {
  423. _currentTraceState = RtTraceState.WaitModuleReady;
  424. }
  425. }
  426. break;
  427. case ActionState.Done:
  428. {
  429. _curAction = queMoveAction.Dequeue();
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. }
  436. private bool PrepareCurrentAction()
  437. {
  438. if (_curAction.targetModule == ModuleName.PMA || _curAction.targetModule == ModuleName.PMB)
  439. {
  440. if ((_curAction.eType == EnumTransferType.Place && !dictSchedulers[_curAction.targetModule].IsReadyForPlace(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1)) ||
  441. (_curAction.eType != EnumTransferType.Place && !dictSchedulers[_curAction.targetModule].IsReadyForPick(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1)))
  442. {
  443. dictSchedulers[_curAction.targetModule].PrepareTransfer(ModuleName.EfemRobot,
  444. _curAction.eType == EnumTransferType.Swap ? EnumTransferType.Pick : _curAction.eType,
  445. _curAction.targetSlot);
  446. _currentTraceState = _curAction.eType == EnumTransferType.Swap ? RtTraceState.WaitPMReadyForPick : RtTraceState.WaitPMReadyForPlace;
  447. return false;
  448. }
  449. else
  450. {
  451. if (_curAction.eType == EnumTransferType.Pick)
  452. return true;
  453. GetWaferTemperatureSetInRecipe(ModuleName.EfemRobot, _curAction.eType == EnumTransferType.Place ? _curAction.robotSlot1 : _curAction.robotSlot2, _curAction.targetModule, out float temp);
  454. if (temp < 0.1)
  455. return true;
  456. if (!((SchedulerPM)dictSchedulers[_curAction.targetModule]).IsTemperatureReady(temp))
  457. {
  458. _currentTraceState = RtTraceState.WaitPMReadyForTemperature;
  459. return false;
  460. }
  461. }
  462. }
  463. return true;
  464. }
  465. private void PreparePMTemp(ModuleName waferModule, int waferSlot, ModuleName pmModule, EnumTransferType type)
  466. {
  467. if (pmModule == ModuleName.PMA || pmModule == ModuleName.PMB)
  468. {
  469. GetWaferTemperatureSetInRecipe(waferModule, waferSlot, pmModule, out float temp);
  470. if (Math.Abs(temp) > 0.1 && !((SchedulerPM)dictSchedulers[pmModule]).IsTemperatureReady(temp))
  471. {
  472. ((SchedulerPM)dictSchedulers[pmModule]).PrepareTransfer(ModuleName.EfemRobot, type, 0, temp, Hand.Blade1, WaferSize.WS12);
  473. }
  474. }
  475. }
  476. private bool RunCurrentAction()
  477. {
  478. if (!IsModuleAvailable(_curAction.targetModule))
  479. {
  480. return false;
  481. }
  482. switch (_curAction.eType)
  483. {
  484. case EnumTransferType.Pick:
  485. {
  486. if (dictSchedulers[_curAction.targetModule].IsReadyForPick(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1))
  487. {
  488. _efemRobot.Pick(_curAction.targetModule, _curAction.targetSlot, (Hand)_curAction.robotSlot1);
  489. dictSchedulers[_curAction.targetModule].WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, _curAction.targetSlot);
  490. // Notify the FA for Port1JobWaferStart
  491. if (ModuleHelper.IsLoadPort(_curAction.targetModule))
  492. {
  493. ProcessJobInfo pj = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot).ProcessJob;
  494. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  495. _faCallback.JobWaferStart(cj, pj, _curAction.targetModule.ToString(), _curAction.targetSlot);
  496. }
  497. return true;
  498. }
  499. else
  500. {
  501. _currentTraceState = RtTraceState.WaitModuleReadyForPick;
  502. }
  503. }
  504. break;
  505. case EnumTransferType.Place:
  506. {
  507. if (dictSchedulers[_curAction.targetModule].IsReadyForPlace(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1))
  508. {
  509. _efemRobot.Place(_curAction.targetModule, _curAction.targetSlot, (Hand)_curAction.robotSlot1);
  510. dictSchedulers[_curAction.targetModule].WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Place, _curAction.targetSlot);
  511. return true;
  512. }
  513. else
  514. {
  515. _currentTraceState = RtTraceState.WaitModuleReadyForPlace;
  516. }
  517. }
  518. break;
  519. case EnumTransferType.Swap:
  520. {
  521. if (dictSchedulers[_curAction.targetModule].IsReadyForPick(ModuleName.EfemRobot, _curAction.targetSlot, (Hand)_curAction.robotSlot1))
  522. {
  523. _efemRobot.PickAndPlace(_curAction.targetModule, _curAction.targetSlot, _curAction.targetSlot, (Hand)_curAction.robotSlot1, (Hand)_curAction.robotSlot2);
  524. dictSchedulers[_curAction.targetModule].WaitTransfer(ModuleName.EfemRobot, EnumTransferType.Swap, _curAction.targetSlot);
  525. return true;
  526. }
  527. else
  528. {
  529. _currentTraceState = RtTraceState.WaitModuleReadyForPick;
  530. }
  531. }
  532. break;
  533. }
  534. return false;
  535. }
  536. private void PostProcessCurrentAction()
  537. {
  538. if (_curAction.eType != EnumTransferType.Pick)
  539. {
  540. var wafer = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot);
  541. if (wafer.IsEmpty)
  542. return;
  543. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  544. return;
  545. if (_curAction.eType == EnumTransferType.Swap)
  546. {
  547. dictSchedulers[_curAction.targetModule].EventWaferLeaved?.Invoke(this, new WaferMoveArgs(_curAction.targetModule,
  548. _curAction.robotSlot2, ModuleName.EfemRobot, _curAction.targetSlot));
  549. if (ModuleHelper.IsLoadPort(_curAction.targetModule) && IsFixedPMMode())
  550. {
  551. AdjustLPPriority(_curAction.targetModule);
  552. }
  553. }
  554. dictSchedulers[_curAction.targetModule].EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.EfemRobot,
  555. _curAction.robotSlot1,
  556. _curAction.targetModule,
  557. _curAction.targetSlot));
  558. if(ModuleHelper.IsLoadPort(_curAction.targetModule))
  559. RemoveWaferPMMark(new SlotItem(_curAction.targetModule, _curAction.targetSlot));
  560. else if (ModuleHelper.IsPm(_curAction.targetModule))
  561. AddWaferPMMark(_curAction.targetModule);
  562. else if (ModuleHelper.IsAligner(_curAction.targetModule))
  563. {
  564. GetWaferSequenceAlignTime(_curAction.targetModule, 0, out float time);
  565. _efemRobot.Align(_curAction.targetModule, time);
  566. }
  567. else if (ModuleHelper.IsCooling(_curAction.targetModule))
  568. {
  569. GetWaferSequenceAlignTime(_curAction.targetModule, 0, out float time);
  570. dictSchedulers[_curAction.targetModule].Cooling((int)time);
  571. }
  572. if (!ModuleHelper.IsLoadPort(_curAction.targetModule))
  573. wafer.NextSequenceStep++;
  574. }
  575. else
  576. {
  577. dictSchedulers[_curAction.targetModule].EventWaferLeaved?.Invoke(this, new WaferMoveArgs(_curAction.targetModule,
  578. _curAction.targetSlot, ModuleName.EfemRobot, _curAction.robotSlot1));
  579. if (IsFixedPMMode())
  580. {
  581. if (ModuleHelper.IsLoadPort(_curAction.targetModule))
  582. {
  583. AdjustLPPriority(_curAction.targetModule);
  584. }
  585. else if (ModuleHelper.IsAligner(_curAction.targetModule))
  586. {
  587. AdjustAlignerPriority(_curAction.targetModule);
  588. }
  589. }
  590. }
  591. }
  592. private bool GetWaferSequenceAlignTime(ModuleName module, int slot, out float time)
  593. {
  594. time = 0;
  595. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  596. return false;
  597. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  598. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  599. return false;
  600. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  601. return false;
  602. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1)
  603. && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2)
  604. && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1)
  605. && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
  606. return false;
  607. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter.ContainsKey("CoolingTime"))
  608. return false;
  609. if (!float.TryParse((string)wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["CoolingTime"],
  610. out time))
  611. return false;
  612. return true;
  613. }
  614. private bool GetWaferTemperatureSetInRecipe(ModuleName waferModule, int waferSlot, ModuleName pmModule, out float temp)
  615. {
  616. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  617. var seq = wafer.ProcessJob.Sequence;
  618. for (int i = wafer.NextSequenceStep; i < seq.Steps.Count; i++)
  619. {
  620. SequenceStepInfo stepInfo = seq.Steps[i];
  621. foreach (var module in stepInfo.StepModules)
  622. {
  623. if (module == pmModule)
  624. {
  625. temp = (float)seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"];
  626. return true;
  627. }
  628. }
  629. }
  630. temp = 0;
  631. LOG.Error($"Can not find wafer {waferModule} {waferSlot + 1} temperature set in recipe");
  632. return false;
  633. }
  634. private SlotItem GetWaferNextReadySlot(SlotItem slot, bool bSwap = false)
  635. {
  636. var nextSlot = new SlotItem(ModuleName.System, -1);
  637. var inWafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
  638. if (inWafer.IsEmpty)
  639. return nextSlot;
  640. if (inWafer.ProcessJob == null || inWafer.ProcessJob.Sequence == null)
  641. return nextSlot;
  642. if (inWafer.NextSequenceStep >= inWafer.ProcessJob.Sequence.Steps.Count) // need return
  643. {
  644. return new SlotItem((ModuleName)inWafer.OriginStation, inWafer.OriginSlot);
  645. }
  646. foreach (var module in inWafer.ProcessJob.Sequence.Steps[inWafer.NextSequenceStep].StepModules)
  647. {
  648. if (IsModuleAvailable(module))
  649. {
  650. // need enhancement
  651. int nMaxSlot = (module == ModuleName.LP1 || module == ModuleName.LP2 || module == ModuleName.LP3) ?
  652. SC.GetValue<int>("EFEM.LoadPort.SlotNumber") : (module == ModuleName.Buffer ? SC.GetValue<int>("EFEM.Buffer.SlotNumber") : 1);
  653. for (int i = 0; i < nMaxSlot; i++)
  654. {
  655. if (WaferManager.Instance.IsWaferSlotLocationValid(module, i))
  656. {
  657. // the processed wafer must enter same pm
  658. if (ModuleHelper.IsPm(module) && ModuleHelper.IsInstalled(ModuleName.Flipper) && dictWaferProcessPM.ContainsKey(inWafer.InnerId) && dictWaferProcessPM[inWafer.InnerId] != module)
  659. continue;
  660. if (bSwap == false && WaferManager.Instance.CheckNoWafer(module, i))
  661. {
  662. return new SlotItem(module, i);
  663. }
  664. if (bSwap && WaferManager.Instance.CheckHasWafer(module, i))
  665. {
  666. return new SlotItem(module, i);
  667. }
  668. }
  669. }
  670. }
  671. }
  672. return nextSlot;
  673. }
  674. private SlotItem GetCanSwapSlot(SlotItem slot)
  675. {
  676. var swapSlot = new SlotItem(ModuleName.System, -1);
  677. var inWafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
  678. if (inWafer.IsEmpty)
  679. return swapSlot;
  680. if (inWafer.ProcessJob == null || inWafer.ProcessJob.Sequence == null)
  681. return swapSlot;
  682. if (inWafer.NextSequenceStep >= inWafer.ProcessJob.Sequence.Steps.Count) // need return
  683. return swapSlot;
  684. foreach (var module in inWafer.ProcessJob.Sequence.Steps[inWafer.NextSequenceStep].StepModules)
  685. {
  686. if (IsModuleAvailable(module))
  687. {
  688. // need enhancement
  689. int nMaxSlot = (module == ModuleName.LP1 || module == ModuleName.LP2 || module == ModuleName.LP3) ?
  690. SC.GetValue<int>("EFEM.LoadPort.SlotNumber") : (module == ModuleName.Buffer ? SC.GetValue<int>("EFEM.Buffer.SlotNumber") : 1);
  691. for (int i = 0; i < nMaxSlot; i++)
  692. {
  693. if (WaferManager.Instance.IsWaferSlotLocationValid(module, i))
  694. {
  695. if (WaferManager.Instance.CheckHasWafer(module, i))
  696. {
  697. var swapWafer = WaferManager.Instance.GetWafer(module, i);
  698. if (!swapWafer.IsEmpty &&
  699. swapWafer.ProcessJob != null &&
  700. swapWafer.ProcessJob.Sequence != null &&
  701. swapWafer.NextSequenceStep < swapWafer.ProcessJob.Sequence.Steps.Count &&
  702. swapWafer.ProcessJob.Sequence.Steps[swapWafer.NextSequenceStep].StepModules.Contains(slot.Module))
  703. {
  704. return new SlotItem(module, i);
  705. }
  706. }
  707. }
  708. }
  709. }
  710. }
  711. return swapSlot;
  712. }
  713. private SlotItem GetWaitInWaferSlot(SlotItem slot)
  714. {
  715. ModulePriority[] prioritys = new ModulePriority[] { ModulePriority.High, ModulePriority.Middle, ModulePriority.Low };
  716. foreach (var prio in prioritys)
  717. {
  718. foreach (var module in dictModules)
  719. {
  720. if (module.Value.priority != prio || module.Key == slot.Module)
  721. continue;
  722. var inSlot = GetReadyOutSlot(module.Key);
  723. if (inSlot.Module != ModuleName.System)
  724. {
  725. var inWafer = WaferManager.Instance.GetWafer(inSlot.Module, inSlot.Slot);
  726. if (inWafer.IsEmpty)
  727. continue;
  728. if (inWafer.ProcessJob == null || inWafer.ProcessJob.Sequence == null)
  729. continue;
  730. if (inWafer.NextSequenceStep >= inWafer.ProcessJob.Sequence.Steps.Count)
  731. continue;
  732. if (inWafer.ProcessJob.Sequence.Steps[inWafer.NextSequenceStep].StepModules
  733. .Contains(slot.Module))
  734. return inSlot;
  735. }
  736. }
  737. }
  738. return new SlotItem(ModuleName.System, -1);
  739. }
  740. private SlotItem GetReadyOutSlot(ModuleName module)
  741. {
  742. if (module == ModuleName.LP1 || module == ModuleName.LP2 || module == ModuleName.LP3)
  743. return GetLPReadyOutSlot(module);
  744. else if (module == ModuleName.Buffer)
  745. return GetBufferReadyOutSlot(module);
  746. else
  747. return GetModuleReadyOutSlot(module);
  748. }
  749. private bool IsWaferCtrlJobRuning(SlotItem slotItem)
  750. {
  751. return IsWaferCtrlJobRuning(slotItem.Module, slotItem.Slot);
  752. }
  753. private bool IsWaferCtrlJobRuning(ModuleName mod, int slot)
  754. {
  755. var wafer = WaferManager.Instance.GetWafer(mod, slot);
  756. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  757. return false;
  758. var waferCtrlJob = _lstControlJobs.Find(item => (int)ModuleHelper.Converter(item.Module) == wafer.OriginStation);
  759. if (waferCtrlJob != null)
  760. {
  761. return waferCtrlJob.State == EnumControlJobState.Executing;
  762. }
  763. return false;
  764. }
  765. private SlotItem GetLPReadyOutSlot(ModuleName lp)
  766. {
  767. var slot = GetNextWaferInJobQueue(lp);
  768. if (slot == null)
  769. return new SlotItem(ModuleName.System, -1);
  770. return slot;
  771. }
  772. private SlotItem GetModuleReadyOutSlot(ModuleName module)
  773. {
  774. var slot = new SlotItem(ModuleName.System, -1);
  775. if (!IsModuleAvailable(module))
  776. return slot;
  777. WaferInfo wafer = WaferManager.Instance.GetWafer(module, 0);
  778. if (wafer.IsEmpty)
  779. return slot;
  780. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  781. return slot;
  782. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count) // return to loadport
  783. return new SlotItem(module, 0);
  784. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
  785. .Contains(module))
  786. return slot;
  787. return new SlotItem(module, 0);
  788. }
  789. private SlotItem GetBufferReadyOutSlot(ModuleName buffer)
  790. {
  791. return dictSchedulers[buffer].GetReadyOutSlot();
  792. }
  793. private RobotFreeHand GetRobotFreeHand()
  794. {
  795. var blade1Enable = SC.GetValue<bool>("EFEM.EfemRobot.LowerBladeEnable");
  796. var blade2Enable = SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable");
  797. var blade1HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0);
  798. var blade2HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1);
  799. if (blade1HasWafer && blade2HasWafer)
  800. return RobotFreeHand.None;
  801. else if (!blade1HasWafer && !blade2HasWafer && blade1Enable && blade2Enable)
  802. return RobotFreeHand.Both;
  803. else if (!blade2HasWafer && blade2Enable)
  804. return RobotFreeHand.Blade2;
  805. else if (!blade1HasWafer && blade1Enable)
  806. return RobotFreeHand.Blade1;
  807. else
  808. return RobotFreeHand.None;
  809. }
  810. private RobotFreeHand SelectRobotFreeHand()
  811. {
  812. var freeHand = GetRobotFreeHand();
  813. return freeHand == RobotFreeHand.Both ? RobotFreeHand.Blade1 : freeHand;
  814. }
  815. private void AddWaferPMMark(ModuleName pm)
  816. {
  817. var wafer = WaferManager.Instance.GetWafer(pm, 0);
  818. if (wafer.IsEmpty)
  819. return;
  820. dictWaferProcessPM[wafer.InnerId] = pm;
  821. }
  822. private void RemoveWaferPMMark(SlotItem slot)
  823. {
  824. var wafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
  825. if (wafer.IsEmpty)
  826. return;
  827. dictWaferProcessPM.Remove(wafer.InnerId);
  828. }
  829. private void ResetTraceFlag()
  830. {
  831. _lastTraceState = _currentTraceState = RtTraceState.Init;
  832. }
  833. public Result Monitor()
  834. {
  835. prelude();
  836. Pump();
  837. Pop();
  838. epilogue();
  839. return Result.RUN;
  840. }
  841. private List<ModuleName> GetPmUsedInRunningPj()
  842. {
  843. var pmUsed = new List<ModuleName>();
  844. foreach (var cj in _lstControlJobs)
  845. {
  846. if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
  847. continue;
  848. foreach (var pj in _lstProcessJobs)
  849. {
  850. if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
  851. {
  852. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  853. {
  854. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  855. foreach (var module in stepInfo.StepModules)
  856. {
  857. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  858. pmUsed.Add(module);
  859. }
  860. }
  861. }
  862. }
  863. }
  864. return pmUsed;
  865. }
  866. private List<SchedulerPM> GetPmNeeded(ControlJobInfo cj)
  867. {
  868. List<SchedulerPM> result = new List<SchedulerPM>();
  869. foreach (var pj in _lstProcessJobs)
  870. {
  871. if (pj.ControlJobName != cj.Name)
  872. continue;
  873. var seq = pj.Sequence;
  874. for (int i = 0; i < seq.Steps.Count; i++)
  875. {
  876. SequenceStepInfo stepInfo = seq.Steps[i];
  877. foreach (var module in stepInfo.StepModules)
  878. {
  879. if (ModuleHelper.IsPm(module))
  880. {
  881. var pm = dictSchedulers[module] as SchedulerPM;
  882. if (pm != null && !result.Contains(pm))
  883. {
  884. result.Add(pm);
  885. }
  886. }
  887. }
  888. }
  889. }
  890. return result;
  891. }
  892. private void InitClean()
  893. {
  894. foreach (var pm in dictSchedulers)
  895. {
  896. if (ModuleHelper.IsPm(pm.Key))
  897. {
  898. var scheduler = pm.Value as SchedulerPM;
  899. scheduler.InitClean();
  900. }
  901. }
  902. }
  903. public Result MonitorCleanTasks()
  904. {
  905. if (!_isInited)
  906. {
  907. _isInited = true;
  908. InitClean();
  909. }
  910. foreach (var pm in dictSchedulers)
  911. {
  912. if (ModuleHelper.IsPm(pm.Key))
  913. {
  914. var scheduler = pm.Value as SchedulerPM;
  915. scheduler.MonitorCleanTasks();
  916. }
  917. }
  918. return Result.RUN;
  919. }
  920. private void PreJobClean(ControlJobInfo cj)
  921. {
  922. if (cj.IsPreJobCleanDone)
  923. return;
  924. cj.IsPreJobCleanDone = true;
  925. List<SchedulerPM> pms = GetPmNeeded(cj);
  926. foreach (var pm in pms)
  927. {
  928. pm.PreJobClean();
  929. }
  930. }
  931. private bool ActiveProcessJob(ProcessJobInfo pj)
  932. {
  933. foreach (var pjSlotWafer in pj.SlotWafers)
  934. {
  935. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  936. wafer.ProcessJob = pj;
  937. wafer.NextSequenceStep = 0;
  938. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  939. }
  940. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  941. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  942. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  943. pj.SetState(EnumProcessJobState.Processing);
  944. PreJobClean(cj);
  945. return true;
  946. }
  947. private void StartNewJob()
  948. {
  949. ControlJobInfo cjActived = null;
  950. List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
  951. foreach (var cj in _lstControlJobs)
  952. {
  953. if (cj.State != EnumControlJobState.Executing)
  954. continue;
  955. cjActived = cj;
  956. foreach (var pjName in cjActived.ProcessJobNameList)
  957. {
  958. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  959. if (pj == null)
  960. {
  961. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  962. continue;
  963. }
  964. if (pj.State == EnumProcessJobState.Queued)
  965. {
  966. if (CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason))
  967. {
  968. ActiveProcessJob(pj);
  969. foreach (var moduleName in pmUsed)
  970. {
  971. if (!pmOccupied.Contains(moduleName))
  972. pmOccupied.Add(moduleName);
  973. }
  974. }
  975. break;
  976. }
  977. }
  978. }
  979. }
  980. private bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  981. {
  982. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  983. if (wafer.IsEmpty)
  984. return false;
  985. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  986. return false;
  987. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  988. return false;
  989. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  990. {
  991. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  992. .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
  993. .Contains(ModuleName.PMB))
  994. {
  995. var hasPmAvailable = false;
  996. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  997. {
  998. var pm = GetScheduler(stepModule) as SchedulerPM;
  999. if (pm != null)
  1000. {
  1001. if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
  1002. {
  1003. hasPmAvailable = true;
  1004. break;
  1005. }
  1006. }
  1007. }
  1008. if (!hasPmAvailable)
  1009. return false;
  1010. if (processIn == ModuleName.System)
  1011. return true;
  1012. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  1013. .Contains(processIn))
  1014. return true;
  1015. }
  1016. }
  1017. return false;
  1018. }
  1019. private bool IsFixedPMMode()
  1020. {
  1021. List<ModuleName> associatedPMs = new List<ModuleName>();
  1022. foreach (var module in dictSchedulers.Keys)
  1023. {
  1024. if (ModuleHelper.IsLoadPort(module))
  1025. {
  1026. if (dictLPAssociatedPM.ContainsKey(module))
  1027. {
  1028. if (dictLPAssociatedPM[module] == ModuleName.System)
  1029. return false;
  1030. if (!associatedPMs.Contains(dictLPAssociatedPM[module]))
  1031. associatedPMs.Add(dictLPAssociatedPM[module]);
  1032. }
  1033. }
  1034. }
  1035. return associatedPMs.Count >= 2;
  1036. }
  1037. void AdjustLPPriority(ModuleName lp)
  1038. {
  1039. foreach (var module in dictModules.Keys)
  1040. {
  1041. if (ModuleHelper.IsLoadPort(module))
  1042. {
  1043. dictModules[module].priority = module == lp ? ModulePriority.Low : ModulePriority.Middle;
  1044. }
  1045. }
  1046. }
  1047. void AdjustAlignerPriority(ModuleName aligner)
  1048. {
  1049. foreach (var module in dictModules.Keys)
  1050. {
  1051. if (ModuleHelper.IsAligner(module))
  1052. {
  1053. dictModules[module].priority = module == aligner ? ModulePriority.Low : ModulePriority.Middle;
  1054. }
  1055. }
  1056. }
  1057. private SlotItem GetNextWaferInJobQueue(ModuleName lpModule)
  1058. {
  1059. if (GetSystemInnerWaferCount() >= SystemInternalWaferCount || GetBufferWaferCount() > _maxBufferWaferCount)
  1060. return new SlotItem(ModuleName.System, -1);
  1061. foreach (var cj in _lstControlJobs)
  1062. {
  1063. if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
  1064. continue;
  1065. if (cj.State == EnumControlJobState.Executing)
  1066. {
  1067. foreach (var pj in _lstProcessJobs)
  1068. {
  1069. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  1070. {
  1071. foreach (var pjSlotWafer in pj.SlotWafers)
  1072. {
  1073. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  1074. {
  1075. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. }
  1082. return new SlotItem(ModuleName.System, -1);
  1083. }
  1084. static public int GetSystemInnerWaferCount()
  1085. {
  1086. int count = 0;
  1087. var lstPosition = new List<ModuleName>()
  1088. {
  1089. ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2, ModuleName.Flipper, ModuleName.PMA, ModuleName.PMB,
  1090. };
  1091. foreach (var moduleName in lstPosition)
  1092. {
  1093. if (ModuleHelper.IsInstalled(moduleName) && WaferManager.Instance.CheckHasWafer(moduleName, 0))
  1094. count++;
  1095. }
  1096. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  1097. count++;
  1098. return count;
  1099. }
  1100. private int GetBufferWaferCount()
  1101. {
  1102. int nCount = 0;
  1103. for (int i = 0; i < SC.GetValue<int>("EFEM.Buffer.SlotNumber"); i++)
  1104. {
  1105. if (WaferManager.Instance.CheckHasWafer(ModuleName.Buffer, i))
  1106. nCount++;
  1107. }
  1108. return nCount;
  1109. }
  1110. #endregion transfer routine
  1111. private void MonitorEfemRobotMapTask()
  1112. {
  1113. if (!_efemRobot.IsAvailable)
  1114. return;
  1115. if (_mapTarget.Count > 0)
  1116. {
  1117. ModuleName first = _mapTarget[0];
  1118. //避免重复map,job信息被清除
  1119. foreach (var cj in _lstControlJobs)
  1120. {
  1121. if (cj.Module != first.ToString())
  1122. continue;
  1123. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1124. {
  1125. EV.PostWarningLog("System", $"{first} is running, can not map again");
  1126. _mapTarget.Remove(first);
  1127. }
  1128. }
  1129. SchedulerLoadPort lp = GetScheduler(first) as SchedulerLoadPort;
  1130. if (lp != null && lp.IsAvailable)
  1131. {
  1132. _efemRobot.Map(first);
  1133. _mapTarget.Remove(first);
  1134. }
  1135. }
  1136. }
  1137. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  1138. {
  1139. pmUsed = new List<ModuleName>();
  1140. reason = "";
  1141. bool pmIsReady = true;
  1142. for (int i = 0; i < seq.Steps.Count; i++)
  1143. {
  1144. SequenceStepInfo stepInfo = seq.Steps[i];
  1145. bool hasPm = false;
  1146. foreach (var module in stepInfo.StepModules)
  1147. {
  1148. if (!ModuleHelper.IsPm(module))
  1149. {
  1150. hasPm = true;
  1151. break;
  1152. }
  1153. PM pm = DEVICE.GetDevice<PM>(module.ToString());
  1154. if (pm != null && pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(module)))
  1155. {
  1156. hasPm = true;
  1157. }
  1158. if (!pmUsed.Contains(module))
  1159. pmUsed.Add(module);
  1160. }
  1161. if (pmIsReady && !hasPm)
  1162. {
  1163. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1164. pmIsReady = false;
  1165. }
  1166. }
  1167. return pmIsReady;
  1168. }
  1169. private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
  1170. {
  1171. reason = "";
  1172. bool foundPm = false;
  1173. bool isAlignerAfterPm = false;
  1174. for (int i = 0; i < seq.Steps.Count; i++)
  1175. {
  1176. SequenceStepInfo stepInfo = seq.Steps[i];
  1177. foreach (var module in stepInfo.StepModules)
  1178. {
  1179. if (ModuleHelper.IsPm(module))
  1180. {
  1181. foundPm = true;
  1182. }
  1183. if (ModuleHelper.IsAligner(module) && foundPm)
  1184. {
  1185. isAlignerAfterPm = true;
  1186. }
  1187. }
  1188. }
  1189. if (!foundPm)
  1190. {
  1191. reason = $"not found PM in the sequence file;";
  1192. }
  1193. if (isAlignerAfterPm)
  1194. {
  1195. reason += "Aligner after PM not support";
  1196. }
  1197. return true;
  1198. }
  1199. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  1200. {
  1201. for (int i = 0; i < seq.Steps.Count; i++)
  1202. {
  1203. SequenceStepInfo stepInfo = seq.Steps[i];
  1204. foreach (var module in stepInfo.StepModules)
  1205. {
  1206. if (ModuleHelper.IsPm(module))
  1207. {
  1208. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  1209. if (stepInfo.StepParameter.ContainsKey(attr)
  1210. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1211. {
  1212. var recipeName = (string)stepInfo.StepParameter[attr];
  1213. if (!string.IsNullOrEmpty(recipeName))
  1214. {
  1215. var recipeContent =
  1216. RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
  1217. if (string.IsNullOrEmpty(recipeContent))
  1218. {
  1219. reason = $"Can not find recipe file{recipeName}";
  1220. return false;
  1221. }
  1222. }
  1223. }
  1224. }
  1225. }
  1226. }
  1227. reason = "";
  1228. return true;
  1229. }
  1230. private bool SetSequenceTemperatureInfo(SequenceInfo seq, out string reason)
  1231. {
  1232. for (int i = 0; i < seq.Steps.Count; i++)
  1233. {
  1234. SequenceStepInfo stepInfo = seq.Steps[i];
  1235. foreach (var module in stepInfo.StepModules)
  1236. {
  1237. if (ModuleHelper.IsPm(module))
  1238. {
  1239. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  1240. if (stepInfo.StepParameter.ContainsKey(attr)
  1241. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1242. {
  1243. var recipeName = (string)stepInfo.StepParameter[attr];
  1244. if (!string.IsNullOrEmpty(recipeName))
  1245. {
  1246. var recipeContent =
  1247. RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
  1248. if (string.IsNullOrEmpty(recipeContent))
  1249. {
  1250. reason = $"Can not find recipe file{recipeName}";
  1251. return false;
  1252. }
  1253. try
  1254. {
  1255. XmlDocument xml = new XmlDocument();
  1256. xml.LoadXml(recipeContent);
  1257. var substrateTemp = xml.DocumentElement.HasAttribute("SubstrateTemp") ? xml.DocumentElement.Attributes["SubstrateTemp"].Value : "";
  1258. if (!float.TryParse(substrateTemp, out float temp))
  1259. {
  1260. reason = $"Invalid substrate temperature in recipe head {recipeName}";
  1261. return false;
  1262. }
  1263. seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"] = temp;
  1264. }
  1265. catch (Exception ex)
  1266. {
  1267. LOG.Write(ex);
  1268. reason = $"recipe not valid, {recipeName}";
  1269. return false;
  1270. }
  1271. }
  1272. }
  1273. }
  1274. }
  1275. }
  1276. reason = "";
  1277. return true;
  1278. }
  1279. private void AssociatedPMWithLP(ControlJobInfo ctrlInfo)
  1280. {
  1281. List<ModuleName> lstPMs = new List<ModuleName>();
  1282. foreach (var process in _lstProcessJobs)
  1283. {
  1284. if (process.ControlJobName == ctrlInfo.Name)
  1285. {
  1286. foreach (var step in process.Sequence.Steps)
  1287. {
  1288. foreach (var module in step.StepModules)
  1289. {
  1290. if (ModuleHelper.IsPm(module))
  1291. {
  1292. if (!lstPMs.Contains(module))
  1293. lstPMs.Add(module);
  1294. }
  1295. }
  1296. }
  1297. }
  1298. }
  1299. var lp = ModuleHelper.Converter(ctrlInfo.Module);
  1300. dictLPAssociatedPM[lp] = lstPMs.Count == 1 ? lstPMs[0] : ModuleName.System;
  1301. }
  1302. private static bool IsWaferNeedGotoModule(WaferInfo wafer, ModuleName module)
  1303. {
  1304. if (wafer.IsEmpty)
  1305. return false;
  1306. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1307. return false;
  1308. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1309. return false;
  1310. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  1311. {
  1312. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  1313. .Contains(module))
  1314. return true;
  1315. }
  1316. return false;
  1317. }
  1318. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1319. {
  1320. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1321. {
  1322. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1323. if (wafer.IsEmpty)
  1324. return false;
  1325. if (checkAllProcessed && IsWaferNeedGotoModule(wafer, ModuleName.PMA) || IsWaferNeedGotoModule(wafer, ModuleName.PMB))
  1326. return false;
  1327. }
  1328. return true;
  1329. }
  1330. private void UpdateProcessJobStatus()
  1331. {
  1332. foreach (var pj in _lstProcessJobs)
  1333. {
  1334. if (pj.State == EnumProcessJobState.Processing)
  1335. {
  1336. if (CheckAllWaferReturned(pj, true))
  1337. {
  1338. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1339. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1340. }
  1341. }
  1342. else if (pj.State == EnumProcessJobState.Stopping)
  1343. {
  1344. if (CheckAllWaferReturned(pj, false))
  1345. {
  1346. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1347. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. private void CompleteJobClean(ControlJobInfo cj)
  1353. {
  1354. List<SchedulerPM> pms = GetPmNeeded(cj);
  1355. foreach (var pm in pms)
  1356. {
  1357. pm.CompleteJobClean();
  1358. }
  1359. }
  1360. private void UpdateControlJobStatus()
  1361. {
  1362. if (_lstControlJobs.Count == 0)
  1363. return;
  1364. if (_curAction.state != ActionState.Done)
  1365. return;
  1366. bool allControlJobComplete = true;
  1367. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1368. foreach (var cj in _lstControlJobs)
  1369. {
  1370. if (!IsModuleAvailable(ModuleHelper.Converter(cj.Module)))
  1371. {
  1372. allControlJobComplete = false;
  1373. continue;
  1374. }
  1375. if (cj.State == EnumControlJobState.Executing)
  1376. {
  1377. bool allPjCompleted = true;
  1378. foreach (var pjName in cj.ProcessJobNameList)
  1379. {
  1380. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1381. if (pj == null)
  1382. {
  1383. LOG.Error($"Not find pj named {pjName} in {cj.Name}");
  1384. continue;
  1385. }
  1386. if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
  1387. {
  1388. allPjCompleted = false;
  1389. break;
  1390. }
  1391. if (allPjCompleted)
  1392. {
  1393. pj.SlotWafers.ForEach(p => {
  1394. if (ModuleHelper.IsLoadPort(p.Item1))
  1395. {
  1396. allPjCompleted = allPjCompleted && WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(p.Item1.ToString()), p.Item2);
  1397. }
  1398. });
  1399. }
  1400. }
  1401. if (allPjCompleted)
  1402. {
  1403. cj.SetState(EnumControlJobState.Completed);
  1404. cj.EndTime = DateTime.Now;
  1405. if (!(_isCycleMode && _cycledCount + 1 < _cycleSetPoint))
  1406. {
  1407. CompleteJobClean(cj);
  1408. }
  1409. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1410. _dbCallback.LotFinished(cj);
  1411. if (!(_isCycleMode&& _cycledCount < _cycleSetPoint))
  1412. (GetScheduler( ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
  1413. }
  1414. }
  1415. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1416. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  1417. {
  1418. cjRemoveList.Add(cj);
  1419. }
  1420. allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
  1421. }
  1422. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1423. {
  1424. int countPerCycle = 0;
  1425. int countProcessed = 0;
  1426. foreach (var pj in _lstProcessJobs)
  1427. {
  1428. foreach (var pjSlotWafer in pj.SlotWafers)
  1429. {
  1430. countPerCycle++;
  1431. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1432. if (!wafer.IsEmpty && !IsWaferNeedGotoModule(wafer, ModuleName.PMA) && !IsWaferNeedGotoModule(wafer, ModuleName.PMB))
  1433. countProcessed++;
  1434. }
  1435. }
  1436. _cycledWafer = _cycledCount * countPerCycle + countProcessed;
  1437. if (allControlJobComplete)
  1438. {
  1439. _cycledCount++;
  1440. if (_cycledCount < _cycleSetPoint)
  1441. {
  1442. foreach (var cj in _lstControlJobs)
  1443. {
  1444. cj.SetState(EnumControlJobState.Executing);
  1445. cj.LotInnerId = Guid.NewGuid();
  1446. _dbCallback.LotCreated(cj);
  1447. }
  1448. foreach (var pj in _lstProcessJobs)
  1449. {
  1450. pj.SetState(EnumProcessJobState.Queued);
  1451. pj.InnerId = Guid.NewGuid();
  1452. foreach (var pjSlotWafer in pj.SlotWafers)
  1453. {
  1454. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1455. wafer.ProcessJob = null;
  1456. wafer.NextSequenceStep = 0;
  1457. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1458. }
  1459. }
  1460. }
  1461. }
  1462. }
  1463. foreach (var cj in cjRemoveList)
  1464. {
  1465. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1466. foreach (var pj in _lstProcessJobs)
  1467. {
  1468. if (pj.ControlJobName == cj.Name)
  1469. pjRemoveList.Add(pj);
  1470. }
  1471. foreach (var pj in pjRemoveList)
  1472. {
  1473. _lstProcessJobs.Remove(pj);
  1474. }
  1475. _lstControlJobs.Remove(cj);
  1476. }
  1477. }
  1478. #region public interface
  1479. private R_TRIG _trigLp1JobComplete = new R_TRIG();
  1480. private R_TRIG _trigLp2JobComplete = new R_TRIG();
  1481. private bool _isAutoUnloadFoup
  1482. {
  1483. get
  1484. {
  1485. return SC.GetValue<bool>("EFEM.LoadPort.EnableAutoUnloadFoup");
  1486. }
  1487. }
  1488. public bool CheckAllJobDone()
  1489. {
  1490. foreach (var moduleKey in dictSchedulers.Keys)
  1491. {
  1492. if (!ModuleHelper.IsLoadPort(moduleKey)) continue;
  1493. var lp = dictSchedulers[moduleKey] as SchedulerLoadPort;
  1494. if (lp != null && lp.IsAvailable)
  1495. {
  1496. var trigLP = lp.Module == ModuleName.LP1 ? _trigLp1JobComplete : _trigLp2JobComplete;
  1497. trigLP.CLK = CheckJobComplete(lp.Module.ToString());
  1498. if (trigLP.Q)
  1499. {
  1500. if (_isAutoUnloadFoup)
  1501. {
  1502. lp.Unload(lp.Module);
  1503. }
  1504. }
  1505. }
  1506. }
  1507. foreach (var cj in _lstControlJobs)
  1508. {
  1509. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1510. return false;
  1511. }
  1512. return dictSchedulers.Where(p=>ModuleHelper.IsLoadPort(p.Key)).Select(p=>p.Value).All(p => p.IsAvailable);
  1513. //foreach (var cj in _lstControlJobs)
  1514. //{
  1515. // if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1516. // return false;
  1517. //}
  1518. //return true;
  1519. }
  1520. private bool CheckJobComplete(string lp = null)
  1521. {
  1522. if (_lstProcessJobs.Count == 0)
  1523. return false;
  1524. if (_lstControlJobs.Count == 0)
  1525. return false;
  1526. if (_isCycleMode && _cycledCount < _cycleSetPoint)
  1527. return false;
  1528. if (lp != null)
  1529. {
  1530. var cj = _lstControlJobs.Find(x => x.Module == lp);
  1531. if (cj == null)
  1532. return false;
  1533. }
  1534. foreach (var pj in _lstProcessJobs)
  1535. {
  1536. if (lp == null)
  1537. {
  1538. if (pj.State != EnumProcessJobState.ProcessingComplete)
  1539. {
  1540. return false;
  1541. }
  1542. }
  1543. }
  1544. foreach (var cj in _lstControlJobs)
  1545. {
  1546. if (lp == null)
  1547. {
  1548. if (cj.State != EnumControlJobState.Completed)
  1549. {
  1550. return false;
  1551. }
  1552. }
  1553. else
  1554. {
  1555. if (cj.Module == lp && cj.State != EnumControlJobState.Completed)
  1556. {
  1557. return false;
  1558. }
  1559. }
  1560. }
  1561. return true;
  1562. }
  1563. public bool CheckJobJustDone(out string sJobName)
  1564. {
  1565. foreach (var cj in _lstControlJobs)
  1566. {
  1567. if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
  1568. {
  1569. //LP;WaferSize;Lot;Number;Start;End;
  1570. sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
  1571. cj.BeenPosted = true;
  1572. return true;
  1573. }
  1574. }
  1575. sJobName = "NULL";
  1576. return false;
  1577. }
  1578. public Result Start(params object[] objs)
  1579. {
  1580. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  1581. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  1582. _cycledWafer = 0;
  1583. _cycledCount = 0;
  1584. queMoveAction.Clear();
  1585. _curAction.state = ActionState.Done;
  1586. bool hasPmOnline = false;
  1587. ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
  1588. foreach (var pm in pms)
  1589. {
  1590. if (IsModuleAvailable(pm))
  1591. {
  1592. var pmSchedule = dictSchedulers[pm] as SchedulerPM;
  1593. pmSchedule.SetPMAuto();
  1594. hasPmOnline = true;
  1595. continue;
  1596. }
  1597. }
  1598. if (!hasPmOnline)
  1599. {
  1600. EV.PostWarningLog("Scheduler", "can not change to auto mode, at least one process chamber be online");
  1601. return Result.FAIL;
  1602. }
  1603. return Result.RUN;
  1604. }
  1605. public void Map(string moduleName)
  1606. {
  1607. ModuleName target = ModuleHelper.Converter(moduleName);
  1608. if (!ModuleHelper.IsLoadPort(target))
  1609. {
  1610. EV.PostWarningLog(LogSource, $"Invalid map target {target}");
  1611. return;
  1612. }
  1613. if (!_mapTarget.Contains(target))
  1614. {
  1615. _mapTarget.Add(target);
  1616. }
  1617. }
  1618. public bool CheckRecipeUsedInJob(string pathName)
  1619. {
  1620. foreach (var pj in _lstProcessJobs)
  1621. {
  1622. var seq = pj.Sequence;
  1623. for (int i = 0; i < seq.Steps.Count; i++)
  1624. {
  1625. SequenceStepInfo stepInfo = seq.Steps[i];
  1626. foreach (var module in stepInfo.StepModules)
  1627. {
  1628. if (ModuleHelper.IsPm(module))
  1629. {
  1630. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  1631. if (stepInfo.StepParameter.ContainsKey(attr)
  1632. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1633. {
  1634. var recipeName = (string)stepInfo.StepParameter[attr];
  1635. if (!string.IsNullOrEmpty(recipeName))
  1636. {
  1637. if (pathName.EndsWith(recipeName + ".rcp"))
  1638. return true;
  1639. }
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. return false;
  1646. }
  1647. public bool CheckSequenceUsedInJob(string pathName)
  1648. {
  1649. foreach (var pj in _lstProcessJobs)
  1650. {
  1651. if (pathName.EndsWith(pj.Sequence.Name + ".seq"))
  1652. return true;
  1653. }
  1654. return false;
  1655. }
  1656. public void CreateJob(Dictionary<string, object> param)
  1657. {
  1658. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  1659. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  1660. string[] slotSequence = (string[])param["SlotSequence"];
  1661. string jobId = (string)param["JobId"];
  1662. string module = (string)param["Module"];
  1663. //bool autoStart = (bool)param["AutoStart"];
  1664. string lotId = jobId;
  1665. if (param.ContainsKey("LotId"))
  1666. lotId = (string)param["LotId"];
  1667. if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  1668. {
  1669. EV.PostWarningLog(LogSource, $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}");
  1670. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1671. return;
  1672. }
  1673. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  1674. {
  1675. EV.PostWarningLog(LogSource, $"{module} should be LoadPort");
  1676. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1677. return;
  1678. }
  1679. if (string.IsNullOrEmpty(jobId))
  1680. {
  1681. jobId = "CJ_Local_" + module;
  1682. }
  1683. if (_lstControlJobs.Exists(x => x.Name == jobId))
  1684. {
  1685. EV.PostWarningLog(LogSource, $"{jobId} already created");
  1686. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1687. return;
  1688. }
  1689. SchedulerLoadPort lp = GetScheduler(ModuleHelper.Converter(module)) as SchedulerLoadPort;
  1690. if (!lp.CheckReadyRunJob())
  1691. {
  1692. EV.PostWarningLog(LogSource, $"{module} not ready");
  1693. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1694. return;
  1695. }
  1696. ControlJobInfo cj = new ControlJobInfo();
  1697. cj.Name = jobId;
  1698. cj.Module = module;
  1699. cj.LotName = lotId;
  1700. cj.LotInnerId = Guid.NewGuid();
  1701. cj.LotWafers = new List<WaferInfo>();
  1702. cj.CarrierID = lp.GetCarrierID();
  1703. cj.SetState(EnumControlJobState.WaitingForStart);
  1704. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  1705. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  1706. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  1707. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  1708. for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
  1709. {
  1710. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  1711. continue;
  1712. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  1713. indexSequence[groupName] = slotSequence[i];
  1714. if (!seqSlot.ContainsKey(groupName))
  1715. {
  1716. seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  1717. }
  1718. if (!seqSlotWafers.ContainsKey(groupName))
  1719. {
  1720. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  1721. }
  1722. seqSlot[groupName][i] = true;
  1723. if (!WaferManager.Instance.CheckHasWafer(module, i))
  1724. {
  1725. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} not in the carrier");
  1726. //return;
  1727. }
  1728. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  1729. {
  1730. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}");
  1731. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1732. return;
  1733. }
  1734. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  1735. {
  1736. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}");
  1737. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1738. return;
  1739. }
  1740. var smallWafer = SC.GetValue<int>($"System.SmallWafer");
  1741. //特殊场景,3寸片第一片不能取放
  1742. if (i == 0 && (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size == WaferSize.WS3) && (int)smallWafer == 3)
  1743. {
  1744. EV.PostWarningLog(LogSource, $"job wafer: {module} 3 inch slot {i + 1} is not supported.");
  1745. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1746. return;
  1747. }
  1748. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  1749. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
  1750. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  1751. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  1752. LOG.Info($"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  1753. }
  1754. if (seqSlotWafers.Count == 0)
  1755. {
  1756. EV.PostWarningLog(LogSource, $"job has not assign wafer");
  1757. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1758. return;
  1759. }
  1760. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  1761. string[] seqs = seqSlot.Keys.ToArray();
  1762. for (int i = 0; i < seqs.Length; i++)
  1763. {
  1764. ProcessJobInfo pj = new ProcessJobInfo();
  1765. pj.Name = jobId + "_" + (i + 1);
  1766. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  1767. pj.ControlJobName = cj.Name;
  1768. pj.LotName = lotId;
  1769. pj.SlotWafers = seqSlotWafers[seqs[i]];
  1770. pj.SetState(EnumProcessJobState.Queued);
  1771. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  1772. {
  1773. EV.PostWarningLog(LogSource, $"no valid chamber for the {reason}");
  1774. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1775. return;
  1776. }
  1777. if (!CheckSequenceOrderOk(pj.Sequence, out reason))
  1778. {
  1779. EV.PostWarningLog(LogSource, $"sequence path not valid, {reason}");
  1780. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1781. return;
  1782. }
  1783. if (!SC.GetValue<bool>("System.IsATMMode") && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  1784. {
  1785. EV.PostWarningLog(LogSource, $"recipe file not valid in the sequence, {reason}");
  1786. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1787. return;
  1788. }
  1789. if (!SetSequenceTemperatureInfo(pj.Sequence, out reason))
  1790. {
  1791. EV.PostWarningLog(LogSource, $"sequence recipe temperature not valid, {reason}");
  1792. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1793. return;
  1794. }
  1795. pjs.Add(pj);
  1796. }
  1797. _dbCallback.LotUpdate(cj);
  1798. foreach (var pj in pjs)
  1799. {
  1800. cj.ProcessJobNameList.Add(pj.Name);
  1801. _lstProcessJobs.Add(pj);
  1802. }
  1803. _lstControlJobs.Add(cj);
  1804. AssociatedPMWithLP(cj);
  1805. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  1806. }
  1807. public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  1808. {
  1809. foreach (var pj in _lstProcessJobs)
  1810. {
  1811. if (pj.ControlJobName == cj.Name)
  1812. return pj;
  1813. }
  1814. return null;
  1815. }
  1816. public void AbortJob(string jobName)
  1817. {
  1818. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1819. if (cj == null)
  1820. {
  1821. EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
  1822. return;
  1823. }
  1824. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  1825. foreach (var pj in _lstProcessJobs)
  1826. {
  1827. if (pj.ControlJobName == cj.Name)
  1828. {
  1829. pj.SetState(EnumProcessJobState.Aborting);
  1830. pjAbortList.Add(pj);
  1831. int unprocessed = 0;
  1832. int aborted = 0;
  1833. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  1834. foreach (var waferInfo in wafers)
  1835. {
  1836. waferInfo.ProcessJob = null;
  1837. waferInfo.NextSequenceStep = 0;
  1838. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  1839. unprocessed++;
  1840. }
  1841. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  1842. }
  1843. }
  1844. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  1845. _dbCallback.LotFinished(cj);
  1846. foreach (var pj in pjAbortList)
  1847. {
  1848. _lstProcessJobs.Remove(pj);
  1849. }
  1850. _lstControlJobs.Remove(cj);
  1851. }
  1852. public void StopJob(string jobName)
  1853. {
  1854. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1855. if (cj == null)
  1856. {
  1857. EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
  1858. return;
  1859. }
  1860. foreach (var pj in _lstProcessJobs)
  1861. {
  1862. if (pj.ControlJobName == cj.Name)
  1863. {
  1864. pj.SetState(EnumProcessJobState.Stopping);
  1865. }
  1866. }
  1867. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  1868. _dbCallback.LotFinished(cj);
  1869. }
  1870. public void ResumeJob(string jobName)
  1871. {
  1872. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1873. if (cj == null)
  1874. {
  1875. EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
  1876. return;
  1877. }
  1878. if (cj.State == EnumControlJobState.Paused)
  1879. {
  1880. cj.SetState(EnumControlJobState.Executing);
  1881. }
  1882. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  1883. }
  1884. public void PauseJob(string jobName)
  1885. {
  1886. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1887. if (cj == null)
  1888. {
  1889. EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
  1890. return;
  1891. }
  1892. if (cj.State == EnumControlJobState.Executing)
  1893. {
  1894. cj.SetState(EnumControlJobState.Paused);
  1895. }
  1896. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  1897. }
  1898. public void StartJob(string jobName)
  1899. {
  1900. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1901. if (cj == null)
  1902. {
  1903. EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
  1904. return;
  1905. }
  1906. if (cj.State == EnumControlJobState.WaitingForStart)
  1907. {
  1908. cj.SetState(EnumControlJobState.Executing);
  1909. //PreJobClean(cj);
  1910. (GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobStart();
  1911. cj.StartTime = DateTime.Now;
  1912. _dbCallback.LotCreated(cj);
  1913. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  1914. if (!_blockingWatcher.IsRunning)
  1915. _blockingWatcher.Restart();
  1916. ResetTraceFlag();
  1917. }
  1918. }
  1919. private void NotifyFaWaferEnd()
  1920. {
  1921. if (ModuleHelper.IsLoadPort(_curAction.targetModule))
  1922. {
  1923. // Notify FA for Port1JobWaferEnd
  1924. if (_curAction.eType == EnumTransferType.Place)
  1925. {
  1926. ProcessJobInfo pj = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot)
  1927. .ProcessJob;
  1928. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1929. _faCallback.JobWaferEnd(cj, pj, _curAction.targetModule.ToString(), _curAction.targetSlot);
  1930. }
  1931. }
  1932. }
  1933. public void ResetIdleCleanTime(string module)
  1934. {
  1935. if (string.IsNullOrEmpty(module))
  1936. {
  1937. ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
  1938. foreach (var schedulerPm in pms)
  1939. {
  1940. var pmSchedule = dictSchedulers[schedulerPm] as SchedulerPM;
  1941. pmSchedule.ResetIdleCleanTime();
  1942. }
  1943. }
  1944. else
  1945. {
  1946. var pm = ModuleHelper.Converter(module);
  1947. if (ModuleHelper.IsPm(pm))
  1948. {
  1949. var pmSchedule = dictSchedulers[pm] as SchedulerPM;
  1950. pmSchedule.ResetIdleCleanTime();
  1951. }
  1952. }
  1953. }
  1954. public void ResetIdlePurgeTime(string module)
  1955. {
  1956. if (string.IsNullOrEmpty(module))
  1957. {
  1958. ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
  1959. foreach (var schedulerPm in pms)
  1960. {
  1961. var pmSchedule = dictSchedulers[schedulerPm] as SchedulerPM;
  1962. pmSchedule.ResetIdlePurgeTime();
  1963. }
  1964. }
  1965. else
  1966. {
  1967. var pm = ModuleHelper.Converter(module);
  1968. if (ModuleHelper.IsPm(pm))
  1969. {
  1970. var pmSchedule = dictSchedulers[pm] as SchedulerPM;
  1971. pmSchedule.ResetIdlePurgeTime();
  1972. }
  1973. }
  1974. }
  1975. public void Clear()
  1976. {
  1977. _efemRobot.ResetTask();
  1978. foreach (var module in dictSchedulers)
  1979. {
  1980. module.Value.ResetTask();
  1981. }
  1982. _lstControlJobs.Clear();
  1983. _lstProcessJobs.Clear();
  1984. _mapTarget.Clear();
  1985. queMoveAction.Clear();
  1986. _curAction.state = ActionState.Done;
  1987. }
  1988. #endregion
  1989. }
  1990. }