TransferJob.cs 62 KB

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