AutoTransfer_T.cs 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  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)
  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)
  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 SlotItem GetLPReadyOutSlot(ModuleName lp)
  749. {
  750. var slot = GetNextWaferInJobQueue(lp);
  751. if (slot == null)
  752. return new SlotItem(ModuleName.System, -1);
  753. return slot;
  754. }
  755. private SlotItem GetModuleReadyOutSlot(ModuleName module)
  756. {
  757. var slot = new SlotItem(ModuleName.System, -1);
  758. if (!IsModuleAvailable(module))
  759. return slot;
  760. WaferInfo wafer = WaferManager.Instance.GetWafer(module, 0);
  761. if (wafer.IsEmpty)
  762. return slot;
  763. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  764. return slot;
  765. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count) // return to loadport
  766. return new SlotItem(module, 0);
  767. if (wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules
  768. .Contains(module))
  769. return slot;
  770. return new SlotItem(module, 0);
  771. }
  772. private SlotItem GetBufferReadyOutSlot(ModuleName buffer)
  773. {
  774. return dictSchedulers[buffer].GetReadyOutSlot();
  775. }
  776. private RobotFreeHand GetRobotFreeHand()
  777. {
  778. var blade1Enable = SC.GetValue<bool>("EFEM.EfemRobot.LowerBladeEnable");
  779. var blade2Enable = SC.GetValue<bool>("EFEM.EfemRobot.UpperBladeEnable");
  780. var blade1HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0);
  781. var blade2HasWafer = WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1);
  782. if (blade1HasWafer && blade2HasWafer)
  783. return RobotFreeHand.None;
  784. else if (!blade1HasWafer && !blade2HasWafer && blade1Enable && blade2Enable)
  785. return RobotFreeHand.Both;
  786. else if (!blade2HasWafer && blade2Enable)
  787. return RobotFreeHand.Blade2;
  788. else if (!blade1HasWafer && blade1Enable)
  789. return RobotFreeHand.Blade1;
  790. else
  791. return RobotFreeHand.None;
  792. }
  793. private RobotFreeHand SelectRobotFreeHand()
  794. {
  795. var freeHand = GetRobotFreeHand();
  796. return freeHand == RobotFreeHand.Both ? RobotFreeHand.Blade1 : freeHand;
  797. }
  798. private void AddWaferPMMark(ModuleName pm)
  799. {
  800. var wafer = WaferManager.Instance.GetWafer(pm, 0);
  801. if (wafer.IsEmpty)
  802. return;
  803. dictWaferProcessPM[wafer.InnerId] = pm;
  804. }
  805. private void RemoveWaferPMMark(SlotItem slot)
  806. {
  807. var wafer = WaferManager.Instance.GetWafer(slot.Module, slot.Slot);
  808. if (wafer.IsEmpty)
  809. return;
  810. dictWaferProcessPM.Remove(wafer.InnerId);
  811. }
  812. private void ResetTraceFlag()
  813. {
  814. _lastTraceState = _currentTraceState = RtTraceState.Init;
  815. }
  816. public Result Monitor()
  817. {
  818. prelude();
  819. Pump();
  820. Pop();
  821. epilogue();
  822. return Result.RUN;
  823. }
  824. private List<ModuleName> GetPmUsedInRunningPj()
  825. {
  826. var pmUsed = new List<ModuleName>();
  827. foreach (var cj in _lstControlJobs)
  828. {
  829. if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
  830. continue;
  831. foreach (var pj in _lstProcessJobs)
  832. {
  833. if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
  834. {
  835. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  836. {
  837. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  838. foreach (var module in stepInfo.StepModules)
  839. {
  840. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  841. pmUsed.Add(module);
  842. }
  843. }
  844. }
  845. }
  846. }
  847. return pmUsed;
  848. }
  849. private List<SchedulerPM> GetPmNeeded(ControlJobInfo cj)
  850. {
  851. List<SchedulerPM> result = new List<SchedulerPM>();
  852. foreach (var pj in _lstProcessJobs)
  853. {
  854. if (pj.ControlJobName != cj.Name)
  855. continue;
  856. var seq = pj.Sequence;
  857. for (int i = 0; i < seq.Steps.Count; i++)
  858. {
  859. SequenceStepInfo stepInfo = seq.Steps[i];
  860. foreach (var module in stepInfo.StepModules)
  861. {
  862. if (ModuleHelper.IsPm(module))
  863. {
  864. var pm = dictSchedulers[module] as SchedulerPM;
  865. if (pm != null && !result.Contains(pm))
  866. {
  867. result.Add(pm);
  868. }
  869. }
  870. }
  871. }
  872. }
  873. return result;
  874. }
  875. private void InitClean()
  876. {
  877. foreach (var pm in dictSchedulers)
  878. {
  879. if (ModuleHelper.IsPm(pm.Key))
  880. {
  881. var scheduler = pm.Value as SchedulerPM;
  882. scheduler.InitClean();
  883. }
  884. }
  885. }
  886. public Result MonitorCleanTasks()
  887. {
  888. if (!_isInited)
  889. {
  890. _isInited = true;
  891. 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.MonitorCleanTasks();
  899. }
  900. }
  901. return Result.RUN;
  902. }
  903. private void PreJobClean(ControlJobInfo cj)
  904. {
  905. if (cj.IsPreJobCleanDone)
  906. return;
  907. cj.IsPreJobCleanDone = true;
  908. List<SchedulerPM> pms = GetPmNeeded(cj);
  909. foreach (var pm in pms)
  910. {
  911. pm.PreJobClean();
  912. }
  913. }
  914. private bool ActiveProcessJob(ProcessJobInfo pj)
  915. {
  916. foreach (var pjSlotWafer in pj.SlotWafers)
  917. {
  918. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  919. wafer.ProcessJob = pj;
  920. wafer.NextSequenceStep = 0;
  921. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  922. }
  923. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  924. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  925. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  926. pj.SetState(EnumProcessJobState.Processing);
  927. PreJobClean(cj);
  928. return true;
  929. }
  930. private void StartNewJob()
  931. {
  932. ControlJobInfo cjActived = null;
  933. List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
  934. foreach (var cj in _lstControlJobs)
  935. {
  936. if (cj.State != EnumControlJobState.Executing)
  937. continue;
  938. cjActived = cj;
  939. foreach (var pjName in cjActived.ProcessJobNameList)
  940. {
  941. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  942. if (pj == null)
  943. {
  944. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  945. continue;
  946. }
  947. if (pj.State == EnumProcessJobState.Queued)
  948. {
  949. if (CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason))
  950. {
  951. ActiveProcessJob(pj);
  952. foreach (var moduleName in pmUsed)
  953. {
  954. if (!pmOccupied.Contains(moduleName))
  955. pmOccupied.Add(moduleName);
  956. }
  957. }
  958. break;
  959. }
  960. }
  961. }
  962. }
  963. private bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  964. {
  965. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  966. if (wafer.IsEmpty)
  967. return false;
  968. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  969. return false;
  970. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  971. return false;
  972. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  973. {
  974. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  975. .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
  976. .Contains(ModuleName.PMB))
  977. {
  978. var hasPmAvailable = false;
  979. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  980. {
  981. var pm = GetScheduler(stepModule) as SchedulerPM;
  982. if (pm != null)
  983. {
  984. if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
  985. {
  986. hasPmAvailable = true;
  987. break;
  988. }
  989. }
  990. }
  991. if (!hasPmAvailable)
  992. return false;
  993. if (processIn == ModuleName.System)
  994. return true;
  995. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  996. .Contains(processIn))
  997. return true;
  998. }
  999. }
  1000. return false;
  1001. }
  1002. private bool IsFixedPMMode()
  1003. {
  1004. List<ModuleName> associatedPMs = new List<ModuleName>();
  1005. foreach (var module in dictSchedulers.Keys)
  1006. {
  1007. if (ModuleHelper.IsLoadPort(module))
  1008. {
  1009. if (dictLPAssociatedPM.ContainsKey(module))
  1010. {
  1011. if (dictLPAssociatedPM[module] == ModuleName.System)
  1012. return false;
  1013. if (!associatedPMs.Contains(dictLPAssociatedPM[module]))
  1014. associatedPMs.Add(dictLPAssociatedPM[module]);
  1015. }
  1016. }
  1017. }
  1018. return associatedPMs.Count >= 2;
  1019. }
  1020. void AdjustLPPriority(ModuleName lp)
  1021. {
  1022. foreach (var module in dictModules.Keys)
  1023. {
  1024. if (ModuleHelper.IsLoadPort(module))
  1025. {
  1026. dictModules[module].priority = module == lp ? ModulePriority.Low : ModulePriority.Middle;
  1027. }
  1028. }
  1029. }
  1030. void AdjustAlignerPriority(ModuleName aligner)
  1031. {
  1032. foreach (var module in dictModules.Keys)
  1033. {
  1034. if (ModuleHelper.IsAligner(module))
  1035. {
  1036. dictModules[module].priority = module == aligner ? ModulePriority.Low : ModulePriority.Middle;
  1037. }
  1038. }
  1039. }
  1040. private SlotItem GetNextWaferInJobQueue(ModuleName lpModule)
  1041. {
  1042. if (GetSystemInnerWaferCount() >= SystemInternalWaferCount || GetBufferWaferCount() > _maxBufferWaferCount)
  1043. return new SlotItem(ModuleName.System, -1);
  1044. foreach (var cj in _lstControlJobs)
  1045. {
  1046. if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
  1047. continue;
  1048. if (cj.State == EnumControlJobState.Executing)
  1049. {
  1050. foreach (var pj in _lstProcessJobs)
  1051. {
  1052. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  1053. {
  1054. foreach (var pjSlotWafer in pj.SlotWafers)
  1055. {
  1056. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  1057. {
  1058. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1059. }
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. return new SlotItem(ModuleName.System, -1);
  1066. }
  1067. static public int GetSystemInnerWaferCount()
  1068. {
  1069. int count = 0;
  1070. var lstPosition = new List<ModuleName>()
  1071. {
  1072. ModuleName.EfemRobot, ModuleName.Aligner1, ModuleName.Aligner2, ModuleName.Cooling1, ModuleName.Cooling2, ModuleName.Flipper, ModuleName.PMA, ModuleName.PMB,
  1073. };
  1074. foreach (var moduleName in lstPosition)
  1075. {
  1076. if (ModuleHelper.IsInstalled(moduleName) && WaferManager.Instance.CheckHasWafer(moduleName, 0))
  1077. count++;
  1078. }
  1079. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  1080. count++;
  1081. return count;
  1082. }
  1083. private int GetBufferWaferCount()
  1084. {
  1085. int nCount = 0;
  1086. for (int i = 0; i < SC.GetValue<int>("EFEM.Buffer.SlotNumber"); i++)
  1087. {
  1088. if (WaferManager.Instance.CheckHasWafer(ModuleName.Buffer, i))
  1089. nCount++;
  1090. }
  1091. return nCount;
  1092. }
  1093. #endregion transfer routine
  1094. private void MonitorEfemRobotMapTask()
  1095. {
  1096. if (!_efemRobot.IsAvailable)
  1097. return;
  1098. if (_mapTarget.Count > 0)
  1099. {
  1100. ModuleName first = _mapTarget[0];
  1101. //避免重复map,job信息被清除
  1102. foreach (var cj in _lstControlJobs)
  1103. {
  1104. if (cj.Module != first.ToString())
  1105. continue;
  1106. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1107. {
  1108. EV.PostWarningLog("System", $"{first} is running, can not map again");
  1109. _mapTarget.Remove(first);
  1110. }
  1111. }
  1112. SchedulerLoadPort lp = GetScheduler(first) as SchedulerLoadPort;
  1113. if (lp != null && lp.IsAvailable)
  1114. {
  1115. _efemRobot.Map(first);
  1116. _mapTarget.Remove(first);
  1117. }
  1118. }
  1119. }
  1120. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  1121. {
  1122. pmUsed = new List<ModuleName>();
  1123. reason = "";
  1124. bool pmIsReady = true;
  1125. for (int i = 0; i < seq.Steps.Count; i++)
  1126. {
  1127. SequenceStepInfo stepInfo = seq.Steps[i];
  1128. bool hasPm = false;
  1129. foreach (var module in stepInfo.StepModules)
  1130. {
  1131. if (!ModuleHelper.IsPm(module))
  1132. {
  1133. hasPm = true;
  1134. break;
  1135. }
  1136. PM pm = DEVICE.GetDevice<PM>(module.ToString());
  1137. if (pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(module)))
  1138. {
  1139. hasPm = true;
  1140. }
  1141. if (!pmUsed.Contains(module))
  1142. pmUsed.Add(module);
  1143. }
  1144. if (pmIsReady && !hasPm)
  1145. {
  1146. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1147. pmIsReady = false;
  1148. }
  1149. }
  1150. return pmIsReady;
  1151. }
  1152. private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
  1153. {
  1154. reason = "";
  1155. bool foundPm = false;
  1156. bool isAlignerAfterPm = false;
  1157. for (int i = 0; i < seq.Steps.Count; i++)
  1158. {
  1159. SequenceStepInfo stepInfo = seq.Steps[i];
  1160. foreach (var module in stepInfo.StepModules)
  1161. {
  1162. if (ModuleHelper.IsPm(module))
  1163. {
  1164. foundPm = true;
  1165. }
  1166. if (ModuleHelper.IsAligner(module) && foundPm)
  1167. {
  1168. isAlignerAfterPm = true;
  1169. }
  1170. }
  1171. }
  1172. if (!foundPm)
  1173. {
  1174. reason = $"not found PM in the sequence file;";
  1175. }
  1176. if (isAlignerAfterPm)
  1177. {
  1178. reason += "Aligner after PM not support";
  1179. }
  1180. return true;
  1181. }
  1182. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  1183. {
  1184. for (int i = 0; i < seq.Steps.Count; i++)
  1185. {
  1186. SequenceStepInfo stepInfo = seq.Steps[i];
  1187. foreach (var module in stepInfo.StepModules)
  1188. {
  1189. if (ModuleHelper.IsPm(module))
  1190. {
  1191. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  1192. if (stepInfo.StepParameter.ContainsKey(attr)
  1193. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1194. {
  1195. var recipeName = (string)stepInfo.StepParameter[attr];
  1196. if (!string.IsNullOrEmpty(recipeName))
  1197. {
  1198. var recipeContent =
  1199. RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
  1200. if (string.IsNullOrEmpty(recipeContent))
  1201. {
  1202. reason = $"Can not find recipe file{recipeName}";
  1203. return false;
  1204. }
  1205. }
  1206. }
  1207. }
  1208. }
  1209. }
  1210. reason = "";
  1211. return true;
  1212. }
  1213. private bool SetSequenceTemperatureInfo(SequenceInfo seq, out string reason)
  1214. {
  1215. for (int i = 0; i < seq.Steps.Count; i++)
  1216. {
  1217. SequenceStepInfo stepInfo = seq.Steps[i];
  1218. foreach (var module in stepInfo.StepModules)
  1219. {
  1220. if (ModuleHelper.IsPm(module))
  1221. {
  1222. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  1223. if (stepInfo.StepParameter.ContainsKey(attr)
  1224. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1225. {
  1226. var recipeName = (string)stepInfo.StepParameter[attr];
  1227. if (!string.IsNullOrEmpty(recipeName))
  1228. {
  1229. var recipeContent =
  1230. RecipeFileManager.Instance.LoadRecipe($"", recipeName, false);
  1231. if (string.IsNullOrEmpty(recipeContent))
  1232. {
  1233. reason = $"Can not find recipe file{recipeName}";
  1234. return false;
  1235. }
  1236. try
  1237. {
  1238. XmlDocument xml = new XmlDocument();
  1239. xml.LoadXml(recipeContent);
  1240. var substrateTemp = xml.DocumentElement.HasAttribute("SubstrateTemp") ? xml.DocumentElement.Attributes["SubstrateTemp"].Value : "";
  1241. if (!float.TryParse(substrateTemp, out float temp))
  1242. {
  1243. reason = $"Invalid substrate temperature in recipe head {recipeName}";
  1244. return false;
  1245. }
  1246. seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMATemp" : "PMBTemp"] = temp;
  1247. }
  1248. catch (Exception ex)
  1249. {
  1250. LOG.Write(ex);
  1251. reason = $"recipe not valid, {recipeName}";
  1252. return false;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. reason = "";
  1260. return true;
  1261. }
  1262. private void AssociatedPMWithLP(ControlJobInfo ctrlInfo)
  1263. {
  1264. List<ModuleName> lstPMs = new List<ModuleName>();
  1265. foreach (var process in _lstProcessJobs)
  1266. {
  1267. if (process.ControlJobName == ctrlInfo.Name)
  1268. {
  1269. foreach (var step in process.Sequence.Steps)
  1270. {
  1271. foreach (var module in step.StepModules)
  1272. {
  1273. if (ModuleHelper.IsPm(module))
  1274. {
  1275. if (!lstPMs.Contains(module))
  1276. lstPMs.Add(module);
  1277. }
  1278. }
  1279. }
  1280. }
  1281. }
  1282. var lp = ModuleHelper.Converter(ctrlInfo.Module);
  1283. dictLPAssociatedPM[lp] = lstPMs.Count == 1 ? lstPMs[0] : ModuleName.System;
  1284. }
  1285. private static bool IsWaferNeedGotoModule(WaferInfo wafer, ModuleName module)
  1286. {
  1287. if (wafer.IsEmpty)
  1288. return false;
  1289. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  1290. return false;
  1291. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  1292. return false;
  1293. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  1294. {
  1295. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  1296. .Contains(module))
  1297. return true;
  1298. }
  1299. return false;
  1300. }
  1301. private bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1302. {
  1303. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1304. {
  1305. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1306. if (wafer.IsEmpty)
  1307. return false;
  1308. if (checkAllProcessed && IsWaferNeedGotoModule(wafer, ModuleName.PMA) || IsWaferNeedGotoModule(wafer, ModuleName.PMB))
  1309. return false;
  1310. }
  1311. return true;
  1312. }
  1313. private void UpdateProcessJobStatus()
  1314. {
  1315. foreach (var pj in _lstProcessJobs)
  1316. {
  1317. if (pj.State == EnumProcessJobState.Processing)
  1318. {
  1319. if (CheckAllWaferReturned(pj, true))
  1320. {
  1321. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1322. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1323. }
  1324. }
  1325. else if (pj.State == EnumProcessJobState.Stopping)
  1326. {
  1327. if (CheckAllWaferReturned(pj, false))
  1328. {
  1329. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1330. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. private void CompleteJobClean(ControlJobInfo cj)
  1336. {
  1337. List<SchedulerPM> pms = GetPmNeeded(cj);
  1338. foreach (var pm in pms)
  1339. {
  1340. pm.CompleteJobClean();
  1341. }
  1342. }
  1343. private void UpdateControlJobStatus()
  1344. {
  1345. if (_lstControlJobs.Count == 0)
  1346. return;
  1347. if (_curAction.state != ActionState.Done)
  1348. return;
  1349. bool allControlJobComplete = true;
  1350. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1351. foreach (var cj in _lstControlJobs)
  1352. {
  1353. if (!IsModuleAvailable(ModuleHelper.Converter(cj.Module)))
  1354. {
  1355. allControlJobComplete = false;
  1356. continue;
  1357. }
  1358. if (cj.State == EnumControlJobState.Executing)
  1359. {
  1360. bool allPjCompleted = true;
  1361. foreach (var pjName in cj.ProcessJobNameList)
  1362. {
  1363. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1364. if (pj == null)
  1365. {
  1366. LOG.Error($"Not find pj named {pjName} in {cj.Name}");
  1367. continue;
  1368. }
  1369. if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
  1370. {
  1371. allPjCompleted = false;
  1372. break;
  1373. }
  1374. if (allPjCompleted)
  1375. {
  1376. pj.SlotWafers.ForEach(p => {
  1377. if (ModuleHelper.IsLoadPort(p.Item1))
  1378. {
  1379. allPjCompleted = allPjCompleted && WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(p.Item1.ToString()), p.Item2);
  1380. }
  1381. });
  1382. }
  1383. }
  1384. if (allPjCompleted)
  1385. {
  1386. cj.SetState(EnumControlJobState.Completed);
  1387. cj.EndTime = DateTime.Now;
  1388. if (!(_isCycleMode && _cycledCount + 1 < _cycleSetPoint))
  1389. {
  1390. CompleteJobClean(cj);
  1391. }
  1392. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1393. _dbCallback.LotFinished(cj);
  1394. if (!(_isCycleMode&& _cycledCount < _cycleSetPoint))
  1395. (GetScheduler( ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobComplete();
  1396. }
  1397. }
  1398. LoadportCassetteState state = (LoadportCassetteState)DATA.Poll($"{cj.Module}.CassetteState");
  1399. if (cj.State == EnumControlJobState.Completed && state != LoadportCassetteState.Normal)
  1400. {
  1401. cjRemoveList.Add(cj);
  1402. }
  1403. allControlJobComplete = allControlJobComplete && cj.State == EnumControlJobState.Completed;
  1404. }
  1405. if (_isCycleMode && _cycledCount < (_isCycleMode ? _cycleSetPoint : 0))
  1406. {
  1407. int countPerCycle = 0;
  1408. int countProcessed = 0;
  1409. foreach (var pj in _lstProcessJobs)
  1410. {
  1411. foreach (var pjSlotWafer in pj.SlotWafers)
  1412. {
  1413. countPerCycle++;
  1414. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1415. if (!wafer.IsEmpty && !IsWaferNeedGotoModule(wafer, ModuleName.PMA) && !IsWaferNeedGotoModule(wafer, ModuleName.PMB))
  1416. countProcessed++;
  1417. }
  1418. }
  1419. _cycledWafer = _cycledCount * countPerCycle + countProcessed;
  1420. if (allControlJobComplete)
  1421. {
  1422. _cycledCount++;
  1423. if (_cycledCount < _cycleSetPoint)
  1424. {
  1425. foreach (var cj in _lstControlJobs)
  1426. {
  1427. cj.SetState(EnumControlJobState.Executing);
  1428. cj.LotInnerId = Guid.NewGuid();
  1429. _dbCallback.LotCreated(cj);
  1430. }
  1431. foreach (var pj in _lstProcessJobs)
  1432. {
  1433. pj.SetState(EnumProcessJobState.Queued);
  1434. pj.InnerId = Guid.NewGuid();
  1435. foreach (var pjSlotWafer in pj.SlotWafers)
  1436. {
  1437. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1438. wafer.ProcessJob = null;
  1439. wafer.NextSequenceStep = 0;
  1440. wafer.ProcessState = EnumWaferProcessStatus.Idle;
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. foreach (var cj in cjRemoveList)
  1447. {
  1448. List<ProcessJobInfo> pjRemoveList = new List<ProcessJobInfo>();
  1449. foreach (var pj in _lstProcessJobs)
  1450. {
  1451. if (pj.ControlJobName == cj.Name)
  1452. pjRemoveList.Add(pj);
  1453. }
  1454. foreach (var pj in pjRemoveList)
  1455. {
  1456. _lstProcessJobs.Remove(pj);
  1457. }
  1458. _lstControlJobs.Remove(cj);
  1459. }
  1460. }
  1461. #region public interface
  1462. public bool CheckAllJobDone()
  1463. {
  1464. foreach (var cj in _lstControlJobs)
  1465. {
  1466. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1467. return false;
  1468. }
  1469. return true;
  1470. }
  1471. public bool CheckJobJustDone(out string sJobName)
  1472. {
  1473. foreach (var cj in _lstControlJobs)
  1474. {
  1475. if (cj.State == EnumControlJobState.Completed && !cj.BeenPosted)
  1476. {
  1477. //LP;WaferSize;Lot;Number;Start;End;
  1478. sJobName = $"{cj.Module};{cj.JobWaferSize};{cj.LotName};{cj.LotWafers.Count};{cj.StartTime:T};{cj.EndTime:T}";
  1479. cj.BeenPosted = true;
  1480. return true;
  1481. }
  1482. }
  1483. sJobName = "NULL";
  1484. return false;
  1485. }
  1486. public Result Start(params object[] objs)
  1487. {
  1488. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  1489. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  1490. _cycledWafer = 0;
  1491. _cycledCount = 0;
  1492. queMoveAction.Clear();
  1493. _curAction.state = ActionState.Done;
  1494. bool hasPmOnline = false;
  1495. ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
  1496. foreach (var pm in pms)
  1497. {
  1498. if (IsModuleAvailable(pm))
  1499. {
  1500. var pmSchedule = dictSchedulers[pm] as SchedulerPM;
  1501. pmSchedule.SetPMAuto();
  1502. hasPmOnline = true;
  1503. continue;
  1504. }
  1505. }
  1506. if (!hasPmOnline)
  1507. {
  1508. EV.PostWarningLog("Scheduler", "can not change to auto mode, at least one process chamber be online");
  1509. return Result.FAIL;
  1510. }
  1511. return Result.RUN;
  1512. }
  1513. public void Map(string moduleName)
  1514. {
  1515. ModuleName target = ModuleHelper.Converter(moduleName);
  1516. if (!ModuleHelper.IsLoadPort(target))
  1517. {
  1518. EV.PostWarningLog(LogSource, $"Invalid map target {target}");
  1519. return;
  1520. }
  1521. if (!_mapTarget.Contains(target))
  1522. {
  1523. _mapTarget.Add(target);
  1524. }
  1525. }
  1526. public bool CheckRecipeUsedInJob(string pathName)
  1527. {
  1528. foreach (var pj in _lstProcessJobs)
  1529. {
  1530. var seq = pj.Sequence;
  1531. for (int i = 0; i < seq.Steps.Count; i++)
  1532. {
  1533. SequenceStepInfo stepInfo = seq.Steps[i];
  1534. foreach (var module in stepInfo.StepModules)
  1535. {
  1536. if (ModuleHelper.IsPm(module))
  1537. {
  1538. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  1539. if (stepInfo.StepParameter.ContainsKey(attr)
  1540. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1541. {
  1542. var recipeName = (string)stepInfo.StepParameter[attr];
  1543. if (!string.IsNullOrEmpty(recipeName))
  1544. {
  1545. if (pathName.EndsWith(recipeName + ".rcp"))
  1546. return true;
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. return false;
  1554. }
  1555. public bool CheckSequenceUsedInJob(string pathName)
  1556. {
  1557. foreach (var pj in _lstProcessJobs)
  1558. {
  1559. if (pathName.EndsWith(pj.Sequence.Name + ".seq"))
  1560. return true;
  1561. }
  1562. return false;
  1563. }
  1564. public void CreateJob(Dictionary<string, object> param)
  1565. {
  1566. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  1567. _cycleSetPoint = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 0;
  1568. string[] slotSequence = (string[])param["SlotSequence"];
  1569. string jobId = (string)param["JobId"];
  1570. string module = (string)param["Module"];
  1571. //bool autoStart = (bool)param["AutoStart"];
  1572. string lotId = jobId;
  1573. if (param.ContainsKey("LotId"))
  1574. lotId = (string)param["LotId"];
  1575. if (slotSequence.Length != SC.GetValue<int>("EFEM.LoadPort.SlotNumber"))
  1576. {
  1577. EV.PostWarningLog(LogSource, $"slot sequence parameter not valid, length is {slotSequence.Length}, should be {SC.GetValue<int>("EFEM.LoadPort.SlotNumber")}");
  1578. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1579. return;
  1580. }
  1581. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  1582. {
  1583. EV.PostWarningLog(LogSource, $"{module} should be LoadPort");
  1584. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1585. return;
  1586. }
  1587. if (string.IsNullOrEmpty(jobId))
  1588. {
  1589. jobId = "CJ_Local_" + module;
  1590. }
  1591. if (_lstControlJobs.Exists(x => x.Name == jobId))
  1592. {
  1593. EV.PostWarningLog(LogSource, $"{jobId} already created");
  1594. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1595. return;
  1596. }
  1597. SchedulerLoadPort lp = GetScheduler(ModuleHelper.Converter(module)) as SchedulerLoadPort;
  1598. if (!lp.CheckReadyRunJob())
  1599. {
  1600. EV.PostWarningLog(LogSource, $"{module} not ready");
  1601. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1602. return;
  1603. }
  1604. ControlJobInfo cj = new ControlJobInfo();
  1605. cj.Name = jobId;
  1606. cj.Module = module;
  1607. cj.LotName = lotId;
  1608. cj.LotInnerId = Guid.NewGuid();
  1609. cj.LotWafers = new List<WaferInfo>();
  1610. cj.CarrierID = lp.GetCarrierID();
  1611. cj.SetState(EnumControlJobState.WaitingForStart);
  1612. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  1613. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  1614. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  1615. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  1616. for (int i = 0; i < SC.GetValue<int>("EFEM.LoadPort.SlotNumber"); i++)
  1617. {
  1618. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  1619. continue;
  1620. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  1621. indexSequence[groupName] = slotSequence[i];
  1622. if (!seqSlot.ContainsKey(groupName))
  1623. {
  1624. seqSlot[groupName] = new bool[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  1625. }
  1626. if (!seqSlotWafers.ContainsKey(groupName))
  1627. {
  1628. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  1629. }
  1630. seqSlot[groupName][i] = true;
  1631. if (!WaferManager.Instance.CheckHasWafer(module, i))
  1632. {
  1633. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} not in the carrier");
  1634. //return;
  1635. }
  1636. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  1637. {
  1638. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}");
  1639. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1640. return;
  1641. }
  1642. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  1643. {
  1644. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}");
  1645. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1646. return;
  1647. }
  1648. var smallWafer = SC.GetValue<int>($"System.SmallWafer");
  1649. //特殊场景,3寸片第一片不能取放
  1650. if (i == 0 && (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size == WaferSize.WS3) && (int)smallWafer == 3)
  1651. {
  1652. EV.PostWarningLog(LogSource, $"job wafer: {module} 3 inch slot {i + 1} is not supported.");
  1653. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1654. return;
  1655. }
  1656. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  1657. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
  1658. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  1659. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  1660. LOG.Info($"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  1661. }
  1662. if (seqSlotWafers.Count == 0)
  1663. {
  1664. EV.PostWarningLog(LogSource, $"job has not assign wafer");
  1665. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1666. return;
  1667. }
  1668. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  1669. string[] seqs = seqSlot.Keys.ToArray();
  1670. for (int i = 0; i < seqs.Length; i++)
  1671. {
  1672. ProcessJobInfo pj = new ProcessJobInfo();
  1673. pj.Name = jobId + "_" + (i + 1);
  1674. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  1675. pj.ControlJobName = cj.Name;
  1676. pj.LotName = lotId;
  1677. pj.SlotWafers = seqSlotWafers[seqs[i]];
  1678. pj.SetState(EnumProcessJobState.Queued);
  1679. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  1680. {
  1681. EV.PostWarningLog(LogSource, $"no valid chamber for the {reason}");
  1682. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1683. return;
  1684. }
  1685. if (!CheckSequenceOrderOk(pj.Sequence, out reason))
  1686. {
  1687. EV.PostWarningLog(LogSource, $"sequence path not valid, {reason}");
  1688. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1689. return;
  1690. }
  1691. if (!SC.GetValue<bool>("System.IsATMMode") && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  1692. {
  1693. EV.PostWarningLog(LogSource, $"recipe file not valid in the sequence, {reason}");
  1694. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1695. return;
  1696. }
  1697. if (!SetSequenceTemperatureInfo(pj.Sequence, out reason))
  1698. {
  1699. EV.PostWarningLog(LogSource, $"sequence recipe temperature not valid, {reason}");
  1700. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  1701. return;
  1702. }
  1703. pjs.Add(pj);
  1704. }
  1705. _dbCallback.LotUpdate(cj);
  1706. foreach (var pj in pjs)
  1707. {
  1708. cj.ProcessJobNameList.Add(pj.Name);
  1709. _lstProcessJobs.Add(pj);
  1710. }
  1711. _lstControlJobs.Add(cj);
  1712. AssociatedPMWithLP(cj);
  1713. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  1714. }
  1715. public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  1716. {
  1717. foreach (var pj in _lstProcessJobs)
  1718. {
  1719. if (pj.ControlJobName == cj.Name)
  1720. return pj;
  1721. }
  1722. return null;
  1723. }
  1724. public void AbortJob(string jobName)
  1725. {
  1726. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1727. if (cj == null)
  1728. {
  1729. EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
  1730. return;
  1731. }
  1732. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  1733. foreach (var pj in _lstProcessJobs)
  1734. {
  1735. if (pj.ControlJobName == cj.Name)
  1736. {
  1737. pj.SetState(EnumProcessJobState.Aborting);
  1738. pjAbortList.Add(pj);
  1739. int unprocessed = 0;
  1740. int aborted = 0;
  1741. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  1742. foreach (var waferInfo in wafers)
  1743. {
  1744. waferInfo.ProcessJob = null;
  1745. waferInfo.NextSequenceStep = 0;
  1746. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  1747. unprocessed++;
  1748. }
  1749. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  1750. }
  1751. }
  1752. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  1753. _dbCallback.LotFinished(cj);
  1754. foreach (var pj in pjAbortList)
  1755. {
  1756. _lstProcessJobs.Remove(pj);
  1757. }
  1758. _lstControlJobs.Remove(cj);
  1759. }
  1760. public void StopJob(string jobName)
  1761. {
  1762. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1763. if (cj == null)
  1764. {
  1765. EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
  1766. return;
  1767. }
  1768. foreach (var pj in _lstProcessJobs)
  1769. {
  1770. if (pj.ControlJobName == cj.Name)
  1771. {
  1772. pj.SetState(EnumProcessJobState.Stopping);
  1773. }
  1774. }
  1775. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  1776. _dbCallback.LotFinished(cj);
  1777. }
  1778. public void ResumeJob(string jobName)
  1779. {
  1780. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1781. if (cj == null)
  1782. {
  1783. EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
  1784. return;
  1785. }
  1786. if (cj.State == EnumControlJobState.Paused)
  1787. {
  1788. cj.SetState(EnumControlJobState.Executing);
  1789. }
  1790. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  1791. }
  1792. public void PauseJob(string jobName)
  1793. {
  1794. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1795. if (cj == null)
  1796. {
  1797. EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
  1798. return;
  1799. }
  1800. if (cj.State == EnumControlJobState.Executing)
  1801. {
  1802. cj.SetState(EnumControlJobState.Paused);
  1803. }
  1804. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  1805. }
  1806. public void StartJob(string jobName)
  1807. {
  1808. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1809. if (cj == null)
  1810. {
  1811. EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
  1812. return;
  1813. }
  1814. if (cj.State == EnumControlJobState.WaitingForStart)
  1815. {
  1816. cj.SetState(EnumControlJobState.Executing);
  1817. //PreJobClean(cj);
  1818. (GetScheduler(ModuleHelper.Converter(cj.Module)) as SchedulerLoadPort).NoteJobStart();
  1819. cj.StartTime = DateTime.Now;
  1820. _dbCallback.LotCreated(cj);
  1821. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  1822. if (!_blockingWatcher.IsRunning)
  1823. _blockingWatcher.Restart();
  1824. ResetTraceFlag();
  1825. }
  1826. }
  1827. private void NotifyFaWaferEnd()
  1828. {
  1829. if (ModuleHelper.IsLoadPort(_curAction.targetModule))
  1830. {
  1831. // Notify FA for Port1JobWaferEnd
  1832. if (_curAction.eType == EnumTransferType.Place)
  1833. {
  1834. ProcessJobInfo pj = WaferManager.Instance.GetWafer(_curAction.targetModule, _curAction.targetSlot)
  1835. .ProcessJob;
  1836. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1837. _faCallback.JobWaferEnd(cj, pj, _curAction.targetModule.ToString(), _curAction.targetSlot);
  1838. }
  1839. }
  1840. }
  1841. public void ResetIdleCleanTime(string module)
  1842. {
  1843. if (string.IsNullOrEmpty(module))
  1844. {
  1845. ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
  1846. foreach (var schedulerPm in pms)
  1847. {
  1848. var pmSchedule = dictSchedulers[schedulerPm] as SchedulerPM;
  1849. pmSchedule.ResetIdleCleanTime();
  1850. }
  1851. }
  1852. else
  1853. {
  1854. var pm = ModuleHelper.Converter(module);
  1855. if (ModuleHelper.IsPm(pm))
  1856. {
  1857. var pmSchedule = dictSchedulers[pm] as SchedulerPM;
  1858. pmSchedule.ResetIdleCleanTime();
  1859. }
  1860. }
  1861. }
  1862. public void ResetIdlePurgeTime(string module)
  1863. {
  1864. if (string.IsNullOrEmpty(module))
  1865. {
  1866. ModuleName[] pms = { ModuleName.PMA, ModuleName.PMB };
  1867. foreach (var schedulerPm in pms)
  1868. {
  1869. var pmSchedule = dictSchedulers[schedulerPm] as SchedulerPM;
  1870. pmSchedule.ResetIdlePurgeTime();
  1871. }
  1872. }
  1873. else
  1874. {
  1875. var pm = ModuleHelper.Converter(module);
  1876. if (ModuleHelper.IsPm(pm))
  1877. {
  1878. var pmSchedule = dictSchedulers[pm] as SchedulerPM;
  1879. pmSchedule.ResetIdlePurgeTime();
  1880. }
  1881. }
  1882. }
  1883. public void Clear()
  1884. {
  1885. _efemRobot.ResetTask();
  1886. foreach (var module in dictSchedulers)
  1887. {
  1888. module.Value.ResetTask();
  1889. }
  1890. _lstControlJobs.Clear();
  1891. _lstProcessJobs.Clear();
  1892. _mapTarget.Clear();
  1893. queMoveAction.Clear();
  1894. _curAction.state = ActionState.Done;
  1895. }
  1896. #endregion
  1897. }
  1898. }