Loadport.cs 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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. //EV.PostInfoLog(mod.ToString(), "Cassette removed");
  710. //OP.DoOperation("System.CassetteLeave"); //For unload light control off afer job done
  711. CarrierManager.Instance.DeleteCarrier(Module.ToString());
  712. WaferManager.Instance.DeleteWafer(this.Module, 0, 25);
  713. _faCallback.CarrierRemoved(this);
  714. JobDone = false;
  715. _waferThicknessType = "";
  716. }
  717. }
  718. else
  719. {
  720. if (bArrived)
  721. {
  722. this.HasCassette = true;
  723. IsLoaded = true;
  724. CarrierManager.Instance.CreateCarrier(Module.ToString());
  725. _faCallback.CarrierArrived(this);
  726. JobDone = false;
  727. _waferThicknessType = "";
  728. }
  729. }
  730. }
  731. #endregion
  732. #region TagData
  733. public void ReadTagData()
  734. {
  735. if (IsBusy)
  736. {
  737. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not read tag data");
  738. return;
  739. }
  740. if (IsError)
  741. {
  742. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not read tag data");
  743. return;
  744. }
  745. IsBusy = true;
  746. _controller.SendEfemAutoCommand(EfemEntity.MSG.ReadTagData, Module);
  747. }
  748. public void OnTagDataRead(string data)
  749. {
  750. IsBusy = false;
  751. IsError = false;
  752. //Regex rg = new Regex("(?<=(" + "LOT :" + "))[.\\s\\S]*?(?=(" + "QTY :" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
  753. //string carrierID = rg.Match(data).Value.Replace(":", "").Trim();
  754. //data =
  755. // "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 ";
  756. var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
  757. CarrierId = "";
  758. foreach (var item in items)
  759. {
  760. if (item.StartsWith("CST:") && item.Length > 4)
  761. CarrierId = item.Substring(4);
  762. if (item.StartsWith("LOT:") && item.Length > 4)
  763. LotId = item.Substring(4).Trim();
  764. }
  765. if (string.IsNullOrEmpty(CarrierId))
  766. {
  767. CarrierId = data;
  768. }
  769. SmartTag = data;
  770. _faCallback.TagDataRead(this);
  771. }
  772. public void OnTagDataReadFailed(string data)
  773. {
  774. IsError = true;
  775. IsBusy = false;
  776. _faCallback.ReadTagDataFailed(this);
  777. }
  778. public void WriteTagData(string tagData)
  779. {
  780. if (IsBusy)
  781. {
  782. EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not write tag data");
  783. return;
  784. }
  785. if (IsError)
  786. {
  787. EV.PostInfoLog(Module.ToString(), $"{Module} is error can not write tag data");
  788. return;
  789. }
  790. IsBusy = true;
  791. _controller.SendEfemAutoCommand(EfemEntity.MSG.WriteTagData, Module, tagData);
  792. }
  793. public void OnTagDataWrite(string data)
  794. {
  795. IsBusy = false;
  796. IsError = false;
  797. var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
  798. CarrierId = "";
  799. foreach (var item in items)
  800. {
  801. if (item.StartsWith("CST:") && item.Length > 4)
  802. CarrierId = item.Substring(4);
  803. }
  804. if (string.IsNullOrEmpty(CarrierId))
  805. {
  806. CarrierId = data;
  807. }
  808. SmartTag = data;
  809. _faCallback.TagDataWrite(this);
  810. }
  811. public void OnTagDataWriteFailed(string data)
  812. {
  813. IsError = true;
  814. IsBusy = false;
  815. _faCallback.WriteTagDataFailed( this);
  816. }
  817. #endregion
  818. public void SetOnline(bool online)
  819. {
  820. OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
  821. }
  822. sealed class LoadPortFACallback
  823. {
  824. private string CARRIER_ARRIVED = "CARRIER_ARRIVED";
  825. private string CARRIER_REMOVED = "CARRIER_REMOVED";
  826. private string SLOT_MAP_AVAILABLE = "SLOT_MAP_AVAILABLE";
  827. private string SLOT_MAP_FAILED = "SLOT_MAP_FAILED";
  828. private const string CARRIER_LOADED = "CARRIER_LOADED";
  829. private const string PortLoadFailed = "PortLoadFailed";
  830. private const string CARRIER_UNLOADED = "CARRIER_UNLOADED";
  831. private const string PortUnloadFailed = "PortUnloadFailed";
  832. private const string PortClamped = "PortClamped";
  833. private const string PortUnclamped = "PortUnclamped";
  834. private const string CARRIER_ID_READ = "CARRIER_ID_READ";
  835. private const string PortReadIDFailed = "PortReadIDFailed";
  836. private const string PortIDWrite = "PortIDWrite";
  837. private const string PortWriteIDFailed = "PortWriteIDFailed";
  838. private const string PortTagDataRead = "PortTagDataRead";
  839. private const string PortReadTagDataFailed = "PortReadTagDataFailed";
  840. private const string PortTagDataWrite = "PortTagDataWrite";
  841. private const string PortWriteTagDataFailed = "PortWriteTagDataFailed";
  842. public LoadPortFACallback()
  843. {
  844. EV.Subscribe(new EventItem("Event", CARRIER_ARRIVED, "Carrier Arrived"));
  845. EV.Subscribe(new EventItem("Event", CARRIER_REMOVED, "Carrier Removed"));
  846. EV.Subscribe(new EventItem("Event", SLOT_MAP_AVAILABLE, "Slot map available"));
  847. EV.Subscribe(new EventItem("Event", SLOT_MAP_FAILED, "Slot map failed"));
  848. EV.Subscribe(new EventItem("Event", CARRIER_LOADED, "Carrier Loaded"));
  849. EV.Subscribe(new EventItem("Event", PortLoadFailed, PortLoadFailed));
  850. EV.Subscribe(new EventItem("Event", CARRIER_UNLOADED, "Carrier Unloaded"));
  851. EV.Subscribe(new EventItem("Event", PortUnloadFailed, PortUnloadFailed));
  852. EV.Subscribe(new EventItem("Event", PortClamped, "Port Clamped"));
  853. EV.Subscribe(new EventItem("Event", PortUnclamped, PortUnclamped));
  854. EV.Subscribe(new EventItem("Event", CARRIER_ID_READ, "Carrier Id Read"));
  855. EV.Subscribe(new EventItem("Event", PortReadIDFailed, PortReadIDFailed));
  856. EV.Subscribe(new EventItem("Event", PortIDWrite, PortIDWrite));
  857. EV.Subscribe(new EventItem("Event", PortWriteIDFailed, PortWriteIDFailed));
  858. EV.Subscribe(new EventItem("Event", PortTagDataRead, PortTagDataRead));
  859. EV.Subscribe(new EventItem("Event", PortReadTagDataFailed, PortReadTagDataFailed));
  860. EV.Subscribe(new EventItem("Event", PortTagDataWrite, PortTagDataWrite));
  861. EV.Subscribe(new EventItem("Event", PortWriteTagDataFailed, PortWriteTagDataFailed));
  862. }
  863. public void CarrierArrived(Loadport lp)
  864. {
  865. SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
  866. dvid["PortID"] = lp.PortId;
  867. EV.Notify(CARRIER_ARRIVED, dvid);
  868. }
  869. public void CarrierRemoved(Loadport lp)
  870. {
  871. SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
  872. dvid["PortID"] = lp.PortId;
  873. dvid["CarrierID"] = lp.CarrierId ?? "";
  874. EV.Notify(CARRIER_REMOVED, dvid);
  875. }
  876. public void CarrierSlotMapComplete(Loadport lp)
  877. {
  878. SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
  879. dvid["SlotMap"] = lp.SlotMap;
  880. dvid["PortID"] = lp.PortId;
  881. dvid["CarrierID"] = lp.CarrierId ?? "";
  882. EV.Notify(SLOT_MAP_AVAILABLE, dvid);
  883. }
  884. public void CarrierSlotMapFailed(Loadport lp)
  885. {
  886. }
  887. public void LoadComplete(Loadport lp)
  888. {
  889. ModuleName moduleName = lp.Module;
  890. var dvid = new SerializableDictionary<string, string>
  891. {
  892. ["CarrierID"] = lp.CarrierId ?? "",
  893. ["PortID"] = lp.PortId.ToString()
  894. };
  895. EV.Notify(CARRIER_LOADED, dvid);
  896. }
  897. public void LoadFailed(Loadport lp)
  898. {
  899. }
  900. public void UnloadComplete(Loadport lp)
  901. {
  902. ModuleName moduleName = lp.Module;
  903. var dvid = new SerializableDictionary<string, string>
  904. {
  905. ["CarrierID"] = lp.CarrierId ?? "",
  906. ["PortID"] = lp.PortId.ToString()
  907. };
  908. EV.Notify(CARRIER_UNLOADED, dvid);
  909. }
  910. public void UnloadFailed(Loadport lp)
  911. {
  912. }
  913. public void Clamped(Loadport lp)
  914. {
  915. }
  916. public void Unclamped(Loadport lp)
  917. {
  918. }
  919. public void IDRead(Loadport lp)
  920. {
  921. }
  922. public void ReadIDFailed(Loadport lp)
  923. {
  924. }
  925. public void IDWrite(Loadport lp)
  926. {
  927. }
  928. public void WriteIDFailed(Loadport lp)
  929. {
  930. }
  931. public void TagDataRead(Loadport lp)
  932. {
  933. }
  934. public void ReadTagDataFailed(Loadport lp)
  935. {
  936. }
  937. public void TagDataWrite(Loadport lp)
  938. {
  939. }
  940. public void WriteTagDataFailed(Loadport lp)
  941. {
  942. }
  943. }
  944. }
  945. }