WaferManager.cs 65 KB

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