WaferManager.cs 32 KB

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