WaferManager.cs 30 KB

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