WaferManager.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.DataCenter;
  7. using Aitex.Core.RT.Event;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.RT.OperationCenter;
  10. using Aitex.Core.Util;
  11. using MECF.Framework.Common.DBCore;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.Utilities;
  14. using MECF.Framework.Common.Schedulers;
  15. using System.Diagnostics;
  16. namespace MECF.Framework.Common.SubstrateTrackings
  17. {
  18. public class WaferManager : Singleton<WaferManager>
  19. {
  20. Dictionary<string, WaferInfo> _dict = new Dictionary<string, WaferInfo>();
  21. object _lockerWaferList = new object();
  22. Dictionary<ModuleName, Dictionary<int, WaferInfo>> _locationWafers = new Dictionary<ModuleName, Dictionary<int, WaferInfo>>();
  23. List<DulicatedWaferInfo> _duplicatedWafers = new List<DulicatedWaferInfo>();
  24. private const string EventWaferLeft = "WAFER_LEFT_POSITION";
  25. private const string EventWaferArrive = "WAFER_ARRIVE_POSITION";
  26. public bool HasDuplicatedWafer => _duplicatedWafers.Count > 0;
  27. public WaferManager()
  28. {
  29. }
  30. public async void Serialize()
  31. {
  32. await Task.Run(() =>
  33. {
  34. try
  35. {
  36. if (_locationWafers != null)
  37. {
  38. BinarySerializer<Dictionary<ModuleName, Dictionary<int, WaferInfo>>>.ToStream(_locationWafers, "WaferManager");
  39. }
  40. }
  41. catch (Exception ex)
  42. {
  43. LOG.WriteExeption(ex);
  44. }
  45. });
  46. }
  47. public async void SerializeDuplicatedWaferInfo()
  48. {
  49. await Task.Run(() =>
  50. {
  51. try
  52. {
  53. BinarySerializer<List<DulicatedWaferInfo>>.ToStream(_duplicatedWafers, "DuplicatedWafers");
  54. }
  55. catch (Exception ex)
  56. {
  57. LOG.WriteExeption(ex);
  58. }
  59. });
  60. }
  61. public void Deserialize()
  62. {
  63. try
  64. {
  65. var ccc = BinarySerializer<Dictionary<ModuleName, Dictionary<int, WaferInfo>>>.FromStream("WaferManager");
  66. if (ccc != null)
  67. {
  68. foreach (var moduleWafers in ccc)
  69. {
  70. if (ModuleHelper.IsLoadPort(moduleWafers.Key))
  71. {
  72. foreach (var waferInfo in moduleWafers.Value)
  73. {
  74. waferInfo.Value.SetEmpty();
  75. }
  76. }
  77. }
  78. _locationWafers = ccc;
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. LOG.WriteExeption(ex);
  84. }
  85. }
  86. public void DeserializeDuplicatedWaferInfo()
  87. {
  88. try
  89. {
  90. var duplicatedWafers = BinarySerializer<List<DulicatedWaferInfo>>.FromStream("DuplicatedWafers");
  91. if (duplicatedWafers != null)
  92. {
  93. _duplicatedWafers = duplicatedWafers;
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. LOG.WriteExeption(ex);
  99. }
  100. }
  101. public void Initialize()
  102. {
  103. EV.Subscribe(new EventItem("Event", EventWaferLeft, "Wafer Left"));
  104. EV.Subscribe(new EventItem("Event", EventWaferArrive, "Wafer Arrived"));
  105. Deserialize();
  106. DeserializeDuplicatedWaferInfo();
  107. }
  108. public void SubscribeLocation(string module, int slotNumber)
  109. {
  110. ModuleName mod;
  111. if (Enum.TryParse(module, out mod))
  112. {
  113. SubscribeLocation(mod, slotNumber);
  114. }
  115. else
  116. {
  117. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed SubscribeLocation, module name invalid, {0} ", module));
  118. }
  119. }
  120. public void SubscribeLocation(ModuleName module, int slotNumber)
  121. {
  122. if (!_locationWafers.ContainsKey(module))
  123. {
  124. _locationWafers[module] = new Dictionary<int, WaferInfo>();
  125. for (int i = 0; i < slotNumber; i++)
  126. {
  127. _locationWafers[module][i] = new WaferInfo();
  128. }
  129. }
  130. DATA.Subscribe(module.ToString(), "ModuleWaferList", () => _locationWafers[module].Values.ToArray());
  131. DATA.Subscribe(module.ToString(), "HasWafer", () => CheckHasWafer(module,0),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  132. }
  133. public void WaferMoved(ModuleName moduleFrom, int slotFrom, ModuleName moduleTo, int slotTo)
  134. {
  135. if (_locationWafers[moduleFrom][slotFrom].IsEmpty)
  136. {
  137. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer move, no wafer at source, {0}{1}=>{2}{3}", moduleFrom, slotFrom+1, moduleTo, slotTo+1));
  138. return;
  139. }
  140. if (!_locationWafers[moduleTo][slotTo].IsEmpty)
  141. {
  142. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer move, destination has wafer, {0}{1}=>{2}{3}", moduleFrom, slotFrom + 1, moduleTo, slotTo + 1));
  143. return;
  144. }
  145. string waferOrigin = _locationWafers[moduleFrom][slotFrom].WaferOrigin;
  146. WaferInfo wafer = CopyWaferInfo(moduleTo, slotTo, _locationWafers[moduleFrom][slotFrom]);
  147. DeleteWafer(moduleFrom, slotFrom);
  148. //EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferMoved, waferOrigin, moduleFrom.ToString(), slotFrom + 1, moduleTo.ToString(), slotTo + 1);
  149. LOG.Write(eEvent.EV_WAFER_MOVED, ModuleName.System, waferOrigin, moduleFrom.ToString(), (slotFrom + 1).ToString(), moduleTo.ToString(), (slotTo + 1).ToString());
  150. WaferMoveHistoryRecorder.WaferMoved(wafer.InnerId.ToString(), moduleTo.ToString(), slotTo, wafer.Status.ToString());
  151. string fromCarrierId = "";
  152. if (ModuleHelper.IsLoadPort(moduleFrom))
  153. {
  154. fromCarrierId = CarrierManager.Instance.GetCarrier(moduleFrom.ToString()).CarrierId ?? "";
  155. }
  156. EV.Notify(EventWaferLeft, new SerializableDictionary<string, string>()
  157. {
  158. {"SLOT_NO", (slotTo+1).ToString("D2")},
  159. {"Slot", (slotTo+1).ToString("D2") },
  160. {"SlotID", (slotTo+1).ToString("D2") },
  161. {"WAFER_ID", wafer.WaferID},
  162. {"SubstID", wafer.WaferID},
  163. {"LotID", wafer.LotId},
  164. {"LOT_ID", wafer.LotId},
  165. { "CAR_ID", fromCarrierId},
  166. { "CarrierID", fromCarrierId},
  167. { "SubstLocID",((ModuleName)wafer.Station).ToString()},
  168. { "SubstLocState", "0" },
  169. {"SubstProcState",((int)wafer.ProcessState).ToString()},
  170. { "LEFT_POS_NAME", $"{moduleFrom}.{(slotFrom+1).ToString("D2")}" },
  171. { "LocationID", $"{moduleTo}.{(slotTo+1).ToString("D2")}" }
  172. });
  173. string toCarrierId = "";
  174. if (ModuleHelper.IsLoadPort(moduleTo))
  175. {
  176. toCarrierId = CarrierManager.Instance.GetCarrier(moduleTo.ToString()).CarrierId ?? "";
  177. }
  178. EV.Notify(EventWaferArrive, new SerializableDictionary<string, string>()
  179. {
  180. {"SLOT_NO", (slotTo+1).ToString("D2")},
  181. {"SlotID", (wafer.OriginSlot+1).ToString()},
  182. {"WAFER_ID", wafer.WaferID},
  183. { "SubstID", wafer.WaferID},
  184. { "LotID", wafer.LotId},
  185. {"LOT_ID", wafer.LotId},
  186. { "SubstLocID",((ModuleName)wafer.Station).ToString()},
  187. { "SubstLocState", "1" },
  188. { "SubstProcState",((int)wafer.ProcessState).ToString()},
  189. { "CAR_ID", toCarrierId},
  190. { "CarrierID", toCarrierId},
  191. { "ARRIVE_POS_NAME", $"{moduleTo}.{(slotTo+1).ToString("D2")}" },
  192. {"PortID", (wafer.OriginStation-(int)ModuleName.LP1+1).ToString()},
  193. { "LocationID", $"{moduleTo}.{(slotTo + 1).ToString("D2")}" }
  194. });
  195. Serialize();
  196. }
  197. public bool IsWaferSlotLocationValid(ModuleName module, int slot)
  198. {
  199. bool s = _locationWafers.ContainsKey(module) && _locationWafers[module].ContainsKey(slot);
  200. return _locationWafers.ContainsKey(module) && _locationWafers[module].ContainsKey(slot);
  201. }
  202. public WaferInfo[] GetWafers(ModuleName module)
  203. {
  204. return _locationWafers[module].Values.ToArray() ;
  205. }
  206. public WaferInfo[] GetWaferByProcessJob(string jobName)
  207. {
  208. List<WaferInfo> wafers = new List<WaferInfo>();
  209. foreach (var moduleWafer in _locationWafers)
  210. {
  211. foreach (var waferInfo in moduleWafer.Value)
  212. {
  213. if (waferInfo.Value!=null && !waferInfo.Value.IsEmpty
  214. && (waferInfo.Value.ProcessJob!=null)
  215. && waferInfo.Value.ProcessJob.Name == jobName)
  216. wafers.Add(waferInfo.Value);
  217. }
  218. }
  219. return wafers.ToArray();
  220. }
  221. public WaferInfo[] GetWafer(string waferID)
  222. {
  223. List<WaferInfo> result = new List<WaferInfo>();
  224. foreach (var locationWafer in _locationWafers)
  225. {
  226. foreach (var wafer in locationWafer.Value)
  227. {
  228. if (wafer.Value.WaferID == waferID)
  229. result.Add(wafer.Value);
  230. }
  231. }
  232. return result.ToArray();
  233. }
  234. public WaferInfo GetWafer(ModuleName module, int slot)
  235. {
  236. return _locationWafers[module][slot];
  237. }
  238. public string GetWaferID(ModuleName module, int slot)
  239. {
  240. return IsWaferSlotLocationValid(module, slot) ? _locationWafers[module][slot].WaferID: "";
  241. }
  242. public bool CheckNoWafer(ModuleName module, int slot)
  243. {
  244. return IsWaferSlotLocationValid(module, slot) && _locationWafers[module][slot].IsEmpty;
  245. }
  246. public bool CheckNoWafer(string module, int slot)
  247. {
  248. return CheckNoWafer((ModuleName)Enum.Parse(typeof(ModuleName), module), slot);
  249. }
  250. public bool CheckHasWafer(ModuleName module, int slot)
  251. {
  252. bool s = IsWaferSlotLocationValid(module, slot) && !_locationWafers[module][slot].IsEmpty;
  253. return IsWaferSlotLocationValid(module, slot) && !_locationWafers[module][slot].IsEmpty;
  254. }
  255. public bool CheckWaferIsDummy(ModuleName module, int slot)
  256. {
  257. return IsWaferSlotLocationValid(module, slot) && !_locationWafers[module][slot].IsEmpty
  258. && _locationWafers[module][slot].Status == WaferStatus.Dummy;
  259. }
  260. /// <summary>
  261. /// Verify the slot map in string[] format, if there's any mis-match it will return false.
  262. /// </summary>
  263. /// <param name="moduleNo">LP No</param>
  264. /// <param name="flagStrings">Flag input</param>
  265. /// <returns></returns>
  266. public bool CheckWaferExistFlag(string moduleNo, string[] flagStrings, out string reason)
  267. {
  268. var i = 0;
  269. reason = string.Empty;
  270. if (!Enum.TryParse($"LP{moduleNo}", out ModuleName module))
  271. {
  272. reason = "Port Number Error";
  273. return false;
  274. }
  275. foreach (var slot in flagStrings)
  276. {
  277. if (slot == "1")
  278. {
  279. if (IsWaferSlotLocationValid(module, i) && _locationWafers[module][i].IsEmpty)
  280. {
  281. reason = "Flag Mis-Match";
  282. return false;
  283. }
  284. }
  285. else
  286. {
  287. if (IsWaferSlotLocationValid(module, i) && !_locationWafers[module][i].IsEmpty)
  288. {
  289. reason = "Flag Mis-Match";
  290. return false;
  291. }
  292. }
  293. i++;
  294. }
  295. return true;
  296. }
  297. public bool CheckHasWafer(string module, int slot)
  298. {
  299. return CheckHasWafer((ModuleName)Enum.Parse(typeof(ModuleName), module), slot);
  300. }
  301. public bool CheckWaferFull(ModuleName module)
  302. {
  303. var wafers = _locationWafers[module];
  304. foreach (var waferInfo in wafers)
  305. {
  306. if (waferInfo.Value.IsEmpty)
  307. return false;
  308. }
  309. return true;
  310. }
  311. public bool CheckWaferEmpty(ModuleName module)
  312. {
  313. var wafers = _locationWafers[module];
  314. foreach (var waferInfo in wafers)
  315. {
  316. if (!waferInfo.Value.IsEmpty)
  317. return false;
  318. }
  319. return true;
  320. }
  321. public bool CheckWafer(ModuleName module, int slot, WaferStatus state)
  322. {
  323. if (module==ModuleName.Robot && slot == 2)
  324. {
  325. return IsWaferSlotLocationValid(module, 0) && (_locationWafers[module][0].Status==state)
  326. && IsWaferSlotLocationValid(module, 1) && (_locationWafers[module][1].Status==state);
  327. }
  328. return IsWaferSlotLocationValid(module, slot) && (_locationWafers[module][slot].Status==state);
  329. }
  330. public WaferInfo CreateWafer(ModuleName module, int slot, WaferStatus state)
  331. {
  332. if (!IsWaferSlotLocationValid(module, slot))
  333. {
  334. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer create, invalid parameter, {0},{1}", module, slot+1));
  335. return null;
  336. }
  337. string carrierInnerId = "";
  338. string carrierID = string.Empty;
  339. if (ModuleHelper.IsLoadPort(module))
  340. {
  341. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  342. if (carrier == null)
  343. {
  344. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System,
  345. string.Format("No carrier at {0}, can not create wafer", module));
  346. return null;
  347. }
  348. carrierInnerId = carrier.InnerId.ToString();
  349. carrierID = carrier.CarrierId;
  350. }
  351. lock (_lockerWaferList)
  352. {
  353. _locationWafers[module][slot].Status = state;
  354. _locationWafers[module][slot].ProcessState = EnumWaferProcessStatus.Idle;
  355. _locationWafers[module][slot].ChuckState = EnumWaferChuckStatus.Init;
  356. _locationWafers[module][slot].WaferID = GenerateWaferId(module, slot,"");
  357. _locationWafers[module][slot].WaferOrigin = GenerateOrigin(module, slot);
  358. _locationWafers[module][slot].Station = (int)module;
  359. _locationWafers[module][slot].Slot = slot;
  360. _locationWafers[module][slot].InnerId = Guid.NewGuid();
  361. _locationWafers[module][slot].OriginStation = (int)module;
  362. _locationWafers[module][slot].OriginSlot = slot;
  363. _locationWafers[module][slot].OriginCarrierID = carrierID;
  364. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  365. }
  366. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID);
  367. Serialize();
  368. return _locationWafers[module][slot];
  369. }
  370. public WaferInfo CreateWafer(ModuleName module, int slot, WaferStatus state,WaferSize wz)
  371. {
  372. if (!IsWaferSlotLocationValid(module, slot))
  373. {
  374. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer create, invalid parameter, {0},{1}", module, slot + 1));
  375. return null;
  376. }
  377. string carrierInnerId = "";
  378. string carrierID = string.Empty;
  379. if (ModuleHelper.IsLoadPort(module) )
  380. {
  381. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  382. if (carrier == null)
  383. {
  384. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("No carrier at {0}, can not create wafer.", module));
  385. return null;
  386. }
  387. carrierInnerId = carrier.InnerId.ToString();
  388. carrierID = carrier.CarrierId;
  389. }
  390. lock (_lockerWaferList)
  391. {
  392. _locationWafers[module][slot].Status = state;
  393. _locationWafers[module][slot].ProcessState = EnumWaferProcessStatus.Idle;
  394. _locationWafers[module][slot].ChuckState = EnumWaferChuckStatus.Init;
  395. _locationWafers[module][slot].WaferID = GenerateWaferId(module, slot, carrierID);
  396. _locationWafers[module][slot].WaferOrigin = GenerateOrigin(module, slot);
  397. _locationWafers[module][slot].Station = (int)module;
  398. _locationWafers[module][slot].Slot = slot;
  399. _locationWafers[module][slot].InnerId = Guid.NewGuid();
  400. _locationWafers[module][slot].OriginStation = (int)module;
  401. _locationWafers[module][slot].OriginSlot = slot;
  402. _locationWafers[module][slot].OriginCarrierID = carrierID;
  403. _locationWafers[module][slot].LotId = "";
  404. _locationWafers[module][slot].LaserMarker = "";
  405. _locationWafers[module][slot].T7Code = "";
  406. _locationWafers[module][slot].Size = wz;
  407. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  408. }
  409. LOG.Write(eEvent.EV_WAFER_MANAGER_NOTIFY, ModuleName.System, "System", $"Create wafer successfully on {module} slot:{slot+1} wafersize:{wz}.");
  410. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID );
  411. Serialize();
  412. return _locationWafers[module][slot];
  413. }
  414. public void CreateDuplicatedWafer(ModuleName source, int sourceSlot, ModuleName destination, int destSlot)
  415. {
  416. if (!IsWaferSlotLocationValid(source, sourceSlot))
  417. {
  418. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer source position for CreateDuplicatedWafer(), invalid parameter, {0},{1}", source, source + 1));
  419. return;
  420. }
  421. if (!IsWaferSlotLocationValid(destination, destSlot))
  422. {
  423. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer destination position for CreateDuplicatedWafer(), invalid parameter, {0},{1}", destination, destSlot + 1));
  424. return;
  425. }
  426. if (_locationWafers[source][sourceSlot].IsEmpty)
  427. {
  428. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("CreateDuplicatedWafer() failed, no wafer at source, {0}{1}=>{2}{3}", source, sourceSlot + 1, destination, destSlot + 1));
  429. return;
  430. }
  431. if (!_locationWafers[destination][destSlot].IsEmpty)
  432. {
  433. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("CreateDuplicatedWafer() failed, destination has wafer, {0}{1}=>{2}{3}", source, sourceSlot + 1, destination, destSlot + 1));
  434. return;
  435. }
  436. string waferOrigin = _locationWafers[source][sourceSlot].WaferOrigin;
  437. _locationWafers[source][sourceSlot].IsDuplicated = true;
  438. WaferInfo wafer = CopyWaferInfo(destination, destSlot, _locationWafers[source][sourceSlot]);
  439. _duplicatedWafers.Add(new DulicatedWaferInfo(wafer.InnerId, (int)source, sourceSlot, (int)destination, destSlot));
  440. LOG.Write(eEvent.EV_WAFER_DUPLICATED, ModuleName.System, waferOrigin, source.ToString(), (source + 1).ToString(), destination.ToString(), (destSlot + 1).ToString());
  441. Serialize();
  442. SerializeDuplicatedWaferInfo();
  443. }
  444. private void deleteDuplicatedWafer(ModuleName module, int slot)
  445. {
  446. var id = _locationWafers[module][slot].InnerId;
  447. var infoIndex = _duplicatedWafers.FindIndex(info => info.waferId == id && ((info.source == (int)module && info.sourceSlot == slot) || (info.destination == (int)module && info.destSlot == slot)));
  448. if(infoIndex == -1)
  449. {
  450. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Delete Duplicated Wafer failed, {0},{1}", module, slot + 1));
  451. return;
  452. }
  453. var duplicatgedInfo = _duplicatedWafers[infoIndex];
  454. var peerModule = duplicatgedInfo.source == (int)module ? duplicatgedInfo.destination : duplicatgedInfo.source;
  455. var peerSlot = duplicatgedInfo.source == (int)module ? duplicatgedInfo.destSlot : duplicatgedInfo.sourceSlot;
  456. if((_locationWafers[(ModuleName)peerModule][peerSlot].IsEmpty || !_locationWafers[(ModuleName)peerModule][peerSlot].IsDuplicated) && !ModuleHelper.IsLoadPort((ModuleName)peerModule))
  457. {
  458. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Delete Duplicated Wafer failed, the opponent wafer at {0},{1} is not a duplicated wafer", peerModule, peerSlot + 1));
  459. return;
  460. }
  461. _locationWafers[module][slot].SetEmpty();
  462. _locationWafers[(ModuleName)peerModule][peerSlot].IsDuplicated = false;
  463. _duplicatedWafers.RemoveAt(infoIndex);
  464. Serialize();
  465. SerializeDuplicatedWaferInfo();
  466. }
  467. public bool CheckDuplicatedWafersBeforeMove(Queue<MoveItem> moveItems)
  468. {
  469. foreach(var item in moveItems)
  470. {
  471. if (item.SourceModule == ModuleName.System)
  472. {
  473. return true;
  474. }
  475. if(_locationWafers[item.SourceModule][item.SourceSlot].IsEmpty)
  476. {
  477. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Cannot move wafer as no wafer at position:{0},{1}", item.SourceModule, item.SourceSlot + 1));
  478. return false;
  479. }
  480. if (_locationWafers[item.SourceModule][item.SourceSlot].IsDuplicated)
  481. {
  482. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Cannot move wafer as the wafer at position:{0},{1} is a duplicated wafer", item.SourceModule, item.SourceSlot + 1));
  483. return false;
  484. }
  485. }
  486. return true;
  487. }
  488. public void DeleteWafer(ModuleName module, int slotFrom, int count = 1)
  489. {
  490. lock (_lockerWaferList)
  491. {
  492. for (int i = 0; i < count; i++)
  493. {
  494. int slot = slotFrom+i;
  495. if (!IsWaferSlotLocationValid(module, slot))
  496. {
  497. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer delete, invalid parameter, {0},{1}", module, slot + 1));
  498. continue;
  499. }
  500. if(_locationWafers[module][slot].IsDuplicated)
  501. {
  502. deleteDuplicatedWafer(module, slotFrom);
  503. return;
  504. }
  505. WaferDataRecorder.DeleteWafer(_locationWafers[module][slot].InnerId.ToString());
  506. _locationWafers[module][slot].SetEmpty();
  507. _dict.Remove(_locationWafers[module][slot].WaferID);
  508. }
  509. }
  510. Serialize();
  511. }
  512. public void UpdateWaferLaser(ModuleName module, int slot, string laserMarker)
  513. {
  514. if (!IsWaferSlotLocationValid(module, slot))
  515. {
  516. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferLaser, invalid parameter, {0},{1}", module, slot + 1));
  517. return;
  518. }
  519. lock (_lockerWaferList)
  520. {
  521. _locationWafers[module][slot].LaserMarker = laserMarker;
  522. WaferDataRecorder.SetWaferMarker(_locationWafers[module][slot].InnerId.ToString(), laserMarker);
  523. }
  524. Serialize();
  525. }
  526. public void UpdateWaferT7Code(ModuleName module, int slot, string T7Code)
  527. {
  528. if (!IsWaferSlotLocationValid(module, slot))
  529. {
  530. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferT7Code, invalid parameter, {0},{1}", module, slot + 1));
  531. return;
  532. }
  533. lock (_lockerWaferList)
  534. {
  535. _locationWafers[module][slot].T7Code = T7Code;
  536. WaferDataRecorder.SetWaferT7Code(_locationWafers[module][slot].InnerId.ToString(), T7Code);
  537. }
  538. Serialize();
  539. }
  540. public void UpdateWaferTransFlag(ModuleName module, int slot, string flag)
  541. {
  542. if (!IsWaferSlotLocationValid(module, slot))
  543. {
  544. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferTransFlag, invalid parameter, {0},{1}", module, slot + 1));
  545. return;
  546. }
  547. lock (_lockerWaferList)
  548. {
  549. _locationWafers[module][slot].TransFlag = flag;
  550. }
  551. Serialize();
  552. }
  553. public void UpdateWaferNotch(ModuleName module, int slot, int angle)
  554. {
  555. if (!IsWaferSlotLocationValid(module, slot))
  556. {
  557. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferNotch, invalid parameter, {0},{1}", module, slot + 1));
  558. return;
  559. }
  560. lock (_lockerWaferList)
  561. {
  562. _locationWafers[module][slot].Notch = angle;
  563. }
  564. Serialize();
  565. }
  566. public void UpdateWaferProcessStatus(ModuleName module, int slot, EnumWaferProcessStatus status)
  567. {
  568. if (!IsWaferSlotLocationValid(module, slot))
  569. {
  570. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  571. return;
  572. }
  573. lock (_lockerWaferList)
  574. {
  575. _locationWafers[module][slot].ProcessState = status;
  576. }
  577. Serialize();
  578. }
  579. public void UpdateWaferChuckStatus(ModuleName module, int slot, EnumWaferChuckStatus status)
  580. {
  581. if (!IsWaferSlotLocationValid(module, slot))
  582. {
  583. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferChuckStatus, invalid parameter, {0},{1}", module, slot + 1));
  584. return;
  585. }
  586. lock (_lockerWaferList)
  587. {
  588. _locationWafers[module][slot].ChuckState = status;
  589. }
  590. Serialize();
  591. }
  592. public void UpdateWaferId(ModuleName module, int slot, string waferId)
  593. {
  594. if (!IsWaferSlotLocationValid(module, slot))
  595. {
  596. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferId, invalid parameter, {0},{1}", module, slot + 1));
  597. return;
  598. }
  599. lock (_lockerWaferList)
  600. {
  601. _locationWafers[module][slot].WaferID = waferId;
  602. }
  603. Serialize();
  604. }
  605. public void UpdateWaferLotId(ModuleName module, int slot, string lotId)
  606. {
  607. if (!IsWaferSlotLocationValid(module, slot))
  608. {
  609. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferLotId, invalid parameter, {0},{1}", module, slot + 1));
  610. return;
  611. }
  612. lock (_lockerWaferList)
  613. {
  614. _locationWafers[module][slot].LotId = lotId;
  615. }
  616. Serialize();
  617. }
  618. public void UpdateWaferProcessStatus(string waferID, EnumWaferProcessStatus status)
  619. {
  620. WaferInfo[] wafers = GetWafer(waferID);
  621. lock (_lockerWaferList)
  622. {
  623. foreach (var waferInfo in wafers)
  624. {
  625. waferInfo.ProcessState = status;
  626. }
  627. }
  628. Serialize();
  629. }
  630. public void UpdateWaferProcess(string waferID, string processId)
  631. {
  632. WaferInfo[] wafers = GetWafer(waferID);
  633. lock (_lockerWaferList)
  634. {
  635. foreach (var waferInfo in wafers)
  636. {
  637. WaferDataRecorder.SetProcessInfo(waferInfo.InnerId.ToString(), processId);
  638. }
  639. }
  640. Serialize();
  641. }
  642. public WaferInfo CopyWaferInfo(ModuleName module, int slot, WaferInfo wafer)
  643. {
  644. if (!IsWaferSlotLocationValid(module, slot))
  645. {
  646. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed CopyWaferInfo, invalid parameter, {0},{1}", module, slot + 1));
  647. return null;
  648. }
  649. lock (_lockerWaferList)
  650. {
  651. _locationWafers[module][slot].Update(wafer);
  652. _locationWafers[module][slot].Station = (int)module;
  653. _locationWafers[module][slot].Slot = slot;
  654. }
  655. return _locationWafers[module][slot];
  656. }
  657. public bool UpdateWaferSize(ModuleName module, int slot, WaferSize size)
  658. {
  659. if (!IsWaferSlotLocationValid(module, slot))
  660. {
  661. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferSize, invalid parameter, {0},{1}", module, slot + 1));
  662. return false;
  663. }
  664. lock (_lockerWaferList)
  665. {
  666. _locationWafers[module][slot].Size = size;
  667. }
  668. Serialize();
  669. return true;
  670. }
  671. private string GenerateWaferId(ModuleName module, int slot,string carrierID)
  672. {
  673. string carrierinfor = "";
  674. //5 + 2(unit) + 2(slot) + time(18) + index{5}
  675. if (string.IsNullOrEmpty(carrierID))
  676. carrierinfor = module.ToString() + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  677. else carrierinfor = carrierID;
  678. return string.Format($"{carrierinfor}.{(slot+1).ToString("00")}");
  679. }
  680. private string GenerateOrigin(ModuleName module, int slot)
  681. {
  682. return string.Format("{0}.{1:D2}", ModuleHelper.GetAbbr(module), slot + 1);
  683. }
  684. }
  685. }