JetEfem.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7. using Venus_Core;
  8. using Venus_RT.Modules;
  9. using MECF.Framework.Common.CommonData;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using Aitex.Sorter.Common;
  13. using Aitex.Core.Common;
  14. using Aitex.Core.RT.SCCore;
  15. using Aitex.Core.RT.Log;
  16. using Aitex.Core.Util;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  18. using Venus_RT.Devices.YASKAWA;
  19. using System.Collections.Concurrent;
  20. namespace Venus_RT.Devices.EFEM
  21. {
  22. class JetEfem : EfemBase
  23. {
  24. private RState _status;
  25. private bool _IsHomed;
  26. private string _waferPresence;
  27. private bool _bIsUnloadClamp;
  28. private RobotMoveInfo _robotMoveInfo = new RobotMoveInfo();
  29. private readonly Loadport[] _LPMs = new Loadport[3];
  30. private readonly SignalTower _signalT = new SignalTower();
  31. private readonly AsyncSocket _socket;
  32. private EfemMessage _currentMsg;
  33. private EfemMessage _backroundMsg;
  34. private EfemMessage _revMsg;
  35. private bool _LiftIsUp = false;
  36. private bool _LiftIsDown = false;
  37. private R_TRIG _busyTrig = new R_TRIG();
  38. private Stopwatch _busyWatch = new Stopwatch();
  39. public override RState Status
  40. {
  41. get
  42. {
  43. _busyTrig.CLK = _status == RState.Running;
  44. if(_busyTrig.Q)
  45. {
  46. _busyWatch.Restart();
  47. }
  48. else if(_busyTrig.M)
  49. {
  50. if(_busyWatch.ElapsedMilliseconds > 30000)
  51. {
  52. _busyWatch.Stop();
  53. _status = RState.Timeout;
  54. }
  55. }
  56. return _status;
  57. }
  58. }
  59. public override bool IsHomed { get { return _IsHomed; } }
  60. public override RobotMoveInfo TMRobotMoveInfo { get { return _robotMoveInfo; } }
  61. public override ILoadport this[ModuleName mod]
  62. {
  63. get
  64. {
  65. if (!ModuleHelper.IsLoadPort(mod))
  66. throw new ApplicationException($"{mod} is NOT Loadport");
  67. return _LPMs[mod - ModuleName.LP1];
  68. }
  69. }
  70. public override bool LiftIsUp { get { return _LiftIsUp; } }
  71. public override bool LiftIsDown { get { return _LiftIsDown; } }
  72. private BlockingCollection<RobotAnimationData> blockingCollection = new BlockingCollection<RobotAnimationData>();
  73. public JetEfem()
  74. {
  75. _socket = new AsyncSocket("");
  76. _socket.Connect(SC.GetStringValue($"EFEM.IPAddress"));
  77. _socket.OnDataChanged += OnReceiveMessage;
  78. _socket.OnErrorHappened += OnErrorHappen;
  79. _status = RState.Init;
  80. _IsHomed = false;
  81. _busyTrig.RST = true;
  82. _LPMs[0] = new Loadport(ModuleName.LP1, this);
  83. _LPMs[1] = new Loadport(ModuleName.LP2, this);
  84. _LPMs[2] = new Loadport(ModuleName.LP3, this);
  85. CarrierManager.Instance.SubscribeLocation(ModuleName.LP1.ToString(), 1);
  86. CarrierManager.Instance.SubscribeLocation(ModuleName.LP2.ToString(), 1);
  87. CarrierManager.Instance.SubscribeLocation(ModuleName.LP3.ToString(), 1);
  88. Action<ModuleName, int> _subscribeLoc = (ModuleName module, int waferCount) =>
  89. {
  90. if (ModuleHelper.IsInstalled(module))
  91. {
  92. WaferManager.Instance.SubscribeLocation(module, waferCount);
  93. }
  94. };
  95. WaferManager.Instance.SubscribeLocation(ModuleName.EfemRobot, 2);
  96. WaferManager.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  97. // _subscribeLoc(ModuleName.EfemRobot, 2);
  98. //_subscribeLoc(ModuleName.Aligner1, 1);
  99. _subscribeLoc(ModuleName.Aligner2, 1);
  100. _subscribeLoc(ModuleName.Cooling1, 1);
  101. _subscribeLoc(ModuleName.Cooling2, 1);
  102. _subscribeLoc(ModuleName.LP1, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  103. _subscribeLoc(ModuleName.LP2, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  104. _subscribeLoc(ModuleName.LP3, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  105. Task.Run(() =>
  106. {
  107. foreach (var data in blockingCollection.GetConsumingEnumerable())
  108. {
  109. _robotMoveInfo.Action = data.Action;
  110. _robotMoveInfo.ArmTarget = data.Hand == Hand.Blade1 ? RobotArm.ArmA : (data.Hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
  111. _robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{data.Target}";
  112. System.Threading.Thread.Sleep(600);
  113. }
  114. });
  115. }
  116. public override void Monitor()
  117. {
  118. }
  119. public override void Terminate()
  120. {
  121. }
  122. public override void Reset()
  123. {
  124. _status = RState.End;
  125. }
  126. public override void SetOnline(bool online)
  127. {
  128. }
  129. public override void SetOnline(ModuleName mod, bool online)
  130. {
  131. }
  132. public override void SetBusy(ModuleName mod, bool online)
  133. {
  134. _status = RState.Running;
  135. }
  136. public override bool HomeAll()
  137. {
  138. if (_status == RState.Running)
  139. _backroundMsg = _currentMsg;
  140. _currentMsg = new EfemMessage
  141. {
  142. Port = ModuleName.EFEM,
  143. Operation = EfemOperation.Home,
  144. Head = EfemMessage.MsgHead.MOV,
  145. Parameters = new List<string> { Constant.ModuleString[ModuleName.EFEM] }
  146. };
  147. _status = RState.Running;
  148. string data = _currentMsg.ToString();
  149. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  150. return _socket.Write(data);
  151. }
  152. public override bool Home(ModuleName mod)
  153. {
  154. if (_status == RState.Running)
  155. _backroundMsg = _currentMsg;
  156. if (ModuleHelper.IsLoadPort(mod))
  157. {
  158. _currentMsg = new EfemMessage
  159. {
  160. Port = mod,
  161. Operation = EfemOperation.Home,
  162. Head = EfemMessage.MsgHead.MOV,
  163. Parameters = new List<string> { Constant.ModuleString[mod] }
  164. };
  165. _status = RState.Running;
  166. return _socket.Write(_currentMsg.ToString());
  167. }
  168. else
  169. {
  170. _currentMsg = new EfemMessage
  171. {
  172. Port = mod,
  173. Operation = EfemOperation.Home,
  174. Head = EfemMessage.MsgHead.MOV,
  175. Parameters = new List<string> { Constant.ModuleString[mod] }
  176. };
  177. _status = RState.Running;
  178. return _socket.Write(_currentMsg.ToString());
  179. }
  180. }
  181. public override bool OriginalSearch(ModuleName mod)
  182. {
  183. if (!CheckEfemStatus())
  184. return false;
  185. _currentMsg = new EfemMessage
  186. {
  187. Port = ModuleName.EFEM,
  188. Operation = EfemOperation.Orgsh,
  189. Head = EfemMessage.MsgHead.MOV,
  190. Parameters = new List<string>
  191. {
  192. Constant.ModuleString[mod]
  193. }
  194. };
  195. _status = RState.Running;
  196. return _socket.Write(_currentMsg.ToString());
  197. }
  198. public override bool CheckWaferPresence()
  199. {
  200. if (!CheckEfemStatus())
  201. return false;
  202. _currentMsg = new EfemMessage
  203. {
  204. Port = ModuleName.EFEM,
  205. Operation = EfemOperation.StateTrack,
  206. Head = EfemMessage.MsgHead.GET,
  207. Parameters = new List<string> { "TRACK" }
  208. };
  209. _waferPresence = string.Empty;
  210. _status = RState.Running;
  211. return _socket.Write(_currentMsg.ToString());
  212. }
  213. public override string GetWaferPresence()
  214. {
  215. return _waferPresence;
  216. }
  217. public override bool Halt()
  218. {
  219. if (_status == RState.Running)
  220. _backroundMsg = _currentMsg;
  221. _currentMsg = new EfemMessage
  222. {
  223. Port = ModuleName.EFEM,
  224. Operation = EfemOperation.EmsStop,
  225. Head = EfemMessage.MsgHead.MOV,
  226. };
  227. _status = RState.Running;
  228. return _socket.Write(_currentMsg.ToString());
  229. }
  230. public override bool ClearError()
  231. {
  232. _currentMsg = new EfemMessage
  233. {
  234. Port = ModuleName.EFEM,
  235. Operation = EfemOperation.ClearError,
  236. Head = EfemMessage.MsgHead.SET,
  237. Parameters = new List<string> { "CLEAR" }
  238. };
  239. _status = RState.Running;
  240. return _socket.Write(_currentMsg.ToString());
  241. }
  242. public override bool PickExtend(ModuleName chamber, int slot, Hand hand)
  243. {
  244. if (!CheckEfemStatus())
  245. return false;
  246. _currentMsg = new EfemMessage
  247. {
  248. Operation = EfemOperation.Extend,
  249. Head = EfemMessage.MsgHead.MOV,
  250. Parameters = new List<string>
  251. {
  252. chamber.ToHWString(),
  253. ExtendPos.GB.ToString(),
  254. Constant.ArmString[hand],
  255. }
  256. };
  257. SetRobotMovingInfo(RobotAction.Extending, hand, chamber);
  258. _status = RState.Running;
  259. return _socket.Write(_currentMsg.ToString());
  260. }
  261. public override bool PickRetract(ModuleName chamber, int slot, Hand hand)
  262. {
  263. if (!CheckEfemStatus())
  264. return false;
  265. _currentMsg = new EfemMessage
  266. {
  267. Operation = EfemOperation.Extend,
  268. Head = EfemMessage.MsgHead.MOV,
  269. Parameters = new List<string>
  270. {
  271. chamber.ToHWString(),
  272. ExtendPos.G4.ToString(),
  273. Constant.ArmString[hand],
  274. }
  275. };
  276. _status = RState.Running;
  277. SetRobotMovingInfo(RobotAction.Retracting, hand, chamber);
  278. return _socket.Write(_currentMsg.ToString());
  279. }
  280. public override bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
  281. {
  282. if (!CheckEfemStatus())
  283. return false;
  284. _currentMsg = new EfemMessage
  285. {
  286. Operation = EfemOperation.Extend,
  287. Head = EfemMessage.MsgHead.MOV,
  288. Parameters = new List<string>
  289. {
  290. chamber.ToHWString(),
  291. ExtendPos.PB.ToString(),
  292. Constant.ArmString[hand],
  293. }
  294. };
  295. _status = RState.Running;
  296. SetRobotMovingInfo(RobotAction.Extending, hand, chamber);
  297. return _socket.Write(_currentMsg.ToString());
  298. }
  299. public override bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
  300. {
  301. if (!CheckEfemStatus())
  302. return false;
  303. _currentMsg = new EfemMessage
  304. {
  305. Operation = EfemOperation.Extend,
  306. Head = EfemMessage.MsgHead.MOV,
  307. Parameters = new List<string>
  308. {
  309. chamber.ToHWString(),
  310. ExtendPos.P4.ToString(),
  311. Constant.ArmString[hand],
  312. }
  313. };
  314. _status = RState.Running;
  315. SetRobotMovingInfo(RobotAction.Retracting, hand, chamber);
  316. return _socket.Write(_currentMsg.ToString());
  317. }
  318. public override bool Pick(ModuleName station, int slot, Hand hand)
  319. {
  320. if (!CheckEfemStatus())
  321. return false;
  322. Position SrcPos = new Position { Module = station, Slot = (byte)slot };
  323. _currentMsg = new EfemMessage
  324. {
  325. Operation = EfemOperation.Pick,
  326. Head = EfemMessage.MsgHead.MOV,
  327. Parameters = new List<string>
  328. {
  329. SrcPos.ToHWString(),
  330. Constant.ArmString[hand],
  331. //WaferSize.WS12.ToString()
  332. }
  333. };
  334. _status = RState.Running;
  335. SetRobotMovingInfo(RobotAction.Picking, hand, station);
  336. return _socket.Write(_currentMsg.ToString());
  337. }
  338. public override bool Place(ModuleName station, int slot, Hand hand)
  339. {
  340. if (!CheckEfemStatus())
  341. return false;
  342. Position DestPos = new Position { Module = station, Slot = (byte)slot };
  343. _currentMsg = new EfemMessage
  344. {
  345. Operation = EfemOperation.Place,
  346. Head = EfemMessage.MsgHead.MOV,
  347. Parameters = new List<string>
  348. {
  349. DestPos.ToHWString(),
  350. Constant.ArmString[hand],
  351. //WaferSize.WS12.ToString()
  352. }
  353. };
  354. _status = RState.Running;
  355. SetRobotMovingInfo(RobotAction.Placing, hand, station);
  356. return _socket.Write(_currentMsg.ToString());
  357. }
  358. public override bool Goto(ModuleName station, Hand hand)
  359. {
  360. if (!CheckEfemStatus())
  361. return false;
  362. Position DestPos = new Position { Module = station, Slot = (byte)0 };
  363. _currentMsg = new EfemMessage
  364. {
  365. Operation = EfemOperation.Goto,
  366. Head = EfemMessage.MsgHead.MOV,
  367. Parameters = new List<string>
  368. {
  369. DestPos.ToHWString(),
  370. Constant.ArmString[hand],
  371. WaferSize.WS12.ToString()
  372. }
  373. };
  374. _status = RState.Running;
  375. return _socket.Write(_currentMsg.ToString());
  376. }
  377. public override bool Grip(Hand blade, bool isGrip)
  378. {
  379. if (!CheckEfemStatus())
  380. return false;
  381. _currentMsg = new EfemMessage
  382. {
  383. Operation = EfemOperation.Grip,
  384. Head = EfemMessage.MsgHead.SET,
  385. Parameters = new List<string>
  386. {
  387. isGrip ? "ON":"OFF",
  388. Constant.ArmString[blade]
  389. }
  390. };
  391. _status = RState.Running;
  392. return _socket.Write(_currentMsg.ToString());
  393. }
  394. public override bool Map(ModuleName mod)
  395. {
  396. if (!CheckEfemStatus())
  397. return false;
  398. _currentMsg = new EfemMessage
  399. {
  400. Operation = EfemOperation.Map,
  401. Head = EfemMessage.MsgHead.MOV,
  402. Parameters = new List<string> { Constant.ModuleString[mod] }
  403. };
  404. _status = RState.Running;
  405. return _socket.Write(_currentMsg.ToString());
  406. }
  407. public override bool SetPinUp(ModuleName mod)
  408. {
  409. if (!CheckEfemStatus())
  410. return false;
  411. _currentMsg = new EfemMessage
  412. {
  413. Operation = EfemOperation.Lift,
  414. Head = EfemMessage.MsgHead.MOV,
  415. Parameters = new List<string> { Constant.ModuleString[mod], "UP" }
  416. };
  417. _status = RState.Running;
  418. return _socket.Write(_currentMsg.ToString());
  419. }
  420. public override bool SetPinDown(ModuleName mod)
  421. {
  422. if (!CheckEfemStatus())
  423. return false;
  424. _currentMsg = new EfemMessage
  425. {
  426. Operation = EfemOperation.Lift,
  427. Head = EfemMessage.MsgHead.MOV,
  428. Parameters = new List<string> { Constant.ModuleString[mod], "DOWN" }
  429. };
  430. _status = RState.Running;
  431. return _socket.Write(_currentMsg.ToString());
  432. }
  433. public override bool Align(ModuleName mod, double angle, float delayTime, WaferSize size)
  434. {
  435. if (!CheckEfemStatus())
  436. return false;
  437. _currentMsg = new EfemMessage
  438. {
  439. Operation = EfemOperation.Align,
  440. Head = EfemMessage.MsgHead.MOV,
  441. Parameters = new List<string> { $"A{angle.ToString("000.00")}" }
  442. };
  443. _status = RState.Running;
  444. return _socket.Write(_currentMsg.ToString());
  445. }
  446. public override bool SetLamp(LightType light, LightStatus status)
  447. {
  448. if (Status == RState.Running)
  449. {
  450. LOG.Write(eEvent.ERR_EFEM_ROBOT, ModuleName.EFEM, "EFEM is busy, please wait a minute");
  451. return false;
  452. }
  453. _currentMsg = new EfemMessage
  454. {
  455. Port = ModuleName.EFEM,
  456. Operation = EfemOperation.Light,
  457. Head = EfemMessage.MsgHead.SET,
  458. Parameters = new List<string> { Constant.STOWER, light.ToString(), status.ToString() }
  459. };
  460. _status = RState.Running;
  461. return _socket.Write(_currentMsg.ToString());
  462. }
  463. public override bool Load(ModuleName mod)
  464. {
  465. if (!CheckEfemStatus())
  466. return false;
  467. _currentMsg = new EfemMessage
  468. {
  469. Port = mod,
  470. Operation = EfemOperation.Load,
  471. Head = EfemMessage.MsgHead.MOV,
  472. Parameters = new List<string> { Constant.ModuleString[mod] }
  473. };
  474. _status = RState.Running;
  475. return _socket.Write(_currentMsg.ToString());
  476. }
  477. public override bool Unload(ModuleName mod)
  478. {
  479. if (!CheckEfemStatus())
  480. return false;
  481. _currentMsg = new EfemMessage
  482. {
  483. Port = mod,
  484. Operation = EfemOperation.Unload,
  485. Head = EfemMessage.MsgHead.MOV,
  486. Parameters = new List<string> { Constant.ModuleString[mod] }
  487. };
  488. _status = RState.Running;
  489. return _socket.Write(_currentMsg.ToString());
  490. }
  491. public override bool ReadCarrierId(ModuleName mod)
  492. {
  493. if (!CheckEfemStatus())
  494. return false;
  495. _currentMsg = new EfemMessage
  496. {
  497. Port = mod,
  498. Operation = EfemOperation.CarrierId,
  499. Head = EfemMessage.MsgHead.GET,
  500. Parameters = new List<string> { Constant.ModuleString[mod] }
  501. };
  502. _status = RState.Running;
  503. return _socket.Write(_currentMsg.ToString());
  504. }
  505. public override bool WriteCarrierId(ModuleName mod, string id)
  506. {
  507. if (!CheckEfemStatus())
  508. return false;
  509. _currentMsg = new EfemMessage
  510. {
  511. Port = mod,
  512. Operation = EfemOperation.CarrierId,
  513. Head = EfemMessage.MsgHead.SET,
  514. Parameters = new List<string> { Constant.ModuleString[mod], id }
  515. };
  516. _status = RState.Running;
  517. return _socket.Write(_currentMsg.ToString());
  518. }
  519. public override bool ReadTagData(ModuleName mod)
  520. {
  521. if (!CheckEfemStatus())
  522. return false;
  523. _currentMsg = new EfemMessage
  524. {
  525. Port = mod,
  526. Operation = EfemOperation.CarrierId,
  527. Head = EfemMessage.MsgHead.GET,
  528. Parameters = new List<string> { Constant.ModuleString[mod] }
  529. };
  530. _status = RState.Running;
  531. return _socket.Write(_currentMsg.ToString());
  532. }
  533. public override bool WriteTagData(ModuleName mod, string tagData)
  534. {
  535. if (!CheckEfemStatus())
  536. return false;
  537. _currentMsg = new EfemMessage
  538. {
  539. Port = mod,
  540. Operation = EfemOperation.CarrierId,
  541. Head = EfemMessage.MsgHead.SET,
  542. Parameters = new List<string> { Constant.ModuleString[mod], tagData }
  543. };
  544. _status = RState.Running;
  545. return _socket.Write(_currentMsg.ToString());
  546. }
  547. public override bool Dock(ModuleName mod)
  548. {
  549. if (!CheckEfemStatus())
  550. return false;
  551. _currentMsg = new EfemMessage
  552. {
  553. Port = mod,
  554. Operation = EfemOperation.Dock,
  555. Head = EfemMessage.MsgHead.MOV,
  556. Parameters = new List<string> { Constant.ModuleString[mod] }
  557. };
  558. _status = RState.Running;
  559. return _socket.Write(_currentMsg.ToString());
  560. }
  561. public override bool Undock(ModuleName mod)
  562. {
  563. if (!CheckEfemStatus())
  564. return false;
  565. _currentMsg = new EfemMessage
  566. {
  567. Port = mod,
  568. Operation = EfemOperation.Undock,
  569. Head = EfemMessage.MsgHead.MOV,
  570. Parameters = new List<string> { Constant.ModuleString[mod] }
  571. };
  572. _status = RState.Running;
  573. return _socket.Write(_currentMsg.ToString());
  574. }
  575. public override bool Clamp(ModuleName mod, bool isUnloadClamp)
  576. {
  577. if (!CheckEfemStatus())
  578. return false;
  579. _currentMsg = new EfemMessage
  580. {
  581. Port = mod,
  582. Operation = EfemOperation.Clamp,
  583. Head = EfemMessage.MsgHead.MOV,
  584. Parameters = new List<string> { Constant.ModuleString[mod] }
  585. };
  586. _status = RState.Running;
  587. _bIsUnloadClamp = isUnloadClamp;
  588. return _socket.Write(_currentMsg.ToString());
  589. }
  590. public override bool Unclamp(ModuleName mod)
  591. {
  592. if (!CheckEfemStatus())
  593. return false;
  594. _currentMsg = new EfemMessage
  595. {
  596. Port = mod,
  597. Operation = EfemOperation.Unclamp,
  598. Head = EfemMessage.MsgHead.MOV,
  599. Parameters = new List<string> { Constant.ModuleString[mod] }
  600. };
  601. _status = RState.Running;
  602. return _socket.Write(_currentMsg.ToString());
  603. }
  604. public override bool SetThickness(ModuleName mod, string thickness)
  605. {
  606. if (!CheckEfemStatus())
  607. return false;
  608. _currentMsg = new EfemMessage
  609. {
  610. Port = mod,
  611. Operation = EfemOperation.SetThickness,
  612. Head = EfemMessage.MsgHead.SET,
  613. Parameters = new List<string> { Constant.ModuleString[mod], thickness.ToUpper() }
  614. };
  615. _status = RState.Running;
  616. return _socket.Write(_currentMsg.ToString());
  617. }
  618. public override void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target)
  619. {
  620. blockingCollection.Add(new RobotAnimationData(action, hand, target));
  621. }
  622. private void OnReceiveMessage(string RevMsg)
  623. {
  624. string[] msgs = RevMsg.Split('\r');
  625. foreach (var msg in msgs)
  626. {
  627. if (string.IsNullOrWhiteSpace(msg)) continue;
  628. EfemMessage rec_msg = msg.ToMessage();
  629. switch (rec_msg.Head)
  630. {
  631. case EfemMessage.MsgHead.ACK:
  632. if (msg.Contains("ERROR"))
  633. {
  634. _revMsg = rec_msg;
  635. }
  636. break;
  637. case EfemMessage.MsgHead.INF:
  638. // 收到INF之后发送ACK确认
  639. string strACK = rec_msg.RawString.Replace("INF", "ACK");
  640. SendBack(strACK);
  641. EfemMessage ack_msg = strACK.ToMessage();
  642. ack_msg.Direct = MsgDirection.To;
  643. _revMsg = rec_msg;
  644. OnCommandUpdated(rec_msg);
  645. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot);
  646. break;
  647. case EfemMessage.MsgHead.EVT:
  648. OnEventUpdated(new EfemEventArgs
  649. {
  650. EvtStr = rec_msg.ToParamString(),
  651. Module = rec_msg.Port,
  652. CommandType = rec_msg.Operation,
  653. DataList = rec_msg.Data
  654. });
  655. if (rec_msg.Operation == EfemOperation.Home)
  656. {
  657. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  658. }
  659. break;
  660. case EfemMessage.MsgHead.NAK:
  661. case EfemMessage.MsgHead.CAN:
  662. case EfemMessage.MsgHead.ABS:
  663. OnErrorOccurred(rec_msg);
  664. break;
  665. }
  666. }
  667. }
  668. private void OnErrorHappen(ErrorEventArgs args)
  669. {
  670. _status = RState.Failed;
  671. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  672. }
  673. private void OnErrorOccurred(EfemMessage message)
  674. {
  675. string description = string.Empty;
  676. switch (message.Head)
  677. {
  678. case EfemMessage.MsgHead.NAK:
  679. description = Constant.FactorString[message.Factor];
  680. break;
  681. case EfemMessage.MsgHead.CAN:
  682. description = Constant.FactorString.ContainsKey(message.Factor) ? Constant.FactorString[message.Factor] : message.Factor;
  683. break;
  684. case EfemMessage.MsgHead.ABS:
  685. description = $"{message.Data[0]}, {message.Data[1]}";
  686. break;
  687. }
  688. _status = RState.Failed;
  689. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  690. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"{description}, [{message.Data[0]}], [{message.Factor}]");
  691. }
  692. private void OnEventUpdated(EfemEventArgs eArg)
  693. {
  694. switch (eArg.CommandType)
  695. {
  696. case EfemOperation.SigStatus:
  697. // EVT:SIGSTAT/Parameter/DATA1/DATA2;
  698. string sParam = eArg.DataList[0]; // "SYSTEM" or "Pn"
  699. // DATA1 & DATA2
  700. int nData1 = Convert.ToInt32(eArg.DataList[1], 16);
  701. int nData2 = Convert.ToInt32(eArg.DataList[2], 16);
  702. BitArray baData1 = new BitArray(new int[] { nData1 });
  703. BitArray baData2 = new BitArray(new int[] { nData2 });
  704. if (0 == string.Compare(sParam, Constant.SYS, true))
  705. {
  706. // EVT:SIGSTAT/System/00000000/00000004;
  707. // DATA1
  708. // Post warning and alarm
  709. if (!baData1[0]) // Bit[0] ON=Normal, OFF=Abnormal
  710. {
  711. //EV.Notify(EFEMVacuumPressureError);
  712. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM System vacuum source pressure low");
  713. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  714. }
  715. if (!baData1[1]) // Bit[1] ON=Normal, OFF=Abnormal
  716. {
  717. //EV.Notify(EFEMIonizerAlarm);
  718. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM Ionizer compressed air error");
  719. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  720. }
  721. if (!baData1[2]) // Bit[2] ON=Normal, OFF=Abnormal
  722. {
  723. //EV.Notify(EFEMCDAError);
  724. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM System compressed air pressure low");
  725. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  726. }
  727. if (!baData1[4]) // Bit[4] ON=Normal, OFF=Abnormal
  728. {
  729. //EV.Notify(EFEMFlowGaugeSensorError);
  730. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM Flow gauge sensor error");
  731. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  732. }
  733. if (!baData1[5]) // Bit[5] ON=Normal, OFF=Abnormal
  734. {
  735. //EV.Notify(EFEMLeakageAlarm);
  736. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM Leakage alarm");
  737. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  738. }
  739. if (!baData1[10]) // Bit[10] ON=Normal, OFF=Abnormal
  740. {
  741. //EV.Notify(EFEMIonizerAlarm);
  742. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM Ionizer alarm");
  743. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  744. }
  745. if (!baData1[11]) // Bit[11] ON=Normal, OFF=Abnormal
  746. {
  747. //EV.Notify(EFEMFFUAlarm);
  748. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "FFU alarm");
  749. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  750. }
  751. if (!baData1[13]) // Bit[13] ON=RUN, OFF=Maintain
  752. {
  753. //EV.Notify(EFEMOffline);
  754. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM switch to Maintain mode, HomeAll to recover");
  755. }
  756. // DATA2
  757. _signalT.ChangeLightStatus(LightType.RED, baData2[0] ? LightStatus.ON : baData2[5] ? LightStatus.BLINK : LightStatus.OFF);
  758. _signalT.ChangeLightStatus(LightType.GREEN, baData2[1] ? LightStatus.ON : baData2[6] ? LightStatus.BLINK : LightStatus.OFF);
  759. _signalT.ChangeLightStatus(LightType.YELLOW, baData2[2] ? LightStatus.ON : baData2[7] ? LightStatus.BLINK : LightStatus.OFF);
  760. _signalT.ChangeLightStatus(LightType.BLUE, baData2[3] ? LightStatus.ON : baData2[8] ? LightStatus.BLINK : LightStatus.OFF);
  761. _signalT.ChangeLightStatus(LightType.WHITE, baData2[4] ? LightStatus.ON : baData2[9] ? LightStatus.BLINK : LightStatus.OFF);
  762. _signalT.ChangeLightStatus(LightType.BUZZER1, baData2[10] ? LightStatus.ON : LightStatus.OFF);
  763. /* EFEM 程序中目前没有实现
  764. _RobotErr.CLK = baData2[27]; // bit 27
  765. bool bArmNotExtendLLA = baData2[30]; // bit 30
  766. bool bArmNotExtendLLB = baData2[31]; // bit 31
  767. */
  768. } // system event
  769. else
  770. {
  771. _LPMs[eArg.Module - ModuleName.LP1].HandleEvent(eArg);
  772. } // FOUP EVENT
  773. break;
  774. case EfemOperation.GetWaferInfo:
  775. _LPMs[eArg.Module - ModuleName.LP1].HandleEvent(eArg);
  776. break;
  777. default:
  778. break;
  779. }
  780. }
  781. private void OnCommandUpdated(EfemMessage message)
  782. {
  783. if (message.Operation != EfemOperation.Ready)
  784. {
  785. if (_currentMsg.Operation != message.Operation && (_backroundMsg == null || _backroundMsg.Operation != message.Operation))
  786. {
  787. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EfemRobot, $"OnCommandUpdated() unexpected return: {message.Operation}, expect: {_currentMsg.Operation}");
  788. return;
  789. }
  790. }
  791. switch (message.Operation)
  792. {
  793. case EfemOperation.ClearError:
  794. case EfemOperation.Align:
  795. case EfemOperation.Map:
  796. case EfemOperation.Pick:
  797. case EfemOperation.Place:
  798. case EfemOperation.Extend:
  799. case EfemOperation.Goto:
  800. case EfemOperation.Orgsh:
  801. case EfemOperation.EmsStop:
  802. case EfemOperation.Light:
  803. _status = RState.End;
  804. break;
  805. case EfemOperation.StateTrack:
  806. {
  807. _waferPresence = message.Data.Count >= 1 ? message.Data.First() : string.Empty;
  808. _IsHomed = true;
  809. _status = RState.End;
  810. }
  811. break;
  812. case EfemOperation.Home:
  813. {
  814. if (_currentMsg.Port == ModuleName.EFEM)
  815. {
  816. _LPMs[0].OnHomed();
  817. _LPMs[1].OnHomed();
  818. _LPMs[2].OnHomed();
  819. }
  820. else if (ModuleHelper.IsLoadPort(_currentMsg.Port))
  821. {
  822. _LPMs[_currentMsg.Port - ModuleName.LP1].OnHomed();
  823. }
  824. _status = RState.End;
  825. }
  826. break;
  827. case EfemOperation.Load:
  828. {
  829. _LPMs[message.Port - ModuleName.LP1].OnLoaded();
  830. _status = RState.End;
  831. }
  832. break;
  833. case EfemOperation.Unload:
  834. {
  835. _LPMs[message.Port - ModuleName.LP1].OnUnloaded();
  836. _status = RState.End;
  837. }
  838. break;
  839. case EfemOperation.CarrierId:
  840. {
  841. if (message.Head == EfemMessage.MsgHead.GET)
  842. {
  843. _LPMs[message.Port - ModuleName.LP1].OnCarrierIDRead(message.Data.First());
  844. }
  845. else
  846. {
  847. _LPMs[message.Port - ModuleName.LP1].OnCarrierIDWrite(message.Data.First());
  848. }
  849. _status = RState.End;
  850. }
  851. break;
  852. case EfemOperation.Clamp:
  853. {
  854. _LPMs[message.Port - ModuleName.LP1].OnClamped(_bIsUnloadClamp);
  855. _status = RState.End;
  856. }
  857. break;
  858. case EfemOperation.Unclamp:
  859. {
  860. _LPMs[message.Port - ModuleName.LP1].OnUnclamped();
  861. _status = RState.End;
  862. }
  863. break;
  864. case EfemOperation.Grip:
  865. {
  866. if (_currentMsg.Parameters[1] == "ARM2")
  867. {
  868. GripStateBlade1 = _currentMsg.Parameters[0];
  869. }
  870. else
  871. {
  872. GripStateBlade2 = _currentMsg.Parameters[0];
  873. }
  874. _status = RState.End;
  875. }
  876. break;
  877. case EfemOperation.Ready:
  878. {
  879. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
  880. }
  881. break;
  882. case EfemOperation.Lift:
  883. {
  884. if (_currentMsg.Parameters[1] == "UP")
  885. {
  886. _LiftIsUp = true;
  887. _LiftIsDown = false;
  888. }
  889. else if (_currentMsg.Parameters[1] == "DOWN")
  890. {
  891. _LiftIsUp = false;
  892. _LiftIsDown = true;
  893. }
  894. _status = RState.End;
  895. }
  896. break;
  897. }
  898. }
  899. void SendBack(string data)
  900. {
  901. _socket.Write(data + '\r');
  902. }
  903. }
  904. }