JetEfem.cs 36 KB

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