WaferManager.cs 31 KB

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