WaferManager.cs 65 KB

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