TransferJob.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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. //有job执行且在charging和discharge状态,先不执行mapping
  718. if (DATA.Poll("Scheduler.CurrentProcessJob") is ProcessJobInfo job && job != null &&
  719. (job.ProcessingState == EnumProcessingState.CoolingBeforeDischarge || job.ProcessingState == EnumProcessingState.Charging || job.ProcessingState == EnumProcessingState.Discharging
  720. || (job.ProcessingState == EnumProcessingState.Processing && DATA.Poll("PM1.RemainTimeToEnterCooling") is double t && t <= SC.GetValue<double>("System.Scheduler.LoadMappingForecastTime"))))
  721. {
  722. continue;
  723. }
  724. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  725. {
  726. stocker = st;
  727. break;
  728. }
  729. }
  730. }
  731. else
  732. {
  733. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  734. {
  735. stocker = st;
  736. break;
  737. }
  738. }
  739. }
  740. }
  741. if (stocker != null && _waferRobot.IsAvailable)
  742. {
  743. if (_carrierRobot.Pick(stocker.Module, 0, Hand.Blade1))
  744. {
  745. stocker.WaitTransfer(ModuleName.CarrierRobot);
  746. return;
  747. }
  748. }
  749. }
  750. if (!_carrierRobot.IsAvailable || tj.Type != EnumTransferJobType.Loading)
  751. return;
  752. //place
  753. carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  754. if (carrier != null && !carrier.IsEmpty &&
  755. tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  756. {
  757. var carrierPara = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  758. SchedulerStocker stocker = null;
  759. foreach (var st in _lstTotlaStockers)
  760. {
  761. if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
  762. continue;
  763. if (st.Module != carrier.InternalModuleName)
  764. continue;
  765. if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0))
  766. {
  767. stocker = st;
  768. break;
  769. }
  770. }
  771. if (stocker != null)
  772. {
  773. if (_carrierRobot.Place(stocker.Module, 0, Hand.Blade1))
  774. {
  775. stocker.WaitTransfer(ModuleName.CarrierRobot);
  776. return;
  777. }
  778. }
  779. }
  780. }
  781. private void MonitorCarrierRobotLPTask()
  782. {
  783. if (!_carrierRobot.IsAvailable || !_lstTransferJobs.Any())
  784. return;
  785. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  786. if (tj == null || tj.CarrierParas == null)
  787. return;
  788. if (tj.Type == EnumTransferJobType.Loading)
  789. {
  790. if (CarrierManager.Instance.CheckNoCarrier(ModuleName.CarrierRobot, 0))
  791. {
  792. foreach (var lp in _lstLPs)
  793. {
  794. if (!lp.IsAvailable)
  795. continue;
  796. if (!tj.CarrierParas.Any(x => x.TargetPort == lp.Module && !x.IsLoaded))
  797. continue;
  798. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  799. if (lp.IsReadyForPick(_carrierRobot.Module, 0) && (lpDevice.IsLoadCompleted|| lpDevice.IsUnloadCompleted))
  800. {
  801. var carrierPara = tj.CarrierParas.First(x => x.TargetPort == lp.Module && !x.IsLoaded);
  802. if (carrierPara != null && _carrierRobot.Load(lp.Module, 0, Hand.Blade1, carrierPara.Stocker, carrierPara.CarrierType, carrierPara.CarrierID, carrierPara))
  803. {
  804. lp.WaitTransfer(ModuleName.CarrierRobot);
  805. return;
  806. }
  807. }
  808. }
  809. }
  810. }
  811. else
  812. {
  813. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  814. if (carrier != null && !carrier.IsEmpty)
  815. {
  816. foreach (var lp in _lstLPs)
  817. {
  818. if (!lp.IsAvailable || !CarrierManager.Instance.CheckNoCarrier(lp.Module, 0))
  819. continue;
  820. var para = tj.CarrierParas.FirstOrDefault(x => x.Stocker == carrier.InternalModuleName);
  821. if (para == null || para.TargetPort != lp.Module)
  822. continue;
  823. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  824. if (lp.IsReadyForPlace(_carrierRobot.Module, 0) && lpDevice.IsLoadCompleted || lpDevice.IsUnloadCompleted)
  825. {
  826. if (_carrierRobot.Unload(lp.Module, 0, Hand.Blade1, para))
  827. {
  828. lp.WaitTransfer(ModuleName.CarrierRobot);
  829. return;
  830. }
  831. }
  832. }
  833. }
  834. }
  835. }
  836. private void MonitorCarrierRobotFIMSTask()
  837. {
  838. if (!_carrierRobot.IsAvailable)
  839. return;
  840. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  841. if (tj == null || tj.CarrierParas == null || tj.Type != EnumTransferJobType.Loading)
  842. return;
  843. //pick
  844. var carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  845. if (carrier != null && carrier.IsEmpty)
  846. {
  847. SchedulerFIMS fims = null;
  848. foreach (var st in _lstFIMSs)
  849. {
  850. if (!st.IsAvailable || !st.IsReadyForPick(ModuleName.CarrierRobot, 0))
  851. continue;
  852. if (CarrierManager.Instance.CheckHasCarrier(st.Module, 0))
  853. {
  854. carrier = CarrierManager.Instance.GetCarrier(st.Module, 0);
  855. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
  856. if (carrier != null && carrier.IsMapped && carrier.IsMapOK &&
  857. fimsDevice.IsUnloadCompleted && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  858. {
  859. if (tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  860. {
  861. fims = st;
  862. break;
  863. }
  864. }
  865. }
  866. }
  867. if (fims != null)
  868. {
  869. if (_carrierRobot.Pick(fims.Module, 0, Hand.Blade1))
  870. {
  871. fims.WaitTransfer(ModuleName.CarrierRobot);
  872. return;
  873. }
  874. }
  875. }
  876. if (!_carrierRobot.IsAvailable)
  877. return;
  878. //place
  879. carrier = CarrierManager.Instance.GetCarrier(ModuleName.CarrierRobot, 0);
  880. if (carrier != null && !carrier.IsEmpty && !carrier.IsMapped &&
  881. tj.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName) &&
  882. !SC.GetValue<bool>("WaferRobot.BypassFIMSMap"))
  883. {
  884. SchedulerFIMS fims = null;
  885. foreach (var st in _lstFIMSs)
  886. {
  887. if (DATA.Poll("Scheduler.CurrentProcessJob") is ProcessJobInfo job && job != null &&
  888. (job.ProcessingState == EnumProcessingState.CoolingBeforeDischarge || job.ProcessingState == EnumProcessingState.Charging || job.ProcessingState == EnumProcessingState.Discharging
  889. || (job.ProcessingState == EnumProcessingState.Processing && DATA.Poll("PM1.RemainTimeToEnterCooling") is double t && t <= SC.GetValue<double>("System.Scheduler.LoadMappingForecastTime"))))
  890. {
  891. continue;
  892. }
  893. if (!st.IsAvailable || !st.IsReadyForPlace(ModuleName.CarrierRobot, 0))
  894. continue;
  895. var fimsDevice = DEVICE.GetDevice<IoFIMS>($"PM1.{st.Module}");
  896. if (CarrierManager.Instance.CheckNoCarrier(st.Module, 0) && fimsDevice.IsUnloadCompleted)
  897. {
  898. fims = st;
  899. break;
  900. }
  901. }
  902. if (fims != null)
  903. {
  904. if (_carrierRobot.Place(fims.Module, 0, Hand.Blade1))
  905. {
  906. fims.WaitTransfer(ModuleName.CarrierRobot);
  907. return;
  908. }
  909. }
  910. }
  911. }
  912. public List<CarrierPara> GetTransferJobStockers()
  913. {
  914. if (!_lstTransferJobs.Any())
  915. return null;
  916. var tj = _lstTransferJobs.Find(x => x.State == EnumTransferJobState.Active);
  917. if (tj == null || tj.CarrierParas == null)
  918. return null;
  919. return tj.CarrierParas;
  920. }
  921. #endregion
  922. #region Job task
  923. public Result MonitorJobTasks()
  924. {
  925. UpdateTransferJobStatus();
  926. StartNewJob();
  927. return Result.RUN;
  928. }
  929. private void UpdateTransferJobStatus()
  930. {
  931. if (!_lstTransferJobs.Any())
  932. return;
  933. if (!_carrierRobot.IsAvailable)
  934. return;
  935. List<TransferJobInfo> removeJobLst = new List<TransferJobInfo>();
  936. foreach (var tj in _lstTransferJobs)
  937. {
  938. if (tj == null || tj.CarrierParas == null)
  939. continue;
  940. bool isComplete = true;
  941. if (tj.Type == EnumTransferJobType.Loading)
  942. {
  943. foreach (var item in tj.CarrierParas)
  944. {
  945. if (!CarrierManager.Instance.CheckHasCarrier(item.Stocker, 0))
  946. {
  947. isComplete = false;
  948. continue;
  949. }
  950. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  951. if (carrier != null && (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded))
  952. {
  953. isComplete = false;
  954. continue;
  955. }
  956. if (carrier != null)
  957. {
  958. if (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded)
  959. {
  960. isComplete = false;
  961. continue;
  962. }
  963. else
  964. {
  965. if (!item.HasTrigEvent)
  966. {
  967. Task.Delay(1000).ContinueWith(x =>
  968. {
  969. _faCallback.CarrierInEnd(item.Stocker);
  970. });
  971. item.HasTrigEvent = true;
  972. }
  973. }
  974. }
  975. }
  976. }
  977. else
  978. {
  979. foreach (var item in tj.CarrierParas)
  980. {
  981. if (!item.IsUnloaded)
  982. continue;
  983. if (!item.HasTrigEvent)
  984. {
  985. foreach (var lp in _lstLPs)
  986. {
  987. if (item.TargetPort == lp.Module)
  988. {
  989. var carrier = CarrierManager.Instance.GetCarrier(item.TargetPort, 0);
  990. if (carrier != null && !carrier.IsEmpty)
  991. {
  992. _faCallback.CarrierOutEnd(carrier);
  993. item.HasTrigEvent = true;
  994. break;
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. foreach (var lp in _lstLPs)
  1001. {
  1002. if (tj.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1003. {
  1004. if (CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
  1005. {
  1006. isComplete = false;
  1007. continue;
  1008. }
  1009. }
  1010. }
  1011. if (tj.CarrierParas.Any(x => !x.IsUnloaded))
  1012. {
  1013. isComplete = false;
  1014. continue;
  1015. }
  1016. }
  1017. if (isComplete)
  1018. {
  1019. tj.State = EnumTransferJobState.Complete;
  1020. removeJobLst.Add(tj);
  1021. string stocker = "";
  1022. tj.CarrierParas.ForEach(x => stocker += $"{x.Stocker}-");
  1023. LOG.Write($"Scheduler:{stocker} {tj.Type} change to complete");
  1024. if (tj.Type == EnumTransferJobType.Loading)
  1025. {
  1026. List<ModuleName> unloadLPs = new List<ModuleName>();
  1027. foreach (var item in tj.CarrierParas)
  1028. {
  1029. if (!unloadLPs.Contains(item.TargetPort) &&
  1030. !_lstTransferJobs.Any(x => (x.State == EnumTransferJobState.Created || x.State == EnumTransferJobState.Active) &&
  1031. x.CarrierParas.Any(ca => ca.TargetPort == item.TargetPort)))
  1032. unloadLPs.Add(item.TargetPort);
  1033. }
  1034. //foreach (var lp in unloadLPs)
  1035. //{
  1036. // (Singleton<EquipmentManager>.Instance.Modules[lp] as LoadPortModule).InvokeUnload();
  1037. // LOG.Write($"Scheduler:{lp} start unload");
  1038. //}
  1039. }
  1040. }
  1041. }
  1042. foreach (var item in removeJobLst)
  1043. {
  1044. _lstTransferJobs.Remove(item);
  1045. }
  1046. }
  1047. private void StartNewJob()
  1048. {
  1049. if (!_lstTransferJobs.Any() || !_carrierRobot.IsAvailable)
  1050. return;
  1051. //没有在process的stocker时,以时间先后为准
  1052. var processingStockers = Singleton<EquipmentManager>.Instance.GetProcessingStockers();
  1053. if (processingStockers != null)
  1054. {
  1055. //有在process的stocker时,以时间先后和所有stokcer都不在process为准
  1056. foreach (var tj in _lstTransferJobs)
  1057. {
  1058. if (tj == null || tj.CarrierParas == null)
  1059. continue;
  1060. bool hasStokcerInProcessing = false;
  1061. foreach (var item in tj.CarrierParas)
  1062. {
  1063. if (processingStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1064. {
  1065. hasStokcerInProcessing = true;
  1066. break;
  1067. }
  1068. }
  1069. if (!hasStokcerInProcessing)
  1070. {
  1071. break;
  1072. }
  1073. }
  1074. }
  1075. var tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Loading);
  1076. if (tjActives.Any())
  1077. {
  1078. foreach (var tjActive in tjActives)
  1079. {
  1080. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Loading)
  1081. {
  1082. bool isStockerReady = true;
  1083. foreach (var stocker in _lstTotlaStockers)
  1084. {
  1085. if (CarrierManager.Instance.CheckHasCarrier(stocker.Module, 0))
  1086. {
  1087. var carrier = CarrierManager.Instance.GetCarrier(stocker.Module, 0);
  1088. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1089. isStockerReady = false;
  1090. }
  1091. }
  1092. if (CarrierManager.Instance.CheckHasCarrier(_carrierRobot.Module, 0))
  1093. {
  1094. var carrier = CarrierManager.Instance.GetCarrier(_carrierRobot.Module, 0);
  1095. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1096. isStockerReady = false;
  1097. }
  1098. foreach (var fims in _lstFIMSs)
  1099. {
  1100. if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  1101. {
  1102. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  1103. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1104. isStockerReady = false;
  1105. }
  1106. }
  1107. if (isStockerReady)
  1108. {
  1109. //transfer job开始
  1110. tjActive.State = EnumTransferJobState.Active;
  1111. }
  1112. if (tjActive.State == EnumTransferJobState.Active)
  1113. {
  1114. foreach (var lp in _lstLPs)
  1115. {
  1116. if (!lp.IsAvailable)
  1117. continue;
  1118. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1119. continue;
  1120. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Unloading);
  1127. if (tjActives.Any())
  1128. {
  1129. foreach (var tjActive in tjActives)
  1130. {
  1131. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Unloading)
  1132. {
  1133. bool isStockerReady = true;
  1134. var allPJStockers = Singleton<EquipmentManager>.Instance.GetAllPJStockers();
  1135. foreach (var item in tjActive.CarrierParas)
  1136. {
  1137. if (CarrierManager.Instance.CheckNoCarrier(item.Stocker, 0))
  1138. {
  1139. isStockerReady = false;
  1140. continue;
  1141. }
  1142. if (allPJStockers != null && allPJStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1143. {
  1144. isStockerReady = false;
  1145. continue;
  1146. }
  1147. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  1148. if (carrier != null && item.Stocker != carrier.InternalModuleName)
  1149. isStockerReady = false;
  1150. }
  1151. if (isStockerReady)
  1152. {
  1153. //transfer job开始
  1154. tjActive.State = EnumTransferJobState.Active;
  1155. }
  1156. if (tjActive.State == EnumTransferJobState.Active)
  1157. {
  1158. foreach (var lp in _lstLPs)
  1159. {
  1160. if (!lp.IsAvailable)
  1161. continue;
  1162. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1163. continue;
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. internal List<TransferJobInfo> GetFirstCreatedTransferJob(EnumTransferJobType type)
  1171. {
  1172. DateTime dtMin = DateTime.MaxValue;
  1173. List<TransferJobInfo> currentTj = new List<TransferJobInfo>();
  1174. var lpNumber = 2;
  1175. List<ModuleName> occupyLPs = new List<ModuleName>();
  1176. foreach (var tj in _lstTransferJobs)
  1177. {
  1178. if (tj == null || tj.State == EnumTransferJobState.Active || tj.State == EnumTransferJobState.Complete || tj.Type != type)
  1179. {
  1180. continue;
  1181. }
  1182. if (occupyLPs.Count == lpNumber)
  1183. break;
  1184. currentTj.Add(tj);
  1185. foreach (var para in tj.CarrierParas)
  1186. {
  1187. if (type == EnumTransferJobType.Loading && !para.IsLoaded && !occupyLPs.Any(x => x == para.TargetPort))
  1188. occupyLPs.Add(para.TargetPort);
  1189. if (type == EnumTransferJobType.Unloading && !para.IsUnloaded && !occupyLPs.Any(x => x == para.TargetPort))
  1190. occupyLPs.Add(para.TargetPort);
  1191. }
  1192. }
  1193. return currentTj;
  1194. }
  1195. public List<string> GetOccupyStockers()
  1196. {
  1197. var occupyStockers = new List<string>();
  1198. var checkModuleLst = new List<ModuleName>();
  1199. checkModuleLst.Add(ModuleName.CarrierRobot);
  1200. foreach (var fims in _lstFIMSs)
  1201. {
  1202. if (fims == null)
  1203. continue;
  1204. checkModuleLst.Add(fims.Module);
  1205. }
  1206. foreach (var stocker in _lstTotlaStockers)
  1207. {
  1208. if (stocker == null)
  1209. continue;
  1210. checkModuleLst.Add(stocker.Module);
  1211. }
  1212. foreach (var module in checkModuleLst)
  1213. {
  1214. var carrier = CarrierManager.Instance.GetCarrier(module, 0);
  1215. if (carrier == null || carrier.IsEmpty)
  1216. continue;
  1217. occupyStockers.Add(carrier.InternalModuleName.ToString());
  1218. }
  1219. var loadCarrierParas = new List<CarrierPara>();
  1220. if (_lstTransferJobs.Any())
  1221. {
  1222. foreach (var tj in _lstTransferJobs)
  1223. {
  1224. if (tj == null || tj.Type != EnumTransferJobType.Loading)
  1225. continue;
  1226. loadCarrierParas.AddRange(tj.CarrierParas);
  1227. }
  1228. }
  1229. if (loadCarrierParas != null && loadCarrierParas.Any())
  1230. {
  1231. foreach (var para in loadCarrierParas)
  1232. {
  1233. occupyStockers.Add(para.Stocker.ToString());
  1234. }
  1235. }
  1236. return occupyStockers;
  1237. }
  1238. #endregion
  1239. }
  1240. }