AutoTransfer_T.cs 89 KB

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