CarrierManager.cs 14 KB

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