WaferManager.cs 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  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.OperationCenter;
  9. using Aitex.Core.Util;
  10. using FabConnect.SecsGemInterface.Common;
  11. using MECF.Framework.Common.DataCenter;
  12. using MECF.Framework.Common.DBCore;
  13. using MECF.Framework.Common.Equipment;
  14. using MECF.Framework.Common.Utilities;
  15. using SciChart.Core.Extensions;
  16. namespace MECF.Framework.Common.SubstrateTrackings
  17. {
  18. public class WaferManager : Singleton<WaferManager>
  19. {
  20. Dictionary<string, WaferInfo> _dict = new Dictionary<string, WaferInfo>();
  21. object _lockerWaferList = new object();
  22. Dictionary<ModuleName, Dictionary<int, WaferInfo>> _locationWafers = new Dictionary<ModuleName, Dictionary<int, WaferInfo>>();
  23. public Dictionary<ModuleName, Dictionary<int, WaferInfo>> AllLocationWafers => _locationWafers;
  24. private const string EventWaferLeft = "WAFER_LEFT_POSITION";
  25. private const string EventWaferArrive = "WAFER_ARRIVE_POSITION";
  26. private const string Event_STS_AtSourcs = "STS_ATSOURCE";
  27. private const string Event_STS_AtWork = "STS_ATWORK";
  28. private const string Event_STS_AtDestination = "STS_ATDESTINATION";
  29. private const string Event_STS_Deleted = "STS_DELETED";
  30. private const string Event_STS_NeedProcessing = "STS_NEEDPROCESSING";
  31. private const string Event_STS_InProcessing = "STS_INPROCESSING";
  32. private const string Event_STS_Processed = "STS_PROCESSED";
  33. private const string Event_STS_Aborted = "STS_ABORTED";
  34. private const string Event_STS_Stopped = "STS_STOPPED";
  35. private const string Event_STS_Rejected = "STS_REJECTED";
  36. private const string Event_STS_Lost = "STS_LOST";
  37. private const string Event_STS_Skipped = "STS_SKIPPED";
  38. //private const string Event_STS_Unoccupied = "STS_UNOCCUPIED";
  39. //private const string Event_STS_Occupied = "STS_OCCUPIED";
  40. private const string Event_STS_Nostate = "STS_NOSTATE";
  41. public const string LotID = "LotID";
  42. public const string SubstDestination = "SubstDestination";
  43. public const string SubstHistory = "SubstHistory";
  44. public const string SubstID = "SubstID";
  45. public const string SubstLocID = "SubstLocID";
  46. public const string SubstLocState = "SubstLocState";
  47. public const string SubstProcState = "SubstProcState";
  48. public const string PrvSubstProcState = "PrvSubstProcState";
  49. public const string SubstSource = "SubstSource";
  50. public const string SubstState = "SubstState";
  51. public const string PrvSubstState = "PrvSubstState";
  52. public const string SubstType = "SubstType";
  53. public const string SubstUsage = "SubstUsage";
  54. public const string SubstMtrlStatus = "SubstMtrlStatus";
  55. public const string SubstSourceSlot = "SourceSlot";
  56. public const string SubstSourceCarrierID = "SourceCarrier";
  57. public const string SubstCurrentSlot = "Slot";
  58. private PeriodicJob _thread;
  59. private bool _needSerialize;
  60. public Dictionary<string, bool> NeedUpdateModule = new Dictionary<string, bool>();
  61. public WaferManager()
  62. {
  63. }
  64. public bool Serialize()
  65. {
  66. if (NeedUpdateModule.Any(r => r.Value))
  67. {
  68. var modules = NeedUpdateModule.Where(r => r.Value).Select(r => r.Key).ToList();
  69. if (!(Singleton<EventManager>.Instance.UpdateWafers(modules) == false))
  70. NeedUpdateModule.Clear();
  71. }
  72. if (!_needSerialize) return true;
  73. _needSerialize = false;
  74. try
  75. {
  76. if (_locationWafers != null)
  77. {
  78. BinarySerializer<Dictionary<ModuleName, Dictionary<int, WaferInfo>>>.ToStream(_locationWafers, "WaferManager");
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. LOG.Write(ex);
  84. }
  85. return true;
  86. }
  87. public void Deserialize()
  88. {
  89. try
  90. {
  91. var ccc = BinarySerializer<Dictionary<ModuleName, Dictionary<int, WaferInfo>>>.FromStream("WaferManager");
  92. if (ccc != null)
  93. {
  94. foreach (var moduleWafers in ccc)
  95. {
  96. if (ModuleHelper.IsLoadPort(moduleWafers.Key))
  97. {
  98. foreach (var waferInfo in moduleWafers.Value)
  99. {
  100. waferInfo.Value.SetEmpty();
  101. }
  102. }
  103. }
  104. _locationWafers = ccc;
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. LOG.Write(ex);
  110. }
  111. }
  112. public void Initialize()
  113. {
  114. EV.Subscribe(new EventItem("Event", EventWaferLeft, "Wafer Left"));
  115. EV.Subscribe(new EventItem("Event", EventWaferArrive, "Wafer Arrived"));
  116. EV.Subscribe(new EventItem("Event", Event_STS_AtSourcs, "Substrate transport state is AT_SOURCE."));
  117. EV.Subscribe(new EventItem("Event", Event_STS_AtWork, "Substrate transport state is AT_WORK."));
  118. EV.Subscribe(new EventItem("Event", Event_STS_AtDestination, "Substrate transport state is AT_DESTINATION."));
  119. EV.Subscribe(new EventItem("Event", Event_STS_Deleted, "Substrate transport state is DELETED."));
  120. EV.Subscribe(new EventItem("Event", Event_STS_NeedProcessing, "Substrate process state is NEEDPROCESSING."));
  121. EV.Subscribe(new EventItem("Event", Event_STS_InProcessing, "Substrate process state is INPROCESSING."));
  122. EV.Subscribe(new EventItem("Event", Event_STS_Processed, "Substrate process state is PROCESSED."));
  123. EV.Subscribe(new EventItem("Event", Event_STS_Aborted, "Substrate process state is ABORTED."));
  124. EV.Subscribe(new EventItem("Event", Event_STS_Stopped, "Substrate process state is STOPPED."));
  125. EV.Subscribe(new EventItem("Event", Event_STS_Rejected, "Substrate process state is REJECTED."));
  126. EV.Subscribe(new EventItem("Event", Event_STS_Lost, "Substrate process state is LOST."));
  127. EV.Subscribe(new EventItem("Event", Event_STS_Skipped, "Substrate process state is SKIPPED."));
  128. EV.Subscribe(new EventItem("Event", Event_STS_Nostate, "Substrate process state is NOSTATE."));
  129. //EV.Subscribe(new EventItem("Event", Event_STS_Unoccupied, "Substrate location state is Unoccupied."));
  130. //EV.Subscribe(new EventItem("Event", Event_STS_Occupied, "Substrate location state is occupied."));
  131. Deserialize();
  132. _thread = new PeriodicJob(500, Serialize, $"SerializeMonitorHandler", true);
  133. }
  134. public void SubscribeLocation(string module, int slotNumber)
  135. {
  136. ModuleName mod;
  137. if (Enum.TryParse(module, out mod))
  138. {
  139. SubscribeLocation(mod, slotNumber);
  140. }
  141. else
  142. {
  143. LOG.Write(string.Format("Failed SubscribeLocation, module name invalid, {0} ", module));
  144. }
  145. }
  146. public void SubscribeLocation(ModuleName module, int slotNumber)
  147. {
  148. if (!_locationWafers.ContainsKey(module))
  149. {
  150. _locationWafers[module] = new Dictionary<int, WaferInfo>();
  151. for (int i = 0; i < slotNumber; i++)
  152. {
  153. _locationWafers[module][i] = new WaferInfo();
  154. }
  155. }
  156. DATA.Subscribe(module.ToString(), "ModuleWaferList", () => _locationWafers[module].Values.ToArray());
  157. NeedUpdateModule[module.ToString()] = true;
  158. }
  159. public void WaferMoved(ModuleName moduleFrom, int slotFrom, ModuleName moduleTo, int slotTo, bool needHistory = true)
  160. {
  161. if (_locationWafers[moduleFrom][slotFrom].IsEmpty)
  162. {
  163. LOG.Write(string.Format("Invalid wafer move, no wafer at source, {0}{1}=>{2}{3}", moduleFrom, slotFrom + 1, moduleTo, slotTo + 1));
  164. return;
  165. }
  166. if (!_locationWafers[moduleTo][slotTo].IsEmpty)
  167. {
  168. LOG.Write(string.Format("Invalid wafer move, destination has wafer, {0}{1}=>{2}{3}", moduleFrom, slotFrom + 1, moduleTo, slotTo + 1));
  169. return;
  170. }
  171. UpdateWaferHistory(moduleFrom, slotFrom, SubstAccessType.Left);
  172. string waferOrigin = _locationWafers[moduleFrom][slotFrom].WaferOrigin;
  173. WaferInfo wafer = CopyWaferInfo(moduleTo, slotTo, _locationWafers[moduleFrom][slotFrom]);
  174. UpdateWaferHistory(moduleTo, slotTo, SubstAccessType.Arrive);
  175. DeleteWaferForMove(moduleFrom, slotFrom);
  176. if (needHistory)
  177. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferMoved, waferOrigin, moduleFrom.ToString(), slotFrom + 1, moduleTo.ToString(), slotTo + 1);
  178. WaferMoveHistoryRecorder.WaferMoved(wafer.InnerId.ToString(), moduleTo.ToString(), slotTo, wafer.Status.ToString());
  179. if (needHistory)
  180. EV.Notify(EventWaferLeft, new SerializableDictionary<string, string>()
  181. {
  182. {"SLOT_NO", (slotFrom+1).ToString("D2")},
  183. {"WAFER_ID", wafer.WaferID},
  184. {"LOT_ID", wafer.LotId},
  185. { "CAR_ID", GetCarrierID(moduleFrom)},
  186. { "LEFT_POS_NAME", $"{moduleFrom}.{(slotFrom+1).ToString("D2")}" }
  187. });
  188. if (ModuleHelper.IsLoadPort(moduleFrom))
  189. {
  190. UpdateWaferTransportState(wafer.WaferID, SubstrateTransportStatus.AtWork);
  191. UpdateWaferE90State(wafer.WaferID, EnumE90Status.InProcess);
  192. }
  193. if (needHistory)
  194. EV.Notify(EventWaferArrive, new SerializableDictionary<string, string>()
  195. {
  196. {"SLOT_NO", (slotTo+1).ToString("D2")},
  197. {"WAFER_ID", wafer.WaferID},
  198. {"LOT_ID", wafer.LotId},
  199. { "CAR_ID", GetCarrierID(moduleTo)},
  200. { "ARRIVE_POS_NAME", $"{moduleTo}.{(slotTo+1).ToString("D2")}" }
  201. });
  202. if (ModuleHelper.IsLoadPort(moduleTo))
  203. {
  204. if (wafer.SubstE90Status == EnumE90Status.InProcess)
  205. UpdateWaferE90State(wafer.WaferID, EnumE90Status.Processed);
  206. if (moduleTo == (ModuleName)wafer.OriginStation && wafer.SubstE90Status != EnumE90Status.Processed)
  207. UpdateWaferTransportState(wafer.WaferID, SubstrateTransportStatus.AtSource);
  208. else
  209. UpdateWaferTransportState(wafer.WaferID, SubstrateTransportStatus.AtDestination);
  210. }
  211. if (needHistory)
  212. EV.PostInfoLog("System", $"Wafer:{wafer.WaferID} moved from {moduleFrom} slot:{slotFrom + 1} to {moduleTo} slot:{slotTo + 1}.");
  213. NeedUpdateModule[moduleFrom.ToString()] = true;
  214. NeedUpdateModule[moduleTo.ToString()] = true;
  215. //Serialize();
  216. _needSerialize = true;
  217. }
  218. //传送过程中出现错误,Wafer未知
  219. public void WaferDuplicated(ModuleName moduleFrom, int slotFrom, ModuleName moduleTo, int slotTo)
  220. {
  221. UpdateWaferHistory(moduleFrom, slotFrom, SubstAccessType.Left);
  222. if (_locationWafers[moduleFrom][slotFrom].IsEmpty)
  223. {
  224. LOG.Write(string.Format("Invalid wafer move, no wafer at source, {0}{1}=>{2}{3}", moduleFrom, slotFrom + 1, moduleTo, slotTo + 1));
  225. return;
  226. }
  227. if (!_locationWafers[moduleTo][slotTo].IsEmpty)
  228. {
  229. LOG.Write(string.Format("Invalid wafer move, destination has wafer, {0}{1}=>{2}{3}", moduleFrom, slotFrom + 1, moduleTo, slotTo + 1));
  230. return;
  231. }
  232. string waferOrigin = _locationWafers[moduleFrom][slotFrom].WaferOrigin;
  233. WaferInfo wafer = CopyWaferInfo(moduleTo, slotTo, _locationWafers[moduleFrom][slotFrom]);
  234. UpdateWaferHistory(moduleTo, slotTo, SubstAccessType.Arrive);
  235. //DeleteWaferForMove(moduleFrom, slotFrom);
  236. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferMoved, waferOrigin, moduleFrom.ToString(), slotFrom + 1, moduleTo.ToString(), slotTo + 1);
  237. WaferMoveHistoryRecorder.WaferMoved(wafer.InnerId.ToString(), moduleTo.ToString(), slotTo, wafer.Status.ToString());
  238. EV.Notify(EventWaferLeft, new SerializableDictionary<string, string>()
  239. {
  240. {"SLOT_NO", (slotFrom+1).ToString("D2")},
  241. {"Slot", (slotFrom+1).ToString("D2")},
  242. {"WAFER_ID", wafer.WaferID},
  243. {"SubstID", wafer.WaferID},
  244. {"LOT_ID", wafer.LotId},
  245. {"LotID", wafer.LotId},
  246. { "CAR_ID", GetCarrierID(moduleFrom)},
  247. { "CarrierID", GetCarrierID(moduleFrom)},
  248. { "LEFT_POS_NAME", $"{moduleFrom}.{(slotFrom+1).ToString("D2")}" }
  249. });
  250. if (ModuleHelper.IsLoadPort(moduleFrom))
  251. {
  252. UpdateWaferTransportState(wafer.WaferID, SubstrateTransportStatus.AtWork);
  253. UpdateWaferE90State(wafer.WaferID, EnumE90Status.InProcess);
  254. }
  255. EV.Notify(EventWaferArrive, new SerializableDictionary<string, string>()
  256. {
  257. {"SLOT_NO", (slotTo+1).ToString("D2")},
  258. {"WAFER_ID", wafer.WaferID},
  259. {"SubstID", wafer.WaferID},
  260. {"LOT_ID", wafer.LotId},
  261. {"LotID", wafer.LotId},
  262. { "CAR_ID", GetCarrierID(moduleTo)},
  263. { "CarrierID", GetCarrierID(moduleTo)},
  264. { "ARRIVE_POS_NAME", $"{moduleTo}.{(slotTo+1).ToString("D2")}" }
  265. });
  266. if (ModuleHelper.IsLoadPort(moduleTo))
  267. {
  268. if (wafer.SubstE90Status == EnumE90Status.InProcess)
  269. UpdateWaferE90State(wafer.WaferID, EnumE90Status.Processed);
  270. if (moduleTo == (ModuleName)wafer.OriginStation && wafer.SubstE90Status != EnumE90Status.Processed)
  271. UpdateWaferTransportState(wafer.WaferID, SubstrateTransportStatus.AtSource);
  272. else
  273. UpdateWaferTransportState(wafer.WaferID, SubstrateTransportStatus.AtDestination);
  274. }
  275. UpdateWaferProcessStatus(moduleFrom, slotFrom, EnumWaferProcessStatus.Failed);
  276. UpdateWaferProcessStatus(moduleTo, slotTo, EnumWaferProcessStatus.Failed);
  277. NeedUpdateModule[moduleFrom.ToString()] = true;
  278. NeedUpdateModule[moduleTo.ToString()] = true;
  279. //Serialize();
  280. _needSerialize = true;
  281. }
  282. private string GetCarrierID(ModuleName module)
  283. {
  284. if (!ModuleHelper.IsLoadPort(module))
  285. return "";
  286. if (DATA.Poll($"{module.ToString()}.CarrierId") == null)
  287. return "";
  288. return DATA.Poll($"{module.ToString()}.CarrierId").ToString();
  289. }
  290. public bool IsWaferSlotLocationValid(ModuleName module, int slot)
  291. {
  292. return _locationWafers.ContainsKey(module) && _locationWafers[module].ContainsKey(slot);
  293. }
  294. public WaferInfo[] GetWafers(ModuleName module)
  295. {
  296. if (!_locationWafers.ContainsKey(module))
  297. return null;
  298. return _locationWafers[module].Values.ToArray();
  299. }
  300. public WaferInfo[] GetWaferByProcessJob(string jobName)
  301. {
  302. List<WaferInfo> wafers = new List<WaferInfo>();
  303. foreach (var moduleWafer in _locationWafers)
  304. {
  305. foreach (var waferInfo in moduleWafer.Value)
  306. {
  307. if (waferInfo.Value != null && !waferInfo.Value.IsEmpty
  308. && (waferInfo.Value.ProcessJob != null)
  309. && waferInfo.Value.ProcessJob.Name == jobName)
  310. wafers.Add(waferInfo.Value);
  311. }
  312. }
  313. return wafers.ToArray();
  314. }
  315. public WaferInfo[] GetWafersByOriginalPosition(ModuleName module, int slot)
  316. {
  317. List<WaferInfo> ret = new List<WaferInfo>();
  318. foreach (var locationWafer in _locationWafers)
  319. {
  320. foreach (var wafer in locationWafer.Value)
  321. {
  322. if (wafer.Value.IsEmpty) continue;
  323. if (wafer.Value.OriginStation == (int)module && wafer.Value.OriginSlot == slot)
  324. ret.Add(wafer.Value);
  325. }
  326. }
  327. return ret.ToArray();
  328. }
  329. public WaferInfo[] GetWafersByOriginalPosition(ModuleName module)
  330. {
  331. List<WaferInfo> ret = new List<WaferInfo>();
  332. foreach (var locationWafer in _locationWafers)
  333. {
  334. foreach (var wafer in locationWafer.Value)
  335. {
  336. if (wafer.Value.IsEmpty) continue;
  337. if (wafer.Value.OriginStation == (int)module)
  338. ret.Add(wafer.Value);
  339. }
  340. }
  341. return ret.ToArray();
  342. }
  343. public WaferInfo[] GetWafer(string waferID)
  344. {
  345. List<WaferInfo> result = new List<WaferInfo>();
  346. foreach (var locationWafer in _locationWafers)
  347. {
  348. foreach (var wafer in locationWafer.Value)
  349. {
  350. if (wafer.Value.WaferID == waferID)
  351. result.Add(wafer.Value);
  352. }
  353. }
  354. return result.ToArray();
  355. }
  356. public WaferInfo GetWafer(ModuleName module, int slot)
  357. {
  358. if (!_locationWafers.ContainsKey(module))
  359. return null;
  360. if (!_locationWafers[module].ContainsKey(slot))
  361. return null;
  362. return _locationWafers[module][slot];
  363. }
  364. public WaferInfo[] GetWafers(string Originalcarrier, int Originalslot)
  365. {
  366. List<WaferInfo> ret = new List<WaferInfo>();
  367. foreach (var locationWafer in _locationWafers)
  368. {
  369. foreach (var wafer in locationWafer.Value)
  370. {
  371. if (wafer.Value.OriginCarrierID == Originalcarrier && wafer.Value.OriginSlot == Originalslot)
  372. ret.Add(wafer.Value);
  373. }
  374. }
  375. return ret.ToArray();
  376. }
  377. public string GetWaferID(ModuleName module, int slot)
  378. {
  379. return IsWaferSlotLocationValid(module, slot) ? _locationWafers[module][slot].WaferID : "";
  380. }
  381. public WaferSize GetWaferSize(ModuleName module, int slot)
  382. {
  383. return IsWaferSlotLocationValid(module, slot) ? _locationWafers[module][slot].Size : WaferSize.WS0;
  384. }
  385. public bool CheckNoWafer(ModuleName module, int slot)
  386. {
  387. return IsWaferSlotLocationValid(module, slot) && _locationWafers[module][slot].IsEmpty;
  388. }
  389. public bool CheckNoWafer(string module, int slot)
  390. {
  391. return CheckNoWafer((ModuleName)Enum.Parse(typeof(ModuleName), module), slot);
  392. }
  393. public bool CheckHasWafer(ModuleName module, int slot)
  394. {
  395. return IsWaferSlotLocationValid(module, slot) && !_locationWafers[module][slot].IsEmpty;
  396. }
  397. public bool CheckWaferIsDummy(ModuleName module, int slot)
  398. {
  399. return IsWaferSlotLocationValid(module, slot) && !_locationWafers[module][slot].IsEmpty
  400. && _locationWafers[module][slot].Status == WaferStatus.Dummy;
  401. }
  402. /// <summary>
  403. /// Verify the slot map in string[] format, if there's any mis-match it will return false.
  404. /// </summary>
  405. /// <param name="moduleNo">LP No</param>
  406. /// <param name="flagStrings">Flag input</param>
  407. /// <returns></returns>
  408. public bool CheckWaferExistFlag(string moduleNo, string[] flagStrings, out string reason)
  409. {
  410. var i = 0;
  411. reason = string.Empty;
  412. if (!Enum.TryParse($"LP{moduleNo}", out ModuleName module))
  413. {
  414. reason = "Port Number Error";
  415. return false;
  416. }
  417. foreach (var slot in flagStrings)
  418. {
  419. if (slot == "1")
  420. {
  421. if (IsWaferSlotLocationValid(module, i) && _locationWafers[module][i].IsEmpty)
  422. {
  423. reason = "Flag Mis-Match";
  424. return false;
  425. }
  426. }
  427. else
  428. {
  429. if (IsWaferSlotLocationValid(module, i) && !_locationWafers[module][i].IsEmpty)
  430. {
  431. reason = "Flag Mis-Match";
  432. return false;
  433. }
  434. }
  435. i++;
  436. }
  437. return true;
  438. }
  439. public bool CheckHasWafer(string module, int slot)
  440. {
  441. return CheckHasWafer((ModuleName)Enum.Parse(typeof(ModuleName), module), slot);
  442. }
  443. public bool CheckWaferFull(ModuleName module)
  444. {
  445. var wafers = _locationWafers[module];
  446. foreach (var waferInfo in wafers)
  447. {
  448. if (waferInfo.Value.IsEmpty)
  449. return false;
  450. }
  451. return true;
  452. }
  453. public bool CheckWaferEmpty(ModuleName module)
  454. {
  455. var wafers = _locationWafers[module];
  456. foreach (var waferInfo in wafers)
  457. {
  458. if (!waferInfo.Value.IsEmpty)
  459. return false;
  460. }
  461. return true;
  462. }
  463. public bool CheckWafer(ModuleName module, int slot, WaferStatus state)
  464. {
  465. return IsWaferSlotLocationValid(module, slot) && (_locationWafers[module][slot].Status == state);
  466. }
  467. public WaferInfo CreateWafer(ModuleName module, int slot, WaferStatus state, WaferType waferType = WaferType.None, string lotId = "")
  468. {
  469. if (!IsWaferSlotLocationValid(module, slot))
  470. {
  471. LOG.Write(string.Format("Invalid wafer create, invalid parameter, {0},{1}", module, slot + 1));
  472. return null;
  473. }
  474. string carrierInnerId = "";
  475. string carrierID = string.Empty;
  476. if (ModuleHelper.IsLoadPort(module) || ModuleHelper.IsCassette(module))
  477. {
  478. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  479. if (carrier == null)
  480. {
  481. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning,
  482. string.Format("No carrier at {0}, can not create wafer", module));
  483. return null;
  484. }
  485. carrierInnerId = carrier.InnerId.ToString();
  486. carrierID = carrier.CarrierId;
  487. }
  488. lock (_lockerWaferList)
  489. {
  490. _locationWafers[module][slot].Status = state;
  491. _locationWafers[module][slot].ProcessState = EnumWaferProcessStatus.Idle;
  492. _locationWafers[module][slot].SubstE90Status = EnumE90Status.NeedProcessing;
  493. _locationWafers[module][slot].WaferID = GenerateWaferId(module, slot, carrierID);
  494. _locationWafers[module][slot].WaferOrigin = GenerateOrigin(module, slot);
  495. _locationWafers[module][slot].Station = (int)module;
  496. _locationWafers[module][slot].Slot = slot;
  497. _locationWafers[module][slot].InnerId = Guid.NewGuid();
  498. _locationWafers[module][slot].OriginStation = (int)module;
  499. _locationWafers[module][slot].OriginSlot = slot;
  500. _locationWafers[module][slot].OriginCarrierID = carrierID;
  501. _locationWafers[module][slot].LotId = lotId;
  502. _locationWafers[module][slot].HostLaserMark1 = "";
  503. _locationWafers[module][slot].HostLaserMark2 = "";
  504. _locationWafers[module][slot].LaserMarker = "";
  505. _locationWafers[module][slot].T7Code = "";
  506. _locationWafers[module][slot].PPID = "";
  507. _locationWafers[module][slot].WaferType = waferType;
  508. SubstHistory hist = new SubstHistory(module.ToString(), slot, DateTime.Now, SubstAccessType.Create);
  509. _locationWafers[module][slot].SubstHists = new SubstHistory[] { hist };
  510. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  511. //EV.Notify(Event_STS_Occupied, new SerializableDictionary<string, object>()
  512. //{
  513. // {SubstLocID,module.ToString()},
  514. // {SubstID,_locationWafers[module][slot].WaferID},
  515. // {SubstLocState,1}
  516. //});
  517. }
  518. UpdateWaferE90State(_locationWafers[module][slot].WaferID, EnumE90Status.NeedProcessing);
  519. UpdateWaferTransportState(_locationWafers[module][slot].WaferID, SubstrateTransportStatus.AtSource);
  520. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID, _locationWafers[module][slot].ProcessState.ToString());
  521. NeedUpdateModule[module.ToString()] = true;
  522. //Serialize();
  523. _needSerialize = true;
  524. EV.PostInfoLog("System", $"Create wafer successfully on {module} slot:{slot + 1}.");
  525. return _locationWafers[module][slot];
  526. }
  527. public WaferInfo CreateWafer(ModuleName module, int slot, ModuleName originModule, int originSlot, WaferStatus state, WaferType waferType = WaferType.None)
  528. {
  529. if (!IsWaferSlotLocationValid(module, slot))
  530. {
  531. LOG.Write(string.Format("Invalid wafer create, invalid parameter, {0},{1}", module, slot + 1));
  532. return null;
  533. }
  534. string carrierInnerId = "";
  535. string carrierID = string.Empty;
  536. if (ModuleHelper.IsLoadPort(module) || ModuleHelper.IsCassette(module))
  537. {
  538. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  539. if (carrier == null)
  540. {
  541. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning,
  542. string.Format("No carrier at {0}, can not create wafer", module));
  543. return null;
  544. }
  545. carrierInnerId = carrier.InnerId.ToString();
  546. carrierID = carrier.CarrierId;
  547. }
  548. lock (_lockerWaferList)
  549. {
  550. _locationWafers[module][slot].Status = state;
  551. _locationWafers[module][slot].ProcessState = EnumWaferProcessStatus.Idle;
  552. _locationWafers[module][slot].SubstE90Status = EnumE90Status.NeedProcessing;
  553. _locationWafers[module][slot].WaferID = GenerateWaferId(originModule, originSlot, carrierID);
  554. _locationWafers[module][slot].WaferOrigin = GenerateOrigin(originModule, originSlot);
  555. _locationWafers[module][slot].Station = (int)module;
  556. _locationWafers[module][slot].Slot = slot;
  557. _locationWafers[module][slot].InnerId = Guid.NewGuid();
  558. _locationWafers[module][slot].OriginStation = (int)originModule;
  559. _locationWafers[module][slot].OriginSlot = originSlot;
  560. _locationWafers[module][slot].OriginCarrierID = carrierID;
  561. _locationWafers[module][slot].LotId = "";
  562. _locationWafers[module][slot].HostLaserMark1 = "";
  563. _locationWafers[module][slot].HostLaserMark2 = "";
  564. _locationWafers[module][slot].LaserMarker = "";
  565. _locationWafers[module][slot].T7Code = "";
  566. _locationWafers[module][slot].PPID = "";
  567. _locationWafers[module][slot].WaferType = waferType;
  568. SubstHistory hist = new SubstHistory(module.ToString(), slot, DateTime.Now, SubstAccessType.Create);
  569. _locationWafers[module][slot].SubstHists = new SubstHistory[] { hist };
  570. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  571. //EV.Notify(Event_STS_Occupied, new SerializableDictionary<string, object>()
  572. //{
  573. // {SubstLocID,module.ToString()},
  574. // {SubstID,_locationWafers[module][slot].WaferID},
  575. // {SubstLocState,1}
  576. //});
  577. }
  578. UpdateWaferE90State(_locationWafers[module][slot].WaferID, EnumE90Status.NeedProcessing);
  579. UpdateWaferTransportState(_locationWafers[module][slot].WaferID, SubstrateTransportStatus.AtSource);
  580. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID, _locationWafers[module][slot].ProcessState.ToString());
  581. //Serialize();
  582. _needSerialize = true;
  583. NeedUpdateModule[module.ToString()] = true;
  584. EV.PostInfoLog("System", $"Create wafer successfully on {module} slot:{slot + 1}.");
  585. return _locationWafers[module][slot];
  586. }
  587. public WaferInfo CreateWafer(ModuleName module, int slot, WaferStatus state, WaferSize wz)
  588. {
  589. if (!IsWaferSlotLocationValid(module, slot))
  590. {
  591. LOG.Write(string.Format("Invalid wafer create, invalid parameter, {0},{1}", module, slot + 1));
  592. return null;
  593. }
  594. string carrierInnerId = "";
  595. string carrierID = string.Empty;
  596. if (ModuleHelper.IsLoadPort(module) || ModuleHelper.IsCassette(module))
  597. {
  598. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(module.ToString());
  599. if (carrier == null)
  600. {
  601. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning,
  602. string.Format("No carrier at {0}, can not create wafer", module));
  603. return null;
  604. }
  605. carrierInnerId = carrier.InnerId.ToString();
  606. carrierID = carrier.CarrierId;
  607. }
  608. lock (_lockerWaferList)
  609. {
  610. _locationWafers[module][slot].Status = state;
  611. _locationWafers[module][slot].ProcessState = EnumWaferProcessStatus.Idle;
  612. _locationWafers[module][slot].SubstE90Status = EnumE90Status.NeedProcessing;
  613. _locationWafers[module][slot].WaferID = GenerateWaferId(module, slot, carrierID);
  614. _locationWafers[module][slot].WaferOrigin = GenerateOrigin(module, slot);
  615. _locationWafers[module][slot].Station = (int)module;
  616. _locationWafers[module][slot].Slot = slot;
  617. _locationWafers[module][slot].InnerId = Guid.NewGuid();
  618. _locationWafers[module][slot].OriginStation = (int)module;
  619. _locationWafers[module][slot].OriginSlot = slot;
  620. _locationWafers[module][slot].OriginCarrierID = carrierID;
  621. _locationWafers[module][slot].LotId = "";
  622. _locationWafers[module][slot].HostLaserMark1 = "";
  623. _locationWafers[module][slot].HostLaserMark2 = "";
  624. _locationWafers[module][slot].LaserMarker = "";
  625. _locationWafers[module][slot].T7Code = "";
  626. _locationWafers[module][slot].PPID = "";
  627. _locationWafers[module][slot].Size = wz;
  628. SubstHistory hist = new SubstHistory(module.ToString(), slot, DateTime.Now, SubstAccessType.Create);
  629. _locationWafers[module][slot].SubstHists = new SubstHistory[] { hist };
  630. _dict[_locationWafers[module][slot].WaferID] = _locationWafers[module][slot];
  631. }
  632. UpdateWaferE90State(_locationWafers[module][slot].WaferID, EnumE90Status.NeedProcessing);
  633. UpdateWaferTransportState(_locationWafers[module][slot].WaferID, SubstrateTransportStatus.AtSource);
  634. EV.PostInfoLog("System", $"Create wafer successfully on {module} slot:{slot + 1} wafersize:{wz}.");
  635. WaferDataRecorder.CreateWafer(_locationWafers[module][slot].InnerId.ToString(), carrierInnerId, module.ToString(), slot, _locationWafers[module][slot].WaferID, _locationWafers[module][slot].ProcessState.ToString());
  636. //Serialize();
  637. _needSerialize = true;
  638. NeedUpdateModule[module.ToString()] = true;
  639. return _locationWafers[module][slot];
  640. }
  641. public void DeleteWafer(ModuleName module, int slotFrom, int count = 1)
  642. {
  643. lock (_lockerWaferList)
  644. {
  645. for (int i = 0; i < count; i++)
  646. {
  647. int slot = slotFrom + i;
  648. if (!IsWaferSlotLocationValid(module, slot))
  649. {
  650. LOG.Write(string.Format("Invalid wafer delete, invalid parameter, {0},{1}", module, slot + 1));
  651. continue;
  652. }
  653. //EV.Notify(Event_STS_Unoccupied, new SerializableDictionary<string, object>()
  654. //{
  655. // {SubstLocID,module.ToString()},
  656. // {SubstID,_locationWafers[module][slot].WaferID},
  657. // {SubstLocState,0}
  658. //});
  659. UpdateWaferE90State(_locationWafers[module][slot].WaferID, EnumE90Status.None);
  660. UpdateWaferTransportState(_locationWafers[module][slot].WaferID, SubstrateTransportStatus.None);
  661. EV.PostInfoLog("System", $"Delete wafer successfully on {module} from slot:{slotFrom + 1} count:{count}.");
  662. WaferDataRecorder.DeleteWafer(_locationWafers[module][slot].InnerId.ToString());
  663. _locationWafers[module][slot].SetEmpty();
  664. _locationWafers[module][slot].SubstHists = null;
  665. _dict.Remove(_locationWafers[module][slot].WaferID);
  666. }
  667. }
  668. NeedUpdateModule[module.ToString()] = true;
  669. //Serialize();
  670. _needSerialize = true;
  671. }
  672. public void DeleteWaferForMove(ModuleName module, int slotFrom, int count = 1)
  673. {
  674. lock (_lockerWaferList)
  675. {
  676. for (int i = 0; i < count; i++)
  677. {
  678. int slot = slotFrom + i;
  679. if (!IsWaferSlotLocationValid(module, slot))
  680. {
  681. LOG.Write(string.Format("Invalid wafer delete, invalid parameter, {0},{1}", module, slot + 1));
  682. continue;
  683. }
  684. //EV.Notify(Event_STS_Unoccupied, new SerializableDictionary<string, object>()
  685. //{
  686. // {SubstLocID,module.ToString()},
  687. // {SubstID,_locationWafers[module][slot].WaferID},
  688. // {SubstLocState,0}
  689. //});
  690. //UpdateWaferTransportState(_locationWafers[module][slot].WaferID, SubstrateTransportStatus.None);
  691. //???
  692. //WaferDataRecorder.DeleteWafer(_locationWafers[module][slot].InnerId.ToString());
  693. _locationWafers[module][slot].SetEmpty();
  694. _locationWafers[module][slot].SubstHists = null;
  695. _dict.Remove(_locationWafers[module][slot].WaferID);
  696. }
  697. }
  698. //Serialize();
  699. _needSerialize = true;
  700. NeedUpdateModule[module.ToString()] = true;
  701. }
  702. public void ManualDeleteWafer(ModuleName module, int slotFrom, int count = 1)
  703. {
  704. for (int i = 0; i < count; i++)
  705. {
  706. int slot = slotFrom + i;
  707. if (!IsWaferSlotLocationValid(module, slot))
  708. {
  709. LOG.Write(string.Format("Invalid wafer delete, invalid parameter, {0},{1}", module, slot + 1));
  710. continue;
  711. }
  712. // EV.Notify(Event_STS_Unoccupied, new SerializableDictionary<string, object>()
  713. //{
  714. // {SubstLocID,module.ToString()},
  715. // {SubstID,_locationWafers[module][slot].WaferID},
  716. // {SubstLocState,0}
  717. //});
  718. UpdateWaferE90State(_locationWafers[module][slot].WaferID, EnumE90Status.Lost);
  719. UpdateWaferTransportState(_locationWafers[module][slot].WaferID, SubstrateTransportStatus.None);
  720. UpdateWaferHistory(module, slotFrom, SubstAccessType.Delete);
  721. lock (_lockerWaferList)
  722. {
  723. WaferDataRecorder.DeleteWafer(_locationWafers[module][slot].InnerId.ToString());
  724. _locationWafers[module][slot].SetEmpty();
  725. _dict.Remove(_locationWafers[module][slot].WaferID);
  726. }
  727. }
  728. //Serialize();
  729. _needSerialize = true;
  730. NeedUpdateModule[module.ToString()] = true;
  731. }
  732. public void UpdateWaferLaser(ModuleName module, int slot, string laserMarker)
  733. {
  734. if (!IsWaferSlotLocationValid(module, slot))
  735. {
  736. LOG.Write(string.Format("Failed UpdateWaferLaser, invalid parameter, {0},{1}", module, slot + 1));
  737. return;
  738. }
  739. lock (_lockerWaferList)
  740. {
  741. _locationWafers[module][slot].LaserMarker = laserMarker;
  742. WaferDataRecorder.SetWaferMarker(_locationWafers[module][slot].InnerId.ToString(), laserMarker);
  743. }
  744. //Serialize();
  745. _needSerialize = true;
  746. NeedUpdateModule[module.ToString()] = true;
  747. }
  748. public void UpdateWaferDestination(ModuleName module, int slot, string destCarrierID, int destslot)
  749. {
  750. if (!IsWaferSlotLocationValid(module, slot))
  751. {
  752. LOG.Write(string.Format("Failed UpdateWaferLaser, invalid parameter, {0},{1}", module, slot + 1));
  753. return;
  754. }
  755. lock (_lockerWaferList)
  756. {
  757. _locationWafers[module][slot].DestinationCarrierID = destCarrierID;
  758. _locationWafers[module][slot].DestinationSlot = destslot;
  759. //WaferDataRecorder.SetWaferMarker(_locationWafers[module][slot].InnerId.ToString(), laserMarker);
  760. }
  761. //Serialize();
  762. _needSerialize = true;
  763. NeedUpdateModule[module.ToString()] = true;
  764. }
  765. public void UpdateWaferDestination(ModuleName module, int slot, ModuleName destmodule, int destslot)
  766. {
  767. if (!IsWaferSlotLocationValid(module, slot))
  768. {
  769. LOG.Write(string.Format("Failed UpdateWaferLaser, invalid parameter, {0},{1}", module, slot + 1));
  770. return;
  771. }
  772. lock (_lockerWaferList)
  773. {
  774. _locationWafers[module][slot].DestinationStation = (int)destmodule;
  775. _locationWafers[module][slot].DestinationSlot = destslot;
  776. //WaferDataRecorder.SetWaferMarker(_locationWafers[module][slot].InnerId.ToString(), laserMarker);
  777. }
  778. //Serialize();
  779. _needSerialize = true;
  780. NeedUpdateModule[module.ToString()] = true;
  781. }
  782. public void UpdateWaferLaserWithScoreAndFileName(ModuleName module, int slot, string laserMarker, string laserMarkerScore, string fileName, string filePath)
  783. {
  784. if (!IsWaferSlotLocationValid(module, slot))
  785. {
  786. LOG.Write(string.Format("Failed UpdateWaferLaser, invalid parameter, {0},{1}", module, slot + 1));
  787. return;
  788. }
  789. lock (_lockerWaferList)
  790. {
  791. _locationWafers[module][slot].LaserMarker = laserMarker;
  792. _locationWafers[module][slot].LaserMarkerScore = laserMarkerScore;
  793. _locationWafers[module][slot].ImageFileName = fileName;
  794. _locationWafers[module][slot].ImageFilePath = filePath;
  795. WaferDataRecorder.SetWaferMarkerWithScoreAndFileName(_locationWafers[module][slot].InnerId.ToString(), laserMarker, laserMarkerScore, fileName, filePath);
  796. }
  797. //Serialize();
  798. _needSerialize = true;
  799. NeedUpdateModule[module.ToString()] = true;
  800. }
  801. public void UpdateWaferT7Code(ModuleName module, int slot, string T7Code)
  802. {
  803. if (!IsWaferSlotLocationValid(module, slot))
  804. {
  805. LOG.Write(string.Format("Failed UpdateWaferT7Code, invalid parameter, {0},{1}", module, slot + 1));
  806. return;
  807. }
  808. lock (_lockerWaferList)
  809. {
  810. _locationWafers[module][slot].T7Code = T7Code;
  811. WaferDataRecorder.SetWaferT7Code(_locationWafers[module][slot].InnerId.ToString(), T7Code);
  812. }
  813. //Serialize();
  814. _needSerialize = true;
  815. NeedUpdateModule[module.ToString()] = true;
  816. }
  817. public void UpdataWaferPPID(ModuleName module, int slot, string PPID)
  818. {
  819. if (!IsWaferSlotLocationValid(module, slot))
  820. {
  821. LOG.Write(string.Format("Failed UpdateWaferPPID, invalid parameter, {0},{1}", module, slot + 1));
  822. return;
  823. }
  824. lock (_lockerWaferList)
  825. {
  826. _locationWafers[module][slot].PPID = PPID;
  827. WaferDataRecorder.SetWaferSequence(_locationWafers[module][slot].InnerId.ToString(), PPID);
  828. }
  829. //Serialize();
  830. _needSerialize = true;
  831. NeedUpdateModule[module.ToString()] = true;
  832. }
  833. public void UpdateWaferT7CodeWithScoreAndFileName(ModuleName module, int slot, string t7Code, string t7CodeScore, string fileName, string filePath)
  834. {
  835. if (!IsWaferSlotLocationValid(module, slot))
  836. {
  837. LOG.Write(string.Format("Failed UpdateWaferT7Code, invalid parameter, {0},{1}", module, slot + 1));
  838. return;
  839. }
  840. lock (_lockerWaferList)
  841. {
  842. _locationWafers[module][slot].T7Code = t7Code;
  843. _locationWafers[module][slot].T7CodeScore = t7CodeScore;
  844. _locationWafers[module][slot].ImageFileName = fileName;
  845. _locationWafers[module][slot].ImageFilePath = filePath;
  846. WaferDataRecorder.SetWaferT7CodeWithScoreAndFileName(_locationWafers[module][slot].InnerId.ToString(), t7Code, t7CodeScore, fileName, filePath);
  847. }
  848. //Serialize();
  849. _needSerialize = true;
  850. NeedUpdateModule[module.ToString()] = true;
  851. }
  852. public void UpdateWaferTransFlag(ModuleName module, int slot, string flag)
  853. {
  854. if (!IsWaferSlotLocationValid(module, slot))
  855. {
  856. LOG.Write(string.Format("Failed UpdateWaferTransFlag, invalid parameter, {0},{1}", module, slot + 1));
  857. return;
  858. }
  859. lock (_lockerWaferList)
  860. {
  861. _locationWafers[module][slot].TransFlag = flag;
  862. }
  863. //Serialize();
  864. _needSerialize = true;
  865. NeedUpdateModule[module.ToString()] = true;
  866. }
  867. public void UpdateWaferNotch(ModuleName module, int slot, int angle)
  868. {
  869. if (!IsWaferSlotLocationValid(module, slot))
  870. {
  871. LOG.Write(string.Format("Failed UpdateWaferNotch, invalid parameter, {0},{1}", module, slot + 1));
  872. return;
  873. }
  874. lock (_lockerWaferList)
  875. {
  876. _locationWafers[module][slot].Notch = angle;
  877. }
  878. //Serialize();
  879. _needSerialize = true;
  880. NeedUpdateModule[module.ToString()] = true;
  881. }
  882. public List<WaferInfo> GetAllWafers()
  883. {
  884. List<WaferInfo> result = new List<WaferInfo>();
  885. lock (_lockerWaferList)
  886. {
  887. if (_locationWafers != null)
  888. {
  889. foreach (var item in _locationWafers.Values)
  890. {
  891. result.AddRange(item.Values.Select(a => a).ToList());
  892. }
  893. }
  894. }
  895. return result;
  896. }
  897. public void UpdateWaferStatistics(ModuleName module, int slot, float useCount, float useTime, float useThick)
  898. {
  899. if (!IsWaferSlotLocationValid(module, slot))
  900. {
  901. LOG.Write(string.Format("Failed UpdateWaferStatistics, invalid parameter, {0},{1}", module, slot + 1));
  902. return;
  903. }
  904. lock (_lockerWaferList)
  905. {
  906. _locationWafers[module][slot].UseCount = useCount;
  907. _locationWafers[module][slot].UseTime = useTime;
  908. _locationWafers[module][slot].UseThick = useThick;
  909. WaferDataRecorder.SetStatistics(_locationWafers[module][slot].InnerId.ToString(), useCount, useTime, useThick);
  910. }
  911. _needSerialize = true;
  912. NeedUpdateModule[module.ToString()] = true;
  913. }
  914. public void UpdateWaferInfo(ModuleName module, int slot, float thick)
  915. {
  916. if (!IsWaferSlotLocationValid(module, slot))
  917. {
  918. LOG.Write(string.Format("Failed UpdateWaferStatistics, invalid parameter, {0},{1}", module, slot + 1));
  919. return;
  920. }
  921. lock (_lockerWaferList)
  922. {
  923. _locationWafers[module][slot].Thick = thick;
  924. }
  925. _needSerialize = true;
  926. NeedUpdateModule[module.ToString()] = true;
  927. }
  928. public void UpdateWaferProcessStatus(ModuleName module, int slot, EnumWaferProcessStatus status)
  929. {
  930. if (!IsWaferSlotLocationValid(module, slot))
  931. {
  932. LOG.Write(string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  933. return;
  934. }
  935. lock (_lockerWaferList)
  936. {
  937. _locationWafers[module][slot].ProcessState = status;
  938. WaferDataRecorder.SetWaferStatus(_locationWafers[module][slot].InnerId.ToString(), status.ToString());
  939. }
  940. //Serialize();
  941. _needSerialize = true;
  942. NeedUpdateModule[module.ToString()] = true;
  943. }
  944. public void UpdateWaferProcessStatus(ModuleName module, int slot, EnumWaferProcessStatus processStatus, WaferStatus waferStatus)
  945. {
  946. if (!IsWaferSlotLocationValid(module, slot))
  947. {
  948. LOG.Write(string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  949. return;
  950. }
  951. lock (_lockerWaferList)
  952. {
  953. _locationWafers[module][slot].ProcessState = processStatus;
  954. _locationWafers[module][slot].Status = waferStatus;
  955. WaferDataRecorder.SetWaferStatus(_locationWafers[module][slot].InnerId.ToString(), processStatus.ToString());
  956. }
  957. _needSerialize = true;
  958. NeedUpdateModule[module.ToString()] = true;
  959. }
  960. #pragma warning disable CS0618
  961. public void UpdateWaferProcessStatus(ModuleName module, int slot, ProcessStatus status)
  962. {
  963. switch (status)
  964. {
  965. case ProcessStatus.Busy:
  966. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.InProcess);
  967. break;
  968. case ProcessStatus.Completed:
  969. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Completed);
  970. break;
  971. case ProcessStatus.Failed:
  972. case ProcessStatus.Abort:
  973. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Failed);
  974. break;
  975. //case ProcessStatus.Abort:
  976. // UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Abort);
  977. // break;
  978. case ProcessStatus.Idle:
  979. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Idle);
  980. break;
  981. case ProcessStatus.Wait:
  982. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.InProcess);
  983. break;
  984. }
  985. }
  986. public void UpdateWaferProcessStatus(string waferID, ProcessStatus status)
  987. {
  988. switch (status)
  989. {
  990. case ProcessStatus.Busy:
  991. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.InProcess);
  992. break;
  993. case ProcessStatus.Completed:
  994. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.Completed);
  995. break;
  996. case ProcessStatus.Failed:
  997. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.Failed);
  998. break;
  999. case ProcessStatus.Idle:
  1000. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.Idle);
  1001. break;
  1002. case ProcessStatus.Wait:
  1003. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.InProcess);
  1004. break;
  1005. }
  1006. }
  1007. #pragma warning restore CS0618
  1008. public void UpdateWaferId(ModuleName module, int slot, string waferId)
  1009. {
  1010. if (!IsWaferSlotLocationValid(module, slot))
  1011. {
  1012. LOG.Write(string.Format("Failed UpdateWaferId, invalid parameter, {0},{1}", module, slot + 1));
  1013. return;
  1014. }
  1015. lock (_lockerWaferList)
  1016. {
  1017. _locationWafers[module][slot].WaferID = waferId;
  1018. }
  1019. UpdateWaferHistory(module, slot, SubstAccessType.UpdateWaferID);
  1020. //Serialize();
  1021. _needSerialize = true;
  1022. NeedUpdateModule[module.ToString()] = true;
  1023. }
  1024. public void UpdateWaferJodID(ModuleName module, int slot, string pjID, string cjID)
  1025. {
  1026. if (!IsWaferSlotLocationValid(module, slot))
  1027. {
  1028. LOG.Write(string.Format("Failed UpdateWaferId, invalid parameter, {0},{1}", module, slot + 1));
  1029. return;
  1030. }
  1031. lock (_lockerWaferList)
  1032. {
  1033. _locationWafers[module][slot].ProcessJobID = pjID;
  1034. _locationWafers[module][slot].ControlJobID = cjID;
  1035. }
  1036. //Serialize();
  1037. _needSerialize = true;
  1038. NeedUpdateModule[module.ToString()] = true;
  1039. }
  1040. public void SlotMapVerifyOK(ModuleName module)
  1041. {
  1042. WaferInfo[] wafers = GetWafers(module);
  1043. foreach (WaferInfo wafer in wafers)
  1044. {
  1045. lock (_lockerWaferList)
  1046. {
  1047. if (wafer.IsEmpty) continue;
  1048. } //Serialize();
  1049. }
  1050. _needSerialize = true;
  1051. }
  1052. public void UpdateWaferTransportState(string waferid, SubstrateTransportStatus ststate)
  1053. {
  1054. if (string.IsNullOrEmpty(waferid)) return;
  1055. WaferInfo[] wafers = GetWafer(waferid);
  1056. lock (_lockerWaferList)
  1057. {
  1058. foreach (var wafer in wafers)
  1059. {
  1060. //_locationWafers[(ModuleName)wafer.Station][wafer.Slot].SubstTransStatus = ststate;
  1061. wafer.SubstTransStatus = ststate;
  1062. var dvid = new SerializableDictionary<string, object>()
  1063. {
  1064. {SubstID, wafer.WaferID},
  1065. {LotID, wafer.LotId},
  1066. {SubstMtrlStatus,(int)wafer.ProcessState },
  1067. {SubstDestination,((ModuleName)wafer.DestinationStation).ToString() },
  1068. {SubstHistory,wafer.SubstHists},
  1069. {SubstLocID,((ModuleName)wafer.Station).ToString()},
  1070. {SubstProcState,(int)wafer.SubstE90Status},
  1071. {SubstSource,((ModuleName)wafer.OriginStation).ToString() },
  1072. {SubstState,(int)wafer.SubstTransStatus},
  1073. };
  1074. if (ststate == SubstrateTransportStatus.AtWork) EV.Notify(Event_STS_AtWork, dvid);
  1075. if (ststate == SubstrateTransportStatus.AtDestination) EV.Notify(Event_STS_AtDestination, dvid);
  1076. if (ststate == SubstrateTransportStatus.AtSource) EV.Notify(Event_STS_AtSourcs, dvid);
  1077. if (ststate == SubstrateTransportStatus.None) EV.Notify(Event_STS_Deleted, dvid);
  1078. }
  1079. }
  1080. //Serialize();
  1081. _needSerialize = true;
  1082. }
  1083. public void UpdateWaferE90State(string waferid, EnumE90Status E90state)
  1084. {
  1085. if (string.IsNullOrEmpty(waferid)) return;
  1086. WaferInfo[] wafers = GetWafer(waferid);
  1087. lock (_lockerWaferList)
  1088. {
  1089. foreach (var wafer in wafers)
  1090. {
  1091. if (wafer.SubstE90Status == E90state)
  1092. continue;
  1093. //_locationWafers[(ModuleName)wafer.Station][wafer.Slot].SubstE90Status = E90state;
  1094. wafer.SubstE90Status = E90state;
  1095. string currentcid = "";
  1096. if (ModuleHelper.IsLoadPort((ModuleName)wafer.Station))
  1097. currentcid = CarrierManager.Instance.GetCarrier(((ModuleName)wafer.Station).ToString()).CarrierId;
  1098. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  1099. data.Add("SourceCarrier", wafer.OriginCarrierID ?? "");
  1100. data.Add("SourceSlot", (wafer.OriginSlot + 1).ToString());
  1101. data.Add("CurrentCarrier", currentcid ?? "");
  1102. data.Add("CurrentSlot", (wafer.Slot + 1).ToString());
  1103. data.Add("LaserMark1", wafer.LaserMarker ?? "");
  1104. data.Add("LaserMark1Score", wafer.LaserMarkerScore ?? "");
  1105. data.Add("LaserMark2", wafer.T7Code ?? "");
  1106. data.Add("LaserMark2Score", wafer.T7CodeScore ?? "");
  1107. var dvid = new SerializableDictionary<string, object>()
  1108. {
  1109. {SubstID, wafer.WaferID},
  1110. {LotID, wafer.LotId},
  1111. {SubstMtrlStatus,(int)wafer.ProcessState },
  1112. {SubstDestination,((ModuleName)wafer.DestinationStation).ToString() },
  1113. {SubstHistory,wafer.SubstHists},
  1114. {SubstLocID,((ModuleName)wafer.Station).ToString()},
  1115. {SubstProcState,(int)wafer.SubstE90Status},
  1116. {SubstState,(int)wafer.SubstTransStatus},
  1117. {SubstSource,((ModuleName)(wafer.OriginStation)).ToString() },
  1118. {SubstSourceCarrierID,wafer.OriginCarrierID },
  1119. {SubstSourceSlot,wafer.OriginSlot +1 },
  1120. {SubstCurrentSlot,wafer.Slot+1 },
  1121. {"LASERMARK",wafer.LaserMarker??"" },
  1122. {"OCRScore",wafer.LaserMarkerScore??"" },
  1123. {"CarrierID",currentcid??"" },
  1124. {"LASERMARK1",wafer.LaserMarker??"" },
  1125. {"LASERMARK2",wafer.T7Code??"" },
  1126. {"LASERMARK1SCORE",wafer.LaserMarkerScore??"" },
  1127. {"LASERMARK2SCORE",wafer.T7CodeScore??"" },
  1128. {"PortID",wafer.Station},
  1129. {"PORT_ID",wafer.Station},
  1130. {"SubstInfoList",data }
  1131. };
  1132. if (E90state == EnumE90Status.InProcess) EV.Notify(Event_STS_InProcessing, dvid);
  1133. if (E90state == EnumE90Status.NeedProcessing) EV.Notify(Event_STS_NeedProcessing, dvid);
  1134. if (E90state == EnumE90Status.Processed) EV.Notify(Event_STS_Processed, dvid);
  1135. if (E90state == EnumE90Status.Aborted) EV.Notify(Event_STS_Aborted, dvid);
  1136. if (E90state == EnumE90Status.Lost) EV.Notify(Event_STS_Lost, dvid);
  1137. if (E90state == EnumE90Status.Rejected) EV.Notify(Event_STS_Rejected, dvid);
  1138. if (E90state == EnumE90Status.Skipped) EV.Notify(Event_STS_Skipped, dvid);
  1139. if (E90state == EnumE90Status.Stopped) EV.Notify(Event_STS_Stopped, dvid);
  1140. }
  1141. }
  1142. //Serialize();
  1143. _needSerialize = true;
  1144. }
  1145. public void UpdateWaferE90State(ModuleName module, int slot, EnumE90Status E90state)
  1146. {
  1147. WaferInfo wafer = GetWafer(module, slot);
  1148. if (wafer.IsEmpty) return;
  1149. lock (_lockerWaferList)
  1150. {
  1151. //_locationWafers[(ModuleName)wafer.Station][wafer.Slot].SubstE90Status = E90state;
  1152. wafer.SubstE90Status = E90state;
  1153. string currentcid = "";
  1154. if (ModuleHelper.IsLoadPort((ModuleName)wafer.Station))
  1155. currentcid = CarrierManager.Instance.GetCarrier(((ModuleName)wafer.Station).ToString()).CarrierId;
  1156. var dvid = new SerializableDictionary<string, object>()
  1157. {
  1158. {SubstID, wafer.WaferID},
  1159. {LotID, wafer.LotId},
  1160. {SubstMtrlStatus,(int)wafer.ProcessState },
  1161. {SubstDestination,((ModuleName)wafer.DestinationStation).ToString() },
  1162. {SubstHistory,wafer.SubstHists},
  1163. {SubstLocID,((ModuleName)wafer.Station).ToString()},
  1164. {SubstProcState,(int)wafer.SubstE90Status},
  1165. {SubstState,(int)wafer.SubstTransStatus},
  1166. {SubstSource,((ModuleName)(wafer.OriginStation)).ToString() },
  1167. {SubstSourceCarrierID,wafer.OriginCarrierID },
  1168. {SubstSourceSlot,wafer.OriginSlot +1 },
  1169. {SubstCurrentSlot,wafer.Slot+1 },
  1170. {"LASERMARK",wafer.LaserMarker },
  1171. {"OCRScore",wafer.LaserMarkerScore },
  1172. {"CarrierID",currentcid }
  1173. };
  1174. if (E90state == EnumE90Status.InProcess) EV.Notify(Event_STS_InProcessing, dvid);
  1175. if (E90state == EnumE90Status.NeedProcessing) EV.Notify(Event_STS_NeedProcessing, dvid);
  1176. if (E90state == EnumE90Status.Processed) EV.Notify(Event_STS_Processed, dvid);
  1177. if (E90state == EnumE90Status.Aborted) EV.Notify(Event_STS_Aborted, dvid);
  1178. if (E90state == EnumE90Status.Lost) EV.Notify(Event_STS_Lost, dvid);
  1179. if (E90state == EnumE90Status.Rejected) EV.Notify(Event_STS_Rejected, dvid);
  1180. if (E90state == EnumE90Status.Skipped) EV.Notify(Event_STS_Skipped, dvid);
  1181. if (E90state == EnumE90Status.Stopped) EV.Notify(Event_STS_Stopped, dvid);
  1182. }
  1183. //Serialize();
  1184. _needSerialize = true;
  1185. NeedUpdateModule[module.ToString()] = true;
  1186. }
  1187. public void UpdateWaferHistory(ModuleName module, int slot, SubstAccessType accesstype)
  1188. {
  1189. if (!IsWaferSlotLocationValid(module, slot))
  1190. {
  1191. LOG.Write(string.Format("Failed UpdateWaferHistory, invalid parameter, {0},{1}", module, slot + 1));
  1192. return;
  1193. }
  1194. lock (_lockerWaferList)
  1195. {
  1196. SubstHistory hist = new SubstHistory(module.ToString(), slot, DateTime.Now, accesstype);
  1197. if (_locationWafers[module][slot].SubstHists == null)
  1198. _locationWafers[module][slot].SubstHists = new SubstHistory[] { hist };
  1199. else
  1200. {
  1201. _locationWafers[module][slot].SubstHists = _locationWafers[module][slot].SubstHists.Concat(new SubstHistory[] { hist }).ToArray();
  1202. }
  1203. }
  1204. //Serialize();
  1205. _needSerialize = true;
  1206. NeedUpdateModule[module.ToString()] = true;
  1207. }
  1208. public void UpdateWaferLotId(ModuleName module, int slot, string lotId)
  1209. {
  1210. if (!IsWaferSlotLocationValid(module, slot))
  1211. {
  1212. LOG.Write(string.Format("Failed UpdateWaferLotId, invalid parameter, {0},{1}", module, slot + 1));
  1213. return;
  1214. }
  1215. lock (_lockerWaferList)
  1216. {
  1217. _locationWafers[module][slot].LotId = lotId;
  1218. WaferDataRecorder.SetWaferLotId(_locationWafers[module][slot].InnerId.ToString(), lotId);
  1219. CarrierManager.Instance.UpdateCarrierLot(module.ToString(), lotId);
  1220. }
  1221. //Serialize();
  1222. _needSerialize = true;
  1223. NeedUpdateModule[module.ToString()] = true;
  1224. }
  1225. public void UpdateWaferHostLM1(ModuleName module, int slot, string lasermark1)
  1226. {
  1227. if (!IsWaferSlotLocationValid(module, slot))
  1228. {
  1229. LOG.Write(string.Format("Failed UpdateWaferHostLM1, invalid parameter, {0},{1}", module, slot + 1));
  1230. return;
  1231. }
  1232. lock (_lockerWaferList)
  1233. {
  1234. _locationWafers[module][slot].HostLaserMark1 = lasermark1;
  1235. }
  1236. //Serialize();
  1237. _needSerialize = true;
  1238. NeedUpdateModule[module.ToString()] = true;
  1239. }
  1240. public void UpdateWaferHostLM2(ModuleName module, int slot, string lasermark2)
  1241. {
  1242. if (!IsWaferSlotLocationValid(module, slot))
  1243. {
  1244. LOG.Write(string.Format("Failed UpdateWaferHostLM2, invalid parameter, {0},{1}", module, slot + 1));
  1245. return;
  1246. }
  1247. lock (_lockerWaferList)
  1248. {
  1249. _locationWafers[module][slot].HostLaserMark2 = lasermark2;
  1250. }
  1251. //Serialize();
  1252. _needSerialize = true;
  1253. NeedUpdateModule[module.ToString()] = true;
  1254. }
  1255. public void UpdateWaferProcessStatus(string waferID, EnumWaferProcessStatus status)
  1256. {
  1257. WaferInfo[] wafers = GetWafer(waferID);
  1258. lock (_lockerWaferList)
  1259. {
  1260. foreach (var waferInfo in wafers)
  1261. {
  1262. waferInfo.ProcessState = status;
  1263. }
  1264. }
  1265. //Serialize();
  1266. _needSerialize = true;
  1267. }
  1268. public void UpdateWaferProcess(string waferID, string processId)
  1269. {
  1270. WaferInfo[] wafers = GetWafer(waferID);
  1271. lock (_lockerWaferList)
  1272. {
  1273. foreach (var waferInfo in wafers)
  1274. {
  1275. WaferDataRecorder.SetProcessInfo(waferInfo.InnerId.ToString(), processId);
  1276. }
  1277. }
  1278. //Serialize();
  1279. _needSerialize = true;
  1280. }
  1281. public WaferInfo CopyWaferInfo(ModuleName module, int slot, WaferInfo wafer)
  1282. {
  1283. if (!IsWaferSlotLocationValid(module, slot))
  1284. {
  1285. LOG.Write(string.Format("Failed CopyWaferInfo, invalid parameter, {0},{1}", module, slot + 1));
  1286. return null;
  1287. }
  1288. lock (_lockerWaferList)
  1289. {
  1290. _locationWafers[module][slot].Update(wafer);
  1291. _locationWafers[module][slot].Station = (int)module;
  1292. _locationWafers[module][slot].Slot = slot;
  1293. }
  1294. return _locationWafers[module][slot];
  1295. }
  1296. public bool CheckWaferSize(ModuleName module, int slot, WaferSize size)
  1297. {
  1298. if (!IsWaferSlotLocationValid(module, slot))
  1299. {
  1300. LOG.Write(string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  1301. return false;
  1302. }
  1303. WaferSize oldSize;
  1304. lock (_lockerWaferList)
  1305. {
  1306. oldSize = _locationWafers[module][slot].Size;
  1307. if (oldSize == WaferSize.WS0)
  1308. {
  1309. _locationWafers[module][slot].Size = size;
  1310. }
  1311. }
  1312. if (oldSize == WaferSize.WS0)
  1313. {
  1314. //Serialize();
  1315. _needSerialize = true;
  1316. return true;
  1317. }
  1318. return oldSize == size;
  1319. }
  1320. public bool UpdateWaferSize(ModuleName module, int slot, WaferSize size)
  1321. {
  1322. if (!IsWaferSlotLocationValid(module, slot))
  1323. {
  1324. LOG.Write(string.Format("Failed UpdateWaferSize, invalid parameter, {0},{1}", module, slot + 1));
  1325. return false;
  1326. }
  1327. lock (_lockerWaferList)
  1328. {
  1329. _locationWafers[module][slot].Size = size;
  1330. }
  1331. _needSerialize = true;
  1332. NeedUpdateModule[module.ToString()] = true;
  1333. Serialize();
  1334. return true;
  1335. }
  1336. private string GenerateWaferId(ModuleName module, int slot, string carrierID)
  1337. {
  1338. string carrierinfor = "";
  1339. //5 + 2(unit) + 2(slot) + time(18) + index{5}
  1340. if (string.IsNullOrEmpty(carrierID))
  1341. carrierinfor = module.ToString() + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  1342. else carrierinfor = carrierID;
  1343. return string.Format($"{carrierinfor}.{(slot + 1).ToString("00")}");
  1344. }
  1345. private string GenerateOrigin(ModuleName module, int slot)
  1346. {
  1347. return string.Format("{0}.{1:D2}", ModuleHelper.GetAbbr(module), slot + 1);
  1348. }
  1349. }
  1350. }