WaferManager.cs 30 KB

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