SchedulerManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. using Aitex.Core.Common;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.Common.SubstrateTrackings;
  5. using MECF.Framework.Common.ToolLayout;
  6. using MECF.Framework.Common.WaferHolder;
  7. using CyberX8_RT.Schedulers.Aligner;
  8. using CyberX8_RT.Schedulers.Dryer;
  9. using CyberX8_RT.Schedulers.EfemRobot;
  10. using CyberX8_RT.Schedulers.Loader;
  11. using CyberX8_RT.Schedulers.Puf;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using CyberX8_RT.Schedulers.Prewet;
  18. using CyberX8_RT.Schedulers.Transporter;
  19. using CyberX8_RT.Schedulers.Rinse;
  20. using CyberX8_RT.Schedulers.Metal;
  21. using CyberX8_RT.Schedulers.Srd;
  22. using CyberX8_RT.Dispatch;
  23. using CyberX8_RT.Modules.Dryer;
  24. using CyberX8_RT.Modules;
  25. namespace CyberX8_RT.Schedulers
  26. {
  27. public class SchedulerManager : Singleton<SchedulerManager>
  28. {
  29. #region 内部变量
  30. /// <summary>
  31. /// 模块类型集合字典
  32. /// </summary>
  33. private Dictionary<ModuleType, List<SchedulerModule>> _scheduleModuleTypeDic = new Dictionary<ModuleType, List<SchedulerModule>>();
  34. /// <summary>
  35. /// 模块字典
  36. /// </summary>
  37. private Dictionary<ModuleName, SchedulerModule> _scheduleModuleDic = new Dictionary<ModuleName, SchedulerModule>();
  38. #endregion
  39. #region 初始化
  40. /// <summary>
  41. /// 初始化
  42. /// </summary>
  43. public void Initialize()
  44. {
  45. AddScheduleModule(ModuleType.EfemRobot, new SchedulerRobot(ModuleName.EfemRobot));
  46. AddScheduleModule(ModuleType.Aligner, new SchedulerAligner(ModuleName.Aligner1));
  47. InitializeSchedulerModules(PufItemManager.Instance.InstalledModules, ModuleType.PUF, typeof(SchedulerPuf));
  48. InitializeSchedulerModules(LoaderItemManager.Instance.InstalledModules, ModuleType.Loader, typeof(SchedulerLoader));
  49. if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
  50. {
  51. InitializeSchedulerModule(ModuleName.Transporter2.ToString(), ModuleType.Transporter, typeof(SchedulerLoaderTransporter));
  52. }
  53. if(ModuleHelper.IsInstalled(ModuleName.Transporter1))
  54. {
  55. InitializeSchedulerModule(ModuleName.Transporter1.ToString(), ModuleType.Transporter, typeof(SchedulerProcessTransporter));
  56. }
  57. InitializeSchedulerModules(PrewetItemManager.Instance.InstalledModules, ModuleType.Prewet, typeof(SchedulerPrewet));
  58. InitializeSchedulerModules(BufferItemManager.Instance.InstalledModules, ModuleType.Buffer, typeof(SchedulerBuffer));
  59. InitializeSchedulerModules(RinseItemManager.Instance.InstalledModules, ModuleType.Rinse, typeof(SchedulerRinse));
  60. InitializeSchedulerModules(DryerItemManager.Instance.InstalledModules,ModuleType.Dryer,typeof(SchedulerDryer));
  61. InitializeSchedulerModules(SrdItemManager.Instance.InstalledModules,ModuleType.SRD,typeof(SchedulerSrd));
  62. InitializeSchedulerModules(MetalItemManager.Instance.InstalledModules, ModuleType.Metal, typeof(SchedulerMetal));
  63. }
  64. /// <summary>
  65. /// 重置
  66. /// </summary>
  67. public void ResetSchedulerModule()
  68. {
  69. List<ModuleName> moduleNames = _scheduleModuleDic.Keys.ToList();
  70. foreach(ModuleName item in moduleNames)
  71. {
  72. _scheduleModuleDic[item].ResetTask();
  73. }
  74. }
  75. /// <summary>
  76. /// 初始化调度Module集合
  77. /// </summary>
  78. private void InitializeSchedulerModules(List<string> installedModules,ModuleType moduleType,Type type)
  79. {
  80. foreach(string item in installedModules)
  81. {
  82. InitializeSchedulerModule(item, moduleType, type);
  83. }
  84. }
  85. /// <summary>
  86. /// 初始化调度Module
  87. /// </summary>
  88. /// <param name="item"></param>
  89. /// <param name="moduleType"></param>
  90. /// <param name="type"></param>
  91. private void InitializeSchedulerModule(string item, ModuleType moduleType, Type type)
  92. {
  93. ModuleName moduleName = (ModuleName)Enum.Parse(typeof(ModuleName), item);
  94. SchedulerModule schedulerModule = (SchedulerModule)System.Activator.CreateInstance(type, moduleName);
  95. AddScheduleModule(moduleType, schedulerModule);
  96. }
  97. /// <summary>
  98. /// 增加调度模块
  99. /// </summary>
  100. /// <param name="moduleType"></param>
  101. /// <param name="module"></param>
  102. private void AddScheduleModule(ModuleType moduleType, SchedulerModule module)
  103. {
  104. List<SchedulerModule> schedulers = new List<SchedulerModule>();
  105. if (_scheduleModuleTypeDic.ContainsKey(moduleType))
  106. {
  107. schedulers = _scheduleModuleTypeDic[moduleType];
  108. }
  109. else
  110. {
  111. _scheduleModuleTypeDic[moduleType] = schedulers;
  112. }
  113. schedulers.Add(module);
  114. _scheduleModuleDic[module.Module] = module;
  115. }
  116. #endregion
  117. /// <summary>
  118. /// 获取调度对象
  119. /// </summary>
  120. /// <param name="moduleName"></param>
  121. /// <returns></returns>
  122. public SchedulerModule GetScheduler(ModuleName moduleName)
  123. {
  124. return _scheduleModuleDic.ContainsKey(moduleName)?_scheduleModuleDic[moduleName]:null;
  125. }
  126. /// <summary>
  127. /// 根据模块类型获取调度模块集合
  128. /// </summary>
  129. /// <param name="moduleType"></param>
  130. /// <returns></returns>
  131. public List<SchedulerModule> GetModuleTypeScheduleModules(ModuleType moduleType)
  132. {
  133. return _scheduleModuleTypeDic.ContainsKey(moduleType) ? _scheduleModuleTypeDic[moduleType]: null;
  134. }
  135. /// <summary>
  136. /// 获取可用的Buffer
  137. /// </summary>
  138. /// <param name="waferSize"></param>
  139. /// <returns></returns>
  140. public WaferHolderInfo GetAvaibleBufferToLoaderWaferHolder(WaferSize waferSize, string crsType, List<string> chemistries)
  141. {
  142. bool isDryer = false;
  143. var result = GetAvaibleWaferHolderInfos(waferSize,crsType,chemistries,ref isDryer);
  144. if (isDryer)
  145. {
  146. return result.avaibleWaferHolders.Count != 0 ? result.avaibleWaferHolders[0] : null;
  147. }
  148. return GetMinTotalUseWaferHolder(result.avaibleWaferHolders);
  149. }
  150. /// <summary>
  151. /// 获取可用Buffer可用WaferHolder数量
  152. /// </summary>
  153. /// <param name="waferSize"></param>
  154. /// <returns></returns>
  155. public bool ExistAvaibleBufferWaferHolder(WaferSize waferSize,string crsType,List<string> chemistries)
  156. {
  157. bool isDryer = false;
  158. var result = GetAvaibleWaferHolderInfos(waferSize,crsType,chemistries, ref isDryer);
  159. return result.avaibleWaferHolders.Count>0;
  160. }
  161. /// <summary>
  162. /// 获取可用WaferHolder集合
  163. /// </summary>
  164. /// <param name="waferSize"></param>
  165. /// <returns></returns>
  166. private (List<WaferHolderInfo> avaibleWaferHolders, List<SchedulerModule> avaibleSchedulerModules)
  167. GetAvaibleWaferHolderInfos(WaferSize waferSize, string crsType, List<string> chemistries,ref bool isDryer)
  168. {
  169. List<WaferHolderInfo> avaibleWaferHolders = new List<WaferHolderInfo>();
  170. List<SchedulerModule> avaibleSchedulerModules = new List<SchedulerModule>();
  171. List<string> dryerModules = DryerItemManager.Instance.InstalledModules;
  172. foreach(string item in dryerModules)
  173. {
  174. DryerEntity dryerEntity = Singleton<RouteManager>.Instance.GetModule<DryerEntity>(item);
  175. if (!dryerEntity.IsIdle)
  176. {
  177. continue;
  178. }
  179. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(item);
  180. if (waferHolderInfo == null)
  181. {
  182. continue;
  183. }
  184. if(!Enum.TryParse(item,out ModuleName dryerModuleName))
  185. {
  186. continue;
  187. }
  188. if (WaferHolderTaskManager.Instance.CheckWaferHolderNotExist(waferHolderInfo))
  189. {
  190. SchedulerModule schedulerModule = Instance.GetScheduler(dryerModuleName);
  191. avaibleWaferHolders.Add(waferHolderInfo);
  192. avaibleSchedulerModules.Add(schedulerModule);
  193. isDryer = true;
  194. return (avaibleWaferHolders, avaibleSchedulerModules);
  195. }
  196. }
  197. List<SchedulerModule> schedulerModules = GetModuleTypeScheduleModules(ModuleType.Buffer);
  198. if (schedulerModules != null)
  199. {
  200. foreach (SchedulerModule item in schedulerModules)
  201. {
  202. WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(item.Module.ToString());
  203. //WaferHolder可用,大小,以及可以移动至Loader
  204. if (waferHolderInfo != null && waferHolderInfo.Enabled && waferHolderInfo.WaferSize == (int)waferSize &&waferHolderInfo.CrsType==crsType &&
  205. IsWaferHolderCanGotoLoader(waferHolderInfo)&&CheckChemistry(waferHolderInfo,chemistries))
  206. {
  207. avaibleWaferHolders.Add(waferHolderInfo);
  208. avaibleSchedulerModules.Add(item);
  209. }
  210. }
  211. }
  212. return (avaibleWaferHolders,avaibleSchedulerModules);
  213. }
  214. /// <summary>
  215. /// 检验WaferHolder化学液是否合规
  216. /// </summary>
  217. /// <param name="waferHolderInfo"></param>
  218. /// <param name="chemistries"></param>
  219. /// <returns></returns>
  220. private bool CheckChemistry(WaferHolderInfo waferHolderInfo,List<string> chemistries)
  221. {
  222. if (chemistries.Count == 0)
  223. {
  224. return true;
  225. }
  226. if (chemistries.Count == 1)
  227. {
  228. string chemistry= chemistries[0];
  229. return waferHolderInfo.Chemistry == "Any" || waferHolderInfo.Chemistry.Trim() == chemistry;
  230. }
  231. else
  232. {
  233. return waferHolderInfo.Chemistry == "Any";
  234. }
  235. }
  236. /// <summary>
  237. /// 获取最少使用次数的Buffer
  238. /// </summary>
  239. /// <param name="avaibleWaferHolders"></param>
  240. /// <param name="modules"></param>
  241. /// <returns></returns>
  242. private SchedulerModule GetMinTotalUseSchedulerBuffer(List<WaferHolderInfo> avaibleWaferHolders,List<SchedulerModule> modules)
  243. {
  244. int min = int.MaxValue;
  245. int index = -1;
  246. for(int i=0;i<avaibleWaferHolders.Count;i++)
  247. {
  248. WaferHolderInfo waferHolderInfo=avaibleWaferHolders[i];
  249. if(waferHolderInfo.TotalUses<min)
  250. {
  251. min = waferHolderInfo.TotalUses;
  252. index = i;
  253. }
  254. }
  255. if(index!=-1)
  256. {
  257. return modules[index];
  258. }
  259. return null;
  260. }
  261. /// <summary>
  262. /// 获取最少使用次数的Buffer
  263. /// </summary>
  264. /// <param name="avaibleWaferHolders"></param>
  265. /// <param name="modules"></param>
  266. /// <returns></returns>
  267. private WaferHolderInfo GetMinTotalUseWaferHolder(List<WaferHolderInfo> avaibleWaferHolders)
  268. {
  269. int min = int.MaxValue;
  270. int index = -1;
  271. for (int i = 0; i < avaibleWaferHolders.Count; i++)
  272. {
  273. WaferHolderInfo waferHolderInfo = avaibleWaferHolders[i];
  274. if(IsWaferHolderExsitProcessedWafer(waferHolderInfo))
  275. {
  276. index = i;
  277. break;
  278. }
  279. if (waferHolderInfo.TotalUses < min)
  280. {
  281. min = waferHolderInfo.TotalUses;
  282. index = i;
  283. }
  284. }
  285. if (index != -1)
  286. {
  287. return avaibleWaferHolders[index];
  288. }
  289. return null;
  290. }
  291. /// <summary>
  292. /// WaferHolder是否存在已经完成的Production Wafer
  293. /// </summary>
  294. /// <param name="waferHolderInfo"></param>
  295. /// <returns></returns>
  296. private bool IsWaferHolderExsitProcessedWafer(WaferHolderInfo waferHolderInfo)
  297. {
  298. if(!string.IsNullOrEmpty(waferHolderInfo.WaferAId))
  299. {
  300. WaferInfo waferInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferAId);
  301. if(waferInfo!=null&&waferInfo.WaferType==WaferType.Production&&waferInfo.ProcessState==EnumWaferProcessStatus.Completed)
  302. {
  303. return true;
  304. }
  305. }
  306. if (!string.IsNullOrEmpty(waferHolderInfo.WaferBId))
  307. {
  308. WaferInfo waferInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferBId);
  309. if (waferInfo != null && waferInfo.WaferType == WaferType.Production && waferInfo.ProcessState == EnumWaferProcessStatus.Completed)
  310. {
  311. return true;
  312. }
  313. }
  314. return false;
  315. }
  316. /// <summary>
  317. /// WaferHolder是否可以去Loader
  318. /// </summary>
  319. /// <returns></returns>
  320. private bool IsWaferHolderCanGotoLoader(WaferHolderInfo waferHolderInfo)
  321. {
  322. if(string.IsNullOrEmpty(waferHolderInfo.WaferAId)||string.IsNullOrEmpty(waferHolderInfo.WaferBId))
  323. {
  324. return false;
  325. }
  326. if(waferHolderInfo.WaferAType==(int)WaferType.Assit||waferHolderInfo.WaferBType==(int)WaferType.Assit)
  327. {
  328. return true;
  329. }
  330. WaferInfo waferAInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferAId);
  331. if(waferAInfo == null)
  332. {
  333. return false;
  334. }
  335. WaferInfo waferBInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferBId);
  336. if(waferBInfo==null)
  337. {
  338. return false;
  339. }
  340. //Wafer还是裸硅片
  341. return waferHolderInfo.IsToLoader;
  342. }
  343. /// <summary>
  344. /// 根据Wafer尺寸获取waferHolder数量
  345. /// </summary>
  346. /// <param name="waferSize"></param>
  347. /// <returns></returns>
  348. public int GetWaferHolderInfoCountByWaferSize(WaferSize waferSize, string crsType, List<string> chemistries)
  349. {
  350. List<WaferHolderInfo> waferHolders = WaferHolderManager.Instance.GetAllWaferHolders();
  351. int count = 0;
  352. foreach (WaferHolderInfo info in waferHolders)
  353. {
  354. if (info.WaferSize == (int)waferSize && info.Enabled && info.CrsType == crsType && CheckChemistry(info,chemistries))
  355. {
  356. count++;
  357. }
  358. }
  359. return count;
  360. }
  361. }
  362. }