CarrierManager.cs 18 KB

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