SETMCycle.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.RecipeCenter;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using Aitex.Sorter.Common;
  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.Robot;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.Linq;
  20. using System.Runtime.Remoting.Contexts;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using Venus_Core;
  24. using Venus_RT.Modules.Schedulers;
  25. using Venus_RT.Scheduler;
  26. using static Aitex.Core.Util.SubscriptionAttribute;
  27. namespace Venus_RT.Modules
  28. {
  29. public class SETMCycle : ModuleRoutineBase, IRoutine
  30. {
  31. enum TMCycleStep
  32. {
  33. Start,
  34. ReturnBack,
  35. Cycling,
  36. End,
  37. }
  38. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  39. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  40. private Dictionary<ModuleName, SchedulerModule> dictSchedulers = new Dictionary<ModuleName, SchedulerModule>();
  41. private List<ModuleName> tmCycleRoutine = new List<ModuleName>()
  42. {
  43. ModuleName.VCE1,
  44. ModuleName.PMA,
  45. ModuleName.PMB,
  46. ModuleName.PMC,
  47. ModuleName.VCE1
  48. };
  49. private int CycleNum = 0;
  50. private bool _isCycleMode;
  51. private ModuleName _sourceModule = ModuleName.VCE1;
  52. private ModuleName _destinationModule = ModuleName.VCE1;
  53. private int _sourceSlotNumber = 25;
  54. //private int _destinationSlotNumber = 25;
  55. private SchedulerSETMRobot _TMRobot = (SchedulerSETMRobot)Singleton<TransferModule>.Instance.GetScheduler(ModuleName.SETM);
  56. private SchedulerFACallback _faCallback;
  57. private SchedulerDBCallback _dbCallback;
  58. //private readonly int INVALID_SLOT = -1;
  59. private Queue<MoveItem> _runningItems = new Queue<MoveItem>();
  60. private Queue<MoveItem> _CycleWafers = new Queue<MoveItem>();
  61. private RState _cycleState = RState.Init;
  62. private Stopwatch _cycleWatch = new Stopwatch();
  63. private List<MoveItem> _moveQueue = new List<MoveItem>();
  64. private List<MovingStatus> movingStatus = new List<MovingStatus>();
  65. private double _throughput = 0;
  66. private DateTime _starttime;
  67. public int? CycleIndex;
  68. private int CycledWafer => _currentWafer + _pastWafer;
  69. private int _currentWafer;
  70. private int _pastWafer;
  71. private bool _IsFirstLot = true;
  72. private bool IsSequenceCycle = false; //判断是否跑货
  73. #region 构造函数
  74. public SETMCycle(ModuleName module) : base(module)
  75. {
  76. Name = "TM Cycle";
  77. _faCallback = new SchedulerFACallback();
  78. _dbCallback = new SchedulerDBCallback();
  79. _currentWafer = 0;
  80. _pastWafer = 0;
  81. DATA.Subscribe("SEScheduler.CycledWafer", ()=> CycledWafer );
  82. DATA.Subscribe("SEScheduler.CycleSetPoint", ()=> CycleNum);
  83. DATA.Subscribe("SEScheduler.CycleCount", ()=> CycleIndex);
  84. DATA.Subscribe("SEScheduler.ThroughPut", ()=> _throughput);
  85. DATA.Subscribe("Scheduler.CurrentRecipeList", ()=> _lstProcessJobs);
  86. }
  87. #endregion
  88. #region Cycle
  89. //run货模式
  90. public RState StartJob(string jobName)
  91. {
  92. //if (_TMRobot.IsVCESlitDoorClosed)
  93. //{
  94. // LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"VCE SlitDoor is Close cannot run!");
  95. // return RState.Failed;
  96. //}
  97. if (RouteManager.IsATMMode)
  98. {
  99. if (!Singleton<RouteManager>.Instance.seTM.TMIsATM)
  100. {
  101. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"TM is not atm, Please vent it first!");
  102. return RState.Failed;
  103. }
  104. if (!Singleton<RouteManager>.Instance.seTM.VCEIsATM)
  105. {
  106. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"VCE is not atm, Please vent it first!");
  107. return RState.Failed;
  108. }
  109. }
  110. //sequenceCycle
  111. CycleIndex = 0;
  112. _pastWafer = 0;
  113. _currentWafer = 0;
  114. //CycleNum = SC.GetValue<int>("System.CycleCount");
  115. _CycleWafers.Clear();
  116. IsSequenceCycle = true;
  117. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  118. if (cj == null)
  119. {
  120. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"start job rejected, not found job with id {jobName}");
  121. return RState.Failed;
  122. }
  123. if (cj.State == EnumControlJobState.Queued)
  124. {
  125. cj.SetState(EnumControlJobState.WaitingForStart);
  126. //PreJobClean(cj);
  127. cj.JetState = EnumJetCtrlJobState.Quequed;
  128. cj.StartTime = DateTime.Now;
  129. cj.IsPreJobCleanDone = false;
  130. cj.IsPreJobCleanStart = false;
  131. cj.IsPostJobCleanDone = false;
  132. cj.IsPostJobCleanStart = false;
  133. if (_IsFirstLot)
  134. {
  135. _dbCallback.LotCreated(cj);
  136. _IsFirstLot = false;
  137. }
  138. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  139. int maxslot = 0;
  140. cj.LotWafers.ForEach(x => maxslot = x.OriginSlot > maxslot ? x.OriginSlot : maxslot);
  141. //waiting status means no use
  142. movingStatus = new List<MovingStatus>();
  143. movingStatus.AddRange(new MovingStatus[maxslot + 1]);
  144. for (int i = 0; i < movingStatus.Count; i++)
  145. movingStatus[i] = MovingStatus.Waiting;
  146. foreach (var wafer in cj.LotWafers)
  147. {
  148. WaferInfo currentWafer = WaferManager.Instance.GetWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  149. WaferManager.Instance.UpdateWaferProcessStatus((ModuleName)wafer.OriginStation, wafer.OriginSlot, EnumWaferProcessStatus.Idle);
  150. currentWafer.ProcessJob = _lstProcessJobs.Find(x => x.Sequence.Name == wafer.SequenceName);
  151. if (currentWafer.ProcessJob.Sequence.Steps[0].StepParameter.ContainsValue("VPA"))
  152. movingStatus[wafer.OriginSlot] = MovingStatus.WaitAlign;
  153. else
  154. movingStatus[wafer.OriginSlot] = MovingStatus.WaitProcess;
  155. }
  156. foreach (var pj in _lstProcessJobs)
  157. {
  158. foreach(ModuleName pm in pj.Sequence.PMs)
  159. _initMoudle(pm, new SchedulerPM(pm));
  160. }
  161. }
  162. if (!_cycleWatch.IsRunning)
  163. {
  164. _cycleWatch.Restart();
  165. }
  166. if (string.IsNullOrEmpty(cj.PreJobClean))
  167. {
  168. cj.IsPreJobCleanStart = true;
  169. cj.IsPreJobCleanDone = true;
  170. }
  171. if (string.IsNullOrEmpty(cj.PostJobClean))
  172. {
  173. cj.IsPostJobCleanStart = true;
  174. cj.IsPostJobCleanDone = true;
  175. }
  176. _starttime = DateTime.Now;
  177. _cycleState = RState.Running;
  178. return _cycleState;
  179. }
  180. void _initMoudle(ModuleName name, SchedulerModule sche)
  181. {
  182. if (ModuleHelper.IsInstalled(name))
  183. {
  184. dictSchedulers[name] = sche;
  185. }
  186. }
  187. //processJob(sequence num) ControlJob(1)
  188. public void CreateJob(Dictionary<string, object> param)
  189. {
  190. _isCycleMode = SC.GetValue<bool>("System.IsCycleMode");
  191. CycleNum = _isCycleMode ? SC.GetValue<int>("System.CycleCount") : 1;
  192. string[] slotSequence = (string[])param["SlotSequence"];
  193. string jobId = (string)param["JobId"];
  194. string module = (string)param["Module"];
  195. string lotId = jobId;
  196. if (param.ContainsKey("LotId"))
  197. lotId = (string)param["LotId"];
  198. if (!ModuleHelper.IsVCE(ModuleHelper.Converter(module)))
  199. {
  200. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{module} should be VCE");
  201. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  202. return;
  203. }
  204. if (string.IsNullOrEmpty(jobId))
  205. {
  206. jobId = "CJ_Local_" + module;
  207. }
  208. if (_lstControlJobs.Exists(x => x.Name == jobId))
  209. {
  210. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"{jobId} already created");
  211. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  212. return;
  213. }
  214. ControlJobInfo cj = new ControlJobInfo();
  215. cj.Name = jobId;
  216. cj.Module = module;
  217. cj.LotName = lotId;
  218. cj.LotInnerId = Guid.NewGuid();
  219. cj.LotWafers = new List<WaferInfo>();
  220. cj.SetState(EnumControlJobState.Queued);
  221. cj.JetState = EnumJetCtrlJobState.Created;
  222. cj.PreJobClean = param.ContainsKey("PreCleanRecipeName") ? (string)param["PreCleanRecipeName"] : string.Empty;
  223. cj.PostJobClean = param.ContainsKey("PostCleanRecipeName") ? (string)param["PostCleanRecipeName"] : string.Empty;
  224. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  225. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  226. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  227. bool enableGroupBySequence = SC.GetValue<bool>("Scheduler.GroupWaferBySequence");
  228. for (int i = 0; i < SC.GetValue<int>("VCE1.SlotNumber"); i++)
  229. {
  230. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  231. continue;
  232. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  233. indexSequence[groupName] = slotSequence[i];
  234. if (!seqSlot.ContainsKey(groupName))
  235. {
  236. seqSlot[groupName] = new bool[SC.GetValue<int>("VCE1.SlotNumber")];
  237. }
  238. if (!seqSlotWafers.ContainsKey(groupName))
  239. {
  240. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  241. }
  242. seqSlot[groupName][i] = true;
  243. if (!WaferManager.Instance.CheckHasWafer(module, i))
  244. {
  245. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} not in the carrier");
  246. return;
  247. }
  248. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  249. {
  250. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}");
  251. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  252. return;
  253. }
  254. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState != EnumWaferProcessStatus.Idle)
  255. {
  256. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job wafer: {module} slot {i + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).ProcessState}");
  257. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  258. return;
  259. }
  260. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  261. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).SequenceName = slotSequence[i];
  262. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  263. cj.JobWaferSize = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Size;
  264. LOG.Write(eEvent.EV_ROUTER, ModuleName.System, $"Assigned wafer job, wafer {module}.{i + 1}, sequence: {slotSequence[i]}");
  265. }
  266. if (seqSlotWafers.Count == 0)
  267. {
  268. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"job has not assign wafer");
  269. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  270. return;
  271. }
  272. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  273. string[] seqs = seqSlot.Keys.ToArray();
  274. for (int i = 0; i < seqs.Length; i++)
  275. {
  276. ProcessJobInfo pj = new ProcessJobInfo();
  277. pj.Name = jobId + "_" + (i + 1);
  278. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  279. pj.ControlJobName = cj.Name;
  280. pj.LotName = lotId;
  281. pj.SlotWafers = seqSlotWafers[seqs[i]];
  282. pj.SetState(EnumProcessJobState.Queued);
  283. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  284. {
  285. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"no valid chamber for the {reason}");
  286. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  287. return;
  288. }
  289. if (!RouteManager.IsATMMode && !CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  290. {
  291. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, $"recipe file not valid in the sequence, {reason}");
  292. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  293. return;
  294. }
  295. pjs.Add(pj);
  296. }
  297. _dbCallback.LotUpdate(cj);
  298. foreach (var pj in pjs)
  299. {
  300. cj.ProcessJobNameList.Add(pj.Name);
  301. _lstProcessJobs.Add(pj);
  302. }
  303. _lstControlJobs.Add(cj);
  304. }
  305. public bool AbortJob(string jobName, out string reason)
  306. {
  307. reason = "";
  308. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  309. if (cj == null)
  310. {
  311. reason = $"abort job rejected, not found job with id {jobName}";
  312. LOG.Write(eEvent.WARN_ROUTER, ModuleName.System, reason);
  313. return false;
  314. }
  315. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  316. foreach (var pj in _lstProcessJobs)
  317. {
  318. if (pj.ControlJobName == cj.Name)
  319. {
  320. pj.SetState(EnumProcessJobState.Aborting);
  321. pjAbortList.Add(pj);
  322. int unprocessed = 0;
  323. int aborted = 0;
  324. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  325. foreach (var waferInfo in wafers)
  326. {
  327. waferInfo.ProcessJob = null;
  328. waferInfo.NextSequenceStep = 0;
  329. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  330. unprocessed++;
  331. }
  332. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  333. }
  334. }
  335. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  336. _dbCallback.LotFinished(cj);
  337. foreach (var pj in pjAbortList)
  338. {
  339. _lstProcessJobs.Remove(pj);
  340. }
  341. _lstControlJobs.Remove(cj);
  342. return true;
  343. }
  344. public RState Start(params object[] objs)
  345. {
  346. //if (_TMRobot.IsVCESlitDoorClosed)
  347. //{
  348. // LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"VCE SlitDoor is Close cannot run!");
  349. // return RState.Failed;
  350. //}
  351. //普通Cycle
  352. if (objs.Length == 2)
  353. {
  354. var modules = ((string[])objs[0]).ToList();
  355. if (modules.Count >= 2)
  356. tmCycleRoutine.Clear();
  357. foreach (var mod in modules)
  358. {
  359. try
  360. {
  361. ModuleName module = ModuleHelper.Converter(mod);
  362. tmCycleRoutine.Add(module);
  363. }
  364. catch (Exception ex)
  365. {
  366. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Invalid module string: {mod}, Exception:{ex}");
  367. return RState.Failed;
  368. }
  369. }
  370. CycleNum = (int)objs[1];
  371. CycleNum = SC.GetValue<int>("System.CycleCount");
  372. _CycleWafers.Clear();
  373. CycleIndex = 0;
  374. for (int i = 0; i < _sourceSlotNumber; i++)
  375. {
  376. if (WaferManager.Instance.CheckHasWafer(_sourceModule, i))
  377. _CycleWafers.Enqueue(new MoveItem(_sourceModule, i, _destinationModule, i, Hand.None));
  378. }
  379. IsSequenceCycle = false;
  380. _cycleState = RState.Running;
  381. }
  382. else if (objs.Length == 0)
  383. {
  384. IsSequenceCycle = true;
  385. _cycleState = RState.Running;
  386. }
  387. else
  388. {
  389. LOG.Write(eEvent.ERR_TM, Module, "Invalid parameter for cycle!");
  390. _cycleState = RState.Failed;
  391. }
  392. return _cycleState;
  393. }
  394. public RState Monitor()
  395. {
  396. if (_cycleState == RState.Running)
  397. {
  398. //run sequence
  399. if (IsSequenceCycle)
  400. {
  401. CheckCleanJobDone();
  402. CheckCycleDone();
  403. SETMRobotTask();
  404. SERunTMRobotTask();
  405. SEPMTask();
  406. }
  407. //only TMCycle
  408. else
  409. {
  410. Cycling();
  411. //PMProcess();
  412. }
  413. }
  414. return _cycleState;
  415. }
  416. #endregion
  417. #region 推进|检查|计数|Clean
  418. private void CheckCleanJobDone()
  419. {
  420. //所有已安装pm都可用
  421. if (IsAllNeedPMsAvailabe() && _TMRobot.IsAvailable)
  422. {
  423. //执行了PreClean 将其置为Executing
  424. if (_lstControlJobs.Exists(x => x.IsPreJobCleanStart && !x.IsPreJobCleanDone && x.State == EnumControlJobState.WaitingForStart))
  425. {
  426. ControlJobInfo cj = _lstControlJobs.Find(x => x.IsPreJobCleanStart && !x.IsPreJobCleanDone && x.State == EnumControlJobState.WaitingForStart);
  427. cj.IsPreJobCleanDone = true;
  428. cj.SetState(EnumControlJobState.Executing);
  429. return;
  430. }
  431. //执行了PostClean 将其置为Executing
  432. if (_lstControlJobs.Exists(x => x.IsPostJobCleanStart && !x.IsPostJobCleanDone && x.State == EnumControlJobState.Executing))
  433. {
  434. ControlJobInfo cj = _lstControlJobs.Find(x => x.IsPostJobCleanStart && !x.IsPostJobCleanDone && x.State == EnumControlJobState.Executing);
  435. cj.IsPostJobCleanDone = true;
  436. cj.SetState(EnumControlJobState.Completed);
  437. return;
  438. }
  439. }
  440. //no exist excuting cj && exist waiting cj
  441. if (!_lstControlJobs.Exists(x => x.State == EnumControlJobState.Executing) &&
  442. _lstControlJobs.Exists(x => !x.IsPreJobCleanStart && !x.IsPreJobCleanDone && x.State == EnumControlJobState.WaitingForStart))
  443. {
  444. ControlJobInfo cj = _lstControlJobs.Find(x => !x.IsPreJobCleanStart && !x.IsPreJobCleanDone && x.State == EnumControlJobState.WaitingForStart);
  445. RunPreCleanJob(cj);
  446. return;
  447. }
  448. if (_lstControlJobs.Exists(x => x.IsPreJobCleanStart && x.IsPreJobCleanDone && x.State == EnumControlJobState.WaitingForStart))
  449. {
  450. ControlJobInfo cj = _lstControlJobs.Find(x => x.IsPreJobCleanStart && x.IsPreJobCleanDone && x.State == EnumControlJobState.WaitingForStart);
  451. cj.SetState(EnumControlJobState.Executing);
  452. }
  453. }
  454. private void RunPreCleanJob(ControlJobInfo cj)
  455. {
  456. foreach (SchedulerPM pm in dictSchedulers.Values)
  457. {
  458. if (ModuleHelper.IsPm(pm.Module) && JobNeedPM(cj,pm.Module) && pm.IsAvailable && pm.RunJobCleanTask(cj.PreJobClean))
  459. {
  460. cj.IsPreJobCleanStart = true;
  461. }
  462. }
  463. if (cj.IsPreJobCleanStart == true && IsAllNeedPMsAvailabe())
  464. {
  465. cj.IsPreJobCleanDone = true;
  466. cj.SetState(EnumControlJobState.Executing);
  467. }
  468. }
  469. private void CheckCycleDone()
  470. {
  471. //how to calculate current wafer? => _currentWafer
  472. //1. wafer in vce
  473. //2. wafer is Idle
  474. _currentWafer = 0;
  475. for (int index = 0; index < movingStatus.Count;++index)
  476. {
  477. if(WaferManager.Instance.CheckHasWafer(ModuleName.VCE1,index) && movingStatus[index] == MovingStatus.Idle)
  478. _currentWafer ++;
  479. }
  480. //throughput = CycledWafer/time, time(h)
  481. _throughput = Math.Round(CycledWafer / (DateTime.Now - _starttime).TotalSeconds * 3600,2);
  482. //how to confirm a sequence is over?
  483. //3、wafer is all in vce
  484. //2、all status is over => idle
  485. //1、TMRobot and PM is available
  486. if (_TMRobot.IsAvailable && AllPMIsAvailable() && ALLStatusIsOver() && WaferAllInVCE())
  487. {
  488. ++CycleIndex;
  489. if (CycleIndex >= CycleNum)
  490. {
  491. //_lstControlJobs.Find(lcj => lcj.State == EnumControlJobState.Executing).SetState(EnumControlJobState.Completed);
  492. if (_lstControlJobs.Exists(lcj => lcj.State == EnumControlJobState.Executing))
  493. {
  494. ControlJobInfo cj = _lstControlJobs.Find(lcj => lcj.State == EnumControlJobState.Executing);
  495. if (!cj.IsPostJobCleanStart)
  496. {
  497. foreach (SchedulerPM pm in dictSchedulers.Values)
  498. {
  499. if (JobNeedPM(cj, pm.Module) && ModuleHelper.IsPm(pm.Module) && pm.IsAvailable)
  500. {
  501. pm.RunJobCleanTask(cj.PostJobClean);
  502. }
  503. }
  504. _pastWafer += _currentWafer;
  505. cj.IsPostJobCleanStart = true;
  506. }
  507. else
  508. {
  509. cj.SetState(EnumControlJobState.Completed);
  510. cj.IsPostJobCleanDone = true;
  511. _cycleState = RState.End;
  512. }
  513. }
  514. if (_lstControlJobs.All(x => x.State == EnumControlJobState.Completed))
  515. {
  516. _cycleState = RState.End;
  517. return;
  518. }
  519. }
  520. else
  521. {
  522. //if the pm is excuting => run postclean
  523. if (_lstControlJobs.Exists(lcj => lcj.State == EnumControlJobState.Executing))
  524. {
  525. ControlJobInfo cj = _lstControlJobs.Find(lcj => lcj.State == EnumControlJobState.Executing);
  526. if (!cj.IsPostJobCleanStart)
  527. {
  528. foreach (SchedulerPM pm in dictSchedulers.Values)
  529. {
  530. if (ModuleHelper.IsPm(pm.Module) && JobNeedPM(cj, pm.Module) && pm.IsAvailable)
  531. {
  532. pm.RunJobCleanTask(cj.PostJobClean);
  533. }
  534. }
  535. _pastWafer += _currentWafer;
  536. cj.IsPostJobCleanStart = true;
  537. }
  538. else
  539. {
  540. cj.SetState(EnumControlJobState.Completed);
  541. cj.IsPostJobCleanDone = true;
  542. }
  543. }
  544. //if is Completed => run preclean
  545. if (_lstControlJobs.Exists(lcj => lcj.State == EnumControlJobState.Completed))
  546. {
  547. ControlJobInfo cj = _lstControlJobs.Find(lcj => lcj.State == EnumControlJobState.Completed);
  548. cj.SetState(EnumControlJobState.WaitingForStart);
  549. if (string.IsNullOrEmpty(cj.PreJobClean))
  550. {
  551. cj.IsPreJobCleanStart = true;
  552. cj.IsPreJobCleanDone = true;
  553. }
  554. else
  555. {
  556. cj.IsPreJobCleanStart = false;
  557. cj.IsPreJobCleanDone = false;
  558. }
  559. if (string.IsNullOrEmpty(cj.PostJobClean))
  560. {
  561. cj.IsPostJobCleanStart = true;
  562. cj.IsPostJobCleanDone = true;
  563. }
  564. else
  565. {
  566. cj.IsPostJobCleanStart = false;
  567. cj.IsPostJobCleanDone = false;
  568. }
  569. _currentWafer = 0;
  570. int maxslot = 0;
  571. cj.LotWafers.ForEach(x => maxslot = x.OriginSlot > maxslot ? x.OriginSlot : maxslot);
  572. //waiting status means no use
  573. movingStatus = new List<MovingStatus>();
  574. movingStatus.AddRange(new MovingStatus[maxslot + 1]);
  575. for (int i = 0; i < movingStatus.Count; i++)
  576. movingStatus[i] = MovingStatus.Waiting;
  577. foreach (var wafer in cj.LotWafers)
  578. {
  579. WaferInfo currentWafer = WaferManager.Instance.GetWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  580. WaferManager.Instance.UpdateWaferProcessStatus((ModuleName)wafer.OriginStation, wafer.OriginSlot, EnumWaferProcessStatus.Idle);
  581. currentWafer.ProcessJob = _lstProcessJobs.Find(x => x.Sequence.Name == wafer.SequenceName);
  582. if (currentWafer.ProcessJob.Sequence.Steps[0].StepParameter.ContainsValue("VPA"))
  583. movingStatus[wafer.OriginSlot] = MovingStatus.WaitAlign;
  584. else
  585. movingStatus[wafer.OriginSlot] = MovingStatus.WaitProcess;
  586. }
  587. RunPreCleanJob(cj);
  588. }
  589. }
  590. }
  591. }
  592. private bool JobNeedPM(ControlJobInfo cj, ModuleName pm)
  593. {
  594. ProcessJobInfo pj = _lstProcessJobs.Find(x => x.LotName == cj.Name);
  595. if (ModuleHelper.IsPm(pm))
  596. return !string.IsNullOrEmpty(pj.Sequence.Steps[2].StepParameter[pm.ToString()+"Recipe"].ToString());
  597. else
  598. return false;
  599. }
  600. //movingStatus is all Idle or no use
  601. private bool ALLStatusIsOver()
  602. {
  603. bool flag = true;
  604. movingStatus.ForEach(x => flag = (x == MovingStatus.Idle || x == MovingStatus.Waiting) && flag) ;
  605. return flag;
  606. }
  607. private bool WaferAllInVCE()
  608. {
  609. bool flag = true;
  610. ControlJobInfo cj = _lstControlJobs.Find(lcj => lcj.State == EnumControlJobState.Executing|| lcj.State == EnumControlJobState.Completed);
  611. cj.LotWafers.ForEach(wafer => flag = WaferManager.Instance.CheckHasWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot) && flag);
  612. return flag;
  613. }
  614. private bool AllPMIsAvailable()
  615. {
  616. foreach (KeyValuePair<ModuleName,SchedulerModule> pair in dictSchedulers)
  617. if (ModuleHelper.IsPm(pair.Key) && !pair.Value.IsAvailable)
  618. return false;
  619. return true;
  620. }
  621. private void SERunTMRobotTask()
  622. {
  623. if (_TMRobot.IsAvailable)
  624. {
  625. if (_moveQueue.Count > 0 &&_TMRobot.PostMoveItems(_moveQueue.ToArray()))
  626. {
  627. foreach (var item in _moveQueue)
  628. {
  629. var wafer = WaferManager.Instance.GetWafer(item.SourceModule, item.SourceSlot);
  630. if (wafer.IsEmpty)
  631. {
  632. // post alarm
  633. _cycleState = RState.Failed;
  634. LOG.Write(eEvent.ERR_ROUTER, ModuleName.System, $"Cannot run TM moving task as Get {item.SourceModule}{item.SourceModule} Wafer Info failed");
  635. return;
  636. }
  637. }
  638. _moveQueue.Clear();
  639. }
  640. }
  641. }
  642. private void SERunPMTask()
  643. {
  644. }
  645. private void SETMRobotTask()
  646. {
  647. //tm is free
  648. if (_TMRobot.IsAvailable)
  649. {
  650. CheckWaferFromVceNeedAlign();
  651. PrepareWaferOnRBToPM();
  652. GetBackWafer();
  653. GetNextWaferPickFromVCE();
  654. }
  655. }
  656. private void SEPMTask()
  657. {
  658. //foreach all pms and the wafer's receipe
  659. foreach (KeyValuePair<ModuleName,SchedulerModule> dict in dictSchedulers)
  660. {
  661. //pm has wafer && pm is available => find the wafer's receipe
  662. if (ModuleHelper.IsPm(dict.Key))
  663. {
  664. if (dict.Value.IsAvailable)
  665. {
  666. foreach (var ctrljob in _lstControlJobs)
  667. {
  668. //Port is run
  669. if (ctrljob.State == EnumControlJobState.Executing)
  670. {
  671. if (WaferManager.Instance.CheckHasWafer(dict.Key, 0))
  672. {
  673. WaferInfo currentWafer = WaferManager.Instance.GetWafer(dict.Key, 0);
  674. switch (movingStatus[currentWafer.OriginSlot])
  675. {
  676. case MovingStatus.WaitProcess:
  677. dict.Value.EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.TMRobot, 0, dict.Key, 0));
  678. movingStatus[currentWafer.OriginSlot] = MovingStatus.StartProcess;
  679. break;
  680. case MovingStatus.Processing:
  681. movingStatus[currentWafer.OriginSlot] = MovingStatus.Idle;
  682. break;
  683. case MovingStatus.StartProcess:
  684. movingStatus[currentWafer.OriginSlot] = MovingStatus.Processing;
  685. break;
  686. default:
  687. break;
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. }
  695. }
  696. //get the wafer need back
  697. private void GetBackWafer()
  698. {
  699. //find
  700. foreach (KeyValuePair<ModuleName, SchedulerModule> dict in dictSchedulers)
  701. {
  702. //pm has wafer && pm is available => find the wafer's receipe
  703. if (ModuleHelper.IsPm(dict.Key) && WaferManager.Instance.CheckHasWafer(dict.Key, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.VPA, 0))
  704. {
  705. WaferInfo currentWafer = WaferManager.Instance.GetWafer(dict.Key, 0);
  706. //if the wafer has been processed, we need to pickfrom it.
  707. if (dict.Value.IsAvailable && movingStatus[currentWafer.OriginSlot] == MovingStatus.Idle && _TMRobot.IsAvailable)
  708. {
  709. _moveQueue.Add(new MoveItem(dict.Key,0, (ModuleName)currentWafer.OriginStation, currentWafer.OriginSlot,0));
  710. //one hand has wafer
  711. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0)
  712. && movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).OriginSlot] == MovingStatus.WaitProcess
  713. && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  714. {
  715. WaferInfo wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0);
  716. if (wafer.ProcessJob.Sequence.PMs.Contains(dict.Key))
  717. {
  718. _moveQueue.Add(new MoveItem(ModuleName.TMRobot,0,dict.Key,0,0));
  719. }
  720. }
  721. else if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1)
  722. && movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).OriginSlot] == MovingStatus.WaitProcess
  723. && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  724. {
  725. WaferInfo wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1);
  726. if (wafer.ProcessJob.Sequence.PMs.Contains(dict.Key))
  727. {
  728. _moveQueue.Add(new MoveItem(ModuleName.TMRobot, 1, dict.Key, 0, (Hand)1));
  729. }
  730. }
  731. return;
  732. }
  733. }
  734. }
  735. }
  736. //get the wafer need Pick From vce
  737. private void GetNextWaferPickFromVCE()
  738. {
  739. if (_TMRobot.IsAvailable)
  740. {
  741. Dictionary<int, ModuleName> nextslot = new Dictionary<int, ModuleName>();
  742. foreach (var ctrljob in _lstControlJobs)
  743. {
  744. //Port is run
  745. if (ctrljob.State == EnumControlJobState.Executing)
  746. {
  747. bool nohastowaitpm = false;
  748. foreach (WaferInfo wafer in ctrljob.LotWafers)
  749. {
  750. //if need pm available =>pick 2
  751. if (!wafer.IsEmpty
  752. && SequenceNeedPMsAvailable(_lstProcessJobs.Find(x => x.Sequence.Name == wafer.SequenceName).Sequence.PMs)
  753. && ModuleHelper.IsVCE((ModuleName)wafer.OriginStation)
  754. && (movingStatus[wafer.OriginSlot] == MovingStatus.WaitProcess))
  755. {
  756. nohastowaitpm = true;
  757. ModuleName _destination = SearchPM(_lstProcessJobs.Find(x => x.Sequence.Name == wafer.SequenceName).Sequence.PMs, nextslot);
  758. nextslot.Add(wafer.OriginSlot, _destination);
  759. _moveQueue.Add(new MoveItem(ModuleName.VCE1, wafer.OriginSlot, _destination, 0, 0));
  760. if (nextslot.Count >= 2 || _moveQueue.Count >= 4)
  761. {
  762. return;
  763. }
  764. }
  765. //if need align available => pick 2
  766. if (!wafer.IsEmpty
  767. && WaferManager.Instance.CheckNoWafer(ModuleName.VPA, 0)
  768. && ModuleHelper.IsVCE((ModuleName)wafer.OriginStation)
  769. && SequenceNeedPMsAvailable(_lstProcessJobs.Find(x => x.Sequence.Name == wafer.SequenceName).Sequence.PMs)
  770. && (movingStatus[wafer.OriginSlot] == MovingStatus.WaitAlign))
  771. {
  772. nohastowaitpm = true;
  773. ModuleName _destination = ModuleName.TMRobot;
  774. //double pick
  775. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  776. {
  777. nextslot.Add(wafer.OriginSlot, _destination);
  778. _moveQueue.Add(new MoveItem(ModuleName.VCE1, wafer.OriginSlot, _destination, 0, 0));
  779. }
  780. if (nextslot.Count >= 2 || _moveQueue.Count >= 4)
  781. {
  782. return;
  783. }
  784. }
  785. }
  786. //if all need PM unavailable =>pick 1 wait for swap
  787. //or 1 can input pm => pick 2, A in pm ,B wait for swap
  788. if (nextslot.Count == 0 || nohastowaitpm && nextslot.Count == 1
  789. && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot,0)
  790. && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot,1)
  791. && WaferManager.Instance.CheckNoWafer(ModuleName.VPA, 0))
  792. {
  793. foreach (WaferInfo wafer in ctrljob.LotWafers)
  794. {
  795. if (wafer.NextSequenceStep == 0 && !wafer.IsEmpty
  796. && ModuleHelper.IsVCE((ModuleName)wafer.SourceStation))
  797. {
  798. ModuleName _destination = _lstProcessJobs.Find(x => x.Sequence.Name == wafer.SequenceName).Sequence.PMs[0];
  799. nextslot.Add(wafer.SourceSlot, _destination);
  800. foreach (KeyValuePair<int, ModuleName> slot in nextslot)
  801. {
  802. _moveQueue.Add(new MoveItem(ModuleName.VCE1, slot.Key, slot.Value, 0, 0));
  803. }
  804. return;
  805. }
  806. if (movingStatus[wafer.OriginSlot] == MovingStatus.WaitAlign && !wafer.IsEmpty
  807. && WaferManager.Instance.CheckHasWafer((ModuleName)wafer.OriginStation, wafer.OriginSlot)
  808. && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0)
  809. && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1)
  810. && _moveQueue.Count == 0
  811. )
  812. {
  813. //ModuleName _destination = ModuleName.TMRobot;
  814. _moveQueue.Add(new MoveItem((ModuleName)wafer.OriginStation, wafer.OriginSlot, ModuleName.TMRobot, 0, 0));
  815. return;
  816. }
  817. }
  818. }
  819. }
  820. }
  821. return;
  822. }
  823. }
  824. private void PrepareWaferOnRBToPM()
  825. {
  826. //tm robot has wafer and wait for process which means have to go to PM
  827. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0)
  828. && movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).OriginSlot] == MovingStatus.WaitProcess
  829. )
  830. {
  831. //find PM has no wafer
  832. WaferInfo wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0);
  833. if (SequenceNeedPMsAvailable(wafer.ProcessJob.Sequence.PMs))
  834. {
  835. ModuleName _destination = SearchPM(wafer.ProcessJob.Sequence.PMs, new Dictionary<int, ModuleName>());
  836. if (ModuleHelper.IsPm(_destination) && _TMRobot.IsAvailable)
  837. {
  838. _moveQueue.Add(new MoveItem(ModuleName.TMRobot, 0, _destination, 0, 0));
  839. SERunTMRobotTask();
  840. return;
  841. }
  842. }
  843. }
  844. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1)
  845. && movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).OriginSlot] == MovingStatus.WaitProcess)
  846. {
  847. WaferInfo wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1);
  848. if (SequenceNeedPMsAvailable(wafer.ProcessJob.Sequence.PMs))
  849. {
  850. ModuleName _destination = SearchPM(wafer.ProcessJob.Sequence.PMs, new Dictionary<int, ModuleName>());
  851. if (ModuleHelper.IsPm(_destination) && _TMRobot.IsAvailable)
  852. {
  853. _moveQueue.Add(new MoveItem(ModuleName.TMRobot, 1, _destination, 0, (Hand)1));
  854. SERunTMRobotTask();
  855. return;
  856. }
  857. }
  858. }
  859. }
  860. private void CheckWaferFromVceNeedAlign()
  861. {
  862. //if has wafer and need align and align is empty => goto PA
  863. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot,0)
  864. && movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).OriginSlot] == MovingStatus.WaitAlign
  865. && WaferManager.Instance.CheckNoWafer(ModuleName.VPA, 0)
  866. &&_TMRobot.IsAvailable)
  867. {
  868. _moveQueue.Add(new MoveItem(ModuleName.TMRobot, 0,ModuleName.VPA, 0, 0));
  869. movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).OriginSlot] = MovingStatus.StartAlign;
  870. SERunTMRobotTask();
  871. return;
  872. }
  873. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1)
  874. && movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).OriginSlot] == MovingStatus.WaitAlign
  875. && WaferManager.Instance.CheckNoWafer(ModuleName.VPA, 0)
  876. && _TMRobot.IsAvailable)
  877. {
  878. _moveQueue.Add(new MoveItem(ModuleName.TMRobot, 1, ModuleName.VPA, 0, (Hand)1));
  879. movingStatus[WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).OriginSlot] = MovingStatus.StartAlign;
  880. SERunTMRobotTask();
  881. return;
  882. }
  883. //PA has wafer need align =>
  884. if (WaferManager.Instance.CheckHasWafer(ModuleName.VPA, 0) && _TMRobot.IsAvailable)
  885. {
  886. WaferInfo currentwafer = WaferManager.Instance.GetWafer(ModuleName.VPA, 0);
  887. switch (movingStatus[currentwafer.OriginSlot])
  888. {
  889. case MovingStatus.StartAlign:
  890. if(_TMRobot.IsAvailable)
  891. {
  892. float angle = float.Parse(currentwafer.ProcessJob.Sequence.Steps[0].StepParameter["AlignAngle"].ToString());
  893. _TMRobot.Align(angle);
  894. movingStatus[currentwafer.OriginSlot] = MovingStatus.Aligning;
  895. SERunTMRobotTask();
  896. return;
  897. }
  898. break;
  899. case MovingStatus.Aligning:
  900. movingStatus[currentwafer.OriginSlot] = MovingStatus.WaitProcess;
  901. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _TMRobot.IsAvailable)
  902. {
  903. _moveQueue.Add(new MoveItem(ModuleName.VPA, 0, ModuleName.TMRobot, 0, 0));
  904. SERunTMRobotTask();
  905. return;
  906. }
  907. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _TMRobot.IsAvailable)
  908. {
  909. _moveQueue.Add(new MoveItem(ModuleName.VPA, 0, ModuleName.TMRobot, 1, (Hand)1));
  910. SERunTMRobotTask();
  911. return;
  912. }
  913. break;
  914. }
  915. }
  916. }
  917. private void PrepareTMMoveitems()
  918. {
  919. }
  920. private void Cycling()
  921. {
  922. //所有的PM都Idle TM都空闲的情况
  923. if (IsAllNeedPMsAvailabe() && IsModuleAvailable(_destinationModule) && IsModuleAvailable(_sourceModule) && _TMRobot.IsAvailable)
  924. {
  925. //如果PM没有wafer tm也闲置 但Cycle数量未达到目标
  926. if (!PMsHasWafers() && _TMRobot.IsAvailable && _CycleWafers.Count == 0)
  927. {
  928. ++CycleIndex;
  929. if (CycleIndex < CycleNum)
  930. {
  931. for (int i = 0; i < _sourceSlotNumber; i++)
  932. {
  933. if (WaferManager.Instance.CheckHasWafer(_sourceModule, i))
  934. _CycleWafers.Enqueue(new MoveItem(_sourceModule, i, _destinationModule, i, Hand.None));
  935. }
  936. }
  937. else
  938. {
  939. _cycleState = RState.End;
  940. return;
  941. }
  942. }
  943. //wafer返回
  944. if (PMsHasWafers())
  945. {
  946. var pmSlots = GetReadyOutPMs();
  947. //var inSlots = GetReadyInSlot(_destinationModule, _destinationSlotNumber);
  948. for (int i = 0; i < pmSlots.Count ; i++)
  949. {
  950. WaferInfo _endwafer = WaferManager.Instance.GetWafer(pmSlots[i], 0);
  951. int _endslot = _endwafer.OriginSlot;
  952. _runningItems.Enqueue(new MoveItem(pmSlots[i], 0, _destinationModule, _endslot, Hand.Both));
  953. }
  954. }
  955. else
  956. {
  957. //进腔环节 可在此处根据PM的角度 增加进入角度
  958. //三个腔体的进入方式
  959. var InPMs = GetReadyInPMs();
  960. if (_CycleWafers.Count > 0 && InPMs.Count >= 1)
  961. {
  962. var item = _CycleWafers.Dequeue();
  963. _runningItems.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, InPMs[0], 0, Hand.Both));
  964. }
  965. if (_CycleWafers.Count > 0 && InPMs.Count >= 2)
  966. {
  967. var item = _CycleWafers.Dequeue();
  968. _runningItems.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, InPMs[1], 0, Hand.Both));
  969. }
  970. if (_CycleWafers.Count > 0 && InPMs.Count >= 3)
  971. {
  972. var item = _CycleWafers.Dequeue();
  973. _runningItems.Enqueue(new MoveItem(item.SourceModule, item.SourceSlot, InPMs[2], 0, Hand.Both));
  974. }
  975. }
  976. if (_runningItems.Count > 0)
  977. {
  978. if (_TMRobot.PostMoveItems(_runningItems.ToArray()))
  979. _runningItems.Clear();
  980. }
  981. }
  982. //存在PM可用
  983. //else if (IsExistPMsAvailabe() && IsModuleAvailable(_destinationModule) && IsModuleAvailable(_sourceModule) && _TMRobot.IsAvailable)
  984. //{
  985. // //获得可以用的chamber 向里面传片
  986. //}
  987. }
  988. private void PMProcess()
  989. {
  990. //foreach (ModuleName chamber in tmCycleRoutine)
  991. //{
  992. // if (ModuleHelper.IsPm(chamber) && WaferManager.Instance.CheckHasWafer(chamber, 0) && ModuleHelper.IsInstalled(chamber))
  993. // {
  994. // WaferInfo info = WaferManager.Instance.GetWafer(chamber, 0);
  995. //
  996. // dictSchedulers[chamber].EventWaferArrived?.Invoke(this, new WaferMoveArgs(ModuleName.TMRobot, 0, chamber, 0));
  997. // }
  998. //}
  999. }
  1000. public void Abort()
  1001. {
  1002. CycleIndex = null;
  1003. _runningItems.Clear();
  1004. _CycleWafers.Clear();
  1005. _moveQueue.Clear();
  1006. movingStatus.Clear();
  1007. foreach(var cj in _lstControlJobs.FindAll(x => x.State == EnumControlJobState.Executing))
  1008. cj.SetState(EnumControlJobState.WaitingForStart);
  1009. _TMRobot._entityTaskToken = (int)FSM_MSG.NONE;
  1010. _cycleState = RState.End;
  1011. }
  1012. #endregion
  1013. #region 搜索函数
  1014. //回到的槽位确认 采用补进方式即自底向上填
  1015. private List<int> GetReadyInSlot(ModuleName module, int slotCount)
  1016. {
  1017. List<int> slots = new List<int>();
  1018. for (int i = 0; i < slotCount; i++)
  1019. {
  1020. if (WaferManager.Instance.CheckNoWafer(module, i))
  1021. slots.Add(i);
  1022. if (slots.Count >= 2)
  1023. return slots;
  1024. }
  1025. return slots;
  1026. }
  1027. //确认
  1028. private List<int> GetReadyOutSlot(ModuleName module, int slotCount)
  1029. {
  1030. List<int> slots = new List<int>();
  1031. for (int i = 0; i < slotCount; i++)
  1032. {
  1033. if (WaferManager.Instance.CheckHasWafer(module, i))
  1034. slots.Add(i);
  1035. if (slots.Count >= 2)
  1036. return slots;
  1037. }
  1038. return slots;
  1039. }
  1040. //确认PM是否可用 且没有wafer
  1041. private List<ModuleName> GetReadyInPMs()
  1042. {
  1043. List<ModuleName> inpm = new List<ModuleName>();
  1044. foreach (var module in tmCycleRoutine)
  1045. {
  1046. if (ModuleHelper.IsPm(module))
  1047. {
  1048. if (IsModuleAvailable(module) && WaferManager.Instance.CheckNoWafer(module, 0))
  1049. {
  1050. inpm.Add(module);
  1051. if (inpm.Count >= 3)
  1052. break;
  1053. }
  1054. }
  1055. }
  1056. return inpm;
  1057. }
  1058. private List<ModuleName> GetReadyOutPMs()
  1059. {
  1060. List<ModuleName> outpm = new List<ModuleName>();
  1061. foreach (var module in tmCycleRoutine)
  1062. {
  1063. if (ModuleHelper.IsPm(module))
  1064. {
  1065. if (IsModuleAvailable(module) && WaferManager.Instance.CheckHasWafer(module, 0))
  1066. {
  1067. outpm.Add(module);
  1068. if (outpm.Count >= 3)
  1069. break;
  1070. }
  1071. }
  1072. }
  1073. return outpm;
  1074. }
  1075. //PM有wafer
  1076. private bool PMsHasWafers()
  1077. {
  1078. foreach (var module in tmCycleRoutine)
  1079. {
  1080. if (ModuleHelper.IsPm(module) && ModuleHelper.IsInstalled(module))
  1081. {
  1082. if (WaferManager.Instance.CheckHasWafer(module, 0))
  1083. return true;
  1084. }
  1085. }
  1086. return false;
  1087. }
  1088. //PM全可用
  1089. private bool IsAllNeedPMsAvailabe()
  1090. {
  1091. foreach (var module in tmCycleRoutine)
  1092. {
  1093. if (ModuleHelper.IsPm(module) && ModuleHelper.IsInstalled(module) && dictSchedulers.Keys.Contains(module))
  1094. {
  1095. if (!IsModuleAvailable(module))
  1096. return false;
  1097. }
  1098. }
  1099. return true;
  1100. }
  1101. //PM存在可用
  1102. private bool SequenceNeedPMsAvailable(List<ModuleName> needPMs)
  1103. {
  1104. foreach (var module in needPMs)
  1105. {
  1106. if (ModuleHelper.IsPm(module) && ModuleHelper.IsInstalled(module))
  1107. {
  1108. if (IsModuleAvailable(module) && WaferManager.Instance.CheckNoWafer(module,0))
  1109. return true;
  1110. }
  1111. }
  1112. return false;
  1113. }
  1114. private ModuleName SearchPM(List<ModuleName> needPMs,Dictionary<int,ModuleName> PMsChoice)
  1115. {
  1116. foreach (var module in needPMs)
  1117. {
  1118. if (ModuleHelper.IsPm(module) && ModuleHelper.IsInstalled(module))
  1119. {
  1120. if (IsModuleAvailable(module) && !PMsChoice.ContainsValue(module) && WaferManager.Instance.CheckNoWafer(module,0))
  1121. return module;
  1122. }
  1123. }
  1124. return ModuleName.TMRobot;
  1125. }
  1126. private bool IsModuleAvailable(ModuleName module)
  1127. {
  1128. return dictSchedulers.Keys.Contains(module) && dictSchedulers[module].IsAvailable;
  1129. }
  1130. //检查需要使用的pm
  1131. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  1132. {
  1133. pmUsed = new List<ModuleName>();
  1134. reason = "";
  1135. bool pmIsReady = true;
  1136. for (int i = 0; i < seq.Steps.Count; i++)
  1137. {
  1138. SequenceStepInfo stepInfo = seq.Steps[i];
  1139. bool hasPm = false;
  1140. foreach (var module in stepInfo.StepModules)
  1141. {
  1142. if (!ModuleHelper.IsPm(module))
  1143. {
  1144. hasPm = true;
  1145. break;
  1146. }
  1147. if (ModuleHelper.IsInstalled(module) && (pmOccupied == null || !pmOccupied.Contains(module)))
  1148. {
  1149. hasPm = true;
  1150. }
  1151. if (!pmUsed.Contains(module))
  1152. pmUsed.Add(module);
  1153. }
  1154. if (pmIsReady && !hasPm)
  1155. {
  1156. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1157. pmIsReady = false;
  1158. }
  1159. }
  1160. return pmIsReady;
  1161. }
  1162. //检查是否又对应PM的recipe
  1163. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  1164. {
  1165. for (int i = 0; i < seq.Steps.Count; i++)
  1166. {
  1167. SequenceStepInfo stepInfo = seq.Steps[i];
  1168. foreach (var module in stepInfo.StepModules)
  1169. {
  1170. if (ModuleHelper.IsPm(module))
  1171. {
  1172. string attr = $"{module}Recipe";
  1173. if (stepInfo.StepParameter.ContainsKey(attr)
  1174. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  1175. {
  1176. var recipeName = (string)stepInfo.StepParameter[attr];
  1177. if (!string.IsNullOrEmpty(recipeName))
  1178. {
  1179. var recipeContent =
  1180. RecipeFileManager.Instance.LoadRecipe($"{module}", recipeName, false, "Process");
  1181. if (string.IsNullOrEmpty(recipeContent))
  1182. {
  1183. reason = $"Can not find recipe file{recipeName}";
  1184. return false;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. }
  1191. reason = "";
  1192. return true;
  1193. }
  1194. //找到对应sequence
  1195. public ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  1196. {
  1197. foreach (var pj in _lstProcessJobs)
  1198. {
  1199. if (pj.ControlJobName == cj.Name)
  1200. return pj;
  1201. }
  1202. return null;
  1203. }
  1204. #endregion
  1205. }
  1206. }