WaferHolderManager.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. using Aitex.Common.Util;
  2. using Aitex.Core.Common;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.Util;
  7. using DocumentFormat.OpenXml.Wordprocessing;
  8. using MECF.Framework.Common.CommonData.Rinse;
  9. using MECF.Framework.Common.DBCore;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.Common.ToolLayout;
  13. using System;
  14. using System.Collections.Concurrent;
  15. using System.Collections.Generic;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. namespace MECF.Framework.Common.WaferHolder
  21. {
  22. public class WaferHolderManager : Singleton<WaferHolderManager>
  23. {
  24. #region 常量
  25. private const string EventWaferHolderLeft = "WAFER_HOLDER_LEFT_POSITION";
  26. private const string EventWaferHolderArrive = "WAFER_HOLDER_ARRIVE_POSITION";
  27. private const string EventWaferHolderCreated = "WAFER_HOLDER_CREATED";
  28. private const string EventWaferHolderRemoved = "WAFER_HOLDER_REMOVED";
  29. private const string EventWaferHolderDeleted = "WAFER_HOLDER_DELETED";
  30. private const string WaferShuttleUsageFileName = "WaferShuttleUsage.log";
  31. private const char CVS_SPLIT_CHAR = ' ';
  32. #endregion
  33. #region 内部变量
  34. /// <summary>
  35. /// 服务
  36. /// </summary>
  37. private WaferHolderDataService _service;
  38. /// <summary>
  39. /// Start Flag
  40. /// </summary>
  41. private bool _isStarted = false;
  42. #endregion
  43. /// <summary>
  44. /// 模块载具字典(key-Location,value-WaferHolder对象)
  45. /// </summary>
  46. ConcurrentDictionary<string,WaferHolderInfo> _locationWaferHolders = new ConcurrentDictionary<string, WaferHolderInfo>();
  47. /// <summary>(key-WaferHolder Id,value-WaferHolder对象)
  48. /// 载具字典
  49. /// </summary>
  50. ConcurrentDictionary<string, WaferHolderInfo> _waferHolderDic = new ConcurrentDictionary<string, WaferHolderInfo>();
  51. /// <summary>
  52. /// 初始化
  53. /// </summary>
  54. public void Initialize()
  55. {
  56. EV.Subscribe(new EventItem("Event", EventWaferHolderLeft, "Wafer Holder Left Event"));
  57. EV.Subscribe(new EventItem("Event", EventWaferHolderArrive, "Wafer Holder Arrived Event"));
  58. EV.Subscribe(new EventItem("Event", EventWaferHolderCreated, "Wafer Holder Creates Event"));
  59. EV.Subscribe(new EventItem("Event", EventWaferHolderRemoved, "Wafer Holder Removed Event"));
  60. EV.Subscribe(new EventItem("Event", EventWaferHolderDeleted, "Wafer Holder Deleted Event"));
  61. OP.Subscribe("WaferHolder.TransferWaferHolder", (cmd, args) => {
  62. string fromModuleName = args[0] as string;
  63. string toModuleName = args[1] as string;
  64. TransferWaferHolder(fromModuleName, fromModuleName, toModuleName);
  65. return true;
  66. });
  67. LoadDatas();
  68. }
  69. /// <summary>
  70. /// 重置LayoutWafers
  71. /// </summary>
  72. /// <param name="parameters"></param>
  73. /// <returns></returns>
  74. public bool ResetLayoutWafers()
  75. {
  76. List<WaferHolderInfo> waferHolderInfos = _locationWaferHolders.Values.ToList();
  77. foreach(WaferHolderInfo item in waferHolderInfos)
  78. {
  79. bool isChanged = false;
  80. if(!Enum.TryParse(item.CurrentLocation,out ModuleName moduleName))
  81. {
  82. continue;
  83. }
  84. if (!string.IsNullOrEmpty(item.WaferAId))
  85. {
  86. WaferInfo waferInfo=WaferManager.Instance.GetWaferByWaferId(item.WaferAId);
  87. if (item.WaferAType == (int)WaferType.Production||waferInfo==null||waferInfo.WaferType==WaferType.Production)
  88. {
  89. WaferManager.Instance.DeleteWaferById(item.WaferAId);
  90. item.WaferAId = $"{item.Id}.01";
  91. item.WaferAType= (int)WaferType.Assit;
  92. CreateModuleWafer(item, moduleName, 0,item.WaferAId);
  93. isChanged = true;
  94. }
  95. else
  96. {
  97. if(item.WaferAId!= $"{item.Id}.01")
  98. {
  99. item.WaferAId = $"{item.Id}.01";
  100. isChanged = true;
  101. }
  102. CreateModuleWafer(item, moduleName, 0,item.WaferAId);
  103. }
  104. }
  105. else
  106. {
  107. item.WaferAId = $"{item.Id}.01";
  108. item.WaferAType = (int)WaferType.Assit;
  109. CreateModuleWafer(item, moduleName, 0,item.WaferAId);
  110. isChanged = true;
  111. }
  112. if (!string.IsNullOrEmpty(item.WaferBId))
  113. {
  114. WaferInfo waferInfo = WaferManager.Instance.GetWaferByWaferId(item.WaferBId);
  115. if (item.WaferBType == (int)WaferType.Production||waferInfo==null||waferInfo.WaferType==WaferType.Production)
  116. {
  117. WaferManager.Instance.DeleteWaferById(item.WaferBId);
  118. item.WaferBId = $"{item.Id}.02";
  119. item.WaferBType = (int)WaferType.Assit;
  120. CreateModuleWafer(item, moduleName, 1, item.WaferBId);
  121. isChanged = true;
  122. }
  123. else
  124. {
  125. if (item.WaferBId != $"{item.Id}.02")
  126. {
  127. item.WaferBId = $"{item.Id}.02";
  128. isChanged = true;
  129. }
  130. CreateModuleWafer(item, moduleName, 1,item.WaferBId);
  131. }
  132. }
  133. else
  134. {
  135. item.WaferBId = $"{item.Id}.02";
  136. item.WaferBType = (int)WaferType.Assit;
  137. isChanged = true;
  138. CreateModuleWafer(item, moduleName,1,item.WaferBId);
  139. }
  140. if (isChanged)
  141. {
  142. WaferHolderDataRecorder.UpdateWaferHolderData(item.Id, item);
  143. }
  144. MaterialTrackerManager.Instance.UpdateModuleMaterial(item.CurrentLocation);
  145. }
  146. return true;
  147. }
  148. /// <summary>
  149. /// 创建Module Wafer
  150. /// </summary>
  151. /// <param name="item"></param>
  152. /// <param name="moduleName"></param>
  153. /// <param name="slot"></param>
  154. private void CreateModuleWafer(WaferHolderInfo item,ModuleName moduleName,int slot,string waferId)
  155. {
  156. if (!WaferManager.Instance.CheckHasWafer(moduleName, slot))
  157. {
  158. WaferManager.Instance.CreateWafer(moduleName, slot, WaferStatus.Normal, (WaferSize)item.WaferSize, WaferType.Assit);
  159. WaferInfo waferInfo = WaferManager.Instance.GetWafer(moduleName, slot);
  160. waferInfo.WaferOrigin = waferId;
  161. waferInfo.WaferID = waferId;
  162. waferInfo.OrginalWaferHolder = item.Id;
  163. waferInfo.ProcessState = EnumWaferProcessStatus.Idle;
  164. }
  165. }
  166. /// <summary>
  167. /// 加载数据
  168. /// </summary>
  169. private void LoadDatas()
  170. {
  171. _service = new WaferHolderDataService();
  172. List<WaferHolderInfo> waferHolderInfos= _service.GetAllWaferHolderDatas();
  173. if(waferHolderInfos!=null&&waferHolderInfos.Count!=0)
  174. {
  175. foreach(WaferHolderInfo info in waferHolderInfos)
  176. {
  177. _locationWaferHolders[info.CurrentLocation] = info;
  178. _waferHolderDic[info.Id] = info;
  179. CellItemManager.Instance.UpdateCellWaferHolder(info.CurrentLocation, true);
  180. }
  181. }
  182. List<string> installedModules = ToolLayoutConfigManager.Instance.InstalledModules;
  183. foreach (string item in installedModules)
  184. {
  185. if (Enum.TryParse(item, out ModuleName moduleName))
  186. {
  187. DeleteHasNoWaferHolderWafers(moduleName);
  188. }
  189. }
  190. DeleteHasNoWaferHolderWafers(ModuleName.Transporter1);
  191. DeleteHasNoWaferHolderWafers(ModuleName.Transporter2);
  192. DeleteHasNoWaferHolderWafers(ModuleName.Loader1);
  193. }
  194. /// <summary>
  195. /// 删除不存在WaferHolder但存在Wafer
  196. /// </summary>
  197. /// <param name="moduleName"></param>
  198. private void DeleteHasNoWaferHolderWafers(ModuleName moduleName)
  199. {
  200. string str = moduleName == ModuleName.Loader1 ? "Loader" : moduleName.ToString();
  201. if (!_locationWaferHolders.ContainsKey(str))
  202. {
  203. if (WaferManager.Instance.CheckHasWafer(moduleName, 0))
  204. {
  205. WaferManager.Instance.DeleteWafer(moduleName.ToString(), 0);
  206. }
  207. if (WaferManager.Instance.CheckHasWafer(moduleName, 1))
  208. {
  209. WaferManager.Instance.DeleteWafer(moduleName.ToString(), 1);
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// 是否为WaferHolder单元
  215. /// </summary>
  216. /// <param name="moduleName"></param>
  217. /// <returns></returns>
  218. private bool IsWaferHolderCell(ModuleName moduleName)
  219. {
  220. return ModuleHelper.IsMetal(moduleName) || ModuleHelper.IsDry(moduleName) || ModuleHelper.IsRinse(moduleName)
  221. || ModuleHelper.IsPrewet(moduleName) || moduleName == ModuleName.Loader1 || moduleName == ModuleName.Transporter1
  222. || moduleName == ModuleName.Transporter2;
  223. }
  224. /// <summary>
  225. /// 根据Id获取载具对象
  226. /// </summary>
  227. /// <param name="id"></param>
  228. /// <returns></returns>
  229. public WaferHolderInfo GetWaferHolderInfoById(string id)
  230. {
  231. return _waferHolderDic.ContainsKey(id) ? _waferHolderDic[id] : null;
  232. }
  233. /// <summary>
  234. /// 创建WaferHolder
  235. /// </summary>
  236. /// <param name="info"></param>
  237. public void CreateWaferHolder(WaferHolderInfo info)
  238. {
  239. _waferHolderDic[info.Id] = info;
  240. }
  241. /// <summary>
  242. /// 由各个模块自己定义注册可以放置几个载盒
  243. /// </summary>
  244. /// <param name="module">模块名称</param>
  245. /// <param name="capacity">有几个位置可以放</param>
  246. public void SubscribeLocation(string module,WaferHolderInfo waferHolder)
  247. {
  248. _locationWaferHolders[module] = waferHolder;
  249. _waferHolderDic[waferHolder.Id] = waferHolder;
  250. EV.Notify(EventWaferHolderArrive, new SerializableDictionary<string, string>()
  251. {
  252. {"WaferHolderID",waferHolder.Id },
  253. {"LocationID",waferHolder.CurrentLocation }
  254. });
  255. WaferHolderHistoryRecord.InsertWaferHolderArriveHistory(waferHolder.Id, waferHolder.CurrentLocation);
  256. CellItemManager.Instance.UpdateCellWaferHolder(waferHolder.CurrentLocation, true);
  257. MaterialTrackerManager.Instance.UpdateModuleMaterial(module);
  258. }
  259. /// <summary>
  260. /// 转移WaferHolder
  261. /// </summary>
  262. /// <param name="fromModule"></param>
  263. /// <param name="toModule"></param>
  264. /// <returns></returns>
  265. public bool TransferWaferHolder(string moduleName,string fromModule,string toModule,bool switchWafer=true)
  266. {
  267. if (!HasWaferHolder(fromModule))
  268. {
  269. LOG.WriteLog(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System", $"Invalid wafer move, no wafer at source, {fromModule}=>{toModule}");
  270. return false;
  271. }
  272. ModuleName fromModuleName = ModuleName.Unknown;
  273. if (fromModule == "Loader")
  274. {
  275. fromModuleName = ModuleName.Loader1;
  276. }
  277. else
  278. {
  279. fromModuleName = (ModuleName)Enum.Parse(typeof(ModuleName), fromModule);
  280. }
  281. ModuleName toModuleName = ModuleName.Unknown;
  282. if (toModule == "Loader")
  283. {
  284. toModuleName = ModuleName.Loader1;
  285. }
  286. else
  287. {
  288. toModuleName= (ModuleName)Enum.Parse(typeof(ModuleName), toModule);
  289. }
  290. if (HasWaferHolder(toModule))
  291. {
  292. LOG.WriteLog(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System",$"Invalid wafer move, destination has wafer, {fromModule}=>{toModule}");
  293. return false;
  294. }
  295. if (_locationWaferHolders.TryRemove(fromModule, out var info))
  296. {
  297. EV.Notify(EventWaferHolderLeft, new SerializableDictionary<string, string>()
  298. {
  299. {"WaferHolderID",info.Id },
  300. {"LocationID",fromModule }
  301. });
  302. CellItemManager.Instance.UpdateCellWaferHolder(fromModule, false);
  303. MaterialTrackerManager.Instance.UpdateModuleMaterial(fromModuleName.ToString());
  304. WaferHolderHistoryRecord.InsertWaferHolderLeftHistory(info.Id, fromModule);
  305. info.CurrentLocation = toModule;
  306. SubscribeLocation(toModule, info);
  307. if (switchWafer)
  308. {
  309. if (WaferManager.Instance.CheckHasWafer(fromModuleName, 0))
  310. {
  311. WaferManager.Instance.WaferMoved(fromModuleName, 0, toModuleName, 0);
  312. }
  313. if (WaferManager.Instance.CheckHasWafer(fromModuleName, 1))
  314. {
  315. WaferManager.Instance.WaferMoved(fromModuleName, 1, toModuleName, 1);
  316. }
  317. }
  318. LOG.WriteLog(eEvent.INFO_TRANSPORTER, "System", $"Wafer Shuttle {info.Id} transfer from {fromModule} to {toModule}");
  319. WaferHolderDataRecorder.UpdateWaferHolderData(info.Id, info);
  320. return true;
  321. }
  322. else
  323. {
  324. return false;
  325. }
  326. }
  327. /// <summary>
  328. /// 是否存在WaferHolder
  329. /// </summary>
  330. /// <param name="moduleName"></param>
  331. /// <returns></returns>
  332. public bool HasWaferHolder(string moduleName)
  333. {
  334. return _locationWaferHolders.ContainsKey(moduleName);
  335. }
  336. /// <summary>
  337. /// 获取WaferHolder
  338. /// </summary>
  339. /// <param name="moduleName"></param>
  340. /// <returns></returns>
  341. public WaferHolderInfo GetWaferHolder(string moduleName)
  342. {
  343. if (moduleName == ModuleName.Loader1.ToString())
  344. {
  345. moduleName = "Loader";
  346. }
  347. return _locationWaferHolders.ContainsKey(moduleName) ? _locationWaferHolders[moduleName]: null;
  348. }
  349. /// <summary>
  350. /// 禁用WaferHolder
  351. /// </summary>
  352. /// <param name="info"></param>
  353. public void DisableWaferHolder(WaferHolderInfo info)
  354. {
  355. info.Enabled = false;
  356. WaferHolderDataRecorder.UpdateWaferHolderEnable(info.Id,false);
  357. }
  358. /// <summary>
  359. /// 移除
  360. /// </summary>
  361. /// <param name="moduleName"></param>
  362. public void Remove(string moduleName)
  363. {
  364. if(_locationWaferHolders.ContainsKey(moduleName))
  365. {
  366. _locationWaferHolders.TryRemove(moduleName, out var info);
  367. if (!string.IsNullOrEmpty(info.WaferAId))
  368. {
  369. WaferManager.Instance.DeleteWaferById(info.WaferAId);
  370. }
  371. if (!string.IsNullOrEmpty(info.WaferBId))
  372. {
  373. WaferManager.Instance.DeleteWaferById(info.WaferBId);
  374. }
  375. MaterialTrackerManager.Instance.UpdateModuleMaterial(moduleName);
  376. CellItemManager.Instance.UpdateCellWaferHolder(moduleName, false);
  377. EV.Notify(EventWaferHolderRemoved, new SerializableDictionary<string, string>()
  378. {
  379. {"WaferHolderID",info.Id },
  380. {"LocationID",moduleName }
  381. });
  382. }
  383. }
  384. /// <summary>
  385. /// 删除
  386. /// </summary>
  387. /// <param name="waferId"></param>
  388. public void RemoveByWaferHolderId(string waferId)
  389. {
  390. _waferHolderDic.TryRemove(waferId, out var info);
  391. if (info!=null)
  392. {
  393. _locationWaferHolders.TryRemove(info.CurrentLocation, out var info1);
  394. WaferHolderHistoryRecord.InsertWaferHolderDeleteHistory(info.Id);
  395. EV.Notify(EventWaferHolderDeleted, new SerializableDictionary<string, string>()
  396. {
  397. {"WaferHolderID",info.Id }
  398. });
  399. }
  400. }
  401. /// <summary>
  402. /// 更换WaferHolder Id
  403. /// </summary>
  404. /// <param name="waferHolderInfo"></param>
  405. /// <param name="transporterName"></param>
  406. /// <param name="newId"></param>
  407. public void SwitchWaferHolderId(WaferHolderInfo waferHolderInfo,string transporterName,string newId)
  408. {
  409. if (waferHolderInfo.Id == newId)
  410. {
  411. return;
  412. }
  413. if(!Enum.TryParse(transporterName,out ModuleName moduleName))
  414. {
  415. return;
  416. }
  417. _locationWaferHolders.TryRemove(waferHolderInfo.CurrentLocation, out var info);
  418. _waferHolderDic.TryRemove(waferHolderInfo.Id, out var tmp);
  419. string preId = waferHolderInfo.Id;
  420. waferHolderInfo.Id = newId;
  421. if (!string.IsNullOrEmpty(waferHolderInfo.WaferAId)&&waferHolderInfo.WaferAType==(int)WaferType.Assit)
  422. {
  423. WaferInfo waferAInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferAId);
  424. int waferAOriginalStation = (int)ModuleName.Unknown;
  425. if (waferAInfo!=null)
  426. {
  427. waferAOriginalStation = waferAInfo.OriginStation;
  428. }
  429. WaferManager.Instance.DeleteWaferById(waferHolderInfo.WaferAId);
  430. waferHolderInfo.WaferAId = $"{newId}.01";
  431. WaferManager.Instance.CreateWafer(moduleName, 0, WaferStatus.Normal, (WaferSize)waferHolderInfo.WaferSize, (WaferType)waferHolderInfo.WaferAType);
  432. WaferInfo waferInfo = WaferManager.Instance.GetWafer(moduleName, 0);
  433. waferInfo.WaferOrigin = waferHolderInfo.WaferAId;
  434. waferInfo.WaferID = waferHolderInfo.WaferAId;
  435. waferInfo.OriginStation = waferAOriginalStation;
  436. }
  437. if (!string.IsNullOrEmpty(waferHolderInfo.WaferBId) && waferHolderInfo.WaferBType == (int)WaferType.Assit)
  438. {
  439. WaferInfo waferBInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferBId);
  440. int waferBOriginalStation = (int)ModuleName.Unknown;
  441. if (waferBInfo != null)
  442. {
  443. waferBOriginalStation = waferBInfo.OriginStation;
  444. }
  445. WaferManager.Instance.DeleteWaferById(waferHolderInfo.WaferBId);
  446. waferHolderInfo.WaferBId = $"{newId}.02";
  447. WaferManager.Instance.CreateWafer(moduleName, 1, WaferStatus.Normal, (WaferSize)waferHolderInfo.WaferSize, (WaferType)waferHolderInfo.WaferBType);
  448. WaferInfo waferInfo = WaferManager.Instance.GetWafer(moduleName, 1);
  449. waferInfo.WaferOrigin = waferHolderInfo.WaferBId;
  450. waferInfo.WaferID = waferHolderInfo.WaferBId;
  451. waferInfo.OriginStation = waferBOriginalStation;
  452. }
  453. _locationWaferHolders[waferHolderInfo.CurrentLocation] = waferHolderInfo;
  454. _waferHolderDic[waferHolderInfo.Id] = waferHolderInfo;
  455. WaferHolderDataRecorder.UpdateWaferHolderData(preId, waferHolderInfo);
  456. MaterialTrackerManager.Instance.UpdateModuleMaterial(transporterName);
  457. }
  458. /// <summary>
  459. /// 启动时检验Wafer缓存
  460. /// </summary>
  461. /// <returns></returns>
  462. public bool CheckStartUpWaferHolderBuffer(ref string reason)
  463. {
  464. bool result = true;
  465. List<WaferHolderInfo> waferHolderInfos = _waferHolderDic.Values.ToList();
  466. foreach (WaferHolderInfo waferHolderInfo in waferHolderInfos)
  467. {
  468. if (!string.IsNullOrEmpty(waferHolderInfo.WaferAId))
  469. {
  470. WaferInfo wafer = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferAId);
  471. if (wafer == null || wafer.IsEmpty)
  472. {
  473. reason = $"{waferHolderInfo.Id} side A has no Wafer";
  474. LOG.Write(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System", reason);
  475. return false;
  476. }
  477. if (wafer!=null&&wafer.WaferType==WaferType.Production)
  478. {
  479. reason = $"{waferHolderInfo.Id} side A Wafer cache error";
  480. LOG.Write(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System", reason);
  481. result = false;
  482. }
  483. }
  484. else
  485. {
  486. reason = $"{waferHolderInfo.Id} side A has no Wafer";
  487. LOG.Write(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System", reason);
  488. return false;
  489. }
  490. if (!string.IsNullOrEmpty(waferHolderInfo.WaferBId))
  491. {
  492. WaferInfo wafer = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferBId);
  493. if (wafer == null||wafer.IsEmpty)
  494. {
  495. reason = $"{waferHolderInfo.Id} side B has no Wafer";
  496. LOG.Write(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System",reason);
  497. return false;
  498. }
  499. if (wafer != null && wafer.WaferType == WaferType.Production)
  500. {
  501. reason = $"{waferHolderInfo.Id} side B Wafer cache error";
  502. LOG.Write(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System", reason);
  503. result = false;
  504. }
  505. }
  506. else
  507. {
  508. reason = $"{waferHolderInfo.Id} side B has no Wafer";
  509. LOG.Write(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "System",reason);
  510. return false;
  511. }
  512. }
  513. return result;
  514. }
  515. /// <summary>
  516. /// 获取所有WaferHolder数据
  517. /// </summary>
  518. /// <returns></returns>
  519. public List<WaferHolderInfo> GetAllWaferHolders()
  520. {
  521. return _waferHolderDic.Values.ToList();
  522. }
  523. /// <summary>
  524. /// 更新WaferHolder信息
  525. /// </summary>
  526. /// <param name="waferHolderInfo"></param>
  527. public void UpdateWaferHolderInfo(WaferHolderInfo waferHolderInfo)
  528. {
  529. WaferHolderInfo sourceInfo = GetWaferHolderInfoById(waferHolderInfo.Id);
  530. sourceInfo.CloneBaseInfo(waferHolderInfo);
  531. _service.UpdateWaferHolderData(waferHolderInfo.Id, sourceInfo,false);
  532. }
  533. /// <summary>
  534. /// 更新WaferHolder信息
  535. /// </summary>
  536. /// <param name="wsID"></param>
  537. /// <param name="waferInfo"></param>
  538. /// <param name="slot"></param>
  539. public void UpdateWaferHolderInfo(string wsID, WaferInfo waferInfo, int slot)
  540. {
  541. WaferHolderInfo wsInfo = GetWaferHolderInfoById(wsID);
  542. if (wsInfo == null || waferInfo == null) return;
  543. if (slot == 0)
  544. {
  545. wsInfo.WaferAId = waferInfo.WaferID;
  546. wsInfo.WaferAType = (int)waferInfo.WaferType;
  547. }
  548. else
  549. {
  550. wsInfo.WaferBId = waferInfo.WaferID;
  551. wsInfo.WaferBType = (int)waferInfo.WaferType;
  552. }
  553. _service.UpdateWaferHolderData(wsInfo.Id, wsInfo, false);
  554. }
  555. /// <summary>
  556. /// 获取模块sequence
  557. /// </summary>
  558. /// <param name="moduleName"></param>
  559. /// <returns></returns>
  560. public string GetModuleSequence(string moduleName)
  561. {
  562. if (_locationWaferHolders.ContainsKey(moduleName))
  563. {
  564. WaferHolderInfo waferHolderInfo= _locationWaferHolders[moduleName];
  565. if(waferHolderInfo == null)
  566. {
  567. return "";
  568. }
  569. if (waferHolderInfo.SequenceRecipe == null)
  570. {
  571. return "";
  572. }
  573. return waferHolderInfo.SequenceRecipe.Ppid;
  574. }
  575. return "";
  576. }
  577. /// <summary>
  578. /// WaferShuttleUsage监控
  579. /// </summary>
  580. public void WaferShuttleUsageMonitor()
  581. {
  582. bool isOnTime = DateTime.Now.Hour.Equals(0) && DateTime.Now.Minute.Equals(0) && DateTime.Now.Second.Equals(0);
  583. if ((!_isStarted || isOnTime) && !JudgeFileChanged())
  584. {
  585. ExportWaferShuttleUsage();
  586. _isStarted = true;
  587. }
  588. }
  589. /// <summary>
  590. /// WaferShuttle用量记录
  591. /// </summary>
  592. private async void ExportWaferShuttleUsage()
  593. {
  594. await Task.Run(() =>
  595. {
  596. try
  597. {
  598. List<WaferHolderInfo> datas = GetAllWaferHolders();
  599. if (datas == null) return;
  600. string filePath = PathManager.GetLotTrackFilePath() + WaferShuttleUsageFileName;
  601. FileInfo file = new FileInfo(filePath);
  602. if (!file.Directory.Exists)
  603. {
  604. file.Directory.Create();
  605. }
  606. FileStream fileStream = new FileStream(file.FullName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
  607. StreamWriter streamWriter = new StreamWriter(fileStream, System.Text.Encoding.UTF8);
  608. string str = string.Format("{0,22}", "") + CVS_SPLIT_CHAR + string.Format("{0, 4}", "#")+ CVS_SPLIT_CHAR + string.Format("{0, 12}", "WSID") + CVS_SPLIT_CHAR
  609. + CVS_SPLIT_CHAR + string.Format("{0, 12}", "IsEnabled")+ CVS_SPLIT_CHAR + string.Format("{0, 12}", "LSType") + CVS_SPLIT_CHAR + string.Format("{0, 12}", "TotalUses")
  610. + CVS_SPLIT_CHAR + string.Format("{0, 12}", "LSAID") + CVS_SPLIT_CHAR + string.Format("{0, 16}", "LSATotalUses") + CVS_SPLIT_CHAR + string.Format("{0, 12}", "LSBID") + CVS_SPLIT_CHAR + string.Format("{0, 16}", "LSBTotalUses")
  611. + CVS_SPLIT_CHAR + string.Format("{0, 12}", "Chemistry");
  612. streamWriter.WriteLine(str);
  613. for (int i = 0; i < 16; i++)
  614. {
  615. WaferHolderInfo data = datas.Find(O => O.BufferId == i + 1);
  616. if (data != null)
  617. {
  618. string tmp = $"{string.Format("{0,22}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))}{CVS_SPLIT_CHAR}{string.Format("{0, 4}", data.BufferId)}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", data.Id)}" +
  619. $"{CVS_SPLIT_CHAR}{string.Format("{0, 13}", data.Enabled.ToString())}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", data.CrsType)}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", data.TotalUses)}" +
  620. $"{CVS_SPLIT_CHAR}{string.Format("{0, 12}", data.CrsAId)}{CVS_SPLIT_CHAR}{string.Format("{0, 16}", data.CrsATotalUses)}" +
  621. $"{CVS_SPLIT_CHAR}{string.Format("{0, 12}", data.CrsBId)}{CVS_SPLIT_CHAR}{string.Format("{0, 16}", data.CrsBTotalUses)}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", data.Chemistry)}";
  622. streamWriter.WriteLine(tmp);
  623. }
  624. else
  625. {
  626. string tmp = $"{string.Format("{0,22}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))}{CVS_SPLIT_CHAR}{string.Format("{0, 4}", (i+1).ToString())}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", "")}" +
  627. $"{CVS_SPLIT_CHAR}{string.Format("{0, 13}", "")}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", "")}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", "")}" +
  628. $"{CVS_SPLIT_CHAR}{string.Format("{0, 12}", "")}{CVS_SPLIT_CHAR}{string.Format("{0, 16}", "")}" +
  629. $"{CVS_SPLIT_CHAR}{string.Format("{0, 12}", "")}{CVS_SPLIT_CHAR}{string.Format("{0, 16}", "")}{CVS_SPLIT_CHAR}{string.Format("{0, 12}", "")}";
  630. streamWriter.WriteLine(tmp);
  631. }
  632. }
  633. streamWriter.WriteLine("");
  634. streamWriter.Close();
  635. fileStream.Close();
  636. }
  637. catch (Exception ex)
  638. {
  639. LOG.WriteLog(eEvent.ERR_WAFER_HOLDER_MANAGER_FAILED, "WaferShuttle", $"Wafer Shuttle Usage file writing is failed!");
  640. }
  641. });
  642. }
  643. /// <summary>
  644. /// 文件更改判断
  645. /// </summary>
  646. /// <returns></returns>
  647. private bool JudgeFileChanged()
  648. {
  649. string filePath = PathManager.GetLotTrackFilePath() + WaferShuttleUsageFileName;
  650. if (!File.Exists(filePath))
  651. {
  652. //未创建文件
  653. return false;
  654. }
  655. FileInfo file = new FileInfo(filePath);
  656. if (file.LastWriteTime.Year.Equals(DateTime.Now.Year) && file.LastWriteTime.Month.Equals(DateTime.Now.Month) && file.LastWriteTime.Day.Equals(DateTime.Now.Day))
  657. {
  658. //当日已修改
  659. return true;
  660. }
  661. else
  662. {
  663. //当日未修改
  664. return false;
  665. }
  666. }
  667. }
  668. }