Loadport.cs 36 KB

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