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