Loadport.cs 38 KB

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