WaferManager.cs 67 KB

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