WaferManager.cs 65 KB

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