TransferJob.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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. if (!SC.GetValue<bool>("System.IsSimulatorMode"))
  529. {
  530. var fims1Device = DEVICE.GetDevice<IoFIMS>($"PM1.FIMS1");
  531. var fims2Device = DEVICE.GetDevice<IoFIMS>($"PM1.FIMS2");
  532. if (fims.Module == ModuleName.FIMS1 && fims2Device.IsRunning)
  533. continue;
  534. if (fims.Module == ModuleName.FIMS2 && fims1Device.IsRunning)
  535. continue;
  536. }
  537. var CheckFimsIsNeedOxygenPressure = pm.CheckFimsIsNeedOxygenPressure(foupEnterFIMSN2purgeConfig, "", out var isCheckO2, false);
  538. if (isCheckO2)
  539. {
  540. tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.CheckInterval = 1;
  541. tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Monitor(pm.GetN2PurgeUnder20PPMStatus(foupEnterLAO2CheckSV) && pm.CheckIsLASide());
  542. pm.SetN2PurgeModePhase(N2PurgeModeEnum.FoupEnter.ToString());
  543. if (tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Trig)
  544. {
  545. if (fims.Load(CheckFimsIsNeedOxygenPressure, N2PurgeModeEnum.FoupEnter.ToString()))
  546. {
  547. tj.FimsCheckOxDensityDict[fims.Module.ToString()].Item1.Restart();
  548. LOG.Info($"FIMS={fims.Module} , FIMS N2PurgeConfig={foupEnterFIMSN2purgeConfig},Currect N2Purge={lACurrectN2purgeMode},Limit O2 Data={foupEnterLAO2CheckSV},transferJob Load,wait FoupEnter 。a");
  549. return;
  550. }
  551. }
  552. }
  553. else
  554. {
  555. if (fims.Load(CheckFimsIsNeedOxygenPressure, N2PurgeModeEnum.FoupEnter.ToString()))
  556. {
  557. LOG.Info($"FIMS={fims.Module} , FIMS N2PurgeConfig={foupEnterFIMSN2purgeConfig},Currect N2Purge={lACurrectN2purgeMode},Limit O2 Data={foupEnterLAO2CheckSV},transferJob Load, direct FoupEnter 。b");
  558. return;
  559. }
  560. }
  561. }
  562. }
  563. }
  564. }
  565. }
  566. else if (tj.Type == EnumTransferJobType.Unloading)
  567. {
  568. //do nothing
  569. }
  570. }
  571. private void MonitorWaferRobotTask()
  572. {
  573. if (!_waferRobot.IsAvailable)
  574. return;
  575. //wafer robot is idle, release all the target
  576. foreach (var fims in _lstFIMSs)
  577. {
  578. if (fims.IsWaitTransfer(ModuleName.WaferRobot))
  579. {
  580. fims.StopWaitTransfer(ModuleName.WaferRobot);
  581. }
  582. }
  583. MonitorWaferRobotFIMSTask();
  584. }
  585. private void MonitorWaferRobotFIMSTask()
  586. {
  587. if (!_waferRobot.IsAvailable || !_lstTransferJobs.Any())
  588. return;
  589. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  590. if (tj == null || tj.CarrierParas == null)
  591. return;
  592. foreach (var fims in _lstFIMSs)
  593. {
  594. if (!fims.IsAvailable)
  595. continue;
  596. if (!CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  597. continue;
  598. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{fims.Module}");
  599. if (!fimsDevice.IsLoadCompleted)
  600. continue;
  601. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  602. if (carrier == null || carrier.IsEmpty || carrier.IsMapped || SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  603. continue;
  604. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  605. {
  606. var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  607. if (carrierPara != null && _waferRobot.Map(fims.Module, carrierPara.WaferCount, carrierPara.SlotMap, carrierPara.IsCompareWithSlotMap, true, Hand.Blade1))
  608. {
  609. fims.WaitTransfer(ModuleName.WaferRobot);
  610. }
  611. }
  612. }
  613. }
  614. private void MonitorCarrierRobotTask()
  615. {
  616. if (!_carrierRobot.IsAvailable)
  617. return;
  618. //carrier robot is idle, release all the target
  619. foreach (var stocker in _lstTotlaStockers)
  620. {
  621. if (stocker.IsWaitTransfer(ModuleName.CarrierRobot))
  622. {
  623. stocker.StopWaitTransfer(ModuleName.CarrierRobot);
  624. }
  625. }
  626. foreach (var fims in _lstFIMSs)
  627. {
  628. if (fims.IsWaitTransfer(ModuleName.CarrierRobot))
  629. {
  630. fims.StopWaitTransfer(ModuleName.CarrierRobot);
  631. }
  632. }
  633. foreach (var lp in _lstLPs)
  634. {
  635. if (lp.IsWaitTransfer(ModuleName.CarrierRobot))
  636. {
  637. lp.StopWaitTransfer(ModuleName.CarrierRobot);
  638. }
  639. }
  640. MonitorCarrierRobotFIMSTask();
  641. if (!_carrierRobot.IsAvailable)
  642. return;
  643. MonitorCarrierRobotStockerTask();
  644. if (!_carrierRobot.IsAvailable)
  645. return;
  646. MonitorCarrierRobotLPTask();
  647. if (!_carrierRobot.IsAvailable)
  648. return;
  649. //MonitorCarrierGotoTask();
  650. }
  651. private void MonitorCarrierGotoTask()
  652. {
  653. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  654. return;
  655. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  656. if (tj == null || tj.CarrierParas == null)
  657. return;
  658. if (tj.Type == EnumTransferJobType.Loading)
  659. {
  660. if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  661. {
  662. foreach (var lp in _lstLPs)
  663. {
  664. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  665. continue;
  666. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  667. if (lpDevice.IsFoupPresent)
  668. {
  669. if (!lpDevice.IsLoadCompleted && _carrierRobot.PreviousTarget != lp.Module && _carrierRobot.Goto(lp.Module, 0, Hand.Blade1, true))
  670. {
  671. return;
  672. }
  673. }
  674. }
  675. if (!SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  676. {
  677. foreach (var fims in _lstFIMSs)
  678. {
  679. if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  680. {
  681. var carrier1 = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  682. if (carrier1 != null && !carrier1.IsMapped)
  683. {
  684. if (tj.CarrierParas.Any(x => x.Stocker == carrier1.InternalModuleName) && _carrierRobot.PreviousTarget != fims.Module &&
  685. _carrierRobot.Goto(fims.Module, 0, Hand.Blade1, true))
  686. {
  687. return;
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. else
  695. {
  696. //goto fims 放
  697. if (!SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  698. {
  699. foreach (var fims in _lstFIMSs)
  700. {
  701. if (!fims.IsAvailable)
  702. continue;
  703. if (CarrierManager.Instance.CheckNoCarrier(fims.Module, 0))
  704. {
  705. var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  706. if (robotCarrier != null && !robotCarrier.IsMapped && tj.CarrierParas.Any(x => x.Stocker == robotCarrier.InternalModuleName))
  707. {
  708. if (_carrierRobot.PreviousTarget != fims.Module && _carrierRobot.Goto(fims.Module, 0, Hand.Blade1, false))
  709. {
  710. return;
  711. }
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. else if (tj.Type == EnumTransferJobType.Unloading)
  719. {
  720. if (CarrierManager.Instance.CheckHasCarrier(ModuleName.CarrierRobot, 0))
  721. {
  722. foreach (var lp in _lstLPs)
  723. {
  724. if (!CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
  725. continue;
  726. var robotCarrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  727. var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == robotCarrier.InternalModuleName);
  728. if (para == null || para.TargetPort != lp.Module)
  729. continue;
  730. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  731. if (!lpDevice.IsFoupPresent)
  732. {
  733. if (!lpDevice.IsLoadCompleted && _carrierRobot.PreviousTarget != lp.Module && _carrierRobot.Goto(lp.Module, 0, Hand.Blade1, false))
  734. {
  735. lp.WaitTransfer(ModuleName.CarrierRobot);
  736. return;
  737. }
  738. }
  739. }
  740. }
  741. }
  742. }
  743. private void MonitorCarrierRobotStockerTask()
  744. {
  745. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  746. return;
  747. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  748. if (tj == null || tj.CarrierParas == null)
  749. return;
  750. //pick
  751. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  752. if (carrier != null && carrier.IsEmpty)
  753. {
  754. SchedulerStocker stocker = null;
  755. foreach (var st in _lstTotlaStockers)
  756. {
  757. if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
  758. continue;
  759. if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
  760. {
  761. carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
  762. if (tj.Type == EnumTransferJobType.Loading)
  763. {
  764. //没有map,FIMS具备map条件时
  765. if (carrier != null && !carrier.IsMapped &&
  766. _lstFIMSs.Any(x => x.IsAvailable && x.IsReadyForPlace(ModuleName.CarrierRobot, 0)) &&
  767. !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  768. {
  769. //有job执行且在charging和discharge状态,先不执行mapping
  770. if (DATA.Poll("Scheduler.CurrentProcessJob") is ProcessJobInfo job && job != null &&
  771. (job.ProcessingState == EnumProcessingState.CoolingBeforeDischarge || job.ProcessingState == EnumProcessingState.Charging || job.ProcessingState == EnumProcessingState.Discharging
  772. || (job.ProcessingState == EnumProcessingState.Processing && DATA.Poll("PM1.RemainTimeToEnterCooling") is double t && t <= SC.GetValue<double>("System.Scheduler.LoadMappingForecastTime"))))
  773. {
  774. continue;
  775. }
  776. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  777. {
  778. stocker = st;
  779. break;
  780. }
  781. }
  782. }
  783. else
  784. {
  785. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  786. {
  787. stocker = st;
  788. break;
  789. }
  790. }
  791. }
  792. }
  793. if (stocker != null && _waferRobot.IsAvailable)
  794. {
  795. if (_carrierRobot.Pick(stocker.Module, 0, Hand.Blade1))
  796. {
  797. stocker.WaitTransfer(ModuleName.CarrierRobot);
  798. return;
  799. }
  800. }
  801. }
  802. if (!_carrierRobot.IsAvailable || tj.Type != EnumTransferJobType.Loading)
  803. return;
  804. //place
  805. carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  806. if (carrier != null && !carrier.IsEmpty &&
  807. tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  808. {
  809. var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  810. SchedulerStocker stocker = null;
  811. foreach (var st in _lstTotlaStockers)
  812. {
  813. if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
  814. continue;
  815. if (st.Module != carrier.InternalModuleName)
  816. continue;
  817. if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0))
  818. {
  819. stocker = st;
  820. break;
  821. }
  822. }
  823. if (stocker != null)
  824. {
  825. if (_carrierRobot.Place(stocker.Module, 0, Hand.Blade1))
  826. {
  827. stocker.WaitTransfer(ModuleName.CarrierRobot);
  828. return;
  829. }
  830. }
  831. }
  832. }
  833. private void MonitorCarrierRobotLPTask()
  834. {
  835. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  836. return;
  837. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  838. if (tj == null || tj.CarrierParas == null)
  839. return;
  840. if (tj.Type == EnumTransferJobType.Loading)
  841. {
  842. if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  843. {
  844. foreach (var lp in _lstLPs)
  845. {
  846. if (!lp.IsAvailable)
  847. continue;
  848. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  849. continue;
  850. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  851. if (lp.IsReadyForPick(_carrierRobot.Module, 0) && (lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted))
  852. {
  853. var carrierPara = tj.CarrierParas.First(x => x.TargetPort == lp.Module && !x.IsLoaded);
  854. if (carrierPara != null && _carrierRobot.Load(lp.Module, 0, Hand.Blade1, carrierPara.Stocker, carrierPara.CarrierType, carrierPara.CarrierID, carrierPara))
  855. {
  856. lp.WaitTransfer(ModuleName.CarrierRobot);
  857. return;
  858. }
  859. }
  860. }
  861. }
  862. }
  863. else
  864. {
  865. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  866. if (carrier != null && !carrier.IsEmpty)
  867. {
  868. foreach (var lp in _lstLPs)
  869. {
  870. if (!lp.IsAvailable || !CarrierManager.Instance.CheckNoCarrier(lp.Module, 0))
  871. continue;
  872. var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  873. if (para == null || para.TargetPort != lp.Module)
  874. continue;
  875. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  876. if (lp.IsReadyForPlace(_carrierRobot.Module, 0) && lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted)
  877. {
  878. if (_carrierRobot.Unload(lp.Module, 0, Hand.Blade1, para))
  879. {
  880. lp.WaitTransfer(ModuleName.CarrierRobot);
  881. return;
  882. }
  883. }
  884. }
  885. }
  886. }
  887. }
  888. private void MonitorCarrierRobotFIMSTask()
  889. {
  890. if (!_carrierRobot.IsAvailable)
  891. return;
  892. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  893. if (tj == null || tj.CarrierParas == null || tj.Type != EnumTransferJobType.Loading)
  894. return;
  895. //pick
  896. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  897. if (carrier != null && carrier.IsEmpty)
  898. {
  899. SchedulerFIMS fims = null;
  900. foreach (var st in _lstFIMSs)
  901. {
  902. if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
  903. continue;
  904. if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
  905. {
  906. carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
  907. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
  908. if (carrier != null && carrier.IsMapped && carrier.IsMapOK &&
  909. fimsDevice.IsUnloadCompleted && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  910. {
  911. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  912. {
  913. fims = st;
  914. break;
  915. }
  916. }
  917. }
  918. }
  919. if (fims != null)
  920. {
  921. if (_carrierRobot.Pick(fims.Module, 0, Hand.Blade1))
  922. {
  923. fims.WaitTransfer(ModuleName.CarrierRobot);
  924. return;
  925. }
  926. }
  927. }
  928. if (!_carrierRobot.IsAvailable)
  929. return;
  930. //place
  931. carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  932. if (carrier != null && !carrier.IsEmpty && !carrier.IsMapped &&
  933. tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName) &&
  934. !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  935. {
  936. SchedulerFIMS fims = null;
  937. foreach (var st in _lstFIMSs)
  938. {
  939. //有job执行且在charging和discharge状态,先不执行mapping
  940. if (DATA.Poll("Scheduler.CurrentProcessJob") is ProcessJobInfo job && job != null &&
  941. (job.ProcessingState == EnumProcessingState.CoolingBeforeDischarge || job.ProcessingState == EnumProcessingState.Charging || job.ProcessingState == EnumProcessingState.Discharging
  942. || (job.ProcessingState == EnumProcessingState.Processing && DATA.Poll("PM1.RemainTimeToEnterCooling") is double t && t <= SC.GetValue<double>("System.Scheduler.LoadMappingForecastTime"))))
  943. {
  944. continue;
  945. }
  946. if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
  947. continue;
  948. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
  949. if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0) && fimsDevice.IsUnloadCompleted)
  950. {
  951. fims = st;
  952. break;
  953. }
  954. }
  955. if (fims != null)
  956. {
  957. if (_carrierRobot.Place(fims.Module, 0, Hand.Blade1))
  958. {
  959. fims.WaitTransfer(ModuleName.CarrierRobot);
  960. return;
  961. }
  962. }
  963. }
  964. }
  965. public List<CarrierPara> GetTransferJobStockers()
  966. {
  967. if (!_lstTransferJobs.Any())
  968. return null;
  969. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  970. if (tj == null || tj.CarrierParas == null)
  971. return null;
  972. return tj.CarrierParas;
  973. }
  974. #endregion
  975. #region Job task
  976. public Result MonitorJobTasks()
  977. {
  978. UpdateTransferJobStatus();
  979. StartNewJob();
  980. return Result.RUN;
  981. }
  982. private void UpdateTransferJobStatus()
  983. {
  984. if (!_lstTransferJobs.Any())
  985. return;
  986. if (!_carrierRobot.IsAvailable)
  987. return;
  988. List<TransferJobInfo> removeJobLst = new List<TransferJobInfo>();
  989. foreach (var tj in _lstTransferJobs)
  990. {
  991. if (tj == null || tj.CarrierParas == null)
  992. continue;
  993. bool isComplete = true;
  994. if (tj.Type == EnumTransferJobType.Loading)
  995. {
  996. foreach (var item in tj.CarrierParas)
  997. {
  998. if (!CarrierManager.Instance.CheckHasCarrier(item.Stocker, 0))
  999. {
  1000. isComplete = false;
  1001. continue;
  1002. }
  1003. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  1004. if (carrier != null && (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded))
  1005. {
  1006. isComplete = false;
  1007. continue;
  1008. }
  1009. if (carrier != null)
  1010. {
  1011. if (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded)
  1012. {
  1013. isComplete = false;
  1014. continue;
  1015. }
  1016. else
  1017. {
  1018. if (!item.HasTrigEvent)
  1019. {
  1020. Task.Delay(1000).ContinueWith(x =>
  1021. {
  1022. _faCallback.CarrierInEnd(item.Stocker);
  1023. });
  1024. item.HasTrigEvent = true;
  1025. }
  1026. }
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. foreach (var item in tj.CarrierParas)
  1033. {
  1034. if (!item.IsUnloaded)
  1035. continue;
  1036. if (!item.HasTrigEvent)
  1037. {
  1038. foreach (var lp in _lstLPs)
  1039. {
  1040. if (item.TargetPort == lp.Module)
  1041. {
  1042. var carrier = CarrierManager.Instance.GetCarrier(item.TargetPort, 0);
  1043. if (carrier != null && !carrier.IsEmpty)
  1044. {
  1045. //_faCallback.CarrierOutEnd(carrier);
  1046. item.HasTrigEvent = true;
  1047. break;
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }
  1053. foreach (var lp in _lstLPs)
  1054. {
  1055. if (tj.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1056. {
  1057. if (CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
  1058. {
  1059. isComplete = false;
  1060. continue;
  1061. }
  1062. }
  1063. }
  1064. if (tj.CarrierParas.Any(x => !x.IsUnloaded))
  1065. {
  1066. isComplete = false;
  1067. continue;
  1068. }
  1069. }
  1070. if (isComplete)
  1071. {
  1072. tj.State = EnumTransferJobState.Complete;
  1073. removeJobLst.Add(tj);
  1074. string stocker = "";
  1075. tj.CarrierParas.ForEach(x => stocker += $"{x.Stocker}-");
  1076. LOG.Write($"Scheduler:{stocker} {tj.Type} change to complete");
  1077. if (tj.Type == EnumTransferJobType.Loading)
  1078. {
  1079. List<ModuleName> unloadLPs = new List<ModuleName>();
  1080. foreach (var item in tj.CarrierParas)
  1081. {
  1082. if (!unloadLPs.Contains(item.TargetPort) &&
  1083. !_lstTransferJobs.Any(x => (x.State == EnumTransferJobState.Created || x.State == EnumTransferJobState.Active) &&
  1084. x.CarrierParas.Any(ca => ca.TargetPort == item.TargetPort)))
  1085. unloadLPs.Add(item.TargetPort);
  1086. }
  1087. //foreach (var lp in unloadLPs)
  1088. //{
  1089. // (Singleton<EquipmentManager>.Instance.Modules[lp] as LoadPortModule).InvokeUnload();
  1090. // LOG.Write($"Scheduler:{lp} start unload");
  1091. //}
  1092. }
  1093. }
  1094. }
  1095. foreach (var item in removeJobLst)
  1096. {
  1097. _lstTransferJobs.Remove(item);
  1098. }
  1099. }
  1100. private void StartNewJob()
  1101. {
  1102. if (!_lstTransferJobs.Any() || !_carrierRobot.IsAvailable)
  1103. return;
  1104. //没有在process的stocker时,以时间先后为准
  1105. var processingStockers = Singleton<EquipmentManager>.Instance.GetProcessingStockers();
  1106. if (processingStockers != null)
  1107. {
  1108. //有在process的stocker时,以时间先后和所有stokcer都不在process为准
  1109. foreach (var tj in _lstTransferJobs)
  1110. {
  1111. if (tj == null || tj.CarrierParas == null)
  1112. continue;
  1113. bool hasStokcerInProcessing = false;
  1114. foreach (var item in tj.CarrierParas)
  1115. {
  1116. if (processingStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1117. {
  1118. hasStokcerInProcessing = true;
  1119. break;
  1120. }
  1121. }
  1122. if (!hasStokcerInProcessing)
  1123. {
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. var tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Loading);
  1129. if (tjActives.Any())
  1130. {
  1131. foreach (var tjActive in tjActives)
  1132. {
  1133. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Loading)
  1134. {
  1135. bool isStockerReady = true;
  1136. foreach (var stocker in _lstTotlaStockers)
  1137. {
  1138. if (CarrierManager.Instance.CheckHasCarrier(stocker.Module, 0))
  1139. {
  1140. var carrier = CarrierManager.Instance.GetCarrier(stocker.Module, 0);
  1141. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1142. isStockerReady = false;
  1143. }
  1144. }
  1145. if (CarrierManager.Instance.CheckHasCarrier(_carrierRobot.Module, 0))
  1146. {
  1147. var carrier = CarrierManager.Instance.GetCarrier(_carrierRobot.Module, 0);
  1148. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1149. isStockerReady = false;
  1150. }
  1151. foreach (var fims in _lstFIMSs)
  1152. {
  1153. if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  1154. {
  1155. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  1156. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1157. isStockerReady = false;
  1158. }
  1159. }
  1160. if (isStockerReady)
  1161. {
  1162. //transfer job开始
  1163. tjActive.State = EnumTransferJobState.Active;
  1164. }
  1165. if (tjActive.State == EnumTransferJobState.Active)
  1166. {
  1167. foreach (var lp in _lstLPs)
  1168. {
  1169. if (!lp.IsAvailable)
  1170. continue;
  1171. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1172. continue;
  1173. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Unloading);
  1180. if (tjActives.Any())
  1181. {
  1182. foreach (var tjActive in tjActives)
  1183. {
  1184. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Unloading)
  1185. {
  1186. bool isStockerReady = true;
  1187. var allPJStockers = Singleton<EquipmentManager>.Instance.GetAllPJStockers();
  1188. foreach (var item in tjActive.CarrierParas)
  1189. {
  1190. if (CarrierManager.Instance.CheckNoCarrier(item.Stocker, 0))
  1191. {
  1192. isStockerReady = false;
  1193. continue;
  1194. }
  1195. if (allPJStockers != null && allPJStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1196. {
  1197. isStockerReady = false;
  1198. continue;
  1199. }
  1200. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  1201. if (carrier != null && item.Stocker != carrier.InternalModuleName)
  1202. isStockerReady = false;
  1203. }
  1204. if (isStockerReady)
  1205. {
  1206. //transfer job开始
  1207. tjActive.State = EnumTransferJobState.Active;
  1208. }
  1209. if (tjActive.State == EnumTransferJobState.Active)
  1210. {
  1211. foreach (var lp in _lstLPs)
  1212. {
  1213. if (!lp.IsAvailable)
  1214. continue;
  1215. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1216. continue;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. internal List<TransferJobInfo> GetFirstCreatedTransferJob(EnumTransferJobType type)
  1224. {
  1225. DateTime dtMin = DateTime.MaxValue;
  1226. List<TransferJobInfo> currentTj = new List<TransferJobInfo>();
  1227. var lpNumber = 2;
  1228. List<ModuleName> occupyLPs = new List<ModuleName>();
  1229. foreach (var tj in _lstTransferJobs)
  1230. {
  1231. if (tj == null || tj.State == EnumTransferJobState.Active || tj.State == EnumTransferJobState.Complete || tj.Type != type)
  1232. {
  1233. continue;
  1234. }
  1235. if (occupyLPs.Count == lpNumber)
  1236. break;
  1237. currentTj.Add(tj);
  1238. foreach (var para in tj.CarrierParas)
  1239. {
  1240. if (type == EnumTransferJobType.Loading && !para.IsLoaded && !occupyLPs.Any(x => x == para.TargetPort))
  1241. occupyLPs.Add(para.TargetPort);
  1242. if (type == EnumTransferJobType.Unloading && !para.IsUnloaded && !occupyLPs.Any(x => x == para.TargetPort))
  1243. occupyLPs.Add(para.TargetPort);
  1244. }
  1245. }
  1246. return currentTj;
  1247. }
  1248. public List<string> GetOccupyStockers()
  1249. {
  1250. var occupyStockers = new List<string>();
  1251. var checkModuleLst = new List<ModuleName>();
  1252. checkModuleLst.Add(ModuleName.CarrierRobot);
  1253. foreach (var fims in _lstFIMSs)
  1254. {
  1255. if (fims == null)
  1256. continue;
  1257. checkModuleLst.Add(fims.Module);
  1258. }
  1259. foreach (var stocker in _lstTotlaStockers)
  1260. {
  1261. if (stocker == null)
  1262. continue;
  1263. checkModuleLst.Add(stocker.Module);
  1264. }
  1265. foreach (var module in checkModuleLst)
  1266. {
  1267. var carrier = CarrierManager.Instance.GetCarrier(module, 0);
  1268. if (carrier == null || carrier.IsEmpty)
  1269. continue;
  1270. occupyStockers.Add(carrier.InternalModuleName.ToString());
  1271. }
  1272. var loadCarrierParas = new List<CarrierPara>();
  1273. if (_lstTransferJobs.Any())
  1274. {
  1275. foreach (var tj in _lstTransferJobs)
  1276. {
  1277. if (tj == null || tj.Type != EnumTransferJobType.Loading)
  1278. continue;
  1279. loadCarrierParas.AddRange(tj.CarrierParas);
  1280. }
  1281. }
  1282. if (loadCarrierParas != null && loadCarrierParas.Any())
  1283. {
  1284. foreach (var para in loadCarrierParas)
  1285. {
  1286. occupyStockers.Add(para.Stocker.ToString());
  1287. }
  1288. }
  1289. return occupyStockers;
  1290. }
  1291. #endregion
  1292. }
  1293. }