WaferManager.cs 66 KB

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