JetEfem.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  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. //2024/09/15,添加unknow状态,解决天车主发inf信号,软件报警
  630. if (rec_msg.Operation == EfemOperation.UnKnow)
  631. {
  632. return;
  633. }
  634. switch (rec_msg.Head)
  635. {
  636. case EfemMessage.MsgHead.ACK:
  637. if (msg.Contains("ERROR"))
  638. {
  639. _revMsg = rec_msg;
  640. }
  641. break;
  642. case EfemMessage.MsgHead.INF:
  643. // 收到INF之后发送ACK确认
  644. string strACK = rec_msg.RawString.Replace("INF", "ACK");
  645. SendBack(strACK);
  646. EfemMessage ack_msg = strACK.ToMessage();
  647. ack_msg.Direct = MsgDirection.To;
  648. _revMsg = rec_msg;
  649. OnCommandUpdated(rec_msg);
  650. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot);
  651. break;
  652. case EfemMessage.MsgHead.EVT:
  653. OnEventUpdated(new EfemEventArgs
  654. {
  655. EvtStr = rec_msg.ToParamString(),
  656. Module = rec_msg.Port,
  657. CommandType = rec_msg.Operation,
  658. DataList = rec_msg.Data
  659. });
  660. if (rec_msg.Operation == EfemOperation.Home)
  661. {
  662. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  663. }
  664. break;
  665. case EfemMessage.MsgHead.NAK:
  666. case EfemMessage.MsgHead.CAN:
  667. case EfemMessage.MsgHead.ABS:
  668. OnErrorOccurred(rec_msg);
  669. break;
  670. }
  671. }
  672. }
  673. private void OnErrorHappen(ErrorEventArgs args)
  674. {
  675. _status = RState.Failed;
  676. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  677. }
  678. private void OnErrorOccurred(EfemMessage message)
  679. {
  680. string description = string.Empty;
  681. switch (message.Head)
  682. {
  683. case EfemMessage.MsgHead.NAK:
  684. description = Constant.FactorString[message.Factor];
  685. break;
  686. case EfemMessage.MsgHead.CAN:
  687. description = Constant.FactorString.ContainsKey(message.Factor) ? Constant.FactorString[message.Factor] : message.Factor;
  688. break;
  689. case EfemMessage.MsgHead.ABS:
  690. description = $"{message.Data[0]}, {message.Data[1]}";
  691. break;
  692. }
  693. _status = RState.Failed;
  694. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  695. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"{description}, [{message.Data[0]}], [{message.Factor}]");
  696. }
  697. private void OnEventUpdated(EfemEventArgs eArg)
  698. {
  699. switch (eArg.CommandType)
  700. {
  701. case EfemOperation.SigStatus:
  702. // EVT:SIGSTAT/Parameter/DATA1/DATA2;
  703. string sParam = eArg.DataList[0]; // "SYSTEM" or "Pn"
  704. // DATA1 & DATA2
  705. int nData1 = Convert.ToInt32(eArg.DataList[1], 16);
  706. int nData2 = Convert.ToInt32(eArg.DataList[2], 16);
  707. BitArray baData1 = new BitArray(new int[] { nData1 });
  708. BitArray baData2 = new BitArray(new int[] { nData2 });
  709. if (0 == string.Compare(sParam, Constant.SYS, true))
  710. {
  711. // EVT:SIGSTAT/System/00000000/00000004;
  712. // DATA1
  713. // Post warning and alarm
  714. if (!baData1[0]) // Bit[0] ON=Normal, OFF=Abnormal
  715. {
  716. //EV.Notify(EFEMVacuumPressureError);
  717. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "System Sensor Vacuum/Air Pressure for Robot1");
  718. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  719. }
  720. if (!baData1[1]) // Bit[1] ON=Normal, OFF=Abnormal
  721. {
  722. //EV.Notify(EFEMIonizerAlarm);
  723. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "System Sensor Vacuum Error For LoadPort");
  724. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  725. }
  726. if (!baData1[2]) // Bit[2] ON=Normal, OFF=Abnormal
  727. {
  728. //EV.Notify(EFEMCDAError);
  729. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "System Sensor Air Pressure for lonizor Abnormal");
  730. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  731. }
  732. if (!baData1[3]) // Bit[3] ON=Normal, OFF=Abnormal
  733. {
  734. //EV.Notify(EFEMCDAError);
  735. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "System Sensor Air Pressure for Loadport Abnormal");
  736. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  737. }
  738. if (!baData1[4]) // Bit[4] ON=Normal, OFF=Abnormal
  739. {
  740. //EV.Notify(EFEMFlowGaugeSensorError);
  741. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Differential pressure sensor setting 1 Abnormal");
  742. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  743. }
  744. if (!baData1[5]) // Bit[5] ON=Normal, OFF=Abnormal
  745. {
  746. //EV.Notify(EFEMLeakageAlarm);
  747. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Differential pressure sensor setting 2 Abnormal");
  748. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  749. }
  750. if (!baData1[6]) // Bit[6] ON=Normal, OFF=Abnormal
  751. {
  752. //EV.Notify(EFEMLeakageAlarm);
  753. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM FFU alarm");
  754. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  755. }
  756. if (!baData1[7]) // Bit[7] ON=Normal, OFF=Abnormal
  757. {
  758. //EV.Notify(EFEMIonizerAlarm);
  759. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM Ionizer alarm");
  760. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  761. }
  762. if (!baData1[8]) // Bit[13] ON=RUN, OFF=Maintain
  763. {
  764. //EV.Notify(EFEMOffline);
  765. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "EFEM switch to Maintain mode, HomeAll to recover");
  766. }
  767. if (!baData1[9]) // Bit[9] ON=RUN, OFF=Maintain
  768. {
  769. //EV.Notify(EFEMOffline);
  770. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Drive power Abnormal");
  771. }
  772. if (!baData1[11]) // Bit[11] ON=Normal, OFF=Abnormal
  773. {
  774. //EV.Notify(EFEMFFUAlarm);
  775. if (SC.GetValue<bool>("EFEM.LightCurtainAlarmEnable") == true)
  776. {
  777. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "Light Curtain Abnormal");
  778. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  779. }
  780. else
  781. {
  782. LOG.Write(eEvent.WARN_EFEM_COMMON_WARN, ModuleName.EFEM, "Light Curtain Abnormal");
  783. }
  784. }
  785. if (!baData1[12]) // Bit[12] ON=Normal, OFF=Abnormal
  786. {
  787. //EV.Notify(EFEMFFUAlarm);
  788. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "System Sensor Vacuum/Air Pressure for PreAligner Abnormal");
  789. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  790. }
  791. //if (!baData1[13]) // Bit[13] ON=Normal, OFF=Abnormal
  792. //{
  793. // //EV.Notify(EFEMFFUAlarm);
  794. // LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, "System Sensor Vacuum/Air Pressure for PreAligner2 Abnormal");
  795. // Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  796. //}
  797. // DATA2
  798. _signalT.ChangeLightStatus(LightType.RED, baData2[0] ? LightStatus.ON : baData2[5] ? LightStatus.BLINK : LightStatus.OFF);
  799. _signalT.ChangeLightStatus(LightType.GREEN, baData2[1] ? LightStatus.ON : baData2[6] ? LightStatus.BLINK : LightStatus.OFF);
  800. _signalT.ChangeLightStatus(LightType.YELLOW, baData2[2] ? LightStatus.ON : baData2[7] ? LightStatus.BLINK : LightStatus.OFF);
  801. _signalT.ChangeLightStatus(LightType.BLUE, baData2[3] ? LightStatus.ON : baData2[8] ? LightStatus.BLINK : LightStatus.OFF);
  802. _signalT.ChangeLightStatus(LightType.WHITE, baData2[4] ? LightStatus.ON : baData2[9] ? LightStatus.BLINK : LightStatus.OFF);
  803. _signalT.ChangeLightStatus(LightType.BUZZER1, baData2[10] ? LightStatus.ON : LightStatus.OFF);
  804. /* EFEM 程序中目前没有实现
  805. _RobotErr.CLK = baData2[27]; // bit 27
  806. bool bArmNotExtendLLA = baData2[30]; // bit 30
  807. bool bArmNotExtendLLB = baData2[31]; // bit 31
  808. */
  809. } // system event
  810. else
  811. {
  812. _LPMs[eArg.Module - ModuleName.LP1].HandleEvent(eArg);
  813. } // FOUP EVENT
  814. break;
  815. case EfemOperation.GetWaferInfo:
  816. _LPMs[eArg.Module - ModuleName.LP1].HandleEvent(eArg);
  817. break;
  818. default:
  819. break;
  820. }
  821. }
  822. private void OnCommandUpdated(EfemMessage message)
  823. {
  824. if (message.Operation != EfemOperation.Ready)
  825. {
  826. if (_currentMsg.Operation != message.Operation && (_backroundMsg == null || _backroundMsg.Operation != message.Operation))
  827. {
  828. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EfemRobot, $"OnCommandUpdated() unexpected return: {message.Operation}, expect: {_currentMsg.Operation}");
  829. return;
  830. }
  831. }
  832. switch (message.Operation)
  833. {
  834. case EfemOperation.ClearError:
  835. case EfemOperation.Align:
  836. case EfemOperation.Map:
  837. case EfemOperation.Pick:
  838. case EfemOperation.Place:
  839. case EfemOperation.Extend:
  840. case EfemOperation.Goto:
  841. case EfemOperation.Orgsh:
  842. case EfemOperation.EmsStop:
  843. case EfemOperation.Light:
  844. _status = RState.End;
  845. break;
  846. case EfemOperation.StateTrack:
  847. {
  848. _waferPresence = message.Data.Count >= 1 ? message.Data.First() : string.Empty;
  849. _IsHomed = true;
  850. _status = RState.End;
  851. }
  852. break;
  853. case EfemOperation.Home:
  854. {
  855. if (_currentMsg.Port == ModuleName.EFEM)
  856. {
  857. _LPMs[0].OnHomed();
  858. _LPMs[1].OnHomed();
  859. _LPMs[2].OnHomed();
  860. }
  861. else if (ModuleHelper.IsLoadPort(_currentMsg.Port))
  862. {
  863. _LPMs[_currentMsg.Port - ModuleName.LP1].OnHomed();
  864. }
  865. _status = RState.End;
  866. }
  867. break;
  868. case EfemOperation.Load:
  869. {
  870. _LPMs[message.Port - ModuleName.LP1].OnLoaded();
  871. _status = RState.End;
  872. }
  873. break;
  874. case EfemOperation.Unload:
  875. {
  876. _LPMs[message.Port - ModuleName.LP1].OnUnloaded();
  877. _status = RState.End;
  878. }
  879. break;
  880. case EfemOperation.CarrierId:
  881. {
  882. //if (message.Head == EfemMessage.MsgHead.GET)
  883. //{
  884. _LPMs[message.Port - ModuleName.LP1].OnCarrierIDRead(message.Data.First());
  885. //}
  886. //else
  887. //{
  888. // _LPMs[message.Port - ModuleName.LP1].OnCarrierIDWrite(message.Data.First());
  889. //}
  890. _status = RState.End;
  891. }
  892. break;
  893. case EfemOperation.Clamp:
  894. {
  895. _LPMs[message.Port - ModuleName.LP1].OnClamped(_bIsUnloadClamp);
  896. _status = RState.End;
  897. }
  898. break;
  899. case EfemOperation.Unclamp:
  900. {
  901. _LPMs[message.Port - ModuleName.LP1].OnUnclamped();
  902. _status = RState.End;
  903. }
  904. break;
  905. case EfemOperation.Grip:
  906. {
  907. if (_currentMsg.Parameters[1] == "ARM2")
  908. {
  909. GripStateBlade1 = _currentMsg.Parameters[0];
  910. }
  911. else
  912. {
  913. GripStateBlade2 = _currentMsg.Parameters[0];
  914. }
  915. _status = RState.End;
  916. }
  917. break;
  918. case EfemOperation.Ready:
  919. {
  920. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
  921. }
  922. break;
  923. case EfemOperation.Lift:
  924. {
  925. if (_currentMsg.Parameters[1] == "UP")
  926. {
  927. _LiftIsUp = true;
  928. _LiftIsDown = false;
  929. }
  930. else if (_currentMsg.Parameters[1] == "DOWN")
  931. {
  932. _LiftIsUp = false;
  933. _LiftIsDown = true;
  934. }
  935. _status = RState.End;
  936. }
  937. break;
  938. }
  939. }
  940. void SendBack(string data)
  941. {
  942. _socket.Write(data + '\r');
  943. }
  944. }
  945. }