CarrierManager.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.Util;
  6. using Aitex.Sorter.RT.Module.DBRecorder;
  7. using DocumentFormat.OpenXml.Wordprocessing;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Utilities;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. namespace MECF.Framework.Common.SubstrateTrackings
  14. {
  15. public class CarrierManager : Singleton<CarrierManager>
  16. {
  17. Dictionary<string, Dictionary<int, CarrierInfo>> _locationCarriers = new Dictionary<string, Dictionary<int, CarrierInfo>>();
  18. object _lockerCarrierList = new object();
  19. private const string EventCarrierMoveIn = "CarrierMoveIn";
  20. private const string EventCarrierMoveOut = "CarrierMoveOut";
  21. private const string DvidCarrierId = "CarrierId";
  22. private const string DvidStation = "Station";
  23. public void Initialize()
  24. {
  25. EV.Subscribe(new EventItem("Event", EventCarrierMoveIn, "carrier move in"));
  26. EV.Subscribe(new EventItem("Event", EventCarrierMoveOut, "carrier move out"));
  27. Deserialize();
  28. }
  29. public void Terminate()
  30. {
  31. lock (_lockerCarrierList)
  32. {
  33. Serialize();
  34. }
  35. }
  36. public void Deserialize()
  37. {
  38. lock (_lockerCarrierList)
  39. {
  40. var ccc = BinarySerializer<Dictionary<string, Dictionary<int, CarrierInfo>>>.FromStream("CarrierManager");
  41. if (ccc != null)
  42. _locationCarriers = ccc;
  43. }
  44. }
  45. public void Serialize()
  46. {
  47. lock (_lockerCarrierList)
  48. {
  49. if (_locationCarriers != null)
  50. {
  51. BinarySerializer<Dictionary<string, Dictionary<int, CarrierInfo>>>.ToStream(_locationCarriers, "CarrierManager");
  52. }
  53. }
  54. }
  55. /// <summary>
  56. /// 由各个模块自己定义注册可以放置几个载盒
  57. /// </summary>
  58. /// <param name="module">模块名称</param>
  59. /// <param name="capacity">有几个位置可以放</param>
  60. public void SubscribeLocation(string module, int capacity = 1, int slot = 25)
  61. {
  62. lock (_lockerCarrierList)
  63. {
  64. if (!_locationCarriers.ContainsKey(module))
  65. {
  66. _locationCarriers[module] = new Dictionary<int, CarrierInfo>();
  67. for (int i = 0; i < capacity; i++)
  68. {
  69. _locationCarriers[module][i] = new CarrierInfo(slot);
  70. }
  71. }
  72. DATA.Subscribe(module, "Carrier", () => _locationCarriers[module][0]);
  73. DATA.Subscribe(module.ToString(), "ModuleCarrierList", () => _locationCarriers[module].Values.ToArray());
  74. }
  75. }
  76. public void CreateCarrier(string module, CarrierType carrierType, string internalModuleName)
  77. {
  78. if (!_locationCarriers.ContainsKey(module))
  79. return;
  80. _locationCarriers[module][0].Status = CarrierStatus.Normal;
  81. _locationCarriers[module][0].InnerId = Guid.NewGuid();
  82. _locationCarriers[module][0].Name = $"Cassette{DateTime.Now.ToString("yyyyMMddHHmmss")}";
  83. _locationCarriers[module][0].LoadTime = DateTime.Now;
  84. _locationCarriers[module][0].CarrierType = carrierType;
  85. if (module == "LP1")
  86. {
  87. _locationCarriers[module][0].PortID = 1;
  88. }
  89. else if (module == "LP2")
  90. {
  91. _locationCarriers[module][0].PortID = 2;
  92. }
  93. _locationCarriers[module][0].InternalModuleName = ModuleHelper.Converter(internalModuleName);
  94. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  95. Serialize();
  96. }
  97. public void CreateCarrier(string module)
  98. {
  99. if (!_locationCarriers.ContainsKey(module))
  100. return;
  101. _locationCarriers[module][0].Status = CarrierStatus.Normal;
  102. _locationCarriers[module][0].InnerId = Guid.NewGuid();
  103. _locationCarriers[module][0].Name = $"Cassette{DateTime.Now.ToString("yyyyMMddHHmmss")}";
  104. _locationCarriers[module][0].LoadTime = DateTime.Now;
  105. if (module == "LP1")
  106. {
  107. _locationCarriers[module][0].PortID = 1;
  108. }
  109. else if (module == "LP2")
  110. {
  111. _locationCarriers[module][0].PortID = 2;
  112. }
  113. _locationCarriers[module][0].InternalModuleName = ModuleHelper.Converter(module);
  114. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  115. Serialize();
  116. }
  117. public void CreateCarrier(string module, ModuleName intCarmodulename, WaferSize size, int slotNumber)
  118. {
  119. if (!_locationCarriers.ContainsKey(module))
  120. return;
  121. _locationCarriers[module][0].Status = CarrierStatus.Normal;
  122. _locationCarriers[module][0].InnerId = Guid.NewGuid();
  123. _locationCarriers[module][0].Name = $"Cassette{DateTime.Now.ToString("yyyyMMddHHmmss")}";
  124. _locationCarriers[module][0].LoadTime = DateTime.Now;
  125. _locationCarriers[module][0].InternalModuleName = intCarmodulename;
  126. _locationCarriers[module][0].CarrierWaferSize = size;
  127. if (!WaferManager.Instance.AllLocationWafers.ContainsKey(intCarmodulename))
  128. WaferManager.Instance.SubscribeLocation(intCarmodulename, slotNumber);
  129. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  130. Serialize();
  131. }
  132. public void DeleteCarrier(string module)
  133. {
  134. if (!_locationCarriers.ContainsKey(module))
  135. return;
  136. CarrierDataRecorder.Unloaded(_locationCarriers[module][0].InnerId.ToString());
  137. _locationCarriers[module][0].Clear();
  138. LOG.Info($"{module} DeleteCarrier");
  139. Serialize();
  140. }
  141. public void DeleteInternalCarrier(string module)
  142. {
  143. if (!_locationCarriers.ContainsKey(module))
  144. return;
  145. CarrierDataRecorder.Unloaded(_locationCarriers[module][0].InnerId.ToString());
  146. _locationCarriers[module][0].Clear();
  147. Serialize();
  148. }
  149. public void RegisterCarrierWafer(string module, int index, WaferInfo wafer)
  150. {
  151. if (!_locationCarriers.ContainsKey(module))
  152. return;
  153. _locationCarriers[module][0].Wafers[index] = wafer;
  154. }
  155. public void UnregisterCarrierWafer(string module, int index)
  156. {
  157. if (!_locationCarriers.ContainsKey(module))
  158. return;
  159. _locationCarriers[module][0].Wafers[index] = null;
  160. }
  161. public CarrierInfo GetCarrier(string module)
  162. {
  163. return GetCarrier(module, 0);
  164. }
  165. public CarrierInfo GetCarrier(ModuleName module)
  166. {
  167. return GetCarrier(module.ToString(), 0);
  168. }
  169. public CarrierInfo GetCarrier(ModuleName module, int slot)
  170. {
  171. return GetCarrier(module.ToString(), slot);
  172. }
  173. public List<CarrierInfo> GetCarrierbytype(CarrierType carrierType)
  174. {
  175. List<CarrierInfo> _crlst = new List<CarrierInfo>();
  176. foreach (var carrier in _locationCarriers.Values)
  177. {
  178. if (carrier[0].CarrierType == carrierType && carrier[0].CarrierId != null && carrier[0].CarrierId != "")
  179. {
  180. _crlst.Add(carrier[0]);
  181. }
  182. }
  183. return _crlst;
  184. }
  185. public List<string> GetStokerCarrierID()
  186. {
  187. List<string> _crids = new List<string>();
  188. foreach (var _cr in _locationCarriers.Keys)
  189. {
  190. if (_cr.Contains("Stocker"))
  191. {
  192. if (_locationCarriers[_cr][0].CarrierId != "" && _locationCarriers[_cr][0].CarrierId != null)
  193. {
  194. _crids.Add(_locationCarriers[_cr][0].CarrierId);
  195. }
  196. }
  197. }
  198. return _crids;
  199. }
  200. public List<string> GetBufferMaterialInfo()
  201. {
  202. List<string> _crids = new List<string>();
  203. foreach (var _cr in _locationCarriers.Keys)
  204. {
  205. if (_cr.Contains("Stocker") || _cr.Contains("FIMS") || _cr.Contains("LP"))
  206. {
  207. if (_locationCarriers[_cr][0].CarrierId != "" && _locationCarriers[_cr][0].CarrierId != null)
  208. {
  209. _crids.Add(_cr + ";" + _locationCarriers[_cr][0].CarrierId);
  210. }
  211. else
  212. {
  213. _crids.Add(_cr + ";" + "emptyid");
  214. }
  215. }
  216. }
  217. return _crids;
  218. }
  219. public CarrierInfo GetCarrier(string module, int slot)
  220. {
  221. if (!_locationCarriers.ContainsKey(module))
  222. return null;
  223. return _locationCarriers[module][slot];
  224. }
  225. public CarrierInfo[] GetCarriers(string module)
  226. {
  227. if (!_locationCarriers.ContainsKey(module))
  228. return null;
  229. return _locationCarriers[module].Values.ToArray();
  230. }
  231. public string GetLocationByCarrierId(string carrierId)
  232. {
  233. foreach (var locationCarrier in _locationCarriers)
  234. {
  235. foreach (var carrierInfo in locationCarrier.Value)
  236. {
  237. if (!carrierInfo.Value.IsEmpty && carrierInfo.Value.CarrierId == carrierId)
  238. return locationCarrier.Key;
  239. }
  240. }
  241. return null;
  242. }
  243. public string GetLocationByInternalCarrierModuleName(ModuleName name, CarrierType carrierType)
  244. {
  245. foreach (var locationCarrier in _locationCarriers)
  246. {
  247. foreach (var carrierInfo in locationCarrier.Value)
  248. {
  249. if (!carrierInfo.Value.IsEmpty && carrierInfo.Value.InternalModuleName == name && carrierInfo.Value.CarrierType == carrierType)
  250. return locationCarrier.Key;
  251. }
  252. }
  253. return null;
  254. }
  255. /// <summary>
  256. /// 传入LPn, 返回该LP的LotId
  257. /// </summary>
  258. /// <param name="moduleName">LP1/2/n</param>
  259. /// <returns>LotId string</returns>
  260. public string GetLotIdByLoadPort(string moduleName)
  261. {
  262. return _locationCarriers.ContainsKey(moduleName) ? _locationCarriers[moduleName][0].LotId : "";
  263. }
  264. public bool HasCarrier(string module, int slot = 0)
  265. {
  266. if (!_locationCarriers.ContainsKey(module))
  267. return false;
  268. return !_locationCarriers[module][0].IsEmpty;
  269. }
  270. public bool CheckHasCarrier(string module, int slot)
  271. {
  272. if (!_locationCarriers.ContainsKey(module))
  273. return false;
  274. return !_locationCarriers[module][0].IsEmpty;
  275. }
  276. public bool CheckHasCarrier(ModuleName module, int slot)
  277. {
  278. return CheckHasCarrier(module.ToString(), 0);
  279. }
  280. public bool CheckNoCarrier(string module, int slot)
  281. {
  282. if (!_locationCarriers.ContainsKey(module))
  283. return false;
  284. return _locationCarriers[module][0].IsEmpty;
  285. }
  286. public bool CheckNoCarrier(ModuleName module, int slot)
  287. {
  288. return CheckNoCarrier(module.ToString(), slot);
  289. }
  290. public bool CheckNeedProcess(string module, int slot)
  291. {
  292. if (!_locationCarriers.ContainsKey(module))
  293. return false;
  294. if (_locationCarriers[module][0].IsEmpty)
  295. return false;
  296. if (!_locationCarriers[module][0].HasWaferIn)
  297. return false;
  298. return !_locationCarriers[module][0].IsProcessCompleted;
  299. }
  300. public bool CheckNeedProcess(ModuleName module, int slot)
  301. {
  302. return CheckNeedProcess(module.ToString(), slot);
  303. }
  304. public bool CheckHasWaferIn(string module, int slot)
  305. {
  306. if (!_locationCarriers.ContainsKey(module))
  307. return false;
  308. if (_locationCarriers[module][0].IsEmpty)
  309. return false;
  310. return _locationCarriers[module][0].HasWaferIn;
  311. }
  312. public bool CheckHasWaferIn(ModuleName module, int slot)
  313. {
  314. return CheckHasWaferIn(module.ToString(), slot);
  315. }
  316. public void CarrierMoved(string moduleFrom, string moduleTo, bool needHistory = true)
  317. {
  318. if (_locationCarriers[moduleFrom][0].IsEmpty)
  319. {
  320. LOG.Write(string.Format("Invalid carrier move, no carrier at source, {0}{1}=>{2}{3}", moduleFrom, 0 + 1, moduleTo, 0 + 1));
  321. return;
  322. }
  323. if (!_locationCarriers[moduleTo][0].IsEmpty)
  324. {
  325. LOG.Write(string.Format("Invalid carrier move, destination has carrier, {0}{1}=>{2}{3}", moduleFrom, 0 + 1, moduleTo, 0 + 1));
  326. return;
  327. }
  328. _locationCarriers[moduleTo][0].CopyInfo(_locationCarriers[moduleFrom][0]);
  329. DeleteCarrier(moduleFrom);
  330. if (needHistory)
  331. {
  332. CarrierInfo carrier = _locationCarriers[moduleTo][0];
  333. CarrierDataRecorder.CarrierMove(carrier.InnerId.ToString(), carrier.LotId, moduleTo, carrier.Status.ToString());
  334. }
  335. EV.Notify(EventCarrierMoveOut, new SerializableDictionary<string, string>()
  336. {
  337. {DvidCarrierId, GetCarrier(moduleFrom).CarrierId},
  338. { DvidStation, moduleFrom}
  339. });
  340. EV.Notify(EventCarrierMoveIn, new SerializableDictionary<string, string>()
  341. {
  342. {DvidCarrierId, GetCarrier(moduleTo).CarrierId},
  343. { DvidStation, moduleTo}
  344. });
  345. if(needHistory)
  346. EV.PostInfoLog(ModuleName.System.ToString(), string.Format("Carrier moved from {0} to {1}", moduleFrom, moduleTo));
  347. //WaferMoveHistoryRecorder.WaferMoved(_locationCarriers[moduleTo][0].InnerId.ToString(), moduleTo.ToString(), 0, _locationCarriers[moduleTo][0].Status.ToString());
  348. Serialize();
  349. }
  350. public void UpdateCarrierId(string module, string carrierId)
  351. {
  352. if (!_locationCarriers.ContainsKey(module))
  353. return;
  354. //if (!string.IsNullOrEmpty(_locationCarriers[module][0].CarrierId))
  355. //{
  356. // DeleteCarrier(module);
  357. // CreateCarrier(module);
  358. //}
  359. _locationCarriers[module][0].CarrierId = carrierId;
  360. CarrierDataRecorder.UpdateCarrierId(_locationCarriers[module][0].InnerId.ToString(), carrierId);
  361. Serialize();
  362. }
  363. public void UpdateRfId(string module, string rfid)
  364. {
  365. if (!_locationCarriers.ContainsKey(module))
  366. return;
  367. if (!string.IsNullOrEmpty(_locationCarriers[module][0].CarrierId))
  368. {
  369. DeleteCarrier(module);
  370. CreateCarrier(module);
  371. }
  372. _locationCarriers[module][0].Rfid = rfid;
  373. Serialize();
  374. }
  375. public void UpdateCarrierLot(string module, string lotId)
  376. {
  377. if (!_locationCarriers.ContainsKey(module))
  378. return;
  379. _locationCarriers[module][0].LotId = lotId;
  380. CarrierDataRecorder.UpdateLotId(_locationCarriers[module][0].InnerId.ToString(), lotId);
  381. Serialize();
  382. }
  383. public bool UpdateWaferSize(ModuleName module, int slot, WaferSize size)
  384. {
  385. // lock (_lockerWaferList)
  386. {
  387. _locationCarriers[module.ToString()][slot].CarrierWaferSize = size;
  388. }
  389. Serialize();
  390. return true;
  391. }
  392. public void UpdateProductCategory(string module, string productCategory)
  393. {
  394. if (!_locationCarriers.ContainsKey(module))
  395. return;
  396. _locationCarriers[module][0].ProductCategory = productCategory;
  397. CarrierDataRecorder.UpdateProductCategory(_locationCarriers[module][0].InnerId.ToString(), productCategory);
  398. Serialize();
  399. }
  400. public void UpdateProcessJob(string module, object job)
  401. {
  402. if (!_locationCarriers.ContainsKey(module))
  403. return;
  404. _locationCarriers[module][0].ProcessJob = job;
  405. Serialize();
  406. }
  407. public void UpdateProcessStatus(string module, bool processed)
  408. {
  409. if (!_locationCarriers.ContainsKey(module))
  410. return;
  411. _locationCarriers[module][0].ProcessStatus[module] = processed;
  412. Serialize();
  413. }
  414. public void UpdateProcessCompleted(ModuleName module, int slot, bool processed)
  415. {
  416. UpdateProcessCompleted(module.ToString(), slot, processed);
  417. }
  418. public void UpdateProcessCompleted(string module, int slot, bool processed)
  419. {
  420. if (!_locationCarriers.ContainsKey(module))
  421. return;
  422. _locationCarriers[module][0].IsProcessCompleted = processed;
  423. Serialize();
  424. }
  425. public void UpdateWaferIn(ModuleName module, int slot, bool waferIn)
  426. {
  427. UpdateWaferIn(module.ToString(), slot, waferIn);
  428. }
  429. public void UpdateWaferIn(string module, int slot, bool waferIn)
  430. {
  431. if (!_locationCarriers.ContainsKey(module))
  432. return;
  433. _locationCarriers[module][0].HasWaferIn = waferIn;
  434. Serialize();
  435. }
  436. }
  437. }