RecipeParserByPort1ToN.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.Common;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  13. namespace Aitex.Sorter.RT.Module.Recipe
  14. {
  15. public class RecipeParserByPort1ToN
  16. {
  17. public List<TransferInfo> Parse(SorterRecipeXml xmlRecipe, out string reason)
  18. {
  19. List<TransferInfo> result = new List<TransferInfo>();
  20. reason = string.Empty;
  21. List<WaferInfo[]> wafersInSourceList = new List<WaferInfo[]>();
  22. List<WaferInfo[]> wafersInDestinationList = new List<WaferInfo[]>();
  23. List<ModuleName> destinationModules = new List<ModuleName>();
  24. bool isLoad = false;
  25. for (int i = 0; i < xmlRecipe.Source.Count; i++)
  26. {
  27. LoadPort lp = DEVICE.GetDevice<LoadPort>(xmlRecipe.Source[i].ToString());
  28. if (lp.IsEnableTransferWafer(out reason))
  29. {
  30. isLoad = true;
  31. WaferInfo[] wafersInSource = WaferManager.Instance.GetWafers(xmlRecipe.Source[i]);
  32. wafersInSourceList.Add(wafersInSource);
  33. }
  34. }
  35. if (!isLoad)
  36. {
  37. if (string.IsNullOrEmpty(reason))
  38. reason = "Source is not valid for transfer.";
  39. return result;
  40. }
  41. reason = string.Empty;
  42. isLoad = false;
  43. for (int i = 0; i < xmlRecipe.Destination.Count; i++)
  44. {
  45. LoadPort lp = DEVICE.GetDevice<LoadPort>(xmlRecipe.Destination[i].ToString());
  46. if (lp.IsEnableTransferWafer(out reason))
  47. {
  48. isLoad = true;
  49. if (!lp.IsEnableTransferWafer())
  50. continue;
  51. destinationModules.Add(xmlRecipe.Destination[i]);
  52. WaferInfo[] wafersInDestination = WaferManager.Instance.GetWafers(xmlRecipe.Destination[i]);
  53. wafersInDestinationList.Add(wafersInDestination);
  54. }
  55. }
  56. if (!isLoad)
  57. {
  58. if (string.IsNullOrEmpty(reason))
  59. reason = "Destination is not valid for transfer..";
  60. return result;
  61. }
  62. if (wafersInSourceList.Count == 0 || wafersInDestinationList.Count == 0)
  63. {
  64. reason = "Recipe has no vaild transfer task.";
  65. return result;
  66. }
  67. switch (xmlRecipe.PlaceModeTransfer1To1)
  68. {
  69. case SorterRecipePlaceModeTransfer1To1.FromBottom:
  70. FromBottom(xmlRecipe, wafersInSourceList, wafersInDestinationList, destinationModules, ref result, out reason);
  71. break;
  72. case SorterRecipePlaceModeTransfer1To1.FromTop:
  73. FromTop(xmlRecipe, wafersInSourceList, wafersInDestinationList, destinationModules, ref result, out reason);
  74. break;
  75. case SorterRecipePlaceModeTransfer1To1.SameSlot:
  76. SameSlot(xmlRecipe, wafersInSourceList, wafersInDestinationList, destinationModules, ref result, out reason);
  77. break;
  78. default:
  79. reason = string.Format("recipe PlaceModeTransfer1To1 {0} not valid", xmlRecipe.PlaceModeTransfer1To1);
  80. return result;
  81. }
  82. //if (result.Count == 0)
  83. // reason = "Recipe has no vaild transfer task.";
  84. return result;
  85. }
  86. /// <summary>
  87. /// 从source最下面开始取wafer,顺序放在destination的最下面
  88. /// </summary>
  89. /// <param name="lst"></param>
  90. /// <param name="reason"></param>
  91. /// <returns></returns>
  92. bool FromBottom(SorterRecipeXml xmlRecipe, List<WaferInfo[]> sourceList, List<WaferInfo[]> destinationList, List<ModuleName> destinationModules, ref List<TransferInfo> lst, out string reason)
  93. {
  94. reason = string.Empty;
  95. SCConfigItem _scLP2Pitch = SC.GetConfigItem("LoadPort.LoadPort2Pitch");
  96. if (_scLP2Pitch == null || _scLP2Pitch.IntValue == 10)
  97. {
  98. int destinationIndex = -1;
  99. for (int i = 0; i < sourceList.Count * sourceList[0].Length; i++)
  100. {
  101. WaferInfo[] source = sourceList[i / sourceList[0].Length];
  102. if (source[i % sourceList[0].Length].IsEmpty)
  103. continue;
  104. int to = destinationIndex;
  105. for (int j = destinationIndex + 1; j < destinationList.Count * destinationList[0].Length; j++)
  106. {
  107. WaferInfo[] destination = destinationList[j / destinationList[0].Length];
  108. if (destination[j % destinationList[0].Length].IsEmpty)
  109. {
  110. to = j;
  111. break;
  112. }
  113. }
  114. if (to == destinationIndex)
  115. break;
  116. destinationIndex = to;
  117. lst.Add(new TransferInfo()
  118. {
  119. Source = (ModuleName)source[i % sourceList[0].Length].Station,
  120. SourceSlot = source[i % sourceList[0].Length].Slot,
  121. Angle = xmlRecipe.AlignAngle,
  122. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  123. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  124. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None) | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  125. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  126. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  127. Slot = to % destinationList[0].Length,
  128. Station = destinationModules[to / destinationList[0].Length],
  129. WaferID = source[i % sourceList[0].Length].WaferID,
  130. }); ;
  131. }
  132. }
  133. else
  134. {
  135. if (sourceList.Count > 1 || destinationList.Count > 1)
  136. {
  137. reason = "Multiple Sources and Destinations are not supported in SameSlot mode";
  138. return false;
  139. }
  140. int destinationIndex = -1;
  141. SCConfigItem _scEnable = SC.GetConfigItem("LoadPort.EnableSlot1OnLP2");
  142. bool isContinue = false;
  143. for (int i = 0; i < sourceList[0].Length; i++)
  144. {
  145. WaferInfo[] source = sourceList[0];
  146. if (isContinue && source[i].IsEmpty)
  147. isContinue = false;
  148. if (source[i].IsEmpty)
  149. {
  150. continue;
  151. }
  152. if (!_scEnable.BoolValue && i == 0)
  153. {
  154. isContinue = true;
  155. continue;
  156. }
  157. if (isContinue)
  158. continue;
  159. int to = destinationIndex;
  160. for (int j = destinationIndex + 1; j < destinationList.Count * destinationList[0].Length; j++)
  161. {
  162. WaferInfo[] destination = destinationList[j / destinationList[0].Length];
  163. if (destination[j % destinationList[0].Length].IsEmpty)
  164. {
  165. to = j;
  166. break;
  167. }
  168. }
  169. if (to == destinationIndex)
  170. break;
  171. destinationIndex = to;
  172. lst.Add(new TransferInfo()
  173. {
  174. Source = (ModuleName)source[i % sourceList[0].Length].Station,
  175. SourceSlot = source[i % sourceList[0].Length].Slot,
  176. Angle = xmlRecipe.AlignAngle,
  177. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  178. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  179. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None)
  180. | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  181. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  182. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  183. Slot = to % destinationList[0].Length,
  184. Station = destinationModules[to / destinationList[0].Length],
  185. WaferID = source[i % sourceList[0].Length].WaferID,
  186. });
  187. }
  188. }
  189. return true;
  190. }
  191. /// <summary>
  192. /// 放在同一位置,如果有冲突,直接忽略
  193. /// </summary>
  194. /// <param name="lst"></param>
  195. /// <param name="reason"></param>
  196. /// <returns></returns>
  197. bool SameSlot(SorterRecipeXml xmlRecipe, List<WaferInfo[]> sourceList, List<WaferInfo[]> destinationList, List<ModuleName> destinationModules, ref List<TransferInfo> lst, out string reason)
  198. {
  199. reason = string.Empty;
  200. if (sourceList.Count > 1 || destinationList.Count > 1)
  201. {
  202. reason = "Multiple Sources and Destinations are not supported in SameSlot mode";
  203. return false;
  204. }
  205. WaferInfo[] source = sourceList[0];
  206. WaferInfo[] destination = destinationList[0];
  207. //int destinationIndex = -1;
  208. SCConfigItem _scLP2Pitch = SC.GetConfigItem("LoadPort.LoadPort2Pitch");
  209. if (_scLP2Pitch == null || _scLP2Pitch.IntValue == 10)
  210. {
  211. for (int i = 0; i < source.Length && i < destination.Length; i++)
  212. {
  213. if (source[i].IsEmpty || (!destination[i].IsEmpty && !(source[i].Station == destination[i].Station
  214. && source[i].Slot == destination[i].Slot)))
  215. continue;
  216. lst.Add(new TransferInfo()
  217. {
  218. Source = (ModuleName)source[i].Station,
  219. SourceSlot = source[i].Slot,
  220. Angle = xmlRecipe.AlignAngle,
  221. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  222. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  223. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None) | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  224. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  225. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  226. Slot = i,
  227. Station = destinationModules[0],
  228. WaferID = source[i].WaferID,
  229. });
  230. }
  231. }
  232. else if (_scLP2Pitch.IntValue == 7 && xmlRecipe.Destination[0] == ModuleName.LP2)
  233. {
  234. SCConfigItem _scEnable = SC.GetConfigItem("LoadPort.EnableSlot1OnLP2");
  235. for (int i = source.Length - 1; i >= 0; i--)
  236. {
  237. if (source[i].IsEmpty || !destination[i].IsEmpty || (!_scEnable.BoolValue && i == 0) || (i > 0 && !destination[i - 1].IsEmpty))
  238. continue;
  239. lst.Add(new TransferInfo()
  240. {
  241. Source = (ModuleName)source[i].Station,
  242. SourceSlot = source[i].Slot,
  243. Angle = xmlRecipe.AlignAngle,
  244. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  245. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  246. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None)
  247. | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  248. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  249. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  250. Slot = i,
  251. Station = destinationModules[0],
  252. WaferID = source[i].WaferID,
  253. });
  254. }
  255. }
  256. else if ((_scLP2Pitch.IntValue == 7 && xmlRecipe.Source[0] == ModuleName.LP2))
  257. {
  258. SCConfigItem _scEnable = SC.GetConfigItem("LoadPort.EnableSlot1OnLP2");
  259. bool isContinue = false;
  260. for (int i = 0; i < source.Length && i < destination.Length; i++)
  261. {
  262. if (isContinue && source[i].IsEmpty)
  263. isContinue = false;
  264. if (source[i].IsEmpty || !destination[i].IsEmpty)
  265. continue;
  266. if (!_scEnable.BoolValue && i == 0 || (i > 0 && !destination[i - 1].IsEmpty))
  267. {
  268. isContinue = true;
  269. continue;
  270. }
  271. if (isContinue)
  272. continue;
  273. lst.Add(new TransferInfo()
  274. {
  275. Source = (ModuleName)source[i].Station,
  276. SourceSlot = source[i].Slot,
  277. Angle = xmlRecipe.AlignAngle,
  278. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  279. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  280. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None)
  281. | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  282. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  283. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  284. Slot = i,
  285. Station = destinationModules[0],
  286. WaferID = source[i].WaferID,
  287. });
  288. }
  289. }
  290. return true;
  291. }
  292. /// <summary>
  293. /// 从source最上面开始取wafer,顺序放在destination的最上面
  294. /// </summary>
  295. /// <param name="lst"></param>
  296. /// <param name="reason"></param>
  297. /// <returns></returns>
  298. bool FromTop(SorterRecipeXml xmlRecipe, List<WaferInfo[]> sourceList, List<WaferInfo[]> destinationList, List<ModuleName> destinationModules, ref List<TransferInfo> lst, out string reason)
  299. {
  300. reason = string.Empty;
  301. SCConfigItem _scLP2Pitch = SC.GetConfigItem("LoadPort.LoadPort2Pitch");
  302. if (_scLP2Pitch == null || _scLP2Pitch.IntValue == 10)
  303. {
  304. int destinationIndex = destinationList.Count * destinationList[0].Length;
  305. for (int i = 0; i < sourceList.Count * sourceList[0].Length; i++)
  306. {
  307. WaferInfo[] source = sourceList[sourceList.Count - i / sourceList[0].Length - 1];
  308. if (source[i % sourceList[0].Length].IsEmpty)
  309. continue;
  310. if (SC.ContainsItem("Process.EnableSlot25OnLP2") && (!SC.GetValue<bool>("Process.EnableSlot25OnLP2")) && destinationModules[0] == ModuleName.LP2 && destinationIndex == 25)
  311. destinationIndex = 24;
  312. int to = destinationIndex;
  313. for (int j = destinationIndex - 1; j >= 0; j--)
  314. {
  315. WaferInfo[] destination = destinationList[destinationList.Count - j / destinationList[0].Length - 1];
  316. if (destination[j % destinationList[0].Length].IsEmpty)
  317. {
  318. to = j;
  319. break;
  320. }
  321. }
  322. if (to == destinationIndex)
  323. break;
  324. destinationIndex = to;
  325. lst.Add(new TransferInfo()
  326. {
  327. Source = (ModuleName)source[i % sourceList[0].Length].Station,
  328. SourceSlot = source[i % sourceList[0].Length].Slot,
  329. Angle = xmlRecipe.AlignAngle,
  330. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  331. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  332. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None) | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  333. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  334. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  335. Slot = to % destinationList[0].Length,
  336. Station = destinationModules[destinationList.Count - to / destinationList[0].Length - 1],
  337. WaferID = source[i % sourceList[0].Length].WaferID,
  338. });
  339. }
  340. }
  341. else
  342. {
  343. if (sourceList.Count > 1 || destinationList.Count > 1)
  344. {
  345. reason = "Multiple Sources and Destinations are not supported in SameSlot mode";
  346. return false;
  347. }
  348. SCConfigItem _scEnable = SC.GetConfigItem("LoadPort.EnableSlot1OnLP2");
  349. if (xmlRecipe.Source[0] == ModuleName.LP2) //Source为LP2
  350. {
  351. bool isContinue = false;
  352. int destinationIndex = destinationList[0].Length;
  353. for (int i = 0; i < sourceList[0].Length; i++)
  354. {
  355. WaferInfo[] source = sourceList[0];
  356. if (isContinue && source[i].IsEmpty)
  357. isContinue = false;
  358. if (source[i].IsEmpty)
  359. continue;
  360. if (!_scEnable.BoolValue && i == 0)
  361. {
  362. isContinue = true;
  363. continue;
  364. }
  365. if (isContinue)
  366. continue;
  367. int to = destinationIndex;
  368. for (int j = destinationIndex - 1; j >= 0; j--)
  369. {
  370. WaferInfo[] destination = destinationList[0];
  371. if (destination[j].IsEmpty)
  372. {
  373. to = j;
  374. break;
  375. }
  376. }
  377. if (to == destinationIndex)
  378. break;
  379. destinationIndex = to;
  380. lst.Add(new TransferInfo()
  381. {
  382. Source = (ModuleName)source[i].Station,
  383. SourceSlot = source[i].Slot,
  384. Angle = xmlRecipe.AlignAngle,
  385. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  386. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  387. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None)
  388. | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  389. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  390. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  391. Slot = to,
  392. Station = destinationModules[0],
  393. WaferID = source[i].WaferID,
  394. });
  395. }
  396. }
  397. else //Station为LP2
  398. {
  399. int destinationIndex = destinationList[0].Length;
  400. if (SC.ContainsItem("Process.EnableSlot25OnLP2") && (!SC.GetValue<bool>("Process.EnableSlot25OnLP2"))&& destinationIndex == 25)
  401. destinationIndex = 24;
  402. for (int i = sourceList[0].Length - 1; i >= 0; i--)
  403. {
  404. WaferInfo[] source = sourceList[0];
  405. if (source[i].IsEmpty)
  406. continue;
  407. int to = destinationIndex;
  408. for (int j = destinationIndex - 1; j >= 0; j--)
  409. {
  410. WaferInfo[] destination = destinationList[0];
  411. if (j == 0)
  412. {
  413. if (_scEnable.BoolValue)
  414. {
  415. if (destination[j].IsEmpty)
  416. {
  417. to = j;
  418. break;
  419. }
  420. }
  421. }
  422. else
  423. {
  424. if (destination[j - 1].IsEmpty && destination[j].IsEmpty)
  425. {
  426. to = j;
  427. break;
  428. }
  429. }
  430. }
  431. if (to == destinationIndex)
  432. break;
  433. destinationIndex = to;
  434. lst.Add(new TransferInfo()
  435. {
  436. Angle = xmlRecipe.AlignAngle,
  437. Option = (xmlRecipe.IsAlign ? MoveOption.Align : MoveOption.None)
  438. | (xmlRecipe.IsReadLaserMarker ? MoveOption.ReadID : MoveOption.None)
  439. | (xmlRecipe.IsReadT7Code ? MoveOption.ReadID2 : MoveOption.None)
  440. | (xmlRecipe.WaferReaderIndex == 1 ? MoveOption.Reader1 : MoveOption.None)
  441. | (xmlRecipe.WaferReaderIndex == 2 ? MoveOption.Reader2 : MoveOption.None)
  442. | (xmlRecipe.IsTurnOver ? MoveOption.Turnover : MoveOption.None),
  443. Slot = to,
  444. Station = destinationModules[0],
  445. WaferID = source[i].WaferID,
  446. });
  447. }
  448. }
  449. }
  450. return true;
  451. }
  452. }
  453. }