WaferManager.cs 67 KB

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