TransferJob.cs 60 KB

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