AutoTransfer_T.cs 86 KB

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