Loadport.cs 33 KB

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