CarrierManager.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using Aitex.Sorter.RT.Module.DBRecorder;
  11. using MECF.Framework.Common.DBCore;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.Utilities;
  14. namespace MECF.Framework.Common.SubstrateTrackings
  15. {
  16. public class CarrierManager : Singleton<CarrierManager>
  17. {
  18. Dictionary<string, Dictionary<int, CarrierInfo>> _locationCarriers = new Dictionary<string, Dictionary<int, CarrierInfo>>();
  19. object _lockerCarrierList = new object();
  20. private const string EventCarrierMoveIn = "CarrierMoveIn";
  21. private const string EventCarrierMoveOut = "CarrierMoveOut";
  22. private const string DvidCarrierId = "CarrierId";
  23. private const string DvidStation = "Station";
  24. public void Initialize()
  25. {
  26. EV.Subscribe(new EventItem("Event", EventCarrierMoveIn, "carrier move in"));
  27. EV.Subscribe(new EventItem("Event", EventCarrierMoveOut, "carrier move out"));
  28. Deserialize();
  29. }
  30. public void Terminate()
  31. {
  32. Serialize();
  33. }
  34. public void Deserialize()
  35. {
  36. var ccc = BinarySerializer<Dictionary<string, Dictionary<int, CarrierInfo>>>.FromStream("CarrierManager");
  37. if (ccc != null)
  38. _locationCarriers = ccc;
  39. }
  40. public void Serialize()
  41. {
  42. if (_locationCarriers != null)
  43. {
  44. BinarySerializer<Dictionary<string, Dictionary<int, CarrierInfo>> >.ToStream(_locationCarriers, "CarrierManager");
  45. }
  46. }
  47. /// <summary>
  48. /// 由各个模块自己定义注册可以放置几个载盒
  49. /// </summary>
  50. /// <param name="module">模块名称</param>
  51. /// <param name="capacity">有几个位置可以放</param>
  52. public void SubscribeLocation(string module, int capacity=1)
  53. {
  54. if (!_locationCarriers.ContainsKey(module))
  55. {
  56. _locationCarriers[module] = new Dictionary<int, CarrierInfo>();
  57. for (int i = 0; i < capacity; i++)
  58. {
  59. _locationCarriers[module][i] = new CarrierInfo(SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  60. }
  61. }
  62. DATA.Subscribe(module, "Carrier", () => _locationCarriers[module][0]);
  63. }
  64. public void CreateCarrier(string module)
  65. {
  66. if (!_locationCarriers.ContainsKey(module))
  67. return;
  68. _locationCarriers[module][0].Status = CarrierStatus.Normal;
  69. _locationCarriers[module][0].InnerId = Guid.NewGuid() ;
  70. _locationCarriers[module][0].Name = $"Cassette{DateTime.Now.ToString("yyyyMMddHHmmss")}";
  71. _locationCarriers[module][0].LoadTime = DateTime.Now;
  72. CarrierDataRecorder.Loaded(_locationCarriers[module][0].InnerId.ToString(), module);
  73. Serialize();
  74. }
  75. public void DeleteCarrier(string module)
  76. {
  77. if (!_locationCarriers.ContainsKey(module))
  78. return;
  79. CarrierDataRecorder.Unloaded(_locationCarriers[module][0].InnerId.ToString());
  80. _locationCarriers[module][0].Clear();
  81. Serialize();
  82. }
  83. public void RegisterCarrierWafer(string module, int index, WaferInfo wafer)
  84. {
  85. if (!_locationCarriers.ContainsKey(module))
  86. return;
  87. _locationCarriers[module][0].Wafers[index] = wafer;
  88. }
  89. public void UnregisterCarrierWafer(string module, int index)
  90. {
  91. if (!_locationCarriers.ContainsKey(module))
  92. return;
  93. _locationCarriers[module][0].Wafers[index] = null;
  94. }
  95. public CarrierInfo GetCarrier(string module)
  96. {
  97. if (!_locationCarriers.ContainsKey(module))
  98. return null;
  99. return _locationCarriers[module][0];
  100. }
  101. public string GetLocationByCarrierId(string carrierId)
  102. {
  103. foreach (var locationCarrier in _locationCarriers)
  104. {
  105. foreach (var carrierInfo in locationCarrier.Value)
  106. {
  107. if (!carrierInfo.Value.IsEmpty && carrierInfo.Value.CarrierId == carrierId)
  108. return locationCarrier.Key;
  109. }
  110. }
  111. return null;
  112. }
  113. /// <summary>
  114. /// 传入LPn, 返回该LP的LotId
  115. /// </summary>
  116. /// <param name="moduleName">LP1/2/n</param>
  117. /// <returns>LotId string</returns>
  118. public string GetLotIdByLoadPort(string moduleName)
  119. {
  120. return _locationCarriers.ContainsKey(moduleName) ? _locationCarriers[moduleName][0].LotId : "";
  121. }
  122. public bool HasCarrier(string module)
  123. {
  124. if (!_locationCarriers.ContainsKey(module))
  125. return false;
  126. return !_locationCarriers[module][0].IsEmpty;
  127. }
  128. public void CarrierMoved(string moduleFrom, string moduleTo)
  129. {
  130. if (_locationCarriers[moduleFrom][0].IsEmpty)
  131. {
  132. LOG.Write(string.Format("Invalid carrier move, no carrier at source, {0}{1}=>{2}{3}", moduleFrom, 0 + 1, moduleTo, 0 + 1));
  133. return;
  134. }
  135. if (!_locationCarriers[moduleTo][0].IsEmpty)
  136. {
  137. LOG.Write(string.Format("Invalid carrier move, destination has carrier, {0}{1}=>{2}{3}", moduleFrom, 0 + 1, moduleTo, 0 + 1));
  138. return;
  139. }
  140. _locationCarriers[moduleTo][0].CopyInfo(_locationCarriers[moduleFrom][0]);
  141. DeleteCarrier(moduleFrom);
  142. EV.Notify(EventCarrierMoveOut, new SerializableDictionary<string, string>()
  143. {
  144. {DvidCarrierId, GetCarrier(moduleFrom).CarrierId},
  145. { DvidStation, moduleFrom}
  146. });
  147. EV.Notify(EventCarrierMoveIn, new SerializableDictionary<string, string>()
  148. {
  149. {DvidCarrierId, GetCarrier(moduleTo).CarrierId},
  150. { DvidStation, moduleTo}
  151. });
  152. EV.PostInfoLog(ModuleName.System.ToString(), string.Format("Carrier moved from {0} to {1}", moduleFrom, moduleTo));
  153. WaferMoveHistoryRecorder.WaferMoved(_locationCarriers[moduleTo][0].InnerId.ToString(), moduleTo.ToString(), 0, _locationCarriers[moduleTo][0].Status.ToString());
  154. Serialize();
  155. }
  156. public void UpdateCarrierId(string module, string carrierId)
  157. {
  158. if (!_locationCarriers.ContainsKey(module))
  159. return;
  160. if (!string.IsNullOrEmpty(_locationCarriers[module][0].CarrierId))
  161. {
  162. DeleteCarrier(module);
  163. CreateCarrier(module);
  164. }
  165. _locationCarriers[module][0].CarrierId = carrierId;
  166. CarrierDataRecorder.UpdateCarrierId(_locationCarriers[module][0].InnerId.ToString(), carrierId);
  167. Serialize();
  168. }
  169. public void UpdateRfId(string module, string rfid)
  170. {
  171. if (!_locationCarriers.ContainsKey(module))
  172. return;
  173. if (!string.IsNullOrEmpty(_locationCarriers[module][0].CarrierId))
  174. {
  175. DeleteCarrier(module);
  176. CreateCarrier(module);
  177. }
  178. _locationCarriers[module][0].Rfid = rfid;
  179. Serialize();
  180. }
  181. public void UpdateCarrierLot(string module, string lotId)
  182. {
  183. if (!_locationCarriers.ContainsKey(module))
  184. return;
  185. _locationCarriers[module][0].LotId = lotId;
  186. CarrierDataRecorder.UpdateLotId(_locationCarriers[module][0].InnerId.ToString(), lotId);
  187. Serialize();
  188. }
  189. public void UpdateProductCategory(string module, string productCategory)
  190. {
  191. if (!_locationCarriers.ContainsKey(module))
  192. return;
  193. _locationCarriers[module][0].ProductCategory = productCategory;
  194. CarrierDataRecorder.UpdateProductCategory(_locationCarriers[module][0].InnerId.ToString(), productCategory);
  195. Serialize();
  196. }
  197. public void UpdateProcessJob(string module, object job)
  198. {
  199. if (!_locationCarriers.ContainsKey(module))
  200. return;
  201. _locationCarriers[module][0].ProcessJob = job;
  202. Serialize();
  203. }
  204. public void UpdateProcessStatus(string module, bool processed)
  205. {
  206. if (!_locationCarriers.ContainsKey(module))
  207. return;
  208. _locationCarriers[module][0].ProcessStatus[module] = processed;
  209. Serialize();
  210. }
  211. }
  212. }