CarrierManager.cs 9.0 KB

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