WaferManager.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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)
  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. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  354. }
  355. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID);
  356. Serialize();
  357. MaterialTrackerManager.Instance.UpdateModuleMaterial(module.ToString());
  358. return _locationWafers[module][slot];
  359. }
  360. public WaferInfo CreateWafer(ModuleName module, int slot, WaferStatus state,WaferSize wz,WaferType waferType)
  361. {
  362. if (!IsWaferSlotLocationValid(module, slot))
  363. {
  364. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer create, invalid parameter, {0},{1}", module, slot + 1));
  365. return null;
  366. }
  367. string carrierInnerId = "";
  368. string carrierID = string.Empty;
  369. if (ModuleHelper.IsLoadPort(module) )
  370. {
  371. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  372. if (carrier == null)
  373. {
  374. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("No carrier at {0}, can not create wafer.", module));
  375. return null;
  376. }
  377. carrierInnerId = carrier.InnerId.ToString();
  378. carrierID = carrier.CarrierId;
  379. }
  380. lock (_lockerWaferList)
  381. {
  382. _locationWafers[module][slot].Status = state;
  383. _locationWafers[module][slot].WaferType = waferType;
  384. _locationWafers[module][slot].ProcessState = EnumWaferProcessStatus.Idle;
  385. _locationWafers[module][slot].ChuckState = EnumWaferChuckStatus.Init;
  386. _locationWafers[module][slot].WaferID = GenerateWaferId(module, slot, carrierID);
  387. _locationWafers[module][slot].WaferOrigin = GenerateOrigin(module, slot);
  388. _locationWafers[module][slot].Station = (int)module;
  389. _locationWafers[module][slot].Slot = slot;
  390. _locationWafers[module][slot].InnerId = Guid.NewGuid();
  391. _locationWafers[module][slot].OriginStation = (int)module;
  392. _locationWafers[module][slot].OriginSlot = slot;
  393. _locationWafers[module][slot].OriginCarrierID = carrierID;
  394. _locationWafers[module][slot].LotId = "";
  395. _locationWafers[module][slot].LaserMarker = "";
  396. _locationWafers[module][slot].T7Code = "";
  397. _locationWafers[module][slot].Size = wz;
  398. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  399. }
  400. LOG.WriteLog(eEvent.EV_WAFER_MANAGER_NOTIFY, ModuleName.System.ToString(), $"Create wafer successfully on {module} slot:{slot+1} wafersize:{wz}.");
  401. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID );
  402. Serialize();
  403. MaterialTrackerManager.Instance.UpdateModuleMaterial(module.ToString());
  404. return _locationWafers[module][slot];
  405. }
  406. public void DeleteWafer(string module, int slotFrom,int count=1)
  407. {
  408. if(Enum.TryParse(module,out ModuleName moduleName))
  409. {
  410. DeleteWafer(moduleName,slotFrom,count);
  411. }
  412. }
  413. public void DeleteWafer(ModuleName module, int slotFrom, int count = 1)
  414. {
  415. lock (_lockerWaferList)
  416. {
  417. for (int i = 0; i < count; i++)
  418. {
  419. int slot = slotFrom+i;
  420. if (!IsWaferSlotLocationValid(module, slot))
  421. {
  422. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Invalid wafer delete, invalid parameter, {0},{1}", module, slot + 1));
  423. continue;
  424. }
  425. WaferDataRecorder.DeleteWafer(_locationWafers[module][slot].InnerId.ToString());
  426. _locationWafers[module][slot].SetEmpty();
  427. _dict.Remove(_locationWafers[module][slot].WaferID);
  428. }
  429. }
  430. Serialize();
  431. MaterialTrackerManager.Instance.UpdateModuleMaterial(module.ToString());
  432. }
  433. /// <summary>
  434. /// 根据Id删除Wafer
  435. /// </summary>
  436. /// <param name="waferId"></param>
  437. public void DeleteWaferById(string waferId)
  438. {
  439. WaferInfo waferInfo=GetWaferByWaferId(waferId);
  440. WaferDataRecorder.DeleteWafer(waferId);
  441. if(waferInfo != null)
  442. {
  443. ModuleName station = (ModuleName)waferInfo.Station;
  444. waferInfo.SetEmpty();
  445. _dict.Remove(waferId);
  446. Serialize();
  447. MaterialTrackerManager.Instance.UpdateModuleMaterial(station.ToString());
  448. }
  449. }
  450. public void UpdateWaferLaser(ModuleName module, int slot, string laserMarker)
  451. {
  452. if (!IsWaferSlotLocationValid(module, slot))
  453. {
  454. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferLaser, invalid parameter, {0},{1}", module, slot + 1));
  455. return;
  456. }
  457. lock (_lockerWaferList)
  458. {
  459. _locationWafers[module][slot].LaserMarker = laserMarker;
  460. WaferDataRecorder.SetWaferMarker(_locationWafers[module][slot].InnerId.ToString(), laserMarker);
  461. }
  462. Serialize();
  463. }
  464. public void UpdateWaferT7Code(ModuleName module, int slot, string T7Code)
  465. {
  466. if (!IsWaferSlotLocationValid(module, slot))
  467. {
  468. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferT7Code, invalid parameter, {0},{1}", module, slot + 1));
  469. return;
  470. }
  471. lock (_lockerWaferList)
  472. {
  473. _locationWafers[module][slot].T7Code = T7Code;
  474. WaferDataRecorder.SetWaferT7Code(_locationWafers[module][slot].InnerId.ToString(), T7Code);
  475. }
  476. Serialize();
  477. }
  478. public void UpdateWaferTransFlag(ModuleName module, int slot, string flag)
  479. {
  480. if (!IsWaferSlotLocationValid(module, slot))
  481. {
  482. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferTransFlag, invalid parameter, {0},{1}", module, slot + 1));
  483. return;
  484. }
  485. lock (_lockerWaferList)
  486. {
  487. _locationWafers[module][slot].TransFlag = flag;
  488. }
  489. Serialize();
  490. }
  491. public void UpdateWaferNotch(ModuleName module, int slot, int angle)
  492. {
  493. if (!IsWaferSlotLocationValid(module, slot))
  494. {
  495. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferNotch, invalid parameter, {0},{1}", module, slot + 1));
  496. return;
  497. }
  498. lock (_lockerWaferList)
  499. {
  500. _locationWafers[module][slot].Notch = angle;
  501. }
  502. Serialize();
  503. }
  504. public void UpdateWaferProcessStatus(ModuleName module, int slot, EnumWaferProcessStatus status)
  505. {
  506. if (!IsWaferSlotLocationValid(module, slot))
  507. {
  508. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  509. return;
  510. }
  511. lock (_lockerWaferList)
  512. {
  513. _locationWafers[module][slot].ProcessState = status;
  514. WaferDataRecorder.SetWaferStatus(_locationWafers[module][slot].InnerId.ToString(), status.ToString());
  515. }
  516. Serialize();
  517. }
  518. public void UpdateWaferChuckStatus(ModuleName module, int slot, EnumWaferChuckStatus status)
  519. {
  520. if (!IsWaferSlotLocationValid(module, slot))
  521. {
  522. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferChuckStatus, invalid parameter, {0},{1}", module, slot + 1));
  523. return;
  524. }
  525. lock (_lockerWaferList)
  526. {
  527. _locationWafers[module][slot].ChuckState = status;
  528. }
  529. Serialize();
  530. }
  531. public void UpdateWaferId(ModuleName module, int slot, string waferId)
  532. {
  533. if (!IsWaferSlotLocationValid(module, slot))
  534. {
  535. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferId, invalid parameter, {0},{1}", module, slot + 1));
  536. return;
  537. }
  538. lock (_lockerWaferList)
  539. {
  540. _locationWafers[module][slot].WaferID = waferId;
  541. }
  542. Serialize();
  543. }
  544. public void UpdateWaferLotId(ModuleName module, int slot, string lotId)
  545. {
  546. if (!IsWaferSlotLocationValid(module, slot))
  547. {
  548. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferLotId, invalid parameter, {0},{1}", module, slot + 1));
  549. return;
  550. }
  551. lock (_lockerWaferList)
  552. {
  553. _locationWafers[module][slot].LotId = lotId;
  554. }
  555. Serialize();
  556. }
  557. public void UpdateWaferProcessStatus(string waferID, EnumWaferProcessStatus status)
  558. {
  559. WaferInfo[] wafers = GetWafer(waferID);
  560. lock (_lockerWaferList)
  561. {
  562. foreach (var waferInfo in wafers)
  563. {
  564. waferInfo.ProcessState = status;
  565. }
  566. }
  567. Serialize();
  568. }
  569. public void UpdateWaferProcess(string waferID, string processId)
  570. {
  571. WaferInfo[] wafers = GetWafer(waferID);
  572. lock (_lockerWaferList)
  573. {
  574. foreach (var waferInfo in wafers)
  575. {
  576. WaferDataRecorder.SetProcessInfo(waferInfo.InnerId.ToString(), processId);
  577. }
  578. }
  579. Serialize();
  580. }
  581. public WaferInfo CopyWaferInfo(ModuleName module, int slot, WaferInfo wafer)
  582. {
  583. if (!IsWaferSlotLocationValid(module, slot))
  584. {
  585. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed CopyWaferInfo, invalid parameter, {0},{1}", module, slot + 1));
  586. return null;
  587. }
  588. lock (_lockerWaferList)
  589. {
  590. _locationWafers[module][slot].Update(wafer);
  591. _locationWafers[module][slot].Station = (int)module;
  592. _locationWafers[module][slot].Slot = slot;
  593. }
  594. return _locationWafers[module][slot];
  595. }
  596. public bool UpdateWaferSize(ModuleName module, int slot, WaferSize size)
  597. {
  598. if (!IsWaferSlotLocationValid(module, slot))
  599. {
  600. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateWaferSize, invalid parameter, {0},{1}", module, slot + 1));
  601. return false;
  602. }
  603. lock (_lockerWaferList)
  604. {
  605. _locationWafers[module][slot].Size = size;
  606. }
  607. Serialize();
  608. return true;
  609. }
  610. /// <summary>
  611. /// 更新LotTrackPath
  612. /// </summary>
  613. /// <param name="module"></param>
  614. /// <param name="slot"></param>
  615. /// <param name="lotTrackPath"></param>
  616. public void UpdateWaferLotTrackPath(ModuleName module, int slot, string lotTrackPath)
  617. {
  618. if (!IsWaferSlotLocationValid(module, slot))
  619. {
  620. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateLotTrackPath, invalid parameter, {0},{1}", module, slot + 1));
  621. return;
  622. }
  623. lock (_lockerWaferList)
  624. {
  625. _locationWafers[module][slot].LotTrackPath = lotTrackPath;
  626. }
  627. Serialize();
  628. }
  629. /// <summary>
  630. /// 清楚WaferLotTrackPath
  631. /// </summary>
  632. /// <param name="module"></param>
  633. /// <param name="slot"></param>
  634. public void ClearWaferLotTrackPath(ModuleName module, int slot)
  635. {
  636. if (!IsWaferSlotLocationValid(module, slot))
  637. {
  638. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, string.Format("Failed UpdateLotTrackPath, invalid parameter, {0},{1}", module, slot + 1));
  639. return;
  640. }
  641. lock (_lockerWaferList)
  642. {
  643. _locationWafers[module][slot].LotTrackPath = "";
  644. }
  645. Serialize();
  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. /// <summary>
  661. /// 检验启动时缓存数据
  662. /// </summary>
  663. /// <returns></returns>
  664. public bool CheckStartUpCache(ref string reason)
  665. {
  666. if (CheckHasWafer(ModuleName.EfemRobot, 0))
  667. {
  668. reason = "EFEM Robot has wafer cache";
  669. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, reason);
  670. return false;
  671. }
  672. if (CheckHasWafer(ModuleName.Aligner1, 0))
  673. {
  674. reason = "EFEM Robot has wafer cache";
  675. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System,reason );
  676. return false;
  677. }
  678. if (CheckHasWafer(ModuleName.PUF1, 0))
  679. {
  680. reason = "PUF1 sideA has wafer cache";
  681. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System,reason );
  682. return false;
  683. }
  684. if (CheckHasWafer(ModuleName.PUF1, 1))
  685. {
  686. reason = "PUF1 sideB has wafer cache";
  687. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, reason);
  688. return false;
  689. }
  690. if (CheckHasWafer(ModuleName.PUF2, 0))
  691. {
  692. reason = "PUF2 sideA has wafer cache";
  693. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System, reason);
  694. return false;
  695. }
  696. if (CheckHasWafer(ModuleName.PUF2, 1))
  697. {
  698. reason = "PUF2 sideB has wafer cache";
  699. LOG.Write(eEvent.ERR_WAFER_MANAGER_FAILED, ModuleName.System,reason);
  700. return false;
  701. }
  702. return true;
  703. }
  704. public int WaferStatusConverter(WaferInfo awafer)
  705. {
  706. if (awafer.Status == WaferStatus.Empty)
  707. return 0;
  708. if (awafer.Status == WaferStatus.Normal)
  709. {
  710. if (awafer.WaferType == WaferType.Assit)
  711. {
  712. return 6;
  713. }
  714. else
  715. {
  716. switch (awafer.ProcessState)
  717. {
  718. case EnumWaferProcessStatus.InProcess: return 3;
  719. case EnumWaferProcessStatus.Completed: return 4;
  720. case EnumWaferProcessStatus.Failed: return 5;
  721. case EnumWaferProcessStatus.Idle:
  722. return awafer.ProcessJob == null ? 1 : 2;
  723. case EnumWaferProcessStatus.Canceled:
  724. return 7;
  725. case EnumWaferProcessStatus.MisProcessed:
  726. return 8;
  727. case EnumWaferProcessStatus.MisSrdProcess:
  728. return 9;
  729. }
  730. }
  731. }
  732. else if (awafer.Status == WaferStatus.Crossed)
  733. {
  734. return 10;
  735. }
  736. else if (awafer.Status == WaferStatus.Double)
  737. {
  738. return 11;
  739. }
  740. else if (awafer.Status == WaferStatus.Unknown)
  741. {
  742. return 0;
  743. }
  744. if (awafer.Status == WaferStatus.Dummy)
  745. {
  746. return 6;
  747. }
  748. return 1;
  749. }
  750. }
  751. }