Loadport.cs 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  11. using SecsGem.Core.Application.E87;
  12. using System;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using System.Diagnostics;
  16. using Venus_Core;
  17. using Venus_RT.Devices.YASKAWA;
  18. using Venus_RT.Modules;
  19. namespace Venus_RT.Devices.EFEM
  20. {
  21. sealed class Loadport : ILoadport
  22. {
  23. private EfemEntity _controller => Singleton<RouteManager>.Instance.EFEM;
  24. //---------------------------------Properties------------------------------------
  25. //
  26. public OnlineFlag OnlineFlag { get; set; }
  27. public ModuleName Module { get; set; }
  28. public DeviceState Status { get; set; }
  29. public WaferSize WaferSize { get; set; }
  30. public WaferStatus[] WaferInfo { get; set; }
  31. public bool HasCassette { get; set; }
  32. public bool Protrusion { get; set; }
  33. public bool IsMapped { get; set; }
  34. public bool JobDone { get; set; }
  35. public Stopwatch TimerNotifyJobDone { get; set; }
  36. public IE87CallBack LPCallBack
  37. {
  38. get { return _lpCallBack; }
  39. set { _lpCallBack = value; }
  40. }
  41. private IE87CallBack _lpCallBack;
  42. public bool IsThicknessValid
  43. {
  44. get
  45. {
  46. return !_enableThickness || !string.IsNullOrEmpty(_waferThicknessType);
  47. }
  48. }
  49. public string ThicknessType
  50. {
  51. get
  52. {
  53. return _waferThicknessType;
  54. }
  55. }
  56. public string PortId
  57. {
  58. get; private set;
  59. }
  60. public bool IsClamped { get; set; }
  61. public bool IsLoaded { get; set; }
  62. public bool IsDocked { get; set; }
  63. public string CarrierId { get; set; }
  64. public string SmartTag { get; set; }
  65. public string LotId { get; set; }
  66. public bool IsBusy { get; set; }
  67. public bool IsError { get; set; }
  68. private string[] _slotMap = new string[25];
  69. public string SlotMap
  70. {
  71. get
  72. {
  73. if (_slotMap == null)
  74. {
  75. _slotMap = new string[SC.GetValue<int>("EFEM.LoadPort.SlotNumber")];
  76. }
  77. for (int i = 0; i < _slotMap.Length; i++)
  78. {
  79. _slotMap[i] = ((int)WaferManager.Instance.GetWafer(Module, i).Status).ToString();
  80. }
  81. return string.Join("", _slotMap);
  82. }
  83. }
  84. private string _waferThicknessType;
  85. private bool _enableThickness;
  86. private string AlarmWaferProtrude = "WaferProtrude";
  87. private LoadPortFACallback _faCallback = new LoadPortFACallback();
  88. // Constructor
  89. //
  90. public Loadport(ModuleName mod, EfemBase efem)
  91. {
  92. Module = mod;
  93. PortId = ((int)mod - (int)ModuleName.LP1 + 1).ToString();
  94. TimerNotifyJobDone = new Stopwatch();
  95. _enableThickness = false;// SC.GetValue<bool>("System.WaferThickness.EnableThickness");
  96. EV.Subscribe(new EventItem("Event", AlarmWaferProtrude, "Wafer protrude", EventLevel.Alarm, EventType.HostNotification));
  97. DATA.Subscribe($"{mod}.WaferSize", () => WaferSize.ToString(),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  98. DATA.Subscribe($"{mod}.CassetteState", () => HasCassette ? LoadportCassetteState.Normal : LoadportCassetteState.Absent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  99. DATA.Subscribe($"{mod}.CassettePresent", () => HasCassette ? 1 : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  100. DATA.Subscribe($"{mod}.CassettePlaced", () => HasCassette);
  101. DATA.Subscribe($"{mod}.SlotMap", () => SlotMap, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  102. DATA.Subscribe($"{mod}.IsWaferProtrude", () => Protrusion ? 1 : 0, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  103. DATA.Subscribe($"{mod}.IsMapped", () => IsMapped, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  104. DATA.Subscribe($"{mod}.IsLoaded", () => IsLoaded);
  105. DATA.Subscribe($"{mod}.IsClamped", () => IsClamped, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  106. DATA.Subscribe($"{mod}.IsDocked", () => IsDocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  107. DATA.Subscribe($"{mod}.CarrierId", () => CarrierId, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  108. DATA.Subscribe($"{mod}.SmartTag", () => SmartTag, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  109. DATA.Subscribe($"{mod}.AccessMode", () => GetAccessModel(), SubscriptionAttribute.FLAG.IgnoreSaveDB);//Auto
  110. DATA.Subscribe($"{mod}.State", () => GetLoadPortState(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  111. DATA.Subscribe($"{Module}.WaferThicknessType", () => _waferThicknessType, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  112. OP.Subscribe($"{Module}.SetThick", (cmd, args) => { SetThick(); return true; });
  113. OP.Subscribe($"{Module}.SetThin", (cmd, args) => { SetThin(); return true; });
  114. _lpCallBack = E87LoadPortManager.Instance.GetLoadPort((int)mod - (int)ModuleName.LP1 + 1);
  115. }
  116. private int GetAccessModel()
  117. {
  118. return 1;//Auto
  119. }
  120. /// <summary>
  121. /// 获取LoadPort状态
  122. /// </summary>
  123. /// <returns></returns>
  124. private int GetLoadPortState()
  125. {
  126. //不存在cassete为0
  127. if(!HasCassette)
  128. {
  129. return 0;
  130. }
  131. else
  132. {
  133. //存在Cassete但没有Load为1
  134. if (!IsLoaded)
  135. {
  136. return 1;
  137. }
  138. else
  139. {
  140. //存在Cassete同时Load为2
  141. return 2;
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 为没有efem的lp设计 部分属性默认设置为true 相关逻辑需要与eap协同
  147. /// </summary>
  148. /// <param name="mod"></param>
  149. public Loadport(ModuleName mod)
  150. {
  151. Module = mod;
  152. PortId = ((int)mod - (int)ModuleName.LP1 + 1).ToString();
  153. TimerNotifyJobDone = new Stopwatch();
  154. _enableThickness = false;// SC.GetValue<bool>("System.WaferThickness.EnableThickness");
  155. IsLoaded = true;
  156. IsClamped = true;
  157. IsDocked = true;
  158. EV.Subscribe(new EventItem("Event", AlarmWaferProtrude, "Wafer protrude", EventLevel.Alarm, EventType.HostNotification));
  159. DATA.Subscribe($"{mod}.WaferSize", () => WaferSize.ToString());
  160. DATA.Subscribe($"{mod}.CassetteState", () => HasCassette ? LoadportCassetteState.Normal : LoadportCassetteState.Absent);
  161. DATA.Subscribe($"{mod}.CassettePresent", () => HasCassette ? 1 : 0);
  162. DATA.Subscribe($"{mod}.CassettePlaced", () => HasCassette);
  163. DATA.Subscribe($"{mod}.SlotMap", () => SlotMap);
  164. DATA.Subscribe($"{mod}.IsWaferProtrude", () => Protrusion ? 1 : 0);
  165. DATA.Subscribe($"{mod}.IsMapped", () => IsMapped);
  166. DATA.Subscribe($"{mod}.IsLoaded", () => IsLoaded);
  167. DATA.Subscribe($"{mod}.IsClamped", () => IsClamped);
  168. DATA.Subscribe($"{mod}.IsDocked", () => IsDocked);
  169. DATA.Subscribe($"{mod}.CarrierId", () => CarrierId);
  170. DATA.Subscribe($"{mod}.SmartTag", () => SmartTag);
  171. DATA.Subscribe($"{Module}.WaferThicknessType", () => _waferThicknessType);
  172. OP.Subscribe($"{Module}.SetThick", (cmd, args) => { SetThick(); return true; });
  173. OP.Subscribe($"{Module}.SetThin", (cmd, args) => { SetThin(); return true; });
  174. _lpCallBack = E87LoadPortManager.Instance.GetLoadPort((int)mod - (int)ModuleName.LP1 + 1);
  175. }
  176. // Methods
  177. //
  178. public void OnError()
  179. {
  180. IsError = true;
  181. IsBusy = false;
  182. }
  183. public void SetThick()
  184. {
  185. _waferThicknessType = "Thick";
  186. SC.SetItemValue($"System.WaferThickness.{Module}WaferThicknessType", _waferThicknessType);
  187. _controller.SendEfemBackroundCommand(EfemEntity.MSG.SetThickness, Module, _waferThicknessType);
  188. }
  189. public void SetThin()
  190. {
  191. _waferThicknessType = "Thin";
  192. SC.SetItemValue($"System.WaferThickness.{Module}WaferThicknessType", _waferThicknessType);
  193. _controller.SendEfemBackroundCommand(EfemEntity.MSG.SetThickness, Module, _waferThicknessType);
  194. }
  195. #region Home
  196. public void Home()
  197. {
  198. if (IsBusy)
  199. {
  200. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not home");
  201. return;
  202. }
  203. IsBusy = true;
  204. _controller.SendEfemBackroundCommand(EfemEntity.MSG.HomeLP, Module);
  205. }
  206. public void NoteJobStart()
  207. {
  208. JobDone = false;
  209. }
  210. public void NoteJobComplete()
  211. {
  212. TimerNotifyJobDone.Restart();
  213. JobDone = true;
  214. }
  215. public void OnHomeFailed(string data)
  216. {
  217. IsError = true;
  218. IsBusy = false;
  219. }
  220. public void OnHomed()
  221. {
  222. IsError = false;
  223. IsBusy = false;
  224. IsClamped = false;
  225. IsLoaded = false;
  226. IsMapped = false;
  227. IsDocked = false;
  228. }
  229. #endregion
  230. #region Load
  231. public void Load()
  232. {
  233. if (IsLoaded)
  234. {
  235. EV.PostWarningLog(Module.ToString(), $"{Module} is loaded, can not load");
  236. return;
  237. }
  238. if (IsBusy)
  239. {
  240. EV.PostInfoLog(Module.ToString(), $"{Module} is busy, can not load");
  241. return;
  242. }
  243. if (IsError)
  244. {
  245. EV.PostInfoLog(Module.ToString(), $"{Module} is error, can not load");
  246. return;
  247. }
  248. IsBusy = true;
  249. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Load, Module);
  250. }
  251. public void LoadStart()
  252. {
  253. if(_lpCallBack!=null)
  254. {
  255. _lpCallBack.LoadStart();
  256. }
  257. }
  258. public void OnLoadFailed(string data)
  259. {
  260. IsError = true;
  261. IsBusy = false;
  262. _faCallback.LoadFailed(this);
  263. }
  264. public void OnLoaded()
  265. {
  266. IsError = false;
  267. IsBusy = false;
  268. IsLoaded = true;
  269. IsMapped = true;
  270. _faCallback.LoadComplete(this);
  271. if(_lpCallBack!=null)
  272. {
  273. _lpCallBack.LoadComplete();
  274. }
  275. }
  276. #endregion
  277. #region unload
  278. public void Unload()
  279. {
  280. //if (!IsLoaded)
  281. //{
  282. // EV.PostWarningLog(Module.ToString(), $"{Module} is not loaded, can not unload");
  283. // return;
  284. //}
  285. if (IsBusy)
  286. {
  287. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not unload");
  288. return;
  289. }
  290. if (IsError)
  291. {
  292. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not unload");
  293. return;
  294. }
  295. IsBusy = true;
  296. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Unload, Module);
  297. }
  298. public void UnloadStart()
  299. {
  300. if(_lpCallBack!=null)
  301. {
  302. _lpCallBack.UnLoadStart();
  303. }
  304. }
  305. public void OnUnloadFailed(string data)
  306. {
  307. IsError = true;
  308. IsBusy = false;
  309. _faCallback.UnloadFailed(this);
  310. }
  311. public void OnUnloaded()
  312. {
  313. IsBusy = false;
  314. IsError = false;
  315. IsLoaded = false;
  316. IsMapped = false;
  317. if (SC.GetValue<bool>("EFEM.AutoUnlockAfterUnload"))
  318. {
  319. _faCallback.UnloadComplete(this);
  320. }
  321. else
  322. {
  323. _faCallback.UnloadComplete(this);
  324. }
  325. }
  326. #endregion
  327. #region Dock
  328. public void Dock()
  329. {
  330. if (IsBusy)
  331. {
  332. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not dock");
  333. return;
  334. }
  335. if (IsError)
  336. {
  337. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not dock");
  338. return;
  339. }
  340. IsBusy = true;
  341. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Dock, Module);
  342. }
  343. public void OnDocked()
  344. {
  345. IsBusy = false;
  346. IsError = false;
  347. IsDocked = true;
  348. }
  349. public void OnDockFailed(string data)
  350. {
  351. IsError = true;
  352. IsBusy = false;
  353. }
  354. #endregion
  355. #region Undock
  356. public void Undock()
  357. {
  358. if (IsBusy)
  359. {
  360. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not undock");
  361. return;
  362. }
  363. if (IsError)
  364. {
  365. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not undock");
  366. return;
  367. }
  368. IsBusy = true;
  369. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Undock, Module);
  370. }
  371. public void OnUndocked()
  372. {
  373. IsBusy = false;
  374. IsError = false;
  375. IsDocked = false;
  376. }
  377. public void OnUndockFailed(string data)
  378. {
  379. IsError = true;
  380. IsBusy = false;
  381. }
  382. #endregion
  383. #region Clamp
  384. public void Clamp(bool isUnloadClamp)
  385. {
  386. if (IsBusy)
  387. {
  388. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not clamp");
  389. return;
  390. }
  391. if (IsError)
  392. {
  393. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not clamp");
  394. return;
  395. }
  396. IsBusy = true;
  397. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Clamp, Module, isUnloadClamp);
  398. }
  399. public void OnClamped(bool isUnloadClamp)
  400. {
  401. IsBusy = false;
  402. IsError = false;
  403. IsClamped = true;
  404. if (isUnloadClamp)
  405. {
  406. _faCallback.UnloadComplete(this);
  407. }
  408. else
  409. {
  410. _faCallback.Clamped(this);
  411. }
  412. }
  413. public void OnClampFailed(string data)
  414. {
  415. IsError = true;
  416. IsBusy = false;
  417. }
  418. #endregion
  419. #region Unclamp
  420. public void Unclamp()
  421. {
  422. if (IsBusy)
  423. {
  424. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not unclamp");
  425. return;
  426. }
  427. if (IsError)
  428. {
  429. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not unclamp");
  430. return;
  431. }
  432. IsBusy = true;
  433. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Unclamp, Module);
  434. }
  435. public void OnUnclamped()
  436. {
  437. IsBusy = false;
  438. IsError = false;
  439. IsClamped = false;
  440. _faCallback.Unclamped(this);
  441. }
  442. public void OnUnclampFailed(string data)
  443. {
  444. }
  445. #endregion
  446. #region map
  447. public void Map()
  448. {
  449. _controller.SendEfemBackroundCommand(EfemEntity.MSG.Map, Module);
  450. }
  451. #endregion
  452. #region carrierID
  453. public void ReadCarrierID()
  454. {
  455. if (IsBusy)
  456. {
  457. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not read carrier ID");
  458. return;
  459. }
  460. if (IsError)
  461. {
  462. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not read carrier ID");
  463. return;
  464. }
  465. IsBusy = true;
  466. _controller.SendEfemBackroundCommand(EfemEntity.MSG.ReadCarrierId, Module);
  467. }
  468. public void OnCarrierIDRead(string data)
  469. {
  470. IsBusy = false;
  471. IsError = false;
  472. //Regex rg = new Regex("(?<=(" + "LOT :" + "))[.\\s\\S]*?(?=(" + "QTY :" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
  473. //string carrierID = rg.Match(data).Value.Replace(":", "").Trim();
  474. //data =
  475. // "CST:C082259 TYPE:CST25_AU LOT:AF2403 QTY:24 FLOW:033000 STATUS:HOLD PRI:3-1 PD:0418A CSRLOT: CLEAN:2021/11/14 19:57:50 EQPGRP:DUMMY STAGE:CP-TEST1 RECIPE:DUMMY EMP:N ";
  476. var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
  477. CarrierId = "";
  478. foreach (var item in items)
  479. {
  480. if (item.StartsWith("CST:") && item.Length > 4)
  481. CarrierId = item.Substring(4).Trim();
  482. if (item.StartsWith("LOT:") && item.Length > 4)
  483. LotId = item.Substring(4).Trim();
  484. }
  485. if (string.IsNullOrEmpty(CarrierId))
  486. {
  487. CarrierId = data;
  488. }
  489. SmartTag = data;
  490. CarrierManager.Instance.UpdateCarrierId(Module.ToString(), data);
  491. _faCallback.IDRead(this);
  492. }
  493. public void OnCarrierIDReadFailed(string data)
  494. {
  495. IsError = true;
  496. IsBusy = false;
  497. _faCallback.ReadIDFailed(this);
  498. }
  499. public void WriteCarrierID(string id)
  500. {
  501. if (IsBusy)
  502. {
  503. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not write carrier ID");
  504. return;
  505. }
  506. if (IsError)
  507. {
  508. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not write carrier ID");
  509. return;
  510. }
  511. IsBusy = true;
  512. _controller.SendEfemBackroundCommand(EfemEntity.MSG.WriteCarrierID, Module, id);
  513. }
  514. public void OnCarrierIDWrite(string data)
  515. {
  516. IsBusy = false;
  517. IsError = false;
  518. var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
  519. CarrierId = "";
  520. foreach (var item in items)
  521. {
  522. if (item.StartsWith("CST:") && item.Length > 4)
  523. CarrierId = item.Substring(4);
  524. }
  525. if (string.IsNullOrEmpty(CarrierId))
  526. {
  527. CarrierId = data;
  528. }
  529. SmartTag = data;
  530. _faCallback.IDWrite(this);
  531. }
  532. public void OnCarrierIDWriteFailed(string data)
  533. {
  534. IsError = true;
  535. IsBusy = false;
  536. _faCallback.WriteIDFailed(this);
  537. }
  538. #endregion
  539. #region event
  540. public void HandleEvent(EfemEventArgs eArg)
  541. {
  542. switch (eArg.CommandType)
  543. {
  544. case EfemOperation.GetWaferInfo:
  545. string sWaferInfo = eArg.DataList[0];
  546. bool resultNormal = true;
  547. for (byte index = 0; index < sWaferInfo.Length; index++)
  548. {
  549. int waferState = int.Parse(sWaferInfo.Substring(index, 1));
  550. //合理的映射到内部支持的叠片/交叉片
  551. if (waferState >= 7) waferState = 7;
  552. else if (waferState >= 2) waferState = 3;
  553. WaferStatus st = (WaferStatus)waferState;
  554. WaferManager.Instance.UpdateWaferSize(this.Module, index, WaferSize);
  555. if (st != WaferStatus.Empty)
  556. {
  557. WaferManager.Instance.CreateWafer(this.Module, index, st);
  558. if (st == WaferStatus.Normal)
  559. {
  560. //EV.PostInfoLog(this.Module.ToString(), $"Found Wafer on Slot {index + 1} {WaferSize}");
  561. }
  562. else
  563. {
  564. resultNormal = false;
  565. }
  566. }
  567. }
  568. if (resultNormal)
  569. {
  570. _faCallback.CarrierSlotMapComplete(this);
  571. }
  572. else
  573. {
  574. _faCallback.CarrierSlotMapFailed(this);
  575. }
  576. this.IsMapped = true;
  577. break;
  578. case EfemOperation.SigStatus:
  579. // EVT: SIGSTAT/P2/00000381/00000000;
  580. string sParam = eArg.DataList[0];
  581. ModuleName mod = sParam.ToModule();
  582. if (!ModuleHelper.IsLoadPort(mod))
  583. return;
  584. // DATA1 & DATA2
  585. int nData1 = Convert.ToInt32(eArg.DataList[1], 16);
  586. int nData2 = Convert.ToInt32(eArg.DataList[2], 16);
  587. BitArray baData1 = new BitArray(new int[] { nData1 });
  588. BitArray baData2 = new BitArray(new int[] { nData2 });
  589. // wafer size
  590. this.WaferSize = !baData1[6] ? WaferSize.WS3 :
  591. !baData1[7] ? WaferSize.WS4 :
  592. !baData1[8] ? WaferSize.WS6 : WaferSize.WS0;
  593. // placement & present
  594. bool bPlacement = baData1[0]; // bit 0
  595. bool bPresence = !baData1[1]; // bit 1
  596. bool bArrived = bPlacement && bPresence;
  597. if (HasCassette)
  598. {
  599. if (!bArrived)
  600. {
  601. this.HasCassette = false;
  602. this.IsMapped = false;
  603. //EV.PostInfoLog(mod.ToString(), "Cassette removed");
  604. //OP.DoOperation("System.CassetteLeave"); //For unload light control off afer job done
  605. CarrierManager.Instance.DeleteCarrier(Module.ToString());
  606. WaferManager.Instance.DeleteWafer(this.Module, 0, 25);
  607. _faCallback.CarrierRemoved(this);
  608. JobDone = false;
  609. _waferThicknessType = "";
  610. CarrierId = "";
  611. }
  612. }
  613. else
  614. {
  615. if (bArrived)
  616. {
  617. this.HasCassette = true;
  618. CarrierManager.Instance.CreateCarrier(Module.ToString());
  619. _faCallback.CarrierArrived(this);
  620. JobDone = false;
  621. _waferThicknessType = "";
  622. }
  623. }
  624. this.Protrusion = !baData1[9];
  625. if (Protrusion)
  626. {
  627. //EV.PostAlarmLog(Module.ToString(), "发现 wafer 突出");
  628. //EV.Notify(AlarmWaferProtrude);
  629. //Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  630. }
  631. // DATA2, loadport上面的LED 灯, 暂时不需要用到
  632. break;
  633. default:
  634. break;
  635. }
  636. }
  637. #endregion
  638. #region TagData
  639. public void ReadTagData()
  640. {
  641. if (IsBusy)
  642. {
  643. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not read tag data");
  644. return;
  645. }
  646. if (IsError)
  647. {
  648. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not read tag data");
  649. return;
  650. }
  651. IsBusy = true;
  652. _controller.SendEfemBackroundCommand(EfemEntity.MSG.ReadTagData, Module);
  653. }
  654. public void OnTagDataRead(string data)
  655. {
  656. IsBusy = false;
  657. IsError = false;
  658. //Regex rg = new Regex("(?<=(" + "LOT :" + "))[.\\s\\S]*?(?=(" + "QTY :" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
  659. //string carrierID = rg.Match(data).Value.Replace(":", "").Trim();
  660. //data =
  661. // "CST:C082259 TYPE:CST25_AU LOT:AF2403 QTY:24 FLOW:033000 STATUS:HOLD PRI:3-1 PD:0418A CSRLOT: CLEAN:2021/11/14 19:57:50 EQPGRP:DUMMY STAGE:CP-TEST1 RECIPE:DUMMY EMP:N ";
  662. var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
  663. CarrierId = "";
  664. foreach (var item in items)
  665. {
  666. if (item.StartsWith("CST:") && item.Length > 4)
  667. CarrierId = item.Substring(4);
  668. if (item.StartsWith("LOT:") && item.Length > 4)
  669. LotId = item.Substring(4).Trim();
  670. }
  671. if (string.IsNullOrEmpty(CarrierId))
  672. {
  673. CarrierId = data;
  674. }
  675. SmartTag = data;
  676. _faCallback.TagDataRead(this);
  677. }
  678. public void OnTagDataReadFailed(string data)
  679. {
  680. IsError = true;
  681. IsBusy = false;
  682. _faCallback.ReadTagDataFailed(this);
  683. }
  684. public void WriteTagData(string tagData)
  685. {
  686. if (IsBusy)
  687. {
  688. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not write tag data");
  689. return;
  690. }
  691. if (IsError)
  692. {
  693. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not write tag data");
  694. return;
  695. }
  696. IsBusy = true;
  697. _controller.SendEfemBackroundCommand(EfemEntity.MSG.WriteTagData, Module, tagData);
  698. }
  699. public void OnTagDataWrite(string data)
  700. {
  701. IsBusy = false;
  702. IsError = false;
  703. var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
  704. CarrierId = "";
  705. foreach (var item in items)
  706. {
  707. if (item.StartsWith("CST:") && item.Length > 4)
  708. CarrierId = item.Substring(4);
  709. }
  710. if (string.IsNullOrEmpty(CarrierId))
  711. {
  712. CarrierId = data;
  713. }
  714. SmartTag = data;
  715. _faCallback.TagDataWrite(this);
  716. }
  717. public void OnTagDataWriteFailed(string data)
  718. {
  719. IsError = true;
  720. IsBusy = false;
  721. _faCallback.WriteTagDataFailed( this);
  722. }
  723. #endregion
  724. public void SetOnline(bool online)
  725. {
  726. OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
  727. }
  728. sealed class LoadPortFACallback
  729. {
  730. private string CARRIER_ARRIVED = "CARRIER_ARRIVED";
  731. private string CARRIER_REMOVED = "CARRIER_REMOVED";
  732. private string SLOT_MAP_AVAILABLE = "SLOT_MAP_AVAILABLE";
  733. private string SLOT_MAP_FAILED = "SLOT_MAP_FAILED";
  734. private const string CARRIER_LOADED = "CARRIER_LOADED";
  735. private const string PortLoadFailed = "PortLoadFailed";
  736. private const string CARRIER_UNLOADED = "CARRIER_UNLOADED";
  737. private const string PortUnloadFailed = "PortUnloadFailed";
  738. private const string PortClamped = "PortClamped";
  739. private const string PortUnclamped = "PortUnclamped";
  740. private const string CARRIER_ID_READ = "CARRIER_ID_READ";
  741. private const string PortReadIDFailed = "PortReadIDFailed";
  742. private const string PortIDWrite = "PortIDWrite";
  743. private const string PortWriteIDFailed = "PortWriteIDFailed";
  744. private const string PortTagDataRead = "PortTagDataRead";
  745. private const string PortReadTagDataFailed = "PortReadTagDataFailed";
  746. private const string PortTagDataWrite = "PortTagDataWrite";
  747. private const string PortWriteTagDataFailed = "PortWriteTagDataFailed";
  748. public LoadPortFACallback()
  749. {
  750. EV.Subscribe(new EventItem("Event", CARRIER_ARRIVED, "Carrier Arrived"));
  751. EV.Subscribe(new EventItem("Event", CARRIER_REMOVED, "Carrier Removed"));
  752. EV.Subscribe(new EventItem("Event", SLOT_MAP_AVAILABLE, "Slot map available"));
  753. EV.Subscribe(new EventItem("Event", SLOT_MAP_FAILED, "Slot map failed"));
  754. EV.Subscribe(new EventItem("Event", CARRIER_LOADED, "Carrier Loaded"));
  755. EV.Subscribe(new EventItem("Event", PortLoadFailed, PortLoadFailed));
  756. EV.Subscribe(new EventItem("Event", CARRIER_UNLOADED, "Carrier Unloaded"));
  757. EV.Subscribe(new EventItem("Event", PortUnloadFailed, PortUnloadFailed));
  758. EV.Subscribe(new EventItem("Event", PortClamped, "Port Clamped"));
  759. EV.Subscribe(new EventItem("Event", PortUnclamped, PortUnclamped));
  760. EV.Subscribe(new EventItem("Event", CARRIER_ID_READ, "Carrier Id Read"));
  761. EV.Subscribe(new EventItem("Event", PortReadIDFailed, PortReadIDFailed));
  762. EV.Subscribe(new EventItem("Event", PortIDWrite, PortIDWrite));
  763. EV.Subscribe(new EventItem("Event", PortWriteIDFailed, PortWriteIDFailed));
  764. EV.Subscribe(new EventItem("Event", PortTagDataRead, PortTagDataRead));
  765. EV.Subscribe(new EventItem("Event", PortReadTagDataFailed, PortReadTagDataFailed));
  766. EV.Subscribe(new EventItem("Event", PortTagDataWrite, PortTagDataWrite));
  767. EV.Subscribe(new EventItem("Event", PortWriteTagDataFailed, PortWriteTagDataFailed));
  768. }
  769. public void CarrierArrived(Loadport lp)
  770. {
  771. SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
  772. dvid["PortID"] = lp.PortId;
  773. EV.Notify(CARRIER_ARRIVED, dvid);
  774. }
  775. public void CarrierRemoved(Loadport lp)
  776. {
  777. SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
  778. dvid["PortID"] = lp.PortId;
  779. dvid["CarrierID"] = lp.CarrierId ?? "";
  780. EV.Notify(CARRIER_REMOVED, dvid);
  781. }
  782. public void CarrierSlotMapComplete(Loadport lp)
  783. {
  784. SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
  785. dvid["SlotMap"] = lp.SlotMap;
  786. dvid["PortID"] = lp.PortId;
  787. dvid["CarrierID"] = lp.CarrierId ?? "";
  788. EV.Notify(SLOT_MAP_AVAILABLE, dvid);
  789. }
  790. public void CarrierSlotMapFailed(Loadport lp)
  791. {
  792. }
  793. public void LoadComplete(Loadport lp)
  794. {
  795. ModuleName moduleName = lp.Module;
  796. var dvid = new SerializableDictionary<string, string>
  797. {
  798. ["CarrierID"] = lp.CarrierId ?? "",
  799. ["PortID"] = lp.PortId.ToString()
  800. };
  801. EV.Notify(CARRIER_LOADED, dvid);
  802. }
  803. public void LoadFailed(Loadport lp)
  804. {
  805. }
  806. public void UnloadComplete(Loadport lp)
  807. {
  808. ModuleName moduleName = lp.Module;
  809. var dvid = new SerializableDictionary<string, string>
  810. {
  811. ["CarrierID"] = lp.CarrierId ?? "",
  812. ["PortID"] = lp.PortId.ToString()
  813. };
  814. EV.Notify(CARRIER_UNLOADED, dvid);
  815. }
  816. public void UnloadFailed(Loadport lp)
  817. {
  818. }
  819. public void Clamped(Loadport lp)
  820. {
  821. ModuleName moduleName = lp.Module;
  822. var dvid = new SerializableDictionary<string, string>
  823. {
  824. ["CarrierID"] = lp.CarrierId ?? "",
  825. ["PortID"] = lp.PortId.ToString()
  826. };
  827. EV.Notify(PortClamped, dvid);
  828. }
  829. public void Unclamped(Loadport lp)
  830. {
  831. ModuleName moduleName = lp.Module;
  832. var dvid = new SerializableDictionary<string, string>
  833. {
  834. ["CarrierID"] = lp.CarrierId ?? "",
  835. ["PortID"] = lp.PortId.ToString()
  836. };
  837. EV.Notify(PortUnclamped, dvid);
  838. }
  839. public void IDRead(Loadport lp)
  840. {
  841. var dvid = new SerializableDictionary<string, string>
  842. {
  843. ["CarrierID"] = lp.CarrierId ?? "",
  844. ["PortID"] = lp.PortId.ToString(),
  845. ["SmartTag"]=lp.SmartTag,
  846. };
  847. EV.Notify(CARRIER_ID_READ, dvid);
  848. }
  849. public void ReadIDFailed(Loadport lp)
  850. {
  851. }
  852. public void IDWrite(Loadport lp)
  853. {
  854. }
  855. public void WriteIDFailed(Loadport lp)
  856. {
  857. }
  858. public void TagDataRead(Loadport lp)
  859. {
  860. }
  861. public void ReadTagDataFailed(Loadport lp)
  862. {
  863. }
  864. public void TagDataWrite(Loadport lp)
  865. {
  866. }
  867. public void WriteTagDataFailed(Loadport lp)
  868. {
  869. }
  870. }
  871. }
  872. }