SchedulerSequenceManager.cs 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. using MECF.Framework.Common.RecipeCenter;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using Aitex.Core.Common;
  10. using MECF.Framework.Common.WaferHolder;
  11. using MECF.Framework.Common.CommonData;
  12. using System.Windows;
  13. using Aitex.Core.RT.IOCore;
  14. using Aitex.Core.RT.Log;
  15. using Aitex.Core.Util;
  16. using MECF.Framework.Common.Routine;
  17. using CyberX8_RT.Modules;
  18. using Aitex.Core.RT.Fsm;
  19. using CyberX8_RT.Modules.PUF;
  20. using CyberX8_RT.Modules.Dummy;
  21. using MECF.Framework.Common.SubstrateTrackings;
  22. using MECF.Framework.Common.ToolLayout;
  23. using CyberX8_RT.Modules.Metal;
  24. using CyberX8_RT.Modules.Rinse;
  25. using MECF.Framework.RT.Core.Equipments;
  26. using MECF.Framework.Common.ProcessCell;
  27. using SecsGem.Core.ItemModel;
  28. using CyberX8_RT.Modules.Transporter;
  29. using CyberX8_Core;
  30. using Aitex.Core.RT.SCCore;
  31. using CyberX8_RT.Modules.Dryer;
  32. using CyberX8_RT.Modules.Prewet;
  33. using CyberX8_RT.Modules.SRD;
  34. using CyberX8_RT.Modules.Reservoir;
  35. using CyberX8_RT.Schedulers.Puf;
  36. namespace CyberX8_RT.Schedulers
  37. {
  38. public class SchedulerSequenceManager : Singleton<SchedulerSequenceManager>
  39. {
  40. #region 常量
  41. private const string ENGINEERING = "Engineering";
  42. private const string PRODUCTION = "Production";
  43. #endregion
  44. /// <summary>
  45. /// 解析Wafer所有调度工序
  46. /// </summary>
  47. /// <param name="sequenceRecipe"></param>
  48. /// <returns></returns>
  49. public List<SchedulerSequence> AnalyWaferAllSchedulerSequence(WaferInfo waferInfo,ModuleName pufModule,string side,WaferHolderInfo waferHolderInfo,SequenceRecipe sequenceRecipe)
  50. {
  51. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  52. int index = 0;
  53. MoveItem moveItem = new MoveItem((ModuleName)waferInfo.OriginStation, waferInfo.OriginSlot, ModuleName.Aligner1, 0, Aitex.Sorter.Common.Hand.Blade1);
  54. List<SchedulerSyncModuleMessage> synModules = new List<SchedulerSyncModuleMessage>();
  55. SchedulerSyncModuleMessage pufModuleMessage = new SchedulerSyncModuleMessage();
  56. pufModuleMessage.ModuleEntity = Singleton<RouteManager>.Instance.GetModule<IModuleEntity>(pufModule.ToString());
  57. pufModuleMessage.ModuleMsg = PUFMSG.ReadyForRobotPlace.ToString();
  58. synModules.Add(pufModuleMessage);
  59. SchedulerSequence efemRobotSequence = CreateEfemRobotSequence(moveItem,synModules,ref index);
  60. schedulerSequences.Add(efemRobotSequence);
  61. SchedulerSequence alignerSequence=CreateAlignerSequence(sequenceRecipe.AlignmentAngle,ref index);
  62. schedulerSequences.Add(alignerSequence);
  63. //从Aligner至Puf B面
  64. MoveItem moveItem2 = new MoveItem(ModuleName.Aligner1, 0, pufModule, 0, Aitex.Sorter.Common.Hand.Blade1);
  65. SchedulerSequence secondEfemRobotSequence = CreateEfemRobotSequence(moveItem2,null,ref index);
  66. schedulerSequences.Add(secondEfemRobotSequence);
  67. SchedulerSequence pufSequence=CreatePufSequence(pufModule,sequenceRecipe,side,true,ref index);
  68. schedulerSequences.Add(pufSequence);
  69. ////Loader
  70. //SchedulerSequence loaderSequence = CreateLoaderSequence(ref index);
  71. //schedulerSequences.Add(loaderSequence);
  72. ////wafer holder装载后的recipe工序
  73. //List<SchedulerSequence> waferHolderAfterLoadedAllSequences = WaferHolderAfterLoadedAllSchedulerSequences(waferHolderInfo, sequenceRecipe, ref index);
  74. //schedulerSequences.AddRange(waferHolderAfterLoadedAllSequences);
  75. ////buffer模块至Loader
  76. //ModuleName bufferModule = ConvertToBufferModule(waferHolderInfo.BufferId);
  77. //WaferHolderMoveItem bufferToLoaderItem = new WaferHolderMoveItem(bufferModule,ModuleType.Buffer , ModuleName.Loader1, ModuleType.Loader);
  78. //SchedulerSequence bufferToLoaderSequence = CreateLoaderTransporterSequence(bufferToLoaderItem, ref index);
  79. //schedulerSequences.Add(bufferToLoaderSequence);
  80. ////Loader
  81. //SchedulerSequence backLoaderSequence = CreateLoaderSequence(ref index);
  82. //schedulerSequences.Add(backLoaderSequence);
  83. //puf模块
  84. SchedulerSequence backPufSequence = CreatePufSequence(pufModule,sequenceRecipe,"",false, ref index);
  85. schedulerSequences.Add(backPufSequence);
  86. //若经过srd
  87. if(SequenceRecipeManager.Instance.IsContainedSrd(sequenceRecipe))
  88. {
  89. SrdRecipe srdRecipe=SequenceRecipeManager.Instance.GetSrdRecipeBySequenceRecipe(sequenceRecipe);
  90. if(srdRecipe!=null)
  91. {
  92. MoveItem pufToSrdItem = new MoveItem();
  93. pufToSrdItem.SourceModule = pufModule;
  94. //A面
  95. pufToSrdItem.SourceSlot = 0;
  96. pufToSrdItem.DestinationType = ModuleType.SRD;
  97. pufToSrdItem.SourceSlot = 0;
  98. pufToSrdItem.DestinationModule = ModuleName.Unknown;
  99. pufToSrdItem.RobotHand = Aitex.Sorter.Common.Hand.Blade1;
  100. SchedulerSequence backEfemRobotSequence = CreateEfemRobotSequence(pufToSrdItem,null, ref index);
  101. schedulerSequences.Add(backEfemRobotSequence);
  102. SchedulerSequence srdSequence = CreateSRDSequence(srdRecipe, ref index);
  103. schedulerSequences.Add(srdSequence);
  104. MoveItem srdToLoadPortItem = new MoveItem();
  105. srdToLoadPortItem.SourceModule = ModuleName.Unknown;
  106. srdToLoadPortItem.SourceType = ModuleType.SRD;
  107. srdToLoadPortItem.SourceSlot = 0;
  108. srdToLoadPortItem.DestinationType = ModuleType.LoadPort;
  109. srdToLoadPortItem.DestinationModule = (ModuleName)waferInfo.OriginStation;
  110. srdToLoadPortItem.DestinationSlot = waferInfo.OriginSlot;
  111. srdToLoadPortItem.RobotHand = Aitex.Sorter.Common.Hand.Blade1;
  112. SchedulerSequence srdToLoadPortSequence = CreateEfemRobotSequence(srdToLoadPortItem,null, ref index);
  113. schedulerSequences.Add(srdToLoadPortSequence);
  114. }
  115. else
  116. {
  117. LOG.WriteLog(eEvent.ERR_SEQUENCE, "System", $"{sequenceRecipe.Ppid} srd recipe is invalid");
  118. return new List<SchedulerSequence>();
  119. }
  120. }
  121. else
  122. {
  123. MoveItem pufToLoadPortItem=new MoveItem(pufModule,0,(ModuleName)waferInfo.OriginStation,
  124. waferInfo.OriginSlot,Aitex.Sorter.Common.Hand.Blade1);
  125. SchedulerSequence pufToLoaderSequence=CreateEfemRobotSequence(pufToLoadPortItem,null, ref index);
  126. schedulerSequences.Add(pufToLoaderSequence);
  127. }
  128. return schedulerSequences;
  129. }
  130. /// <summary>
  131. /// 解析WaferHolder的所有工序
  132. /// </summary>
  133. /// <param name="waferHolderInfo"></param>
  134. /// <param name="sequenceRecipe"></param>
  135. /// <returns></returns>
  136. public List<SchedulerSequence> AnalyWaferHolderAllSchedulerSequence(WaferHolderInfo waferHolderInfo, SequenceRecipe sequenceRecipe,int waferCount)
  137. {
  138. int index = 0;
  139. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  140. //Buffer To Loader
  141. ModuleName currentLocationModuleName = (ModuleName)Enum.Parse(typeof(ModuleName), waferHolderInfo.CurrentLocation);
  142. WaferHolderMoveItem bufferMoveToLoaderItem = new WaferHolderMoveItem(currentLocationModuleName, ModuleType.Buffer, ModuleName.Loader1, ModuleType.Loader);
  143. SchedulerSequence bufferToLoaderSequence = CreateLoaderTransporterSequence(bufferMoveToLoaderItem, ref index);
  144. schedulerSequences.Add(bufferToLoaderSequence);
  145. //Loader
  146. SchedulerSequence loaderSequence = CreateLoaderSequence(waferCount,ref index);
  147. schedulerSequences.Add(loaderSequence);
  148. //wafer holder装载后的recipe工序
  149. List<SchedulerSequence> waferHolderAfterLoadedAllSequences = WaferHolderAfterLoadedAllSchedulerSequences(waferHolderInfo, sequenceRecipe,ref index);
  150. schedulerSequences.AddRange(waferHolderAfterLoadedAllSequences);
  151. return schedulerSequences;
  152. }
  153. /// <summary>
  154. /// Dummy Wafer对应WaferHolder任务
  155. /// </summary>
  156. /// <param name="waferHolderInfo"></param>
  157. /// <returns></returns>
  158. public List<SchedulerSequence> AnalyseDummyWaferHolderAllSchedulerSequence(WaferHolderInfo waferHolderInfo,int waferCount)
  159. {
  160. int index = 0;
  161. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  162. //Buffer To Loader
  163. ModuleName currentLocationModuleName = (ModuleName)Enum.Parse(typeof(ModuleName), waferHolderInfo.CurrentLocation);
  164. ModuleName bufferModule = (ModuleName)Enum.Parse(typeof(ModuleName), waferHolderInfo.OriginalBuffer);
  165. WaferHolderMoveItem bufferMoveToLoaderItem = new WaferHolderMoveItem(currentLocationModuleName, ModuleType.Buffer, ModuleName.Loader1, ModuleType.Loader);
  166. SchedulerSequence bufferToLoaderSequence = CreateLoaderTransporterSequence(bufferMoveToLoaderItem, ref index);
  167. schedulerSequences.Add(bufferToLoaderSequence);
  168. //Loader
  169. SchedulerSequence loaderSequence = CreateLoaderSequence(waferCount,ref index);
  170. schedulerSequences.Add(loaderSequence);
  171. //Loader To Buffer
  172. WaferHolderMoveItem loaderMoveToBufferItem = new WaferHolderMoveItem(ModuleName.Loader1, ModuleType.Loader,
  173. bufferModule, ModuleType.Buffer);
  174. SchedulerSequence loaderToBufferSequence = CreateLoaderTransporterSequence(loaderMoveToBufferItem, ref index);
  175. schedulerSequences.Add(loaderToBufferSequence);
  176. return schedulerSequences;
  177. }
  178. /// <summary>
  179. /// 解析Dummy Wafer所有调度工序
  180. /// </summary>
  181. /// <param name="sequenceRecipe"></param>
  182. /// <returns></returns>
  183. public List<SchedulerSequence> AnalyDummyWaferAllSchedulerSequence(SequenceRecipe sequenceRecipe,WaferInfo waferInfo, ModuleName pufModule,string side)
  184. {
  185. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  186. int index = 0;
  187. //DummyCassete至Aligner
  188. MoveItem moveItem = new MoveItem((ModuleName)waferInfo.Station, waferInfo.Slot, ModuleName.Aligner1, 0, Aitex.Sorter.Common.Hand.Blade1);
  189. SchedulerSequence secondEfemRobotSequence = CreateEfemRobotSequence(moveItem, null, ref index);
  190. schedulerSequences.Add(secondEfemRobotSequence);
  191. //Aligner
  192. SchedulerSequence alignerSequence = null;
  193. if (sequenceRecipe == null)
  194. {
  195. alignerSequence= CreateAlignerSequence(0, ref index);
  196. }
  197. else
  198. {
  199. alignerSequence=CreateAlignerSequence(sequenceRecipe.AlignmentAngle, ref index);
  200. }
  201. schedulerSequences.Add(alignerSequence);
  202. //Aligner至Puf
  203. MoveItem alignerToPufMoveItem = new MoveItem(ModuleName.Aligner1, 0, pufModule, 1, Aitex.Sorter.Common.Hand.Blade1);
  204. SchedulerSequence alignerToPufEfemRobotSequence = CreateEfemRobotSequence(alignerToPufMoveItem, null, ref index);
  205. schedulerSequences.Add(alignerToPufEfemRobotSequence);
  206. SchedulerSequence pufSequence = CreatePufSequence(pufModule,sequenceRecipe, side,true, ref index);
  207. schedulerSequences.Add(pufSequence);
  208. return schedulerSequences;
  209. }
  210. /// <summary>
  211. /// Loader装载后Recipe工序
  212. /// </summary>
  213. /// <param name="waferHolderInfo"></param>
  214. /// <param name="sequenceRecipe"></param>
  215. /// <param name="index"></param>
  216. /// <returns></returns>
  217. private List<SchedulerSequence> WaferHolderAfterLoadedAllSchedulerSequences(WaferHolderInfo waferHolderInfo,SequenceRecipe sequenceRecipe,ref int index)
  218. {
  219. List<SchedulerSequence> schedulerSequences = new List<SchedulerSequence>();
  220. if(!Enum.TryParse(waferHolderInfo.OriginalBuffer,out ModuleName moduleName))
  221. {
  222. return schedulerSequences;
  223. }
  224. //Loader To Buffer
  225. WaferHolderMoveItem loaderMoveToBufferItem = new WaferHolderMoveItem(ModuleName.Loader1, ModuleType.Loader,
  226. moduleName, ModuleType.Buffer);
  227. SchedulerSequence loaderToBufferSequence = CreateLoaderTransporterSequence(loaderMoveToBufferItem, ref index);
  228. schedulerSequences.Add(loaderToBufferSequence);
  229. //解析sequence recipe后续的工序
  230. var result = AnalyseSequenceRecipeScheduler(sequenceRecipe);
  231. //buffer to recipe第一个工序
  232. WaferHolderMoveItem bufferToFirstItem = new WaferHolderMoveItem(moduleName, ModuleType.Buffer, ModuleName.Unknown, result.firstModuleType);
  233. SchedulerSequence bufferSequence = CreateLoaderTransporterSequence(bufferToFirstItem, ref index);
  234. schedulerSequences.Add(bufferSequence);
  235. //调整工序后面的索引
  236. foreach (SchedulerSequence item in result.sequences)
  237. {
  238. item.SequenceIndex = index;
  239. index++;
  240. }
  241. schedulerSequences.AddRange(result.sequences);
  242. //从recipe最后工序
  243. WaferHolderMoveItem lastToBufferItem = new WaferHolderMoveItem(ModuleName.Unknown, result.lastModuleType, moduleName, ModuleType.Buffer);
  244. SchedulerSequence lastToBufferSequence = CreateLoaderTransporterSequence(lastToBufferItem, ref index);
  245. schedulerSequences.Add(lastToBufferSequence);
  246. return schedulerSequences;
  247. }
  248. /// <summary>
  249. /// 分析Sequence recipe对应的调度步骤
  250. /// </summary>
  251. /// <param name="sequenceRecipe"></param>
  252. /// <returns></returns>
  253. private (ModuleType firstModuleType,List<SchedulerSequence> sequences,ModuleType lastModuleType) AnalyseSequenceRecipeScheduler(SequenceRecipe sequenceRecipe)
  254. {
  255. ModuleType firstModuleType = default;
  256. ModuleType lastModuleType = default;
  257. List<SchedulerSequence> schedulerSequences= new List<SchedulerSequence>();
  258. List<SchedulerSequence> tmpLst = new List<SchedulerSequence>();
  259. var processResult = AnalyseLastProcessRecipeIndex(sequenceRecipe.Recipes);
  260. bool isExistSrd = sequenceRecipe.Recipes.FindIndex(O=>O.ToLower().EndsWith("srd.rcp"))!=-1;
  261. int lastIndex = isExistSrd ? sequenceRecipe.Recipes.Count - 2 : sequenceRecipe.Recipes.Count - 1;
  262. for(int i=0;i<sequenceRecipe.Recipes.Count;i++)
  263. {
  264. string item = sequenceRecipe.Recipes[i];
  265. if(item.ToLower().EndsWith("srd.rcp"))//跳过SRD
  266. {
  267. continue;
  268. }
  269. SchedulerSequence schedulerSequence = new SchedulerSequence();
  270. schedulerSequence.ModuleName = ModuleName.Unknown;
  271. schedulerSequence.ModuleType=SequenceRecipeManager.Instance.GetModuleType(item);
  272. schedulerSequence.SequenceIndex=i;
  273. MECF.Framework.Common.RecipeCenter.RecipeType recipeType =SequenceRecipeManager.Instance.GetRecipeType(item);
  274. schedulerSequence.Recipe = SequenceRecipeManager.Instance.LoadSequenceTypeRecipe(sequenceRecipe.SequenceType,item, recipeType);
  275. schedulerSequence.SequenceType = sequenceRecipe.SequenceType;
  276. schedulerSequence.State = RState.Init;
  277. schedulerSequence.MaterialType = MaterialType.WaferHolder;
  278. tmpLst.Add(schedulerSequence);
  279. if (i == 0)
  280. {
  281. firstModuleType = schedulerSequence.ModuleType;
  282. }
  283. if(i==lastIndex)
  284. {
  285. lastModuleType = schedulerSequence.ModuleType;
  286. }
  287. else
  288. {
  289. string nextModule = sequenceRecipe.Recipes[i + 1];
  290. schedulerSequence.NextModuleType= SequenceRecipeManager.Instance.GetModuleType(nextModule);
  291. MECF.Framework.Common.RecipeCenter.RecipeType nextRecipeType = SequenceRecipeManager.Instance.GetRecipeType(nextModule);
  292. schedulerSequence.NextRecipe= SequenceRecipeManager.Instance.LoadSequenceTypeRecipe(sequenceRecipe.SequenceType,nextModule,nextRecipeType);
  293. }
  294. schedulerSequence.IsProcessSequece = true;
  295. if(i==processResult.lastIndex)
  296. {
  297. schedulerSequence.IsLastProcessSequence = true;
  298. }
  299. }
  300. int index = 0;
  301. for(int i=0;i<tmpLst.Count;i++)
  302. {
  303. tmpLst[i].SequenceIndex = 0;
  304. schedulerSequences.Add(tmpLst[i]);
  305. index++;
  306. if(i<tmpLst.Count-1)
  307. {
  308. WaferHolderMoveItem moveItem = new WaferHolderMoveItem(ModuleName.Unknown, tmpLst[i].ModuleType, ModuleName.Unknown, tmpLst[i + 1].ModuleType);
  309. SchedulerSequence schedulerSequence=CreateProcessTransporterSequence(moveItem,ref index);
  310. schedulerSequences.Add(schedulerSequence);
  311. }
  312. }
  313. return (firstModuleType,schedulerSequences,lastModuleType);
  314. }
  315. /// <summary>
  316. /// 分析最后加工recipe索引
  317. /// </summary>
  318. /// <param name="recipes"></param>
  319. /// <returns></returns>
  320. private (int lastIndex,List<int> processIndexList) AnalyseLastProcessRecipeIndex(List<string> recipes)
  321. {
  322. int index = 0;
  323. List<int> lst = new List<int>();
  324. for(int i=0;i<recipes.Count; i++)
  325. {
  326. string item=recipes[i];
  327. if(item.ToLower().EndsWith("dep.rcp"))
  328. {
  329. index = i;
  330. if(lst.Contains(i))
  331. {
  332. lst.Add(i);
  333. }
  334. }
  335. }
  336. if(lst.Count==0)
  337. {
  338. lst.Add(0);
  339. }
  340. return (index,lst);
  341. }
  342. /// <summary>
  343. /// 创建EFEM Robot步骤
  344. /// </summary>
  345. /// <param name="index"></param>
  346. /// <returns></returns>
  347. private SchedulerSequence CreateEfemRobotSequence(MoveItem moveItem,List<SchedulerSyncModuleMessage> synModules,ref int index)
  348. {
  349. SchedulerSequence sequence = new SchedulerSequence();
  350. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.EfemRobot);
  351. sequence.SequenceIndex= index;
  352. sequence.ModuleName=ModuleName.EfemRobot;
  353. sequence.State = RState.Init;
  354. sequence.Recipe = null;
  355. sequence.ModuleType=ModuleType.EfemRobot;
  356. sequence.Parameters =moveItem;
  357. sequence.MaterialType = MaterialType.Wafer;
  358. sequence.SynchronousModuleMessages = synModules;
  359. index++;
  360. return sequence;
  361. }
  362. /// <summary>
  363. /// 创建Aligner步骤
  364. /// </summary>
  365. /// <param name="index"></param>
  366. /// <returns></returns>
  367. private SchedulerSequence CreateAlignerSequence(double angle,ref int index)
  368. {
  369. SchedulerSequence sequence = new SchedulerSequence();
  370. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Aligner1);
  371. sequence.SequenceIndex = index;
  372. sequence.ModuleName = ModuleName.Aligner1;
  373. sequence.State = RState.Init;
  374. sequence.Recipe = null;
  375. sequence.ModuleType = ModuleType.Aligner;
  376. sequence.Parameters = angle;
  377. sequence.MaterialType = MaterialType.Wafer;
  378. index++;
  379. return sequence;
  380. }
  381. /// <summary>
  382. /// 创建PUF步骤
  383. /// </summary>
  384. /// <param name="pufModuleName"></param>
  385. /// <param name="index"></param>
  386. /// <returns></returns>
  387. private SchedulerSequence CreatePufSequence(ModuleName pufModuleName,SequenceRecipe sequenceRecipe,string side,bool forward,ref int index)
  388. {
  389. SchedulerSequence sequence = new SchedulerSequence();
  390. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(pufModuleName);
  391. sequence.SequenceIndex = index;
  392. sequence.ModuleName = pufModuleName;
  393. sequence.State = RState.Init;
  394. sequence.Recipe = sequenceRecipe;
  395. PufSchedulerParameter parameter = new PufSchedulerParameter()
  396. {
  397. IsForward = forward,
  398. Side = side,
  399. };
  400. sequence.Parameters = parameter;
  401. sequence.IsWaitNotify = !forward;
  402. sequence.ModuleType = ModuleType.PUF;
  403. sequence.MaterialType = MaterialType.Wafer;
  404. index++;
  405. return sequence;
  406. }
  407. /// <summary>
  408. /// 创建Loader步骤
  409. /// </summary>
  410. /// <param name="index"></param>
  411. /// <returns></returns>
  412. private SchedulerSequence CreateLoaderSequence(int waferCount,ref int index)
  413. {
  414. SchedulerSequence sequence = new SchedulerSequence();
  415. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Loader1);
  416. sequence.SequenceIndex = index;
  417. sequence.ModuleName = ModuleName.Loader1;
  418. sequence.State = RState.Init;
  419. sequence.Recipe = null;
  420. sequence.Parameters = waferCount;
  421. sequence.ModuleType = ModuleType.Loader;
  422. sequence.MaterialType = MaterialType.WaferHolder;
  423. index++;
  424. return sequence;
  425. }
  426. /// <summary>
  427. /// 创建Loader步骤
  428. /// </summary>
  429. /// <param name="index"></param>
  430. /// <returns></returns>
  431. private SchedulerSequence CreateSRDSequence(SrdRecipe recipe,ref int index)
  432. {
  433. SchedulerSequence sequence = new SchedulerSequence();
  434. sequence.SequenceIndex = index;
  435. sequence.State = RState.Init;
  436. sequence.Recipe = recipe;
  437. sequence.ModuleType = ModuleType.SRD;
  438. sequence.MaterialType = MaterialType.Wafer;
  439. index++;
  440. return sequence;
  441. }
  442. /// <summary>
  443. /// 创建LoaderTransporter步骤
  444. /// </summary>
  445. /// <param name="index"></param>
  446. /// <returns></returns>
  447. private SchedulerSequence CreateLoaderTransporterSequence(WaferHolderMoveItem waferHolderMoveItem, ref int index)
  448. {
  449. SchedulerSequence sequence = new SchedulerSequence();
  450. sequence.ModuleType = ModuleType.Transporter;
  451. sequence.ModuleName = ModuleName.Transporter2;
  452. sequence.SequenceIndex = index;
  453. sequence.State = RState.Init;
  454. sequence.Recipe = null;
  455. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Transporter2);
  456. sequence.Parameters = waferHolderMoveItem;
  457. sequence.MaterialType = MaterialType.WaferHolder;
  458. index++;
  459. return sequence;
  460. }
  461. /// <summary>
  462. /// 创建LoaderTransporter步骤
  463. /// </summary>
  464. /// <param name="index"></param>
  465. /// <returns></returns>
  466. private SchedulerSequence CreateProcessTransporterSequence(WaferHolderMoveItem waferHolderMoveItem,ref int index)
  467. {
  468. SchedulerSequence sequence = new SchedulerSequence();
  469. sequence.ModuleType = ModuleType.Transporter;
  470. sequence.ModuleName = ModuleName.Transporter1;
  471. sequence.SequenceIndex = index;
  472. sequence.State = RState.Init;
  473. sequence.Recipe = null;
  474. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(ModuleName.Transporter1);
  475. sequence.Parameters= waferHolderMoveItem;
  476. sequence.MaterialType = MaterialType.WaferHolder;
  477. index++;
  478. return sequence;
  479. }
  480. /// <summary>
  481. /// 获取可用Dummy slot
  482. /// </summary>
  483. /// <param name="moduleType"></param>
  484. /// <returns></returns>
  485. public (ModuleName moduleName,int slot) GetAvaibleDummySlots()
  486. {
  487. if(ModuleHelper.IsInstalled(ModuleName.Dummy1))
  488. {
  489. DummyEntity dummyEntity = Singleton<RouteManager>.Instance.GetModule<DummyEntity>(ModuleName.Dummy1.ToString());
  490. for(int i=0;i<dummyEntity.MaxSlotNumber;i++)
  491. {
  492. if(WaferManager.Instance.CheckNoWafer(ModuleName.Dummy1,i))
  493. {
  494. return (ModuleName.Dummy1, i);
  495. }
  496. }
  497. }
  498. if(ModuleHelper.IsInstalled(ModuleName.Dummy2))
  499. {
  500. DummyEntity dummyEntity = Singleton<RouteManager>.Instance.GetModule<DummyEntity>(ModuleName.Dummy2.ToString());
  501. for (int i = 0; i < dummyEntity.MaxSlotNumber; i++)
  502. {
  503. if (WaferManager.Instance.CheckNoWafer(ModuleName.Dummy2, i))
  504. {
  505. return (ModuleName.Dummy2, i);
  506. }
  507. }
  508. }
  509. return (ModuleName.Unknown, -1);
  510. }
  511. /// <summary>
  512. /// 根据模块类型获取可用模块
  513. /// </summary>
  514. /// <param name="moduleType"></param>
  515. /// <returns></returns>
  516. public ModuleName GetAvaibleModuleCell(string sequenceType,ModuleType moduleType, ModuleName moduleName = ModuleName.Unknown)
  517. {
  518. if (ModuleHelper.IsMetal(moduleName))
  519. {
  520. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  521. return GetMetalAvaibleRinseModule(entities, moduleName);
  522. }
  523. else
  524. {
  525. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  526. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  527. foreach (var item in entities)
  528. {
  529. bool result = CheckAvaibleModule(item,moduleType,sequenceType);
  530. if (result)
  531. {
  532. avaibles.Add(item);
  533. }
  534. }
  535. return GetMinTimeToReadyModule(avaibles,moduleType);
  536. }
  537. }
  538. /// <summary>
  539. /// 根据模块类型获取可用模块(不包含WH)
  540. /// </summary>
  541. /// <param name="moduleType"></param>
  542. /// <returns></returns>
  543. public ModuleName GetAvaibleEmptyModuleCell(ModuleType moduleType,string sequenceType, ModuleName moduleName = ModuleName.Unknown)
  544. {
  545. if (ModuleHelper.IsMetal(moduleName))
  546. {
  547. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  548. return GetMetalAvaibleEmptyRinseModule(entities, moduleName);
  549. }
  550. else
  551. {
  552. List<IModuleEntity> entities = Singleton<RouteManager>.Instance.GetModulesByModuleType(moduleType);
  553. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  554. foreach (var item in entities)
  555. {
  556. bool result = CheckAvaibleModule(item,moduleType,sequenceType);
  557. if (result&&!WaferHolderManager.Instance.HasWaferHolder(item.Module.ToString()))
  558. {
  559. avaibles.Add(item);
  560. }
  561. }
  562. return avaibles.Count != 0 ? avaibles[0].Module : ModuleName.Unknown;
  563. }
  564. }
  565. /// <summary>
  566. /// 根据化学液计算时间获取可用MetalCell(参考其他Metal剩余时间)
  567. /// </summary>
  568. /// <param name="chemistry"></param>
  569. /// <returns></returns>
  570. public ModuleName CalculateAvaibleMetalCellByChemistry(string chemistry,string startRinse,string sequenceType,ref bool isExistEnableMetal)
  571. {
  572. if(!Enum.TryParse(startRinse,out ModuleName startRinseModule)||!ModuleHelper.IsRinse(startRinseModule))
  573. {
  574. startRinse = "";
  575. }
  576. isExistEnableMetal = false;
  577. List<MetalEntity> moduleEntities = GetAvaibleMetalList(chemistry,sequenceType,true);
  578. List<IModuleEntity> avaibleMetalEntities = new List<IModuleEntity>();
  579. foreach (var item in moduleEntities)
  580. {
  581. if(CheckAvaibleModule(item,ModuleType.Metal,sequenceType))
  582. {
  583. if (item.WaferHolderInfo == null)
  584. {
  585. if (CheckMetalModuleRinseAvaible(item, startRinse))
  586. {
  587. avaibleMetalEntities.Add(item);
  588. }
  589. }
  590. isExistEnableMetal = true;
  591. }
  592. }
  593. if (avaibleMetalEntities.Count > 0)
  594. {
  595. return GetMinUsageMetal(avaibleMetalEntities);
  596. }
  597. return ModuleName.Unknown;
  598. }
  599. /// <summary>
  600. /// 根据化学液获取可用Metal
  601. /// </summary>
  602. /// <param name="chemistry"></param>
  603. /// <param name="sequenceType"></param>
  604. /// <returns></returns>
  605. public bool CalculateAvaibleMetalCellByChemistry(string chemistry,string sequenceType)
  606. {
  607. List<MetalEntity> moduleEntities = GetAvaibleMetalList(chemistry, sequenceType, false);
  608. return moduleEntities.Count != 0;
  609. }
  610. /// <summary>
  611. /// 检验Metal模块Rinse可用性
  612. /// </summary>
  613. /// <param name="item"></param>
  614. /// <returns></returns>
  615. private bool CheckMetalModuleRinseAvaible(MetalEntity item,string startRinse)
  616. {
  617. List<LayoutCellItem> rinseItems = CellItemManager.Instance.GetRinseItemsByMetal(item.Module.ToString());
  618. List<string> sharedRinseItems = new List<string>();
  619. List<string> singleRinseItems = new List<string>();
  620. foreach (var cellItem in rinseItems)
  621. {
  622. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(cellItem.ModuleName);
  623. if (!CellItemManager.Instance.CheckRinseIsShared(cellItem.ModuleName))
  624. {
  625. if (CheckAvaibleModule(rinseEntity, ModuleType.Rinse, "") && rinseEntity.WaferHolderInfo == null)
  626. {
  627. singleRinseItems.Add(cellItem.ModuleName);
  628. }
  629. }
  630. else
  631. {
  632. if (CheckAvaibleModule(rinseEntity,ModuleType.Rinse,"") && rinseEntity.WaferHolderInfo == null)
  633. {
  634. sharedRinseItems.Add(cellItem.ModuleName);
  635. }
  636. //增加自己
  637. if (cellItem.ModuleName == startRinse && rinseEntity != null && (rinseEntity.IsIdle||rinseEntity.State==(int)RinseState.KeepWeting))
  638. {
  639. sharedRinseItems.Add(startRinse);
  640. }
  641. }
  642. }
  643. //独立的Rinse集合
  644. if(singleRinseItems.Count!=0)
  645. {
  646. bool result = CheckSingleRinseItemsCanUsed(singleRinseItems, item.Module.ToString());
  647. if(result)
  648. {
  649. return true;
  650. }
  651. }
  652. //仅剩下共享Rinse
  653. List<string> avaibleSharedList = new List<string>();
  654. if (sharedRinseItems.Count != 0)
  655. {
  656. foreach (string sharedRinse in sharedRinseItems)
  657. {
  658. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(sharedRinse);
  659. if (rinseEntity.IsBusy&&sharedRinse!=startRinse)
  660. {
  661. continue;
  662. }
  663. //检验共享Rinse是否可用
  664. if (CheckShardRinseCanUse(sharedRinse, item.Module.ToString(),startRinse))
  665. {
  666. avaibleSharedList.Add(sharedRinse);
  667. }
  668. }
  669. }
  670. if (avaibleSharedList.Count != 0)
  671. {
  672. var result = CalculateMetalReservoirAllBusyMetalCount(item.Module.ToString());
  673. if (result.success)
  674. {
  675. bool transporterTransfering = CheckProcessTransporterTransfering(avaibleSharedList);
  676. if(transporterTransfering)
  677. {
  678. return result.busyCount + 1 < avaibleSharedList.Count;
  679. }
  680. else
  681. {
  682. return result.busyCount < avaibleSharedList.Count+singleRinseItems.Count;
  683. }
  684. }
  685. }
  686. return false;
  687. }
  688. /// <summary>
  689. /// 检验Process transporter正在Transfer WH移动至Rinse
  690. /// </summary>
  691. /// <returns></returns>
  692. private bool CheckProcessTransporterTransfering(List<string> rinseList)
  693. {
  694. TransporterEntity processTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter1.ToString());
  695. if(processTransporterEntity!=null)
  696. {
  697. if (processTransporterEntity.IsBusy)
  698. {
  699. string targetCell = processTransporterEntity.TargetCell;
  700. if (rinseList.Contains(targetCell))
  701. {
  702. return true;
  703. }
  704. }
  705. }
  706. return false;
  707. }
  708. /// <summary>
  709. /// 计算Metal所在Reservoir Busy Metal数量
  710. /// </summary>
  711. /// <param name="item"></param>
  712. /// <returns></returns>
  713. private (bool success,int busyCount) CalculateMetalReservoirAllBusyMetalCount(string metalName)
  714. {
  715. string reservoirName = ReservoirItemManager.Instance.GetReservoirByMetal(metalName);
  716. if (string.IsNullOrEmpty(reservoirName))
  717. {
  718. return (false,0);
  719. }
  720. List<string> metals = ReservoirItemManager.Instance.GetMetalsByReservoir(reservoirName);
  721. int count = 0;
  722. foreach (string item in metals)
  723. {
  724. if (metalName == item)
  725. {
  726. continue;
  727. }
  728. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(item);
  729. if (metalEntity.IsBusy || metalEntity.WaferHolderInfo != null)
  730. {
  731. count++;
  732. }
  733. }
  734. return (true,count);
  735. }
  736. /// <summary>
  737. /// 检验独立Rinse是否可用
  738. /// </summary>
  739. /// <param name="singleRinseItems"></param>
  740. /// <param name="metalName"></param>
  741. /// <returns></returns>
  742. private bool CheckSingleRinseItemsCanUsed(List<string> singleRinseItems, string metalName)
  743. {
  744. var result = CalculateMetalReservoirAllBusyMetalCount(metalName);
  745. if(result.success)
  746. {
  747. bool transporterTransfering = CheckProcessTransporterTransfering(singleRinseItems);
  748. if (transporterTransfering)
  749. {
  750. return result.busyCount + 1 < singleRinseItems.Count;
  751. }
  752. else
  753. {
  754. return result.busyCount < singleRinseItems.Count;
  755. }
  756. }
  757. return false;
  758. }
  759. /// <summary>
  760. /// 检验共享Rinse是否可用
  761. /// </summary>
  762. /// <param name="sharedRinse"></param>
  763. /// <param name="metalName"></param>
  764. /// <returns></returns>
  765. private bool CheckShardRinseCanUse(string sharedRinse, string metalName,string startRinse)
  766. {
  767. string reservoirName = ReservoirItemManager.Instance.GetReservoirByMetal(metalName);
  768. List<string> shardReservoirs = CellItemManager.Instance.GetReservoirsBySharedRinse(sharedRinse);
  769. if (shardReservoirs == null || shardReservoirs.Count == 0)
  770. {
  771. return false;
  772. }
  773. foreach (string reservoir in shardReservoirs)
  774. {
  775. if (reservoir==reservoirName)
  776. {
  777. continue;
  778. }
  779. List<string> metals=ReservoirItemManager.Instance.GetMetalsByReservoir(reservoir);
  780. int metalCount = 0;
  781. int busyMetalCount = 0;
  782. foreach(string metal in metals)
  783. {
  784. MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(metal);
  785. if(metalEntity.IsAuto&&metalEntity.IsInitialized)
  786. {
  787. metalCount++;
  788. }
  789. if(metalEntity.IsBusy||metalEntity.WaferHolderInfo!=null)
  790. {
  791. busyMetalCount++;
  792. }
  793. }
  794. List<string> reservoirRinseLst = CellItemManager.Instance.GetRinsesByReservoir(reservoir);
  795. int rinseCount = 0;
  796. int busyRinseCount = 0;
  797. foreach(string rinseItem in reservoirRinseLst)
  798. {
  799. RinseEntity rinseEntity = Singleton<RouteManager>.Instance.GetModule<RinseEntity>(rinseItem);
  800. if(rinseEntity.IsAuto&&rinseEntity.IsInitialized)
  801. {
  802. rinseCount++;
  803. }
  804. if (rinseItem == sharedRinse)
  805. {
  806. continue;
  807. }
  808. if (rinseItem == startRinse)
  809. {
  810. continue;
  811. }
  812. if(rinseEntity.IsBusy||rinseEntity.WaferHolderInfo!=null)
  813. {
  814. busyRinseCount++;
  815. }
  816. }
  817. int resRinseCount=rinseCount- busyRinseCount;
  818. //计算剩余Rinse数量小于等于busy metal数量,则不可用
  819. if (resRinseCount <= busyMetalCount)
  820. {
  821. return false;
  822. }
  823. }
  824. return true;
  825. }
  826. /// <summary>
  827. /// 检验模块是否可用(不包含WH)
  828. /// </summary>
  829. /// <param name="item"></param>
  830. /// <returns></returns>
  831. private bool CheckAvaibleEmptyModule(IModuleEntity item,ModuleType moduleType,string sequenceType)
  832. {
  833. if (!CheckAvaibleModule(item, moduleType, sequenceType))
  834. {
  835. return false;
  836. }
  837. if (!ModuleHelper.IsSRD(item.Module))
  838. {
  839. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(item.Module.ToString());
  840. if (waferHolderInfo == null)
  841. {
  842. return true;
  843. }
  844. }
  845. else
  846. {
  847. if (!WaferManager.Instance.CheckHasWafer(item.Module, 0))
  848. {
  849. return true;
  850. }
  851. }
  852. return false;
  853. }
  854. /// <summary>
  855. /// 检验模块是否可用
  856. /// </summary>
  857. /// <param name="item"></param>
  858. /// <returns></returns>
  859. public bool CheckAvaibleModule(IModuleEntity item,ModuleType moduleType,string sequenceType)
  860. {
  861. if (item.IsDisable)
  862. {
  863. return false;
  864. }
  865. if (!item.IsAuto)
  866. {
  867. return false;
  868. }
  869. if (item.IsError)
  870. {
  871. return false;
  872. }
  873. if (item.IsInit)
  874. {
  875. return false;
  876. }
  877. if (moduleType==ModuleType.Metal)
  878. {
  879. if(item.IsProduction && sequenceType == ENGINEERING)
  880. return false;
  881. if (item.IsEngineering && sequenceType == PRODUCTION)
  882. return false;
  883. }
  884. return true;
  885. }
  886. /// <summary>
  887. /// 获取剩余时间最小的模块
  888. /// </summary>
  889. /// <param name="avaibles"></param>
  890. /// <returns></returns>
  891. private ModuleName GetMinTimeToReadyModule(List<IModuleEntity> avaibles,ModuleType moduleType)
  892. {
  893. if (avaibles.Count == 1)
  894. {
  895. return avaibles[0].Module;
  896. }
  897. int timeToReady = int.MaxValue;
  898. IModuleEntity selectedModule = null;
  899. List<IModuleEntity> idleModuleEtities = new List<IModuleEntity>();
  900. foreach (var item in avaibles)
  901. {
  902. if (item.IsIdle)
  903. {
  904. if(moduleType!=ModuleType.Metal)
  905. {
  906. return item.Module;
  907. }
  908. idleModuleEtities.Add(item);
  909. }
  910. if (item.TimeToReady < timeToReady&&idleModuleEtities.Count==0)
  911. {
  912. timeToReady = item.TimeToReady;
  913. selectedModule = item;
  914. }
  915. }
  916. if (idleModuleEtities.Count != 0)
  917. {
  918. return GetMinUsageMetal(idleModuleEtities);
  919. }
  920. if (selectedModule != null)
  921. {
  922. return selectedModule.Module;
  923. }
  924. return ModuleName.Unknown;
  925. }
  926. /// <summary>
  927. /// 获取电量最小的Metal
  928. /// </summary>
  929. /// <param name="idleModuleEntities"></param>
  930. /// <returns></returns>
  931. private ModuleName GetMinUsageMetal(List<IModuleEntity> idleModuleEntities)
  932. {
  933. double usage = double.MaxValue;
  934. ModuleName selectedModuleName = ModuleName.Unknown;
  935. foreach (var item in idleModuleEntities)
  936. {
  937. MetalEntity metalEntity= item as MetalEntity;
  938. if(metalEntity!=null)
  939. {
  940. MetalUsage metalUsage = metalEntity.MetalUsage;
  941. if (metalUsage == null)
  942. {
  943. return metalEntity.Module;
  944. }
  945. if (metalUsage.TotalUsage < usage)
  946. {
  947. usage= metalUsage.TotalUsage;
  948. selectedModuleName = metalEntity.Module;
  949. }
  950. }
  951. }
  952. return selectedModuleName;
  953. }
  954. /// <summary>
  955. /// 获取Metal可用的Rinse模块
  956. /// </summary>
  957. /// <param name="metalName"></param>
  958. /// <returns></returns>
  959. private ModuleName GetMetalAvaibleRinseModule(List<IModuleEntity> items, ModuleName metalName)
  960. {
  961. int metalId = CellItemManager.Instance.GetCellIdByModuleName(metalName.ToString());
  962. if (metalId == 0)
  963. {
  964. return ModuleName.Unknown;
  965. }
  966. List<LayoutCellItem> rinseItems = CellItemManager.Instance.GetRinseItemsByMetal(metalName.ToString());
  967. if (rinseItems.Count == 0)
  968. {
  969. return ModuleName.Unknown;
  970. }
  971. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  972. foreach (var item in items)
  973. {
  974. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  975. if (cellItem != null)
  976. {
  977. RinseEntity rinseEntity = (RinseEntity)item;
  978. if (rinseEntity.IsInitialized && rinseEntity.IsAuto)
  979. {
  980. avaibles.Add(rinseEntity);
  981. }
  982. }
  983. }
  984. int minInterval = int.MaxValue;
  985. IModuleEntity moduleEntity = null;
  986. foreach (var item in avaibles)
  987. {
  988. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  989. if (cellItem != null)
  990. {
  991. int abiasId = Math.Abs(metalId - cellItem.CellID);
  992. if (abiasId < minInterval)
  993. {
  994. minInterval = abiasId;
  995. moduleEntity = item;
  996. }
  997. }
  998. }
  999. if (moduleEntity != null)
  1000. {
  1001. return moduleEntity.Module;
  1002. }
  1003. return ModuleName.Unknown;
  1004. }
  1005. /// <summary>
  1006. /// 检验Metal可用的Rinse模块
  1007. /// </summary>
  1008. /// <param name="metalName"></param>
  1009. /// <returns></returns>
  1010. private ModuleName GetMetalAvaibleEmptyRinseModule(List<IModuleEntity> items, ModuleName metalName)
  1011. {
  1012. int metalId = CellItemManager.Instance.GetCellIdByModuleName(metalName.ToString());
  1013. if (metalId == 0)
  1014. {
  1015. return ModuleName.Unknown;
  1016. }
  1017. List<LayoutCellItem> rinseItems = CellItemManager.Instance.GetRinseItemsByMetal(metalName.ToString());
  1018. if (rinseItems.Count == 0)
  1019. {
  1020. return ModuleName.Unknown;
  1021. }
  1022. List<IModuleEntity> avaibles = new List<IModuleEntity>();
  1023. List<ModuleName> sharedRinseList = new List<ModuleName>();
  1024. foreach (var item in items)
  1025. {
  1026. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  1027. if (cellItem != null)
  1028. {
  1029. RinseEntity rinseEntity = (RinseEntity)item;
  1030. if (rinseEntity.IsIdle && rinseEntity.IsAuto && rinseEntity.WaferHolderInfo == null)
  1031. {
  1032. avaibles.Add(rinseEntity);
  1033. if(CellItemManager.Instance.CheckRinseIsShared(rinseEntity.Module.ToString()))
  1034. {
  1035. sharedRinseList.Add(rinseEntity.Module);
  1036. }
  1037. }
  1038. }
  1039. }
  1040. int minInterval = int.MaxValue;
  1041. IModuleEntity moduleEntity = null;
  1042. foreach (var item in avaibles)
  1043. {
  1044. if (sharedRinseList.Contains(item.Module))
  1045. {
  1046. continue;
  1047. }
  1048. LayoutCellItem cellItem = rinseItems.Find(O => O.ModuleName == item.Module.ToString());
  1049. if (cellItem != null)
  1050. {
  1051. int abiasId = Math.Abs(metalId - cellItem.CellID);
  1052. if (abiasId < minInterval)
  1053. {
  1054. minInterval = abiasId;
  1055. moduleEntity = item;
  1056. }
  1057. }
  1058. }
  1059. if (moduleEntity != null)
  1060. {
  1061. return moduleEntity.Module;
  1062. }
  1063. else if(sharedRinseList.Count!=0)
  1064. {
  1065. return sharedRinseList[0];
  1066. }
  1067. return ModuleName.Unknown;
  1068. }
  1069. /// <summary>
  1070. /// 检验Metal cell recipe时间是否可用
  1071. /// </summary>
  1072. /// <param name="depRecipe"></param>
  1073. /// <returns></returns>
  1074. public bool CheckMetalCellRecipeTimeAvaible(IModuleEntity metalEntity,DepRecipe depRecipe)
  1075. {
  1076. List<IModuleEntity> metalEntities=Singleton<RouteManager>.Instance.GetModulesByModuleType(ModuleType.Metal);
  1077. int maxTimeToReady = 0;
  1078. foreach (MetalEntity item in metalEntities)
  1079. {
  1080. if (metalEntity.Module == item.Module)
  1081. {
  1082. continue;
  1083. }
  1084. if(item.IsBusy)
  1085. {
  1086. if(maxTimeToReady>item.TimeToReady)
  1087. {
  1088. maxTimeToReady = item.TimeToReady;
  1089. }
  1090. }
  1091. }
  1092. int transferOffSecond = SC.GetValue<int>("Transporter.TransporterTransferOffSeconds");
  1093. int recipeTotalTime = depRecipe.CalculateRecipeTotalTime();
  1094. //增加了Transporter最大传输时间和最小传输时间的差值
  1095. if (recipeTotalTime>=maxTimeToReady+transferOffSecond)
  1096. {
  1097. return true;
  1098. }
  1099. return false;
  1100. }
  1101. /// <summary>
  1102. /// 根据化学液获取可用的metal集合
  1103. /// </summary>
  1104. /// <param name="chemistry"></param>
  1105. /// <returns></returns>
  1106. public List<MetalEntity> GetAvaibleMetalList(string chemistry, string sequenceType, bool isEmpty)
  1107. {
  1108. List<IModuleEntity> reservoirEntities = Singleton<RouteManager>.Instance.GetModulesByModuleType(ModuleType.Reservoir);
  1109. List<string> avaibles = new List<string>();
  1110. foreach (IModuleEntity item in reservoirEntities)
  1111. {
  1112. ReservoirEntity entity = item as ReservoirEntity;
  1113. if (entity.Chemistry == chemistry && entity.IsAuto && entity.IsInitialized)
  1114. {
  1115. avaibles.Add(entity.Module.ToString());
  1116. }
  1117. }
  1118. List<MetalEntity> metals = new List<MetalEntity>();
  1119. foreach (string item in avaibles)
  1120. {
  1121. ReservoirItem reservoirItem = ReservoirItemManager.Instance.GetReservoirItem(item);
  1122. if (reservoirItem == null)
  1123. {
  1124. continue;
  1125. }
  1126. foreach (MetalItem subItem in reservoirItem.MetalCells)
  1127. {
  1128. MetalEntity entity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>($"Metal{subItem.MetalID}");
  1129. if (!CheckAvaibleModule(entity, ModuleType.Metal, sequenceType))
  1130. {
  1131. continue;
  1132. }
  1133. if (!isEmpty || (isEmpty && entity.WaferHolderInfo == null))
  1134. {
  1135. metals.Add(entity);
  1136. }
  1137. }
  1138. }
  1139. return metals;
  1140. }
  1141. /// <summary>
  1142. /// 获取上一个Metal
  1143. /// </summary>
  1144. /// <param name="sequenceIndex"></param>
  1145. /// <param name="sequences"></param>
  1146. /// <returns></returns>
  1147. public ModuleName GetPreMetalModuleName(int sequenceIndex,List<SchedulerSequence> sequences)
  1148. {
  1149. for(int i = sequenceIndex - 1; i >= 0; i--)
  1150. {
  1151. SchedulerSequence schedulerSequence= sequences[i];
  1152. if (schedulerSequence.ModuleType == ModuleType.Metal && ModuleHelper.IsMetal(schedulerSequence.ModuleName))
  1153. {
  1154. return schedulerSequence.ModuleName;
  1155. }
  1156. }
  1157. return ModuleName.Unknown;
  1158. }
  1159. }
  1160. }