TransferJob.cs 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. using Aitex.Common.Util;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using FurnaceRT.Equipments.CarrierRobots;
  18. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  19. using FurnaceRT.Equipments.Schedulers;
  20. using FurnaceRT.Equipments.Systems;
  21. using FurnaceRT.Equipments.WaferRobots;
  22. using MECF.Framework.Common.Jobs;
  23. using FurnaceRT.Equipments.LPs;
  24. using FurnaceRT.Equipments.Stockers;
  25. using Aitex.Core.RT.Log;
  26. using FurnaceRT.Equipments.FIMSs;
  27. using Aitex.Core.RT.DataCenter;
  28. using FurnaceRT.Devices;
  29. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  30. using FurnaceRT.Equipments.PMs;
  31. using MECF.Framework.Common.Tolerance;
  32. using MECF.Framework.Common.CommonData.SorterDefines;
  33. namespace FurnaceRT.Equipments.Jobs
  34. {
  35. public class TransferJob : SchedulerModuleFactory
  36. {
  37. private List<TransferJobInfo> _lstTransferJobs = new List<TransferJobInfo>();
  38. private SchedulerFACallback _faCallback;
  39. private SchedulerDBCallback _dbCallback;
  40. private const string LogSource = "System";
  41. private LoadPortModule _lp1Module;
  42. private LoadPortModule _lp2Module;
  43. public bool HasJobRunning
  44. {
  45. get { return _lstTransferJobs.Count > 0; }
  46. }
  47. public TransferJob()
  48. {
  49. _faCallback = new SchedulerFACallback();
  50. _dbCallback = new SchedulerDBCallback();
  51. InitModule();
  52. _lp1Module = Singleton<EquipmentManager>.Instance.Modules.ContainsKey(ModuleName.LP1) ?
  53. Singleton<EquipmentManager>.Instance.Modules[ModuleName.LP1] as LoadPortModule : null;
  54. _lp2Module = Singleton<EquipmentManager>.Instance.Modules.ContainsKey(ModuleName.LP2) ?
  55. Singleton<EquipmentManager>.Instance.Modules[ModuleName.LP2] as LoadPortModule : null;
  56. DATA.Subscribe($"Scheduler.TransferJobList", () =>
  57. {
  58. return _lstTransferJobs;
  59. });
  60. DATA.Subscribe($"Scheduler.CurrentTransferJob", () =>
  61. {
  62. var pj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  63. return pj;
  64. });
  65. DATA.Subscribe($"Scheduler.OccupyStockers", () =>
  66. {
  67. return GetOccupyStockers();
  68. });
  69. }
  70. public void ResetTask(ModuleName module)
  71. {
  72. if (module == _waferRobot.Module)
  73. _waferRobot.ResetTask();
  74. if (module == _carrierRobot.Module)
  75. _carrierRobot.ResetTask();
  76. }
  77. public void Clear()
  78. {
  79. _carrierRobot.ResetTask();
  80. _waferRobot.ResetTask();
  81. foreach (var lp in _lstLPs)
  82. {
  83. lp.ResetTask();
  84. }
  85. foreach (var fims in _lstFIMSs)
  86. {
  87. fims.ResetTask();
  88. }
  89. _lstTransferJobs.Clear();
  90. }
  91. #region Job Management
  92. public Result CreateJob(params object[] objs)
  93. {
  94. if (objs == null || objs.Length == 0)
  95. {
  96. Singleton<EquipmentManager>.Instance.TransferJobStartFailedWarning.Set("Parameter not valid");
  97. return Result.FAIL;
  98. }
  99. var param = (Dictionary<string, object>)objs[0];
  100. if (param == null)
  101. {
  102. Singleton<EquipmentManager>.Instance.TransferJobStartFailedWarning.Set("Parameter not valid");
  103. return Result.FAIL;
  104. }
  105. var content = "";
  106. foreach (var key in param.Keys)
  107. {
  108. content += $"{key}-{param[key]}#";
  109. }
  110. LOG.Write($"Transfer Job: {content}");
  111. var waferTypeString = param.ContainsKey("WaferType") ? (string)param["WaferType"] : "";
  112. var transferTypeString = (string)param["TransferType"];
  113. TransferJobInfo tj = new TransferJobInfo();
  114. tj.CreateTime = DateTime.Now;
  115. tj.BatchName = param.ContainsKey("Batch") ? (string)param["Batch"] : "";
  116. tj.CarrierType = (CarrierType)Enum.Parse(typeof(CarrierType), waferTypeString);
  117. tj.Type = (EnumTransferJobType)Enum.Parse(typeof(EnumTransferJobType), transferTypeString);
  118. tj.State = EnumTransferJobState.Created;
  119. tj.CarrierParas = new List<CarrierPara>();
  120. tj.FimsCheckOxDensityDict = new Dictionary<string, Tuple<FilterChecker, double>>();
  121. List<string> carrierIdLst = new List<string>();
  122. List<ModuleName> moduleLst = new List<ModuleName>();
  123. foreach (var module in Singleton<EquipmentManager>.Instance.Modules.Keys)
  124. {
  125. if ((Singleton<EquipmentManager>.Instance.Modules[module] is StockerModule) ||
  126. (Singleton<EquipmentManager>.Instance.Modules[module] is FIMSModule))
  127. {
  128. if (CarrierManager.Instance.HasCarrier(module.ToString()))
  129. {
  130. var carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  131. carrierIdLst.Add(carrier.CarrierId);
  132. moduleLst.Add(carrier.InternalModuleName);
  133. }
  134. }
  135. }
  136. if (param.ContainsKey("CarrierPara"))
  137. {
  138. if (tj.Type == EnumTransferJobType.Loading)
  139. {
  140. //Stocker1,P_00000036,25,Exist,1111111111111111111111111,LP1;Stocker2,P_00000037,25,Exist,1111111111111111111111111,LP2
  141. var paras = param["CarrierPara"].ToString().Split(';');
  142. if (paras != null && paras.Length > 0)
  143. {
  144. foreach (var item in paras)
  145. {
  146. var arry = item.Split(',');
  147. if (arry != null && arry.Length == 6)
  148. {
  149. CarrierPara carrierPara = new CarrierPara()
  150. {
  151. Stocker = ModuleHelper.Converter(arry[0]),
  152. CarrierID = arry[1],
  153. //WaferCount = int.Parse(arry[2]),
  154. IsCompareWithSlotMap = arry[3].ToLower() == "exist",
  155. SlotMap = arry[4],
  156. TargetPort = ModuleHelper.Converter(arry[5]),
  157. CarrierType = tj.CarrierType,
  158. };
  159. if (carrierIdLst.Any(x => x == carrierPara.CarrierID) || moduleLst.Any(x => x == carrierPara.Stocker))
  160. {
  161. Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Carrier ID ={carrierPara.CarrierID} of {carrierPara.Stocker} is already exist");
  162. return Result.FAIL;
  163. }
  164. if (CarrierManager.Instance.HasCarrier($"{carrierPara.Stocker}"))
  165. {
  166. Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Carrier of {carrierPara.Stocker} is already exist in stocker");
  167. return Result.FAIL;
  168. }
  169. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  170. {
  171. var stockerModule = Singleton<EquipmentManager>.Instance.Modules[carrierPara.Stocker] as StockerModule;
  172. if (stockerModule != null && stockerModule.IsFoupPresent)
  173. {
  174. Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Cassette of {carrierPara.Stocker} is already exist in stocker");
  175. return Result.FAIL;
  176. }
  177. }
  178. tj.CarrierParas.Add(carrierPara);
  179. carrierIdLst.Add(arry[1]);
  180. moduleLst.Add(carrierPara.Stocker);
  181. }
  182. }
  183. }
  184. }
  185. else
  186. {
  187. //Stocker1,LP1;Stocker2,LP2
  188. var paras = param["CarrierPara"].ToString().Split(';');
  189. if (paras != null && paras.Length > 0)
  190. {
  191. foreach (var item in paras)
  192. {
  193. var arry = item.Split(',');
  194. CarrierPara carrierPara = null;
  195. if (arry != null && arry.Length >= 2)
  196. {
  197. //两个参数是Unload,6个参数是Load Process Unload
  198. carrierPara = new CarrierPara()
  199. {
  200. Stocker = ModuleHelper.Converter(arry[0]),
  201. TargetPort = arry.Length == 6 ? ModuleHelper.Converter(arry[5]) : ModuleHelper.Converter(arry[1]),
  202. };
  203. if (arry.Length != 6)
  204. {
  205. if (!CarrierManager.Instance.HasCarrier($"{carrierPara.Stocker}"))
  206. {
  207. Singleton<EquipmentManager>.Instance.UnloadCassetteJobStartFailedWarning.Set($"Carrier of {carrierPara.Stocker} is not exist in stocker");
  208. return Result.FAIL;
  209. }
  210. if (CarrierManager.Instance.GetCarrier($"{carrierPara.Stocker}", 0).InternalModuleName != carrierPara.Stocker)
  211. {
  212. Singleton<EquipmentManager>.Instance.UnloadCassetteJobStartFailedWarning.Set($"Carrier of {carrierPara.Stocker} is not match stocker module name {CarrierManager.Instance.GetCarrier($"{carrierPara.Stocker}", 0).InternalModuleName}");
  213. return Result.FAIL;
  214. }
  215. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  216. {
  217. var stockerModule = Singleton<EquipmentManager>.Instance.Modules[carrierPara.Stocker] as StockerModule;
  218. if (stockerModule != null && !stockerModule.IsFoupPresent)
  219. {
  220. Singleton<EquipmentManager>.Instance.LoadCassetteJobStartFailedWarning.Set($"Cassette of {carrierPara.Stocker} is not exist in stocker");
  221. return Result.FAIL;
  222. }
  223. }
  224. }
  225. }
  226. if (carrierPara != null)
  227. {
  228. carrierPara.CarrierID = CarrierManager.Instance.GetCarrier($"{carrierPara.Stocker}").CarrierId;
  229. tj.CarrierParas.Add(carrierPara);
  230. }
  231. }
  232. }
  233. }
  234. }
  235. _lstTransferJobs.Add(tj);
  236. var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
  237. foreach (var item in _lstFIMSs)
  238. {
  239. if (!tj.FimsCheckOxDensityDict.ContainsKey(item.Module.ToString()))
  240. {
  241. tj.FimsCheckOxDensityDict.Add(item.Module.ToString(), Tuple.Create(new FilterChecker(), pm.GetFoupEnterLAO2CheckSV()));
  242. }
  243. }
  244. return Result.RUN;
  245. }
  246. internal void AbortJob(string jobName)
  247. {
  248. var tj = _lstTransferJobs.Find(x => x.Name == jobName);
  249. if (tj == null)
  250. {
  251. EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
  252. return;
  253. }
  254. tj.State = EnumTransferJobState.Aborting;
  255. }
  256. internal void CancelUnloadingJob(string port, string CarrierId)
  257. {
  258. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  259. if (tj == null)
  260. {
  261. EV.PostWarningLog(LogSource, $"cancel unloading job rejected, not found job with CarrierId {CarrierId}");
  262. return;
  263. }
  264. var carrierPara = tj.CarrierParas.Find(x => x.TargetPort.ToString() == port && x.CarrierID == CarrierId);
  265. if (carrierPara != null)
  266. tj.CarrierParas.Remove(carrierPara);
  267. }
  268. internal bool StartJob(string jobName)
  269. {
  270. return true;
  271. }
  272. #endregion Job Management
  273. public Result Monitor()
  274. {
  275. TransferJobInfo tjActive = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  276. if (tjActive != null)
  277. {
  278. MonitorModuleTasks();
  279. }
  280. MonitorJobTasks();
  281. UpdateLoadPortLotIDList();
  282. return Result.RUN;
  283. }
  284. public bool CheckAllJobDone()
  285. {
  286. foreach (var tj in _lstTransferJobs)
  287. {
  288. if (tj.State == EnumTransferJobState.Created ||
  289. tj.State == EnumTransferJobState.Active)
  290. return false;
  291. }
  292. return true;
  293. }
  294. private void UpdateLoadPortLotIDList()
  295. {
  296. TransferJobInfo tjActive = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  297. if (tjActive != null && tjActive.CarrierParas != null)
  298. {
  299. if (_lp1Module != null)
  300. {
  301. _lp1Module.CurrentLotId = "";
  302. }
  303. if (_lp2Module != null)
  304. {
  305. _lp2Module.CurrentLotId = "";
  306. }
  307. List<string> lp1WaitLotId = new List<string>();
  308. List<string> lp2WaitLotId = new List<string>();
  309. foreach (var item in tjActive.CarrierParas)
  310. {
  311. if ((tjActive.Type == EnumTransferJobType.Loading && !item.IsLoaded) ||
  312. (tjActive.Type == EnumTransferJobType.Unloading && !item.IsUnloaded))
  313. {
  314. var lpModule = Singleton<EquipmentManager>.Instance.Modules[item.TargetPort] as LoadPortModule;
  315. if (lpModule != null && item.TargetPort == ModuleName.LP1 && string.IsNullOrEmpty(lpModule.CurrentLotId))
  316. {
  317. _lp1Module.CurrentLotId = item.CarrierID;
  318. }
  319. if (lpModule != null && item.TargetPort == ModuleName.LP2 && string.IsNullOrEmpty(lpModule.CurrentLotId))
  320. {
  321. _lp2Module.CurrentLotId = item.CarrierID;
  322. }
  323. if (item.TargetPort == ModuleName.LP1)
  324. {
  325. lp1WaitLotId.Add(item.CarrierID);
  326. }
  327. if (item.TargetPort == ModuleName.LP2)
  328. {
  329. lp2WaitLotId.Add(item.CarrierID);
  330. }
  331. }
  332. }
  333. if (_lp1Module != null)
  334. {
  335. _lp1Module.WaitLotId = lp1WaitLotId;
  336. }
  337. if (_lp2Module != null)
  338. {
  339. _lp2Module.WaitLotId = lp2WaitLotId;
  340. }
  341. }
  342. else
  343. {
  344. if (_lp1Module != null)
  345. {
  346. _lp1Module.CurrentLotId = "";
  347. if (_lp1Module.WaitLotId == null || _lp1Module.WaitLotId.Any())
  348. _lp1Module.WaitLotId = new List<string>();
  349. }
  350. if (_lp2Module != null)
  351. {
  352. _lp2Module.CurrentLotId = "";
  353. if (_lp2Module.WaitLotId == null || _lp2Module.WaitLotId.Any())
  354. _lp2Module.WaitLotId = new List<string>();
  355. }
  356. }
  357. }
  358. #region Module task
  359. public Result MonitorModuleTasks()
  360. {
  361. MonitorLPClampInLoadingTask();
  362. MonitorCarrierRobotTask();
  363. MonitorWaferRobotTask();
  364. MonitorLPTask();
  365. MonitorFIMSTask();
  366. return Result.RUN;
  367. }
  368. private void MonitorLPClampInLoadingTask()
  369. {
  370. if (!_lstTransferJobs.Any())
  371. return;
  372. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  373. if (tj == null || tj.CarrierParas == null)
  374. return;
  375. if (tj.Type == EnumTransferJobType.Loading)
  376. {
  377. foreach (var lp in _lstLPs)
  378. {
  379. if (!lp.IsAvailable)
  380. continue;
  381. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  382. continue;
  383. var lpModule = Singleton<EquipmentManager>.Instance.Modules[lp.Module] as LoadPortModule;
  384. if (lpModule.LPDevice.IsFoupPresent)
  385. {
  386. //FOUP放上去之后,先上锁
  387. if (!lpModule.IsClamp && lpModule.LPDevice.Clamp(out _))
  388. {
  389. return;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. private void MonitorLPTask()
  396. {
  397. if (!_lstTransferJobs.Any())
  398. return;
  399. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  400. if (tj == null || tj.CarrierParas == null)
  401. return;
  402. if (tj.Type == EnumTransferJobType.Loading)
  403. {
  404. foreach (var lp in _lstLPs)
  405. {
  406. if (!lp.IsAvailable)
  407. continue;
  408. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  409. continue;
  410. var lpModule = Singleton<EquipmentManager>.Instance.Modules[lp.Module] as LoadPortModule;
  411. if (lpModule.LPDevice.IsFoupPresent)
  412. {
  413. //FOUP放上去之后,先上锁
  414. if (!lpModule.IsClamp && lpModule.LPDevice.Clamp(out _))
  415. {
  416. return;
  417. }
  418. }
  419. else
  420. {
  421. //空的,先松开锁
  422. if (!lpModule.IsReleased && lpModule.LPDevice.Unclamp(out _))
  423. {
  424. return;
  425. }
  426. }
  427. }
  428. }
  429. else if (tj.Type == EnumTransferJobType.Unloading)
  430. {
  431. foreach (var lp in _lstLPs)
  432. {
  433. if (!lp.IsAvailable)
  434. continue;
  435. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  436. continue;
  437. var lpModule = Singleton<EquipmentManager>.Instance.Modules[lp.Module] as LoadPortModule;
  438. if (lpModule.LPDevice.IsFoupPresent)
  439. {
  440. if (!lpModule.IsReleased && lpModule.LPDevice.Unclamp(out _))
  441. {
  442. return;
  443. }
  444. }
  445. else
  446. {
  447. //空的,先松开锁
  448. if (!lpModule.IsReleased && lpModule.LPDevice.Unclamp(out _))
  449. {
  450. return;
  451. }
  452. }
  453. }
  454. }
  455. }
  456. private void MonitorFIMSTask()
  457. {
  458. var pm = (Singleton<EquipmentManager>.Instance.Modules[ModuleName.PM1] as PMModule);
  459. if (!_lstTransferJobs.Any() || SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  460. return;
  461. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  462. if (tj == null || tj.CarrierParas == null)
  463. return;
  464. if (tj.Type == EnumTransferJobType.Loading)
  465. {
  466. var hasNotMappedCarrier = false;
  467. var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  468. if (robotCarrier != null && !robotCarrier.IsEmpty && !robotCarrier.IsMapped)
  469. {
  470. if (tj.CarrierParas.Any(x => x.Stocker == robotCarrier.InternalModuleName && x.IsLoaded))
  471. {
  472. hasNotMappedCarrier = true;
  473. }
  474. }
  475. foreach (var item in tj.CarrierParas)
  476. {
  477. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  478. if (carrier == null || carrier.IsEmpty || carrier.IsMapped)
  479. continue;
  480. if (item.IsLoaded)
  481. {
  482. hasNotMappedCarrier = true;
  483. break;
  484. }
  485. }
  486. bool haveLoadingFims = false;
  487. foreach (var fims in _lstFIMSs)
  488. {
  489. if ((Singleton<EquipmentManager>.Instance.Modules[fims.Module] as FIMSModule).IsLoading)
  490. {
  491. haveLoadingFims = true;
  492. break;
  493. }
  494. }
  495. foreach (var fims in _lstFIMSs)
  496. {
  497. if (!fims.IsAvailable)
  498. continue;
  499. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{fims.Module}");
  500. if (CarrierManager.Instance.CheckNoCarrier(fims.Module, 0))
  501. {
  502. if (hasNotMappedCarrier && fimsDevice.IsWaferRobotEX1AxisHomePosition && fimsDevice.IsWaferRobotEX2AxisHomePosition &&
  503. !fimsDevice.IsUnloadCompleted && fims.Unload())
  504. {
  505. return;
  506. }
  507. }
  508. else
  509. {
  510. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  511. if (carrier == null || carrier.IsEmpty)
  512. continue;
  513. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName && x.IsLoaded))
  514. {
  515. if (carrier.IsMapped && fimsDevice.IsWaferRobotEX1AxisHomePosition && fimsDevice.IsWaferRobotEX2AxisHomePosition &&
  516. !fimsDevice.IsUnloadCompleted)
  517. {
  518. if (fims.Unload())
  519. {
  520. return;
  521. }
  522. }
  523. if (!haveLoadingFims && !carrier.IsMapped && !fimsDevice.IsLoadCompleted)
  524. {
  525. var foupEnterFIMSN2purgeConfig = pm.GetFoupEnterFIMSN2purgeConfig();
  526. var foupEnterLAO2CheckSV = pm.GetFoupEnterLAO2CheckSV();
  527. var lACurrectN2purgeMode = pm.GetLACurrectN2purgeMode();
  528. var CheckFimsIsNeedOxygenPressure = pm.CheckFimsIsNeedOxygenPressure(foupEnterFIMSN2purgeConfig, "", out var isCheckO2, false);
  529. if (isCheckO2)
  530. {
  531. tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.CheckInterval = 1;
  532. tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Monitor(pm.GetN2PurgeUnder20PPMStatus(foupEnterLAO2CheckSV));
  533. if (tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Trig)
  534. {
  535. if (fims.Load(CheckFimsIsNeedOxygenPressure, N2PurgeModeEnum.FoupEnter.ToString()))
  536. {
  537. tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Restart();
  538. LOG.Info($"FIMS={fims.Module} , FIMS N2PurgeConfig={foupEnterFIMSN2purgeConfig},Currect N2Purge={lACurrectN2purgeMode},Limit O2 Data={foupEnterLAO2CheckSV},transferJob Load,wait FoupEnter 。a");
  539. return;
  540. }
  541. }
  542. }
  543. else
  544. {
  545. if (fims.Load(CheckFimsIsNeedOxygenPressure, N2PurgeModeEnum.FoupEnter.ToString()))
  546. {
  547. LOG.Info($"FIMS={fims.Module} , FIMS N2PurgeConfig={foupEnterFIMSN2purgeConfig},Currect N2Purge={lACurrectN2purgeMode},Limit O2 Data={foupEnterLAO2CheckSV},transferJob Load, direct FoupEnter 。b");
  548. return;
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. else if (tj.Type == EnumTransferJobType.Unloading)
  557. {
  558. //do nothing
  559. }
  560. }
  561. private void MonitorWaferRobotTask()
  562. {
  563. if (!_waferRobot.IsAvailable)
  564. return;
  565. //wafer robot is idle, release all the target
  566. foreach (var fims in _lstFIMSs)
  567. {
  568. if (fims.IsWaitTransfer(ModuleName.WaferRobot))
  569. {
  570. fims.StopWaitTransfer(ModuleName.WaferRobot);
  571. }
  572. }
  573. MonitorWaferRobotFIMSTask();
  574. }
  575. private void MonitorWaferRobotFIMSTask()
  576. {
  577. if (!_waferRobot.IsAvailable || !_lstTransferJobs.Any())
  578. return;
  579. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  580. if (tj == null || tj.CarrierParas == null)
  581. return;
  582. foreach (var fims in _lstFIMSs)
  583. {
  584. if (!fims.IsAvailable)
  585. continue;
  586. if (!CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  587. continue;
  588. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{fims.Module}");
  589. if (!fimsDevice.IsLoadCompleted)
  590. continue;
  591. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  592. if (carrier == null || carrier.IsEmpty || carrier.IsMapped || SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  593. continue;
  594. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  595. {
  596. var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  597. if (carrierPara != null && _waferRobot.Map(fims.Module, carrierPara.WaferCount, carrierPara.SlotMap, carrierPara.IsCompareWithSlotMap, true, Hand.Blade1))
  598. {
  599. fims.WaitTransfer(ModuleName.WaferRobot);
  600. }
  601. }
  602. }
  603. }
  604. private void MonitorCarrierRobotTask()
  605. {
  606. if (!_carrierRobot.IsAvailable)
  607. return;
  608. //carrier robot is idle, release all the target
  609. foreach (var stocker in _lstTotlaStockers)
  610. {
  611. if (stocker.IsWaitTransfer(ModuleName.CarrierRobot))
  612. {
  613. stocker.StopWaitTransfer(ModuleName.CarrierRobot);
  614. }
  615. }
  616. foreach (var fims in _lstFIMSs)
  617. {
  618. if (fims.IsWaitTransfer(ModuleName.CarrierRobot))
  619. {
  620. fims.StopWaitTransfer(ModuleName.CarrierRobot);
  621. }
  622. }
  623. foreach (var lp in _lstLPs)
  624. {
  625. if (lp.IsWaitTransfer(ModuleName.CarrierRobot))
  626. {
  627. lp.StopWaitTransfer(ModuleName.CarrierRobot);
  628. }
  629. }
  630. MonitorCarrierRobotFIMSTask();
  631. if (!_carrierRobot.IsAvailable)
  632. return;
  633. MonitorCarrierRobotStockerTask();
  634. if (!_carrierRobot.IsAvailable)
  635. return;
  636. MonitorCarrierRobotLPTask();
  637. if (!_carrierRobot.IsAvailable)
  638. return;
  639. //MonitorCarrierGotoTask();
  640. }
  641. private void MonitorCarrierGotoTask()
  642. {
  643. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  644. return;
  645. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  646. if (tj == null || tj.CarrierParas == null)
  647. return;
  648. if (tj.Type == EnumTransferJobType.Loading)
  649. {
  650. if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  651. {
  652. foreach (var lp in _lstLPs)
  653. {
  654. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  655. continue;
  656. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  657. if (lpDevice.IsFoupPresent)
  658. {
  659. if (!lpDevice.IsLoadCompleted && _carrierRobot.PreviousTarget != lp.Module && _carrierRobot.Goto(lp.Module, 0, Hand.Blade1, true))
  660. {
  661. return;
  662. }
  663. }
  664. }
  665. if (!SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  666. {
  667. foreach (var fims in _lstFIMSs)
  668. {
  669. if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  670. {
  671. var carrier1 = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  672. if (carrier1 != null && !carrier1.IsMapped)
  673. {
  674. if (tj.CarrierParas.Any(x => x.Stocker == carrier1.InternalModuleName) && _carrierRobot.PreviousTarget != fims.Module &&
  675. _carrierRobot.Goto(fims.Module, 0, Hand.Blade1, true))
  676. {
  677. return;
  678. }
  679. }
  680. }
  681. }
  682. }
  683. }
  684. else
  685. {
  686. //goto fims 放
  687. if (!SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  688. {
  689. foreach (var fims in _lstFIMSs)
  690. {
  691. if (!fims.IsAvailable)
  692. continue;
  693. if (CarrierManager.Instance.CheckNoCarrier(fims.Module, 0))
  694. {
  695. var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  696. if (robotCarrier != null && !robotCarrier.IsMapped && tj.CarrierParas.Any(x => x.Stocker == robotCarrier.InternalModuleName))
  697. {
  698. if (_carrierRobot.PreviousTarget != fims.Module && _carrierRobot.Goto(fims.Module, 0, Hand.Blade1, false))
  699. {
  700. return;
  701. }
  702. }
  703. }
  704. }
  705. }
  706. }
  707. }
  708. else if (tj.Type == EnumTransferJobType.Unloading)
  709. {
  710. if (CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
  711. {
  712. foreach (var lp in _lstLPs)
  713. {
  714. if (!CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
  715. continue;
  716. var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  717. var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == robotCarrier.InternalModuleName);
  718. if (para == null || para.TargetPort != lp.Module)
  719. continue;
  720. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  721. if (!lpDevice.IsFoupPresent)
  722. {
  723. if (!lpDevice.IsLoadCompleted && _carrierRobot.PreviousTarget != lp.Module && _carrierRobot.Goto(lp.Module, 0, Hand.Blade1, false))
  724. {
  725. lp.WaitTransfer(ModuleName.CarrierRobot);
  726. return;
  727. }
  728. }
  729. }
  730. }
  731. }
  732. }
  733. private void MonitorCarrierRobotStockerTask()
  734. {
  735. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  736. return;
  737. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  738. if (tj == null || tj.CarrierParas == null)
  739. return;
  740. //pick
  741. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  742. if (carrier != null && carrier.IsEmpty)
  743. {
  744. SchedulerStocker stocker = null;
  745. foreach (var st in _lstTotlaStockers)
  746. {
  747. if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
  748. continue;
  749. if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
  750. {
  751. carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
  752. if (tj.Type == EnumTransferJobType.Loading)
  753. {
  754. //没有map,FIMS具备map条件时
  755. if (carrier != null && !carrier.IsMapped &&
  756. _lstFIMSs.Any(x => x.IsAvailable && x.IsReadyForPlace(ModuleName.CarrierRobot, 0)) &&
  757. !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  758. {
  759. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  760. {
  761. stocker = st;
  762. break;
  763. }
  764. }
  765. }
  766. else
  767. {
  768. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  769. {
  770. stocker = st;
  771. break;
  772. }
  773. }
  774. }
  775. }
  776. if (stocker != null && _waferRobot.IsAvailable)
  777. {
  778. if (_carrierRobot.Pick(stocker.Module, 0, Hand.Blade1))
  779. {
  780. stocker.WaitTransfer(ModuleName.CarrierRobot);
  781. return;
  782. }
  783. }
  784. }
  785. if (!_carrierRobot.IsAvailable || tj.Type != EnumTransferJobType.Loading)
  786. return;
  787. //place
  788. carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  789. if (carrier != null && !carrier.IsEmpty &&
  790. tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  791. {
  792. var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  793. SchedulerStocker stocker = null;
  794. foreach (var st in _lstTotlaStockers)
  795. {
  796. if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
  797. continue;
  798. if (st.Module != carrier.InternalModuleName)
  799. continue;
  800. if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0))
  801. {
  802. stocker = st;
  803. break;
  804. }
  805. }
  806. //map正常完成或者FIMS不具备map条件
  807. if (stocker != null && ((carrier.IsMapped && carrier.IsMapOK) ||
  808. SC.GetValue<bool>("WaferRobot.BypassFIMSMap") ||
  809. !_lstFIMSs.Any(x => x.IsOnline && CarrierManager.Instance.CheckNoCarrier(x.Module, 0))))
  810. {
  811. if (_carrierRobot.Place(stocker.Module, 0, Hand.Blade1))
  812. {
  813. stocker.WaitTransfer(ModuleName.CarrierRobot);
  814. return;
  815. }
  816. }
  817. }
  818. }
  819. private void MonitorCarrierRobotLPTask()
  820. {
  821. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  822. return;
  823. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  824. if (tj == null || tj.CarrierParas == null)
  825. return;
  826. if (tj.Type == EnumTransferJobType.Loading)
  827. {
  828. if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  829. {
  830. foreach (var lp in _lstLPs)
  831. {
  832. if (!lp.IsAvailable)
  833. continue;
  834. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  835. continue;
  836. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  837. if (lp.IsReadyForPick(_carrierRobot.Module, 0) && (lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted))
  838. {
  839. var carrierPara = tj.CarrierParas.First(x => x.TargetPort == lp.Module && !x.IsLoaded);
  840. if (carrierPara != null && _carrierRobot.Load(lp.Module, 0, Hand.Blade1, carrierPara.Stocker, carrierPara.CarrierType, carrierPara.CarrierID, carrierPara))
  841. {
  842. lp.WaitTransfer(ModuleName.CarrierRobot);
  843. return;
  844. }
  845. }
  846. }
  847. }
  848. }
  849. else
  850. {
  851. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  852. if (carrier != null && !carrier.IsEmpty)
  853. {
  854. foreach (var lp in _lstLPs)
  855. {
  856. if (!lp.IsAvailable || !CarrierManager.Instance.CheckNoCarrier(lp.Module, 0))
  857. continue;
  858. var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  859. if (para == null || para.TargetPort != lp.Module)
  860. continue;
  861. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  862. if (lp.IsReadyForPlace(_carrierRobot.Module, 0) && lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted)
  863. {
  864. if (_carrierRobot.Unload(lp.Module, 0, Hand.Blade1, para))
  865. {
  866. lp.WaitTransfer(ModuleName.CarrierRobot);
  867. return;
  868. }
  869. }
  870. }
  871. }
  872. }
  873. }
  874. private void MonitorCarrierRobotFIMSTask()
  875. {
  876. if (!_carrierRobot.IsAvailable)
  877. return;
  878. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  879. if (tj == null || tj.CarrierParas == null || tj.Type != EnumTransferJobType.Loading)
  880. return;
  881. //pick
  882. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  883. if (carrier != null && carrier.IsEmpty)
  884. {
  885. SchedulerFIMS fims = null;
  886. foreach (var st in _lstFIMSs)
  887. {
  888. if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
  889. continue;
  890. if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
  891. {
  892. carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
  893. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
  894. if (carrier != null && carrier.IsMapped && carrier.IsMapOK &&
  895. fimsDevice.IsUnloadCompleted && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  896. {
  897. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  898. {
  899. fims = st;
  900. break;
  901. }
  902. }
  903. }
  904. }
  905. if (fims != null)
  906. {
  907. if (_carrierRobot.Pick(fims.Module, 0, Hand.Blade1))
  908. {
  909. fims.WaitTransfer(ModuleName.CarrierRobot);
  910. return;
  911. }
  912. }
  913. }
  914. if (!_carrierRobot.IsAvailable)
  915. return;
  916. //place
  917. carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  918. if (carrier != null && !carrier.IsEmpty && !carrier.IsMapped &&
  919. tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName) &&
  920. !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  921. {
  922. SchedulerFIMS fims = null;
  923. foreach (var st in _lstFIMSs)
  924. {
  925. if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
  926. continue;
  927. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
  928. if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0) && fimsDevice.IsUnloadCompleted)
  929. {
  930. fims = st;
  931. break;
  932. }
  933. }
  934. if (fims != null)
  935. {
  936. if (_carrierRobot.Place(fims.Module, 0, Hand.Blade1))
  937. {
  938. fims.WaitTransfer(ModuleName.CarrierRobot);
  939. return;
  940. }
  941. }
  942. }
  943. }
  944. public List<CarrierPara> GetTransferJobStockers()
  945. {
  946. if (!_lstTransferJobs.Any())
  947. return null;
  948. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  949. if (tj == null || tj.CarrierParas == null)
  950. return null;
  951. return tj.CarrierParas;
  952. }
  953. #endregion
  954. #region Job task
  955. public Result MonitorJobTasks()
  956. {
  957. UpdateTransferJobStatus();
  958. StartNewJob();
  959. return Result.RUN;
  960. }
  961. private void UpdateTransferJobStatus()
  962. {
  963. if (!_lstTransferJobs.Any())
  964. return;
  965. if (!_carrierRobot.IsAvailable)
  966. return;
  967. List<TransferJobInfo> removeJobLst = new List<TransferJobInfo>();
  968. foreach (var tj in _lstTransferJobs)
  969. {
  970. if (tj == null || tj.CarrierParas == null)
  971. continue;
  972. bool isComplete = true;
  973. if (tj.Type == EnumTransferJobType.Loading)
  974. {
  975. foreach (var item in tj.CarrierParas)
  976. {
  977. if (!CarrierManager.Instance.CheckHasCarrier(item.Stocker, 0))
  978. {
  979. isComplete = false;
  980. continue;
  981. }
  982. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  983. if (carrier != null && (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded))
  984. {
  985. isComplete = false;
  986. continue;
  987. }
  988. if (carrier != null)
  989. {
  990. if (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded)
  991. {
  992. isComplete = false;
  993. continue;
  994. }
  995. else
  996. {
  997. if (!item.HasTrigEvent)
  998. {
  999. Task.Delay(1000).ContinueWith(x =>
  1000. {
  1001. _faCallback.CarrierInEnd(item.Stocker);
  1002. });
  1003. item.HasTrigEvent = true;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. else
  1010. {
  1011. foreach (var item in tj.CarrierParas)
  1012. {
  1013. if (!item.IsUnloaded)
  1014. continue;
  1015. if (!item.HasTrigEvent)
  1016. {
  1017. foreach (var lp in _lstLPs)
  1018. {
  1019. if (item.TargetPort == lp.Module)
  1020. {
  1021. var carrier = CarrierManager.Instance.GetCarrier(item.TargetPort, 0);
  1022. if (carrier != null && !carrier.IsEmpty)
  1023. {
  1024. //_faCallback.CarrierOutEnd(carrier);
  1025. item.HasTrigEvent = true;
  1026. break;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. }
  1032. foreach (var lp in _lstLPs)
  1033. {
  1034. if (tj.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1035. {
  1036. if (CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
  1037. {
  1038. isComplete = false;
  1039. continue;
  1040. }
  1041. }
  1042. }
  1043. if (tj.CarrierParas.Any(x => !x.IsUnloaded))
  1044. {
  1045. isComplete = false;
  1046. continue;
  1047. }
  1048. }
  1049. if (isComplete)
  1050. {
  1051. tj.State = EnumTransferJobState.Complete;
  1052. removeJobLst.Add(tj);
  1053. string stocker = "";
  1054. tj.CarrierParas.ForEach(x => stocker += $"{x.Stocker}-");
  1055. LOG.Write($"Scheduler:{stocker} {tj.Type} change to complete");
  1056. if (tj.Type == EnumTransferJobType.Loading)
  1057. {
  1058. List<ModuleName> unloadLPs = new List<ModuleName>();
  1059. foreach (var item in tj.CarrierParas)
  1060. {
  1061. if (!unloadLPs.Contains(item.TargetPort) &&
  1062. !_lstTransferJobs.Any(x => (x.State == EnumTransferJobState.Created || x.State == EnumTransferJobState.Active) &&
  1063. x.CarrierParas.Any(ca => ca.TargetPort == item.TargetPort)))
  1064. unloadLPs.Add(item.TargetPort);
  1065. }
  1066. //foreach (var lp in unloadLPs)
  1067. //{
  1068. // (Singleton<EquipmentManager>.Instance.Modules[lp] as LoadPortModule).InvokeUnload();
  1069. // LOG.Write($"Scheduler:{lp} start unload");
  1070. //}
  1071. }
  1072. }
  1073. }
  1074. foreach (var item in removeJobLst)
  1075. {
  1076. _lstTransferJobs.Remove(item);
  1077. }
  1078. }
  1079. private void StartNewJob()
  1080. {
  1081. if (!_lstTransferJobs.Any() || !_carrierRobot.IsAvailable)
  1082. return;
  1083. //没有在process的stocker时,以时间先后为准
  1084. var processingStockers = Singleton<EquipmentManager>.Instance.GetProcessingStockers();
  1085. if (processingStockers != null)
  1086. {
  1087. //有在process的stocker时,以时间先后和所有stokcer都不在process为准
  1088. foreach (var tj in _lstTransferJobs)
  1089. {
  1090. if (tj == null || tj.CarrierParas == null)
  1091. continue;
  1092. bool hasStokcerInProcessing = false;
  1093. foreach (var item in tj.CarrierParas)
  1094. {
  1095. if (processingStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1096. {
  1097. hasStokcerInProcessing = true;
  1098. break;
  1099. }
  1100. }
  1101. if (!hasStokcerInProcessing)
  1102. {
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. var tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Loading);
  1108. if (tjActives.Any())
  1109. {
  1110. foreach (var tjActive in tjActives)
  1111. {
  1112. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Loading)
  1113. {
  1114. bool isStockerReady = true;
  1115. foreach (var stocker in _lstTotlaStockers)
  1116. {
  1117. if (CarrierManager.Instance.CheckHasCarrier(stocker.Module, 0))
  1118. {
  1119. var carrier = CarrierManager.Instance.GetCarrier(stocker.Module, 0);
  1120. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1121. isStockerReady = false;
  1122. }
  1123. }
  1124. if (CarrierManager.Instance.CheckHasCarrier(_carrierRobot.Module, 0))
  1125. {
  1126. var carrier = CarrierManager.Instance.GetCarrier(_carrierRobot.Module, 0);
  1127. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1128. isStockerReady = false;
  1129. }
  1130. foreach (var fims in _lstFIMSs)
  1131. {
  1132. if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  1133. {
  1134. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  1135. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1136. isStockerReady = false;
  1137. }
  1138. }
  1139. if (isStockerReady)
  1140. {
  1141. //transfer job开始
  1142. tjActive.State = EnumTransferJobState.Active;
  1143. }
  1144. if (tjActive.State == EnumTransferJobState.Active)
  1145. {
  1146. foreach (var lp in _lstLPs)
  1147. {
  1148. if (!lp.IsAvailable)
  1149. continue;
  1150. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1151. continue;
  1152. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  1153. }
  1154. }
  1155. }
  1156. }
  1157. }
  1158. tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Unloading);
  1159. if (tjActives.Any())
  1160. {
  1161. foreach (var tjActive in tjActives)
  1162. {
  1163. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Unloading)
  1164. {
  1165. bool isStockerReady = true;
  1166. var allPJStockers = Singleton<EquipmentManager>.Instance.GetAllPJStockers();
  1167. foreach (var item in tjActive.CarrierParas)
  1168. {
  1169. if (CarrierManager.Instance.CheckNoCarrier(item.Stocker, 0))
  1170. {
  1171. isStockerReady = false;
  1172. continue;
  1173. }
  1174. if (allPJStockers != null && allPJStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1175. {
  1176. isStockerReady = false;
  1177. continue;
  1178. }
  1179. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  1180. if (carrier != null && item.Stocker != carrier.InternalModuleName)
  1181. isStockerReady = false;
  1182. }
  1183. if (isStockerReady)
  1184. {
  1185. //transfer job开始
  1186. tjActive.State = EnumTransferJobState.Active;
  1187. }
  1188. if (tjActive.State == EnumTransferJobState.Active)
  1189. {
  1190. foreach (var lp in _lstLPs)
  1191. {
  1192. if (!lp.IsAvailable)
  1193. continue;
  1194. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1195. continue;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. internal List<TransferJobInfo> GetFirstCreatedTransferJob(EnumTransferJobType type)
  1203. {
  1204. DateTime dtMin = DateTime.MaxValue;
  1205. List<TransferJobInfo> currentTj = new List<TransferJobInfo>();
  1206. var lpNumber = 2;
  1207. List<ModuleName> occupyLPs = new List<ModuleName>();
  1208. foreach (var tj in _lstTransferJobs)
  1209. {
  1210. if (tj == null || tj.State == EnumTransferJobState.Active || tj.State == EnumTransferJobState.Complete || tj.Type != type)
  1211. {
  1212. continue;
  1213. }
  1214. if (occupyLPs.Count == lpNumber)
  1215. break;
  1216. currentTj.Add(tj);
  1217. foreach (var para in tj.CarrierParas)
  1218. {
  1219. if (type == EnumTransferJobType.Loading && !para.IsLoaded && !occupyLPs.Any(x => x == para.TargetPort))
  1220. occupyLPs.Add(para.TargetPort);
  1221. if (type == EnumTransferJobType.Unloading && !para.IsUnloaded && !occupyLPs.Any(x => x == para.TargetPort))
  1222. occupyLPs.Add(para.TargetPort);
  1223. }
  1224. }
  1225. return currentTj;
  1226. }
  1227. public List<string> GetOccupyStockers()
  1228. {
  1229. var occupyStockers = new List<string>();
  1230. var checkModuleLst = new List<ModuleName>();
  1231. checkModuleLst.Add(ModuleName.CarrierRobot);
  1232. foreach (var fims in _lstFIMSs)
  1233. {
  1234. if (fims == null)
  1235. continue;
  1236. checkModuleLst.Add(fims.Module);
  1237. }
  1238. foreach (var stocker in _lstTotlaStockers)
  1239. {
  1240. if (stocker == null)
  1241. continue;
  1242. checkModuleLst.Add(stocker.Module);
  1243. }
  1244. foreach (var module in checkModuleLst)
  1245. {
  1246. var carrier = CarrierManager.Instance.GetCarrier(module, 0);
  1247. if (carrier == null || carrier.IsEmpty)
  1248. continue;
  1249. occupyStockers.Add(carrier.InternalModuleName.ToString());
  1250. }
  1251. var loadCarrierParas = new List<CarrierPara>();
  1252. if (_lstTransferJobs.Any())
  1253. {
  1254. foreach (var tj in _lstTransferJobs)
  1255. {
  1256. if (tj == null || tj.Type != EnumTransferJobType.Loading)
  1257. continue;
  1258. loadCarrierParas.AddRange(tj.CarrierParas);
  1259. }
  1260. }
  1261. if (loadCarrierParas != null && loadCarrierParas.Any())
  1262. {
  1263. foreach (var para in loadCarrierParas)
  1264. {
  1265. occupyStockers.Add(para.Stocker.ToString());
  1266. }
  1267. }
  1268. return occupyStockers;
  1269. }
  1270. #endregion
  1271. }
  1272. }