WaferManager.cs 60 KB

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