Loadport.cs 37 KB

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