TransferJob.cs 55 KB

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