WaferManager.cs 68 KB

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