WaferManager.cs 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  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. }
  867. _needSerialize = true;
  868. }
  869. public void UpdateWaferInfo(ModuleName module, int slot, float thick)
  870. {
  871. if (!IsWaferSlotLocationValid(module, slot))
  872. {
  873. LOG.Write(string.Format("Failed UpdateWaferStatistics, invalid parameter, {0},{1}", module, slot + 1));
  874. return;
  875. }
  876. lock (_lockerWaferList)
  877. {
  878. _locationWafers[module][slot].Thick = thick;
  879. }
  880. _needSerialize = true;
  881. }
  882. public void UpdateWaferProcessStatus(ModuleName module, int slot, EnumWaferProcessStatus status)
  883. {
  884. if (!IsWaferSlotLocationValid(module, slot))
  885. {
  886. LOG.Write(string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  887. return;
  888. }
  889. lock (_lockerWaferList)
  890. {
  891. _locationWafers[module][slot].ProcessState = status;
  892. WaferDataRecorder.SetWaferStatus(_locationWafers[module][slot].InnerId.ToString(), status.ToString());
  893. }
  894. //Serialize();
  895. _needSerialize = true;
  896. }
  897. public void UpdateWaferProcessStatus(ModuleName module, int slot, EnumWaferProcessStatus processStatus, WaferStatus waferStatus)
  898. {
  899. if (!IsWaferSlotLocationValid(module, slot))
  900. {
  901. LOG.Write(string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  902. return;
  903. }
  904. lock (_lockerWaferList)
  905. {
  906. _locationWafers[module][slot].ProcessState = processStatus;
  907. _locationWafers[module][slot].Status = waferStatus;
  908. WaferDataRecorder.SetWaferStatus(_locationWafers[module][slot].InnerId.ToString(), processStatus.ToString());
  909. }
  910. _needSerialize = true;
  911. }
  912. #pragma warning disable CS0618
  913. public void UpdateWaferProcessStatus(ModuleName module, int slot, ProcessStatus status)
  914. {
  915. switch (status)
  916. {
  917. case ProcessStatus.Busy:
  918. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.InProcess);
  919. break;
  920. case ProcessStatus.Completed:
  921. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Completed);
  922. break;
  923. case ProcessStatus.Failed:
  924. case ProcessStatus.Abort:
  925. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Failed);
  926. break;
  927. //case ProcessStatus.Abort:
  928. // UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Abort);
  929. // break;
  930. case ProcessStatus.Idle:
  931. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.Idle);
  932. break;
  933. case ProcessStatus.Wait:
  934. UpdateWaferProcessStatus(module, slot, EnumWaferProcessStatus.InProcess);
  935. break;
  936. }
  937. }
  938. public void UpdateWaferProcessStatus(string waferID, ProcessStatus status)
  939. {
  940. switch (status)
  941. {
  942. case ProcessStatus.Busy:
  943. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.InProcess);
  944. break;
  945. case ProcessStatus.Completed:
  946. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.Completed);
  947. break;
  948. case ProcessStatus.Failed:
  949. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.Failed);
  950. break;
  951. case ProcessStatus.Idle:
  952. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.Idle);
  953. break;
  954. case ProcessStatus.Wait:
  955. UpdateWaferProcessStatus(waferID, EnumWaferProcessStatus.InProcess);
  956. break;
  957. }
  958. }
  959. #pragma warning restore CS0618
  960. public void UpdateWaferId(ModuleName module, int slot, string waferId)
  961. {
  962. if (!IsWaferSlotLocationValid(module, slot))
  963. {
  964. LOG.Write(string.Format("Failed UpdateWaferId, invalid parameter, {0},{1}", module, slot + 1));
  965. return;
  966. }
  967. lock (_lockerWaferList)
  968. {
  969. _locationWafers[module][slot].WaferID = waferId;
  970. }
  971. UpdateWaferHistory(module, slot, SubstAccessType.UpdateWaferID);
  972. //Serialize();
  973. _needSerialize = true;
  974. }
  975. public void UpdateWaferJodID(ModuleName module, int slot, string pjID,string cjID)
  976. {
  977. if (!IsWaferSlotLocationValid(module, slot))
  978. {
  979. LOG.Write(string.Format("Failed UpdateWaferId, invalid parameter, {0},{1}", module, slot + 1));
  980. return;
  981. }
  982. lock (_lockerWaferList)
  983. {
  984. _locationWafers[module][slot].ProcessJobID = pjID;
  985. _locationWafers[module][slot].ControlJobID = cjID;
  986. }
  987. //Serialize();
  988. _needSerialize = true;
  989. }
  990. public void SlotMapVerifyOK(ModuleName module)
  991. {
  992. WaferInfo[] wafers = GetWafers(module);
  993. foreach(WaferInfo wafer in wafers)
  994. {
  995. lock (_lockerWaferList)
  996. {
  997. if (wafer.IsEmpty) continue;
  998. } //Serialize();
  999. }
  1000. _needSerialize = true;
  1001. }
  1002. public void UpdateWaferTransportState(string waferid,SubstrateTransportStatus ststate)
  1003. {
  1004. if (string.IsNullOrEmpty(waferid)) return;
  1005. WaferInfo[] wafers = GetWafer(waferid);
  1006. lock (_lockerWaferList)
  1007. {
  1008. foreach (var wafer in wafers)
  1009. {
  1010. //_locationWafers[(ModuleName)wafer.Station][wafer.Slot].SubstTransStatus = ststate;
  1011. wafer.SubstTransStatus = ststate;
  1012. var dvid = new SerializableDictionary<string, object>()
  1013. {
  1014. {SubstID, wafer.WaferID},
  1015. {LotID, wafer.LotId},
  1016. {SubstMtrlStatus,(int)wafer.ProcessState },
  1017. {SubstDestination,((ModuleName)wafer.DestinationStation).ToString() },
  1018. {SubstHistory,wafer.SubstHists},
  1019. {SubstLocID,((ModuleName)wafer.Station).ToString()},
  1020. {SubstProcState,(int)wafer.SubstE90Status},
  1021. {SubstSource,((ModuleName)wafer.OriginStation).ToString() },
  1022. {SubstState,(int)wafer.SubstTransStatus},
  1023. };
  1024. if (ststate == SubstrateTransportStatus.AtWork) EV.Notify(Event_STS_AtWork,dvid );
  1025. if (ststate == SubstrateTransportStatus.AtDestination) EV.Notify(Event_STS_AtDestination, dvid);
  1026. if (ststate == SubstrateTransportStatus.AtSource) EV.Notify(Event_STS_AtSourcs, dvid);
  1027. if (ststate == SubstrateTransportStatus.None) EV.Notify(Event_STS_Deleted, dvid);
  1028. }
  1029. }
  1030. //Serialize();
  1031. _needSerialize = true;
  1032. //Serialize();
  1033. _needSerialize = true;
  1034. }
  1035. public void UpdateWaferE90State(string waferid, EnumE90Status E90state)
  1036. {
  1037. if (string.IsNullOrEmpty(waferid)) return;
  1038. WaferInfo[] wafers = GetWafer(waferid);
  1039. lock (_lockerWaferList)
  1040. {
  1041. foreach (var wafer in wafers)
  1042. {
  1043. if (wafer.SubstE90Status == E90state)
  1044. continue;
  1045. //_locationWafers[(ModuleName)wafer.Station][wafer.Slot].SubstE90Status = E90state;
  1046. wafer.SubstE90Status = E90state;
  1047. string currentcid = "";
  1048. if (ModuleHelper.IsLoadPort((ModuleName)wafer.Station))
  1049. currentcid = CarrierManager.Instance.GetCarrier(((ModuleName)wafer.Station).ToString()).CarrierId;
  1050. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  1051. data.Add("SourceCarrier", wafer.OriginCarrierID??"");
  1052. data.Add("SourceSlot", (wafer.OriginSlot+1).ToString());
  1053. data.Add("CurrentCarrier", currentcid ?? "");
  1054. data.Add("CurrentSlot", (wafer.Slot + 1).ToString());
  1055. data.Add("LaserMark1", wafer.LaserMarker ?? "");
  1056. data.Add("LaserMark1Score", wafer.LaserMarkerScore ?? "");
  1057. data.Add("LaserMark2", wafer.T7Code ?? "");
  1058. data.Add("LaserMark2Score", wafer.T7CodeScore ?? "");
  1059. var dvid = new SerializableDictionary<string, object>()
  1060. {
  1061. {SubstID, wafer.WaferID},
  1062. {LotID, wafer.LotId},
  1063. {SubstMtrlStatus,(int)wafer.ProcessState },
  1064. {SubstDestination,((ModuleName)wafer.DestinationStation).ToString() },
  1065. {SubstHistory,wafer.SubstHists},
  1066. {SubstLocID,((ModuleName)wafer.Station).ToString()},
  1067. {SubstProcState,(int)wafer.SubstE90Status},
  1068. {SubstState,(int)wafer.SubstTransStatus},
  1069. {SubstSource,((ModuleName)(wafer.OriginStation)).ToString() },
  1070. {SubstSourceCarrierID,wafer.OriginCarrierID },
  1071. {SubstSourceSlot,wafer.OriginSlot +1 },
  1072. {SubstCurrentSlot,wafer.Slot+1 },
  1073. {"LASERMARK",wafer.LaserMarker??"" },
  1074. {"OCRScore",wafer.LaserMarkerScore??"" },
  1075. {"CarrierID",currentcid??"" },
  1076. {"LASERMARK1",wafer.LaserMarker??"" },
  1077. {"LASERMARK2",wafer.T7Code??"" },
  1078. {"LASERMARK1SCORE",wafer.LaserMarkerScore??"" },
  1079. {"LASERMARK2SCORE",wafer.T7CodeScore??"" },
  1080. {"PortID",wafer.Station},
  1081. {"PORT_ID",wafer.Station},
  1082. {"SubstInfoList",data }
  1083. };
  1084. if (E90state == EnumE90Status.InProcess) EV.Notify(Event_STS_InProcessing,dvid );
  1085. if (E90state == EnumE90Status.NeedProcessing) EV.Notify(Event_STS_NeedProcessing, dvid);
  1086. if (E90state == EnumE90Status.Processed) EV.Notify(Event_STS_Processed, dvid);
  1087. if (E90state == EnumE90Status.Aborted) EV.Notify(Event_STS_Aborted, dvid);
  1088. if (E90state == EnumE90Status.Lost) EV.Notify(Event_STS_Lost, dvid);
  1089. if (E90state == EnumE90Status.Rejected) EV.Notify(Event_STS_Rejected, dvid);
  1090. if (E90state == EnumE90Status.Skipped) EV.Notify(Event_STS_Skipped, dvid);
  1091. if (E90state == EnumE90Status.Stopped) EV.Notify(Event_STS_Stopped, dvid);
  1092. }
  1093. }
  1094. //Serialize();
  1095. _needSerialize = true;
  1096. }
  1097. public void UpdateWaferE90State(ModuleName module,int slot, EnumE90Status E90state)
  1098. {
  1099. WaferInfo wafer = GetWafer(module,slot);
  1100. if (wafer.IsEmpty) return;
  1101. lock (_lockerWaferList)
  1102. {
  1103. //_locationWafers[(ModuleName)wafer.Station][wafer.Slot].SubstE90Status = E90state;
  1104. wafer.SubstE90Status = E90state;
  1105. string currentcid = "";
  1106. if (ModuleHelper.IsLoadPort((ModuleName)wafer.Station))
  1107. currentcid = CarrierManager.Instance.GetCarrier(((ModuleName)wafer.Station).ToString()).CarrierId;
  1108. var dvid = new SerializableDictionary<string, object>()
  1109. {
  1110. {SubstID, wafer.WaferID},
  1111. {LotID, wafer.LotId},
  1112. {SubstMtrlStatus,(int)wafer.ProcessState },
  1113. {SubstDestination,((ModuleName)wafer.DestinationStation).ToString() },
  1114. {SubstHistory,wafer.SubstHists},
  1115. {SubstLocID,((ModuleName)wafer.Station).ToString()},
  1116. {SubstProcState,(int)wafer.SubstE90Status},
  1117. {SubstState,(int)wafer.SubstTransStatus},
  1118. {SubstSource,((ModuleName)(wafer.OriginStation)).ToString() },
  1119. {SubstSourceCarrierID,wafer.OriginCarrierID },
  1120. {SubstSourceSlot,wafer.OriginSlot +1 },
  1121. {SubstCurrentSlot,wafer.Slot+1 },
  1122. {"LASERMARK",wafer.LaserMarker },
  1123. {"OCRScore",wafer.LaserMarkerScore },
  1124. {"CarrierID",currentcid }
  1125. };
  1126. if (E90state == EnumE90Status.InProcess) EV.Notify(Event_STS_InProcessing, dvid);
  1127. if (E90state == EnumE90Status.NeedProcessing) EV.Notify(Event_STS_NeedProcessing, dvid);
  1128. if (E90state == EnumE90Status.Processed) EV.Notify(Event_STS_Processed, dvid);
  1129. if (E90state == EnumE90Status.Aborted) EV.Notify(Event_STS_Aborted, dvid);
  1130. if (E90state == EnumE90Status.Lost) EV.Notify(Event_STS_Lost, dvid);
  1131. if (E90state == EnumE90Status.Rejected) EV.Notify(Event_STS_Rejected, dvid);
  1132. if (E90state == EnumE90Status.Skipped) EV.Notify(Event_STS_Skipped, dvid);
  1133. if (E90state == EnumE90Status.Stopped) EV.Notify(Event_STS_Stopped, dvid);
  1134. }
  1135. //Serialize();
  1136. _needSerialize = true;
  1137. }
  1138. public void UpdateWaferHistory(ModuleName module, int slot, SubstAccessType accesstype)
  1139. {
  1140. if (!IsWaferSlotLocationValid(module, slot))
  1141. {
  1142. LOG.Write(string.Format("Failed UpdateWaferHistory, invalid parameter, {0},{1}", module, slot + 1));
  1143. return;
  1144. }
  1145. lock (_lockerWaferList)
  1146. {
  1147. SubstHistory hist = new SubstHistory(module.ToString(), slot, DateTime.Now, accesstype);
  1148. if (_locationWafers[module][slot].SubstHists == null)
  1149. _locationWafers[module][slot].SubstHists = new SubstHistory[] { hist };
  1150. else
  1151. {
  1152. _locationWafers[module][slot].SubstHists = _locationWafers[module][slot].SubstHists.Concat(new SubstHistory[]{ hist}).ToArray();
  1153. }
  1154. }
  1155. //Serialize();
  1156. _needSerialize = true;
  1157. }
  1158. public void UpdateWaferLotId(ModuleName module, int slot, string lotId)
  1159. {
  1160. if (!IsWaferSlotLocationValid(module, slot))
  1161. {
  1162. LOG.Write(string.Format("Failed UpdateWaferLotId, invalid parameter, {0},{1}", module, slot + 1));
  1163. return;
  1164. }
  1165. lock (_lockerWaferList)
  1166. {
  1167. _locationWafers[module][slot].LotId = lotId;
  1168. WaferDataRecorder.SetWaferLotId(_locationWafers[module][slot].InnerId.ToString(), lotId);
  1169. CarrierManager.Instance.UpdateCarrierLot(module.ToString(), lotId);
  1170. }
  1171. //Serialize();
  1172. _needSerialize = true;
  1173. }
  1174. public void UpdateWaferHostLM1(ModuleName module, int slot, string lasermark1)
  1175. {
  1176. if (!IsWaferSlotLocationValid(module, slot))
  1177. {
  1178. LOG.Write(string.Format("Failed UpdateWaferHostLM1, invalid parameter, {0},{1}", module, slot + 1));
  1179. return;
  1180. }
  1181. lock (_lockerWaferList)
  1182. {
  1183. _locationWafers[module][slot].HostLaserMark1 = lasermark1;
  1184. }
  1185. //Serialize();
  1186. _needSerialize = true;
  1187. }
  1188. public void UpdateWaferHostLM2(ModuleName module, int slot, string lasermark2)
  1189. {
  1190. if (!IsWaferSlotLocationValid(module, slot))
  1191. {
  1192. LOG.Write(string.Format("Failed UpdateWaferHostLM2, invalid parameter, {0},{1}", module, slot + 1));
  1193. return;
  1194. }
  1195. lock (_lockerWaferList)
  1196. {
  1197. _locationWafers[module][slot].HostLaserMark2 = lasermark2;
  1198. }
  1199. //Serialize();
  1200. _needSerialize = true;
  1201. }
  1202. public void UpdateWaferProcessStatus(string waferID, EnumWaferProcessStatus status)
  1203. {
  1204. WaferInfo[] wafers = GetWafer(waferID);
  1205. lock (_lockerWaferList)
  1206. {
  1207. foreach (var waferInfo in wafers)
  1208. {
  1209. waferInfo.ProcessState = status;
  1210. }
  1211. }
  1212. //Serialize();
  1213. _needSerialize = true;
  1214. }
  1215. public void UpdateWaferProcess(string waferID, string processId)
  1216. {
  1217. WaferInfo[] wafers = GetWafer(waferID);
  1218. lock (_lockerWaferList)
  1219. {
  1220. foreach (var waferInfo in wafers)
  1221. {
  1222. WaferDataRecorder.SetProcessInfo(waferInfo.InnerId.ToString(), processId);
  1223. }
  1224. }
  1225. //Serialize();
  1226. _needSerialize = true;
  1227. }
  1228. public WaferInfo CopyWaferInfo(ModuleName module, int slot, WaferInfo wafer)
  1229. {
  1230. if (!IsWaferSlotLocationValid(module, slot))
  1231. {
  1232. LOG.Write(string.Format("Failed CopyWaferInfo, invalid parameter, {0},{1}", module, slot + 1));
  1233. return null;
  1234. }
  1235. lock (_lockerWaferList)
  1236. {
  1237. _locationWafers[module][slot].Update(wafer);
  1238. _locationWafers[module][slot].Station = (int)module;
  1239. _locationWafers[module][slot].Slot = slot;
  1240. }
  1241. return _locationWafers[module][slot];
  1242. }
  1243. public bool CheckWaferSize(ModuleName module, int slot,WaferSize size)
  1244. {
  1245. if (!IsWaferSlotLocationValid(module, slot))
  1246. {
  1247. LOG.Write(string.Format("Failed UpdateWaferProcessStatus, invalid parameter, {0},{1}", module, slot + 1));
  1248. return false;
  1249. }
  1250. WaferSize oldSize;
  1251. lock (_lockerWaferList)
  1252. {
  1253. oldSize = _locationWafers[module][slot].Size;
  1254. if (oldSize == WaferSize.WS0)
  1255. {
  1256. _locationWafers[module][slot].Size = size;
  1257. }
  1258. }
  1259. if (oldSize == WaferSize.WS0)
  1260. {
  1261. //Serialize();
  1262. _needSerialize = true;
  1263. return true;
  1264. }
  1265. return oldSize == size;
  1266. }
  1267. public bool UpdateWaferSize(ModuleName module, int slot, WaferSize size)
  1268. {
  1269. if (!IsWaferSlotLocationValid(module, slot))
  1270. {
  1271. LOG.Write(string.Format("Failed UpdateWaferSize, invalid parameter, {0},{1}", module, slot + 1));
  1272. return false;
  1273. }
  1274. lock (_lockerWaferList)
  1275. {
  1276. _locationWafers[module][slot].Size = size;
  1277. }
  1278. _needSerialize = true;
  1279. Serialize();
  1280. return true;
  1281. }
  1282. private string GenerateWaferId(ModuleName module, int slot,string carrierID)
  1283. {
  1284. string carrierinfor = "";
  1285. //5 + 2(unit) + 2(slot) + time(18) + index{5}
  1286. if (string.IsNullOrEmpty(carrierID))
  1287. carrierinfor = module.ToString() + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  1288. else carrierinfor = carrierID;
  1289. return string.Format($"{carrierinfor}.{(slot+1).ToString("00")}");
  1290. }
  1291. private string GenerateOrigin(ModuleName module, int slot)
  1292. {
  1293. return string.Format("{0}.{1:D2}", ModuleHelper.GetAbbr(module), slot + 1);
  1294. }
  1295. }
  1296. }