TransferJob.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  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|| lpDevice.IsUnloadCompleted))
  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 || lpDevice.IsUnloadCompleted)
  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. if (carrier != null)
  947. {
  948. if (carrier.IsEmpty || (!carrier.IsMapped && !SC.GetValue<bool>("WaferRobot.BypassFIMSMap")) || !item.IsLoaded)
  949. {
  950. isComplete = false;
  951. continue;
  952. }
  953. else
  954. {
  955. if (!item.HasTrigEvent)
  956. {
  957. Task.Delay(1000).ContinueWith(x =>
  958. {
  959. _faCallback.CarrierInEnd(item.Stocker);
  960. });
  961. item.HasTrigEvent = true;
  962. }
  963. }
  964. }
  965. }
  966. }
  967. else
  968. {
  969. foreach (var item in tj.CarrierParas)
  970. {
  971. if (!item.IsUnloaded)
  972. continue;
  973. if (!item.HasTrigEvent)
  974. {
  975. foreach (var lp in _lstLPs)
  976. {
  977. if (item.TargetPort == lp.Module)
  978. {
  979. var carrier = CarrierManager.Instance.GetCarrier(item.TargetPort, 0);
  980. if (carrier != null && !carrier.IsEmpty)
  981. {
  982. _faCallback.CarrierOutEnd(carrier);
  983. item.HasTrigEvent = true;
  984. break;
  985. }
  986. }
  987. }
  988. }
  989. }
  990. foreach (var lp in _lstLPs)
  991. {
  992. if (tj.CarrierParas.Any(x => x.TargetPort == lp.Module))
  993. {
  994. if (CarrierManager.Instance.CheckHasCarrier(lp.Module, 0))
  995. {
  996. isComplete = false;
  997. continue;
  998. }
  999. }
  1000. }
  1001. if (tj.CarrierParas.Any(x => !x.IsUnloaded))
  1002. {
  1003. isComplete = false;
  1004. continue;
  1005. }
  1006. }
  1007. if (isComplete)
  1008. {
  1009. tj.State = EnumTransferJobState.Complete;
  1010. removeJobLst.Add(tj);
  1011. string stocker = "";
  1012. tj.CarrierParas.ForEach(x => stocker += $"{x.Stocker}-");
  1013. LOG.Write($"Scheduler:{stocker} {tj.Type} change to complete");
  1014. if (tj.Type == EnumTransferJobType.Loading)
  1015. {
  1016. List<ModuleName> unloadLPs = new List<ModuleName>();
  1017. foreach (var item in tj.CarrierParas)
  1018. {
  1019. if (!unloadLPs.Contains(item.TargetPort) &&
  1020. !_lstTransferJobs.Any(x => (x.State == EnumTransferJobState.Created || x.State == EnumTransferJobState.Active) &&
  1021. x.CarrierParas.Any(ca => ca.TargetPort == item.TargetPort)))
  1022. unloadLPs.Add(item.TargetPort);
  1023. }
  1024. //foreach (var lp in unloadLPs)
  1025. //{
  1026. // (Singleton<EquipmentManager>.Instance.Modules[lp] as LoadPortModule).InvokeUnload();
  1027. // LOG.Write($"Scheduler:{lp} start unload");
  1028. //}
  1029. }
  1030. }
  1031. }
  1032. foreach (var item in removeJobLst)
  1033. {
  1034. _lstTransferJobs.Remove(item);
  1035. }
  1036. }
  1037. private void StartNewJob()
  1038. {
  1039. if (!_lstTransferJobs.Any() || !_carrierRobot.IsAvailable)
  1040. return;
  1041. //没有在process的stocker时,以时间先后为准
  1042. var processingStockers = Singleton<EquipmentManager>.Instance.GetProcessingStockers();
  1043. if (processingStockers != null)
  1044. {
  1045. //有在process的stocker时,以时间先后和所有stokcer都不在process为准
  1046. foreach (var tj in _lstTransferJobs)
  1047. {
  1048. if (tj == null || tj.CarrierParas == null)
  1049. continue;
  1050. bool hasStokcerInProcessing = false;
  1051. foreach (var item in tj.CarrierParas)
  1052. {
  1053. if (processingStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1054. {
  1055. hasStokcerInProcessing = true;
  1056. break;
  1057. }
  1058. }
  1059. if (!hasStokcerInProcessing)
  1060. {
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. var tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Loading);
  1066. if (tjActives.Any())
  1067. {
  1068. foreach (var tjActive in tjActives)
  1069. {
  1070. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Loading)
  1071. {
  1072. bool isStockerReady = true;
  1073. foreach (var stocker in _lstTotlaStockers)
  1074. {
  1075. if (CarrierManager.Instance.CheckHasCarrier(stocker.Module, 0))
  1076. {
  1077. var carrier = CarrierManager.Instance.GetCarrier(stocker.Module, 0);
  1078. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1079. isStockerReady = false;
  1080. }
  1081. }
  1082. if (CarrierManager.Instance.CheckHasCarrier(_carrierRobot.Module, 0))
  1083. {
  1084. var carrier = CarrierManager.Instance.GetCarrier(_carrierRobot.Module, 0);
  1085. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1086. isStockerReady = false;
  1087. }
  1088. foreach (var fims in _lstFIMSs)
  1089. {
  1090. if (CarrierManager.Instance.CheckHasCarrier(fims.Module, 0))
  1091. {
  1092. var carrier = CarrierManager.Instance.GetCarrier(fims.Module, 0);
  1093. if (carrier != null && tjActive.CarrierParas.Any(x => x.Stocker == carrier.InternalModuleName))
  1094. isStockerReady = false;
  1095. }
  1096. }
  1097. if (isStockerReady)
  1098. {
  1099. //transfer job开始
  1100. tjActive.State = EnumTransferJobState.Active;
  1101. }
  1102. if (tjActive.State == EnumTransferJobState.Active)
  1103. {
  1104. foreach (var lp in _lstLPs)
  1105. {
  1106. if (!lp.IsAvailable)
  1107. continue;
  1108. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1109. continue;
  1110. var lpDevice = DEVICE.GetDevice<IoLP>($"PM1.{lp.Module}");
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }
  1116. tjActives = GetFirstCreatedTransferJob(EnumTransferJobType.Unloading);
  1117. if (tjActives.Any())
  1118. {
  1119. foreach (var tjActive in tjActives)
  1120. {
  1121. if (tjActive != null && tjActive.State == EnumTransferJobState.Created && tjActive.Type == EnumTransferJobType.Unloading)
  1122. {
  1123. bool isStockerReady = true;
  1124. var allPJStockers = Singleton<EquipmentManager>.Instance.GetAllPJStockers();
  1125. foreach (var item in tjActive.CarrierParas)
  1126. {
  1127. if (CarrierManager.Instance.CheckNoCarrier(item.Stocker, 0))
  1128. {
  1129. isStockerReady = false;
  1130. continue;
  1131. }
  1132. if (allPJStockers != null && allPJStockers.Any(x => x.Item1 == item.Stocker.ToString()))
  1133. {
  1134. isStockerReady = false;
  1135. continue;
  1136. }
  1137. var carrier = CarrierManager.Instance.GetCarrier(item.Stocker, 0);
  1138. if (carrier != null && item.Stocker != carrier.InternalModuleName)
  1139. isStockerReady = false;
  1140. }
  1141. if (isStockerReady)
  1142. {
  1143. //transfer job开始
  1144. tjActive.State = EnumTransferJobState.Active;
  1145. }
  1146. if (tjActive.State == EnumTransferJobState.Active)
  1147. {
  1148. foreach (var lp in _lstLPs)
  1149. {
  1150. if (!lp.IsAvailable)
  1151. continue;
  1152. if (!tjActive.CarrierParas.Any(x => x.TargetPort == lp.Module))
  1153. continue;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. internal List<TransferJobInfo> GetFirstCreatedTransferJob(EnumTransferJobType type)
  1161. {
  1162. DateTime dtMin = DateTime.MaxValue;
  1163. List<TransferJobInfo> currentTj = new List<TransferJobInfo>();
  1164. var lpNumber = 2;
  1165. List<ModuleName> occupyLPs = new List<ModuleName>();
  1166. foreach (var tj in _lstTransferJobs)
  1167. {
  1168. if (tj == null || tj.State == EnumTransferJobState.Active || tj.State == EnumTransferJobState.Complete || tj.Type != type)
  1169. {
  1170. continue;
  1171. }
  1172. if (occupyLPs.Count == lpNumber)
  1173. break;
  1174. currentTj.Add(tj);
  1175. foreach (var para in tj.CarrierParas)
  1176. {
  1177. if (type == EnumTransferJobType.Loading && !para.IsLoaded && !occupyLPs.Any(x => x == para.TargetPort))
  1178. occupyLPs.Add(para.TargetPort);
  1179. if (type == EnumTransferJobType.Unloading && !para.IsUnloaded && !occupyLPs.Any(x => x == para.TargetPort))
  1180. occupyLPs.Add(para.TargetPort);
  1181. }
  1182. }
  1183. return currentTj;
  1184. }
  1185. public List<string> GetOccupyStockers()
  1186. {
  1187. var occupyStockers = new List<string>();
  1188. var checkModuleLst = new List<ModuleName>();
  1189. checkModuleLst.Add(ModuleName.CarrierRobot);
  1190. foreach (var fims in _lstFIMSs)
  1191. {
  1192. if (fims == null)
  1193. continue;
  1194. checkModuleLst.Add(fims.Module);
  1195. }
  1196. foreach (var stocker in _lstTotlaStockers)
  1197. {
  1198. if (stocker == null)
  1199. continue;
  1200. checkModuleLst.Add(stocker.Module);
  1201. }
  1202. foreach (var module in checkModuleLst)
  1203. {
  1204. var carrier = CarrierManager.Instance.GetCarrier(module, 0);
  1205. if (carrier == null || carrier.IsEmpty)
  1206. continue;
  1207. occupyStockers.Add(carrier.InternalModuleName.ToString());
  1208. }
  1209. var loadCarrierParas = new List<CarrierPara>();
  1210. if (_lstTransferJobs.Any())
  1211. {
  1212. foreach (var tj in _lstTransferJobs)
  1213. {
  1214. if (tj == null || tj.Type != EnumTransferJobType.Loading)
  1215. continue;
  1216. loadCarrierParas.AddRange(tj.CarrierParas);
  1217. }
  1218. }
  1219. if (loadCarrierParas != null && loadCarrierParas.Any())
  1220. {
  1221. foreach (var para in loadCarrierParas)
  1222. {
  1223. occupyStockers.Add(para.Stocker.ToString());
  1224. }
  1225. }
  1226. return occupyStockers;
  1227. }
  1228. #endregion
  1229. }
  1230. }