CarrierManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. _locationCarriers[module][0].InternalModuleName = ModuleHelper.Converter(internalModuleName);
  85. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  86. Serialize();
  87. }
  88. public void CreateCarrier(string module)
  89. {
  90. if (!_locationCarriers.ContainsKey(module))
  91. return;
  92. _locationCarriers[module][0].Status = CarrierStatus.Normal;
  93. _locationCarriers[module][0].InnerId = Guid.NewGuid();
  94. _locationCarriers[module][0].Name = $"Cassette{DateTime.Now.ToString("yyyyMMddHHmmss")}";
  95. _locationCarriers[module][0].LoadTime = DateTime.Now;
  96. _locationCarriers[module][0].InternalModuleName = ModuleHelper.Converter(module);
  97. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  98. Serialize();
  99. }
  100. public void CreateCarrier(string module, ModuleName intCarmodulename, WaferSize size, int slotNumber)
  101. {
  102. if (!_locationCarriers.ContainsKey(module))
  103. return;
  104. _locationCarriers[module][0].Status = CarrierStatus.Normal;
  105. _locationCarriers[module][0].InnerId = Guid.NewGuid();
  106. _locationCarriers[module][0].Name = $"Cassette{DateTime.Now.ToString("yyyyMMddHHmmss")}";
  107. _locationCarriers[module][0].LoadTime = DateTime.Now;
  108. _locationCarriers[module][0].InternalModuleName = intCarmodulename;
  109. _locationCarriers[module][0].CarrierWaferSize = size;
  110. if (!WaferManager.Instance.AllLocationWafers.ContainsKey(intCarmodulename))
  111. WaferManager.Instance.SubscribeLocation(intCarmodulename, slotNumber);
  112. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  113. Serialize();
  114. }
  115. public void DeleteCarrier(string module)
  116. {
  117. if (!_locationCarriers.ContainsKey(module))
  118. return;
  119. CarrierDataRecorder.Unloaded(_locationCarriers[module][0].InnerId.ToString());
  120. _locationCarriers[module][0].Clear();
  121. Serialize();
  122. }
  123. public void DeleteInternalCarrier(string module)
  124. {
  125. if (!_locationCarriers.ContainsKey(module))
  126. return;
  127. CarrierDataRecorder.Unloaded(_locationCarriers[module][0].InnerId.ToString());
  128. _locationCarriers[module][0].Clear();
  129. Serialize();
  130. }
  131. public void RegisterCarrierWafer(string module, int index, WaferInfo wafer)
  132. {
  133. if (!_locationCarriers.ContainsKey(module))
  134. return;
  135. _locationCarriers[module][0].Wafers[index] = wafer;
  136. }
  137. public void UnregisterCarrierWafer(string module, int index)
  138. {
  139. if (!_locationCarriers.ContainsKey(module))
  140. return;
  141. _locationCarriers[module][0].Wafers[index] = null;
  142. }
  143. public CarrierInfo GetCarrier(string module)
  144. {
  145. return GetCarrier(module, 0);
  146. }
  147. public CarrierInfo GetCarrier(ModuleName module)
  148. {
  149. return GetCarrier(module.ToString(), 0);
  150. }
  151. public CarrierInfo GetCarrier(ModuleName module, int slot)
  152. {
  153. return GetCarrier(module.ToString(), slot);
  154. }
  155. public CarrierInfo GetCarrier(string module, int slot)
  156. {
  157. if (!_locationCarriers.ContainsKey(module))
  158. return null;
  159. return _locationCarriers[module][slot];
  160. }
  161. public CarrierInfo[] GetCarriers(string module)
  162. {
  163. if (!_locationCarriers.ContainsKey(module))
  164. return null;
  165. return _locationCarriers[module].Values.ToArray();
  166. }
  167. public string GetLocationByCarrierId(string carrierId)
  168. {
  169. foreach (var locationCarrier in _locationCarriers)
  170. {
  171. foreach (var carrierInfo in locationCarrier.Value)
  172. {
  173. if (!carrierInfo.Value.IsEmpty && carrierInfo.Value.CarrierId == carrierId)
  174. return locationCarrier.Key;
  175. }
  176. }
  177. return null;
  178. }
  179. public string GetLocationByInternalCarrierModuleName(ModuleName name, CarrierType carrierType)
  180. {
  181. foreach (var locationCarrier in _locationCarriers)
  182. {
  183. foreach (var carrierInfo in locationCarrier.Value)
  184. {
  185. if (!carrierInfo.Value.IsEmpty && carrierInfo.Value.InternalModuleName == name && carrierInfo.Value.CarrierType == carrierType)
  186. return locationCarrier.Key;
  187. }
  188. }
  189. return null;
  190. }
  191. /// <summary>
  192. /// 传入LPn, 返回该LP的LotId
  193. /// </summary>
  194. /// <param name="moduleName">LP1/2/n</param>
  195. /// <returns>LotId string</returns>
  196. public string GetLotIdByLoadPort(string moduleName)
  197. {
  198. return _locationCarriers.ContainsKey(moduleName) ? _locationCarriers[moduleName][0].LotId : "";
  199. }
  200. public bool HasCarrier(string module, int slot = 0)
  201. {
  202. if (!_locationCarriers.ContainsKey(module))
  203. return false;
  204. return !_locationCarriers[module][0].IsEmpty;
  205. }
  206. public bool CheckHasCarrier(string module, int slot)
  207. {
  208. if (!_locationCarriers.ContainsKey(module))
  209. return false;
  210. return !_locationCarriers[module][0].IsEmpty;
  211. }
  212. public bool CheckHasCarrier(ModuleName module, int slot)
  213. {
  214. return CheckHasCarrier(module.ToString(), 0);
  215. }
  216. public bool CheckNoCarrier(string module, int slot)
  217. {
  218. if (!_locationCarriers.ContainsKey(module))
  219. return false;
  220. return _locationCarriers[module][0].IsEmpty;
  221. }
  222. public bool CheckNoCarrier(ModuleName module, int slot)
  223. {
  224. return CheckNoCarrier(module.ToString(), slot);
  225. }
  226. public bool CheckNeedProcess(string module, int slot)
  227. {
  228. if (!_locationCarriers.ContainsKey(module))
  229. return false;
  230. if (_locationCarriers[module][0].IsEmpty)
  231. return false;
  232. if (!_locationCarriers[module][0].HasWaferIn)
  233. return false;
  234. return !_locationCarriers[module][0].IsProcessCompleted;
  235. }
  236. public bool CheckNeedProcess(ModuleName module, int slot)
  237. {
  238. return CheckNeedProcess(module.ToString(), slot);
  239. }
  240. public bool CheckHasWaferIn(string module, int slot)
  241. {
  242. if (!_locationCarriers.ContainsKey(module))
  243. return false;
  244. if (_locationCarriers[module][0].IsEmpty)
  245. return false;
  246. return _locationCarriers[module][0].HasWaferIn;
  247. }
  248. public bool CheckHasWaferIn(ModuleName module, int slot)
  249. {
  250. return CheckHasWaferIn(module.ToString(), slot);
  251. }
  252. public void CarrierMoved(string moduleFrom, string moduleTo, bool needHistory = true)
  253. {
  254. if (_locationCarriers[moduleFrom][0].IsEmpty)
  255. {
  256. LOG.Write(string.Format("Invalid carrier move, no carrier at source, {0}{1}=>{2}{3}", moduleFrom, 0 + 1, moduleTo, 0 + 1));
  257. return;
  258. }
  259. if (!_locationCarriers[moduleTo][0].IsEmpty)
  260. {
  261. LOG.Write(string.Format("Invalid carrier move, destination has carrier, {0}{1}=>{2}{3}", moduleFrom, 0 + 1, moduleTo, 0 + 1));
  262. return;
  263. }
  264. _locationCarriers[moduleTo][0].CopyInfo(_locationCarriers[moduleFrom][0]);
  265. DeleteCarrier(moduleFrom);
  266. if (needHistory)
  267. {
  268. CarrierInfo carrier = _locationCarriers[moduleTo][0];
  269. CarrierDataRecorder.CarrierMove(carrier.InnerId.ToString(), carrier.LotId, moduleTo, carrier.Status.ToString());
  270. }
  271. EV.Notify(EventCarrierMoveOut, new SerializableDictionary<string, string>()
  272. {
  273. {DvidCarrierId, GetCarrier(moduleFrom).CarrierId},
  274. { DvidStation, moduleFrom}
  275. });
  276. EV.Notify(EventCarrierMoveIn, new SerializableDictionary<string, string>()
  277. {
  278. {DvidCarrierId, GetCarrier(moduleTo).CarrierId},
  279. { DvidStation, moduleTo}
  280. });
  281. if(needHistory)
  282. EV.PostInfoLog(ModuleName.System.ToString(), string.Format("Carrier moved from {0} to {1}", moduleFrom, moduleTo));
  283. //WaferMoveHistoryRecorder.WaferMoved(_locationCarriers[moduleTo][0].InnerId.ToString(), moduleTo.ToString(), 0, _locationCarriers[moduleTo][0].Status.ToString());
  284. Serialize();
  285. }
  286. public void UpdateCarrierId(string module, string carrierId)
  287. {
  288. if (!_locationCarriers.ContainsKey(module))
  289. return;
  290. if (!string.IsNullOrEmpty(_locationCarriers[module][0].CarrierId))
  291. {
  292. DeleteCarrier(module);
  293. CreateCarrier(module);
  294. }
  295. _locationCarriers[module][0].CarrierId = carrierId;
  296. CarrierDataRecorder.UpdateCarrierId(_locationCarriers[module][0].InnerId.ToString(), carrierId);
  297. Serialize();
  298. }
  299. public void UpdateRfId(string module, string rfid)
  300. {
  301. if (!_locationCarriers.ContainsKey(module))
  302. return;
  303. if (!string.IsNullOrEmpty(_locationCarriers[module][0].CarrierId))
  304. {
  305. DeleteCarrier(module);
  306. CreateCarrier(module);
  307. }
  308. _locationCarriers[module][0].Rfid = rfid;
  309. Serialize();
  310. }
  311. public void UpdateCarrierLot(string module, string lotId)
  312. {
  313. if (!_locationCarriers.ContainsKey(module))
  314. return;
  315. _locationCarriers[module][0].LotId = lotId;
  316. CarrierDataRecorder.UpdateLotId(_locationCarriers[module][0].InnerId.ToString(), lotId);
  317. Serialize();
  318. }
  319. public bool UpdateWaferSize(ModuleName module, int slot, WaferSize size)
  320. {
  321. // lock (_lockerWaferList)
  322. {
  323. _locationCarriers[module.ToString()][slot].CarrierWaferSize = size;
  324. }
  325. Serialize();
  326. return true;
  327. }
  328. public void UpdateProductCategory(string module, string productCategory)
  329. {
  330. if (!_locationCarriers.ContainsKey(module))
  331. return;
  332. _locationCarriers[module][0].ProductCategory = productCategory;
  333. CarrierDataRecorder.UpdateProductCategory(_locationCarriers[module][0].InnerId.ToString(), productCategory);
  334. Serialize();
  335. }
  336. public void UpdateProcessJob(string module, object job)
  337. {
  338. if (!_locationCarriers.ContainsKey(module))
  339. return;
  340. _locationCarriers[module][0].ProcessJob = job;
  341. Serialize();
  342. }
  343. public void UpdateProcessStatus(string module, bool processed)
  344. {
  345. if (!_locationCarriers.ContainsKey(module))
  346. return;
  347. _locationCarriers[module][0].ProcessStatus[module] = processed;
  348. Serialize();
  349. }
  350. public void UpdateProcessCompleted(ModuleName module, int slot, bool processed)
  351. {
  352. UpdateProcessCompleted(module.ToString(), slot, processed);
  353. }
  354. public void UpdateProcessCompleted(string module, int slot, bool processed)
  355. {
  356. if (!_locationCarriers.ContainsKey(module))
  357. return;
  358. _locationCarriers[module][0].IsProcessCompleted = processed;
  359. Serialize();
  360. }
  361. public void UpdateWaferIn(ModuleName module, int slot, bool waferIn)
  362. {
  363. UpdateWaferIn(module.ToString(), slot, waferIn);
  364. }
  365. public void UpdateWaferIn(string module, int slot, bool waferIn)
  366. {
  367. if (!_locationCarriers.ContainsKey(module))
  368. return;
  369. _locationCarriers[module][0].HasWaferIn = waferIn;
  370. Serialize();
  371. }
  372. }
  373. }