SunWayRobot.cs 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7. using CyberX8_Core;
  8. using CyberX8_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 CyberX8_RT.Devices.YASKAWA;
  19. using System.Collections.Concurrent;
  20. using System.Diagnostics;
  21. using System.Data.SqlTypes;
  22. using System.Windows.Media.Media3D;
  23. using System.ComponentModel;
  24. using MECF.Framework.Common.Beckhoff.Station;
  25. using System.Runtime.Remoting.Contexts;
  26. using System.Windows.Markup;
  27. using CyberX8_RT.Modules.LPs;
  28. using MECF.Framework.Common.ToolLayout;
  29. namespace CyberX8_RT.Devices.EFEM
  30. {
  31. public class SunWayRobot : EfemBase
  32. {
  33. #region 常量
  34. private const string NONE = "None";
  35. #endregion
  36. private RState _status;
  37. private bool _IsHomed;
  38. private bool _bIsUnloadClamp;
  39. private RobotMoveInfo _robotMoveInfo = new RobotMoveInfo();
  40. private readonly SignalTower _signalT = new SignalTower();
  41. private readonly AsyncSocket _socket;
  42. private EfemMessage _currentMessage;
  43. private string _error;
  44. private bool _LiftIsUp = false;
  45. private bool _LiftIsDown = false;
  46. private R_TRIG _busyTrig = new R_TRIG();
  47. private Stopwatch _busyWatch = new Stopwatch();
  48. private Dictionary<string, int> _moduleStationNumberDictionary = new Dictionary<string, int>();
  49. private Dictionary<Hand, string> _armString = new Dictionary<Hand, string>
  50. {
  51. [Hand.Blade1] = "A",
  52. [Hand.Blade2] = "B"
  53. };
  54. public override RState Status
  55. {
  56. get
  57. {
  58. _busyTrig.CLK = _status == RState.Running;
  59. if (_busyTrig.Q)
  60. {
  61. _busyWatch.Restart();
  62. }
  63. else if (_busyTrig.M)
  64. {
  65. int timeOut = 5000;
  66. if (
  67. _currentMessage.Operation == EfemOperation.Home ||
  68. _currentMessage.Operation == EfemOperation.Map ||
  69. _currentMessage.Operation == EfemOperation.Pick ||
  70. _currentMessage.Operation == EfemOperation.Place)
  71. {
  72. timeOut = 30000;
  73. }
  74. if (_busyWatch.ElapsedMilliseconds > timeOut)
  75. {
  76. _busyWatch.Stop();
  77. _status = RState.Timeout;
  78. }
  79. }
  80. return _status;
  81. }
  82. }
  83. public override bool IsHomed { get { return _IsHomed; } }
  84. public override RobotMoveInfo TMRobotMoveInfo { get { return _robotMoveInfo; } }
  85. public override bool LiftIsUp { get { return _LiftIsUp; } }
  86. public override bool LiftIsDown { get { return _LiftIsDown; } }
  87. private BlockingCollection<RobotAnimationData> blockingCollection = new BlockingCollection<RobotAnimationData>();
  88. private string _address = "";
  89. public SunWayRobot()
  90. {
  91. _socket = new AsyncSocket("","",DataType.Ascii,true);
  92. try
  93. {
  94. _address = SC.GetStringValue($"EFEM.IPAddress");
  95. _socket.Connect(_address);
  96. _socket.OnConnect += Socket_OnConnect;
  97. _socket.OnDataChanged += OnReceiveMessage;
  98. _socket.OnErrorHappened += OnErrorHappen;
  99. }
  100. catch(Exception ex)
  101. {
  102. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", ex.Message);
  103. }
  104. _status = RState.Init;
  105. _IsHomed = false;
  106. _busyTrig.RST = true;
  107. InitializeModuleStation(ModuleName.LP1);
  108. InitializeModuleStation(ModuleName.LP2);
  109. InitializeModuleStation(ModuleName.LP3);
  110. InitializeModuleStation(ModuleName.Dummy1);
  111. InitializeModuleStation(ModuleName.Dummy2);
  112. InitializeModuleStation(ModuleName.Aligner1);
  113. InitializeModuleStation(ModuleName.SRD1);
  114. InitializeModuleStation(ModuleName.SRD2);
  115. InitializeModuleStation(ModuleName.PUF1);
  116. CarrierManager.Instance.SubscribeLocation(ModuleName.LP1.ToString(), 1);
  117. CarrierManager.Instance.SubscribeLocation(ModuleName.LP2.ToString(), 1);
  118. CarrierManager.Instance.SubscribeLocation(ModuleName.LP3.ToString(), 1);
  119. WaferManager.Instance.SubscribeLocation(ModuleName.EfemRobot, 2);
  120. WaferManager.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  121. WaferManager.Instance.SubscribeLocation(ModuleName.LP1, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  122. WaferManager.Instance.SubscribeLocation(ModuleName.LP2, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  123. WaferManager.Instance.SubscribeLocation(ModuleName.LP3, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  124. Task.Run(() =>
  125. {
  126. foreach (var data in blockingCollection.GetConsumingEnumerable())
  127. {
  128. _robotMoveInfo.Action = data.Action;
  129. _robotMoveInfo.ArmTarget = data.Hand == Hand.Blade1 ? RobotArm.ArmA : (data.Hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
  130. _robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{data.Target}";
  131. System.Threading.Thread.Sleep(600);
  132. }
  133. });
  134. }
  135. /// <summary>
  136. /// 初始化Module Station
  137. /// </summary>
  138. /// <param name="module"></param>
  139. private void InitializeModuleStation(ModuleName module)
  140. {
  141. int cassete200Station = SC.GetValue<int>($"EFEM.{module}.Cassete200Station");
  142. _moduleStationNumberDictionary[$"{module}_200"] = cassete200Station;
  143. int cassete150Station = SC.GetValue<int>($"EFEM.{module}.Cassete150Station");
  144. _moduleStationNumberDictionary[$"{module}_150"] = cassete150Station;
  145. int cassete100Station = SC.GetValue<int>($"EFEM.{module}.Cassete100Station");
  146. _moduleStationNumberDictionary[$"{module}_100"]=cassete100Station;
  147. }
  148. private void Socket_OnConnect()
  149. {
  150. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
  151. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), $"connect {_address} success");
  152. }
  153. private void OnErrorHappen(ErrorEventArgs args)
  154. {
  155. _status = RState.Failed;
  156. if (_error != args.Reason)
  157. {
  158. _error = args.Reason;
  159. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"{Module} {_error}");
  160. }
  161. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  162. }
  163. public override void Monitor()
  164. {
  165. }
  166. public override void Terminate()
  167. {
  168. }
  169. public override void Reset()
  170. {
  171. _status = RState.End;
  172. _currentMessage = null;
  173. }
  174. public override void SetOnline(bool online)
  175. {
  176. }
  177. public override void SetOnline(ModuleName mod, bool online)
  178. {
  179. }
  180. public override void SetBusy(ModuleName mod, bool online)
  181. {
  182. _status = RState.Running;
  183. }
  184. public override bool HomeAll()
  185. {
  186. if (_status == RState.Running&&_currentMessage!=null)
  187. {
  188. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home All");
  189. return false;
  190. }
  191. //判断socket是否链接
  192. if (!_socket.IsConnected)
  193. {
  194. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  195. return false ;
  196. }
  197. _status = RState.Running;
  198. string data = "HOME ALL\r";
  199. _currentMessage =new EfemMessage(){
  200. Operation= EfemOperation.Home,
  201. Module=ModuleName.EFEM
  202. };
  203. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  204. return WriteCommand(data);
  205. }
  206. public override bool Home(ModuleName mod)
  207. {
  208. if (_status == RState.Running && _currentMessage!= null)
  209. {
  210. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home {mod}");
  211. return false;
  212. }
  213. if (mod != ModuleName.Aligner1&&mod!=ModuleName.EfemRobot)
  214. {
  215. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{mod} can not support home method");
  216. return false;
  217. }
  218. //判断socket是否链接
  219. if (!_socket.IsConnected)
  220. {
  221. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  222. return false;
  223. }
  224. if(mod == ModuleName.EfemRobot) SetRobotMovingInfo(RobotAction.Homing, Hand.Blade1, ModuleName.EfemRobot);
  225. _status = RState.Running;
  226. string cmd = "Home ALL\r";
  227. if (mod == ModuleName.Aligner1)
  228. {
  229. cmd = "ALIGNER HOME\r";
  230. }
  231. _currentMessage = new EfemMessage()
  232. {
  233. Operation = EfemOperation.Home,
  234. Module = ModuleName.Aligner1
  235. };
  236. return WriteCommand(cmd);
  237. }
  238. public override bool OriginalSearch(ModuleName mod)
  239. {
  240. return true;
  241. }
  242. public override bool CheckWaferPresence()
  243. {
  244. if (_status == RState.Running && _currentMessage != null)
  245. {
  246. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot check wafer");
  247. return false;
  248. }
  249. //判断socket是否链接
  250. if (!_socket.IsConnected)
  251. {
  252. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  253. return false;
  254. }
  255. if (!CheckEfemStatus())
  256. return false;
  257. _currentMessage = new EfemMessage()
  258. {
  259. Operation = EfemOperation.StateTrack,
  260. Module = ModuleName.EfemRobot
  261. };
  262. _status = RState.Running;
  263. string cmd = $"RQ LOAD {_armString[Hand.Blade1]}\r";
  264. return WriteCommand(cmd);
  265. }
  266. public override string GetWaferPresence()
  267. {
  268. return "";
  269. }
  270. public override bool Halt()
  271. {
  272. //判断socket是否链接
  273. if (!_socket.IsConnected)
  274. {
  275. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  276. return false;
  277. }
  278. _currentMessage = new EfemMessage()
  279. {
  280. Operation = EfemOperation.Abort,
  281. Module = ModuleName.EfemRobot
  282. };
  283. string cmd = "HALT\r";
  284. return WriteCommand(cmd);
  285. }
  286. public override bool ClearError()
  287. {
  288. return true;
  289. }
  290. public override bool CloseBuzzer()
  291. {
  292. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.TurnOffBuzzer]}");
  293. return false;
  294. }
  295. public override bool PickExtend(ModuleName chamber, int slot, Hand hand)
  296. {
  297. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  298. return false;
  299. }
  300. public override bool PickRetract(ModuleName chamber, int slot, Hand hand)
  301. {
  302. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  303. return false;
  304. }
  305. public override bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
  306. {
  307. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  308. return false;
  309. }
  310. public override bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
  311. {
  312. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  313. return false;
  314. }
  315. public override bool Pick(ModuleName station, int slot, Hand hand)
  316. {
  317. if (_status == RState.Running && _currentMessage != null)
  318. {
  319. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot pick");
  320. return false;
  321. }
  322. //判断socket是否链接
  323. if (!_socket.IsConnected)
  324. {
  325. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  326. return false;
  327. }
  328. //判断Loadport的门是否打开
  329. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  330. //{
  331. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  332. // return false;
  333. //}
  334. if (!CheckEfemStatus())
  335. return false;
  336. int waferSize = GetModuleSlotWaferSize(station,slot);
  337. if (waferSize == 0)
  338. {
  339. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Pick Action");
  340. return false;
  341. }
  342. string strModuleWaferSize = $"{station}_{waferSize}";
  343. if (!_moduleStationNumberDictionary.ContainsKey(strModuleWaferSize))
  344. {
  345. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s number is not exist, Cannot Execute Pick Action");
  346. return false;
  347. }
  348. int stationNumber= _moduleStationNumberDictionary[strModuleWaferSize];
  349. string cmd = $"PICK {stationNumber} SLOT {slot+1} ARM {_armString[hand]}\r";
  350. if(ModuleHelper.IsPUF(station)||ModuleHelper.IsAligner(station)||ModuleHelper.IsSRD(station))
  351. {
  352. cmd = $"PICK {stationNumber} SLOT 1 ARM {_armString[hand]}\r";
  353. }
  354. _currentMessage = new EfemMessage()
  355. {
  356. Operation=EfemOperation.Pick
  357. };
  358. _status = RState.Running;
  359. SetRobotMovingInfo(RobotAction.Picking, hand, station);
  360. return WriteCommand(cmd);
  361. }
  362. private Loadport GetLoadPort(ModuleName station)
  363. {
  364. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  365. return loadPortModule.LPDevice;
  366. }
  367. public override bool Place(ModuleName station, int slot, Hand hand)
  368. {
  369. if (_status == RState.Running && _currentMessage != null)
  370. {
  371. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot place");
  372. return false;
  373. }
  374. //判断socket是否链接
  375. if (!_socket.IsConnected)
  376. {
  377. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  378. return false;
  379. }
  380. //判断Loadport的门是否打开
  381. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  382. //{
  383. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  384. // return false;
  385. //}
  386. if (!CheckEfemStatus())
  387. return false;
  388. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, (int)hand);
  389. if (waferSize == 0)
  390. {
  391. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Place Action");
  392. return false;
  393. }
  394. string strModuleWaferSize = $"{station}_{waferSize}";
  395. _currentMessage = new EfemMessage()
  396. {
  397. Operation = EfemOperation.Place
  398. };
  399. _status = RState.Running;
  400. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  401. string cmd = $"PLACE {stationNumber} SLOT {slot+1} ARM {_armString[hand]}\r";
  402. if (ModuleHelper.IsPUF(station)||ModuleHelper.IsSRD(station))
  403. {
  404. cmd = $"PLACE {stationNumber} SLOT 1 ARM {_armString[hand]}\r";
  405. }
  406. if (ModuleHelper.IsAligner(station))
  407. {
  408. cmd = $"PLACE {stationNumber} PHOME\r";
  409. }
  410. SetRobotMovingInfo(RobotAction.Placing, hand, station);
  411. return WriteCommand(cmd);
  412. }
  413. public override bool Goto(ModuleName station, Hand hand, string updown = "UP")
  414. {
  415. if (_status == RState.Running && _currentMessage != null)
  416. {
  417. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto");
  418. return false;
  419. }
  420. if (!CheckEfemStatus())
  421. return false;
  422. //判断socket是否链接
  423. if (!_socket.IsConnected)
  424. {
  425. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  426. return false;
  427. }
  428. _currentMessage = new EfemMessage()
  429. {
  430. Operation = EfemOperation.Goto
  431. };
  432. int waferSize = GetModuleNameWaferSize(station);
  433. if (waferSize == 0)
  434. {
  435. return false;
  436. }
  437. string strModuleWaferSize = $"{station}_{waferSize}";
  438. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  439. string cmd = $"GOTO N {stationNumber} R EX Z {updown} ARM SLOT 1 {_armString[hand]}\r";
  440. _status = RState.Running;
  441. return WriteCommand(cmd);
  442. }
  443. public override bool Grip(Hand blade, bool isGrip)
  444. {
  445. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Grip]}");
  446. return false;
  447. }
  448. public override bool GotoMap(ModuleName mod,Hand hand,string extend="EX")
  449. {
  450. if (_status == RState.Running && _currentMessage != null)
  451. {
  452. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto map");
  453. return false;
  454. }
  455. //判断socket是否链接
  456. if (!_socket.IsConnected)
  457. {
  458. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  459. return false;
  460. }
  461. if (!CheckEfemStatus())
  462. return false;
  463. int waferSize = GetModuleNameWaferSize(mod);
  464. if (waferSize == 0)
  465. {
  466. return false;
  467. }
  468. string strModuleWaferSize = $"{mod}_{waferSize}";
  469. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  470. string cmd = $"GOTO N {stationNumber} MAP {extend} ARM {_armString[hand]}\r";
  471. _currentMessage = new EfemMessage()
  472. {
  473. Operation = EfemOperation.Goto,
  474. Module= mod
  475. };
  476. _status = RState.Running;
  477. return WriteCommand(cmd);
  478. }
  479. public override bool Map(ModuleName mod)
  480. {
  481. if (_status == RState.Running && _currentMessage != null)
  482. {
  483. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot map");
  484. return false;
  485. }
  486. //判断socket是否链接
  487. if (!_socket.IsConnected)
  488. {
  489. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  490. return false;
  491. }
  492. if (!CheckEfemStatus())
  493. return false;
  494. int waferSize = GetModuleNameWaferSize(mod);
  495. if (waferSize == 0)
  496. {
  497. return false;
  498. }
  499. string strModuleWaferSize = $"{mod}_{waferSize}";
  500. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  501. _currentMessage = new EfemMessage()
  502. {
  503. Operation = EfemOperation.Home,
  504. Module = mod
  505. };
  506. string cmd = $"MAP {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  507. _status = RState.Running;
  508. return WriteCommand(cmd);
  509. }
  510. public override bool RequestMapResult(ModuleName mod)
  511. {
  512. if (_status == RState.Running && _currentMessage != null)
  513. {
  514. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot request map");
  515. return false;
  516. }
  517. //判断socket是否链接
  518. if (!_socket.IsConnected)
  519. {
  520. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  521. return false;
  522. }
  523. if (!CheckEfemStatus())
  524. return false;
  525. int waferSize = GetModuleNameWaferSize(mod);
  526. if (waferSize == 0)
  527. {
  528. return false;
  529. }
  530. string strModuleWaferSize = $"{mod}_{waferSize}";
  531. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  532. _currentMessage = new EfemMessage()
  533. {
  534. Operation = EfemOperation.RequestMapResult,
  535. Module = mod
  536. };
  537. string cmd = $"RSR {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  538. _status = RState.Running;
  539. return WriteCommand(cmd);
  540. }
  541. public override bool Vacuum(ModuleName mod,bool VacuumState)
  542. {
  543. if (_status == RState.Running && _currentMessage != null)
  544. {
  545. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot vacuum");
  546. return false;
  547. }
  548. //判断socket是否链接
  549. if (!_socket.IsConnected)
  550. {
  551. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  552. return false;
  553. }
  554. _currentMessage = new EfemMessage()
  555. {
  556. Operation = EfemOperation.Vacuum,
  557. Module = mod
  558. };
  559. _status = RState.Running;
  560. string strVacuum = VacuumState ? "ON" : "OFF";
  561. string cmd = "";
  562. if (ModuleName.Aligner1 == mod)
  563. {
  564. cmd = $"ALIGNER VAC {strVacuum}\r";
  565. }
  566. else
  567. {
  568. cmd = $"VAC {strVacuum} ARM {_armString[Hand.Blade1]}\r";
  569. }
  570. return WriteCommand(cmd);
  571. }
  572. public override bool GetWaferSize(ModuleName mod)
  573. {
  574. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support GetWaferSize");
  575. return false;
  576. }
  577. public override bool SetWaferSize(ModuleName mod, int WaferSize)
  578. {
  579. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support SetWaferSize");
  580. return false;
  581. }
  582. public override bool SetPinUp(ModuleName mod)
  583. {
  584. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  585. return false;
  586. }
  587. public override bool SetPinDown(ModuleName mod)
  588. {
  589. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  590. return false;
  591. }
  592. public override bool SetAlignAngle(ModuleName mod, double angle)
  593. {
  594. if (_status == RState.Running && _currentMessage != null)
  595. {
  596. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Angle");
  597. return false;
  598. }
  599. if (!CheckEfemStatus())
  600. return false;
  601. //判断socket是否链接
  602. if (!_socket.IsConnected)
  603. {
  604. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  605. return false;
  606. }
  607. _currentMessage = new EfemMessage()
  608. {
  609. Operation = EfemOperation.Align,
  610. };
  611. string cmd = $"SET ALIGNER POSTPOS 1 POS {angle*1000}\r";
  612. _status = RState.Running;
  613. return WriteCommand(cmd);
  614. }
  615. public override bool SetRobotSpeed(ModuleName mod, int speed)
  616. {
  617. if (_status == RState.Running && _currentMessage != null)
  618. {
  619. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Speed");
  620. return false;
  621. }
  622. //判断socket是否链接
  623. if (!_socket.IsConnected)
  624. {
  625. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  626. return false;
  627. }
  628. _currentMessage = new EfemMessage()
  629. {
  630. Operation = EfemOperation.Speed
  631. };
  632. string cmd = $"SET ACTION SPEEDS {speed}\r";
  633. _status = RState.Running;
  634. return WriteCommand(cmd);
  635. }
  636. public override bool RobotPowerOn(ModuleName mod, bool Status)
  637. {
  638. if (_status == RState.Running && _currentMessage != null)
  639. {
  640. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot PowerOn");
  641. return false;
  642. }
  643. //判断socket是否链接
  644. if (!_socket.IsConnected)
  645. {
  646. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  647. return false;
  648. }
  649. string status = Status? "ON":"OFF";
  650. _currentMessage = new EfemMessage()
  651. {
  652. Operation = EfemOperation.PowerOn
  653. };
  654. string cmd = $"SET SERVOS {status}\r";
  655. _status = RState.Running;
  656. return WriteCommand(cmd);
  657. }
  658. public override bool Align(ModuleName mod, double angle, float delayTime, WaferSize size)
  659. {
  660. if (_status == RState.Running && _currentMessage != null)
  661. {
  662. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align");
  663. return false;
  664. }
  665. //判断socket是否链接
  666. if (!_socket.IsConnected)
  667. {
  668. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  669. return false;
  670. }
  671. if (!CheckEfemStatus())
  672. return false;
  673. _currentMessage = new EfemMessage()
  674. {
  675. Operation = EfemOperation.Align
  676. };
  677. _status = RState.Running;
  678. string cmd = "ALIGNER ALGN\r";
  679. return WriteCommand(cmd);
  680. }
  681. public override bool SetLamp(LightType light, LightStatus status)
  682. {
  683. return false;
  684. }
  685. public override bool Load(ModuleName mod)
  686. {
  687. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Load");
  688. return false;
  689. }
  690. public override bool Unload(ModuleName mod)
  691. {
  692. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unload");
  693. return false;
  694. }
  695. public override bool ReadCarrierId(ModuleName mod)
  696. {
  697. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support ReadCarrierId");
  698. return false;
  699. }
  700. public override bool WriteCarrierId(ModuleName mod, string id)
  701. {
  702. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support WriteCarrierId");
  703. return false;
  704. }
  705. public override bool ReadTagData(ModuleName mod)
  706. {
  707. return ReadCarrierId(mod);
  708. }
  709. public override bool WriteTagData(ModuleName mod, string tagData)
  710. {
  711. return WriteCarrierId(mod, tagData);
  712. }
  713. public override bool Dock(ModuleName mod)
  714. {
  715. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Dock");
  716. return false;
  717. }
  718. public override bool Undock(ModuleName mod)
  719. {
  720. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Undock");
  721. return false;
  722. }
  723. public override bool Clamp(ModuleName mod, bool isUnloadClamp)
  724. {
  725. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Clamp");
  726. return false;
  727. }
  728. public override bool Unclamp(ModuleName mod)
  729. {
  730. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unclamp");
  731. return false;
  732. }
  733. public override bool SetThickness(ModuleName mod, string thickness)
  734. {
  735. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.SetThickness]}");
  736. return false;
  737. }
  738. public override void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target)
  739. {
  740. blockingCollection.Add(new RobotAnimationData(action, hand, target));
  741. }
  742. private void OnReceiveMessage(string msg)
  743. {
  744. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), msg.Replace("\r",""));
  745. if (_currentMessage == null)
  746. {
  747. return;
  748. }
  749. if(msg.StartsWith("_ERR"))
  750. {
  751. string error = msg.Replace("_ERR", "").Trim();
  752. OnErrorOccurred(error);
  753. _currentMessage = null;
  754. return;
  755. }
  756. else if(msg.StartsWith("_RDY"))
  757. {
  758. _status = RState.End;
  759. switch (_currentMessage.Operation)
  760. {
  761. case EfemOperation.Home:
  762. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  763. break;
  764. case EfemOperation.Map:
  765. case EfemOperation.GotoMap:
  766. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  767. {
  768. GetLoadPort(_currentMessage.Module).OnMaped();
  769. }
  770. break;
  771. case EfemOperation.Pick:
  772. case EfemOperation.Place:
  773. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot);
  774. break;
  775. }
  776. }
  777. else
  778. {
  779. switch (_currentMessage.Operation)
  780. {
  781. case EfemOperation.StateTrack:
  782. DealStateTrack(msg);
  783. break;
  784. case EfemOperation.RequestMapResult:
  785. DealMapResult(msg);
  786. break;
  787. }
  788. _status = RState.End;
  789. _currentMessage = null;
  790. }
  791. }
  792. /// <summary>
  793. /// 处理StateTrack结果
  794. /// </summary>
  795. /// <param name="msg"></param>
  796. private void DealStateTrack(string msg)
  797. {
  798. if (msg.StartsWith("LOAD"))
  799. {
  800. string[] strAry = msg.Trim().Split(' ');
  801. if (strAry.Length >= 2)
  802. {
  803. bool hasWafer = strAry[2] == "ON" ? true : false;
  804. if (strAry[1] == _armString[Hand.Blade1])
  805. {
  806. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)&& hasWafer)
  807. {
  808. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 0, WaferStatus.Normal);
  809. }
  810. }
  811. else if (strAry[1] == _armString[Hand.Blade2])
  812. {
  813. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && hasWafer)
  814. {
  815. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 1, WaferStatus.Normal);
  816. }
  817. }
  818. }
  819. }
  820. }
  821. /// <summary>
  822. /// 处理Map结果
  823. /// </summary>
  824. /// <param name="msg"></param>
  825. private void DealMapResult(string msg)
  826. {
  827. if (_currentMessage.Operation != EfemOperation.RequestMapResult)
  828. {
  829. return;
  830. }
  831. if(!msg.StartsWith("MAP"))
  832. {
  833. return;
  834. }
  835. string[] sWaferInfo = msg.Split(new char[] { ' ', '\r', '\n' });
  836. if (sWaferInfo.Length <= 2)
  837. {
  838. return;
  839. }
  840. int slotMap = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
  841. WaferType waferType = WaferType.Production;
  842. if (ModuleHelper.IsDummy(_currentMessage.Module))
  843. {
  844. DummyCassetteItem item = DummyCasseteItemManager.Instance.GetDummyCassetteItem(_currentMessage.Module.ToString());
  845. if (item != null)
  846. {
  847. slotMap = item.MaxNumberOfSlots;
  848. }
  849. waferType = WaferType.Assit;
  850. }
  851. int waferSize = GetModuleNameWaferSize(_currentMessage.Module);
  852. //Map 结果(1 1 1 1 1 1 1 ...0)
  853. int startIndex = 1;
  854. int count = slotMap >= sWaferInfo.Length-startIndex? sWaferInfo.Length-startIndex : slotMap;
  855. bool result = true;
  856. for (int index = startIndex; index <= count; index++)
  857. {
  858. string strState = sWaferInfo[index];
  859. int waferState = 0;
  860. //合理的映射到内部支持的叠片/交叉片
  861. if (strState == "1") waferState = (int)WaferStatus.Normal;
  862. else if (strState == "2") waferState = (int)WaferStatus.Double;
  863. else if (strState == "3") waferState = (int)WaferStatus.Crossed;
  864. else if (strState == "5") waferState = (int)WaferStatus.Thin;
  865. else if(strState=="?") waferState=(int)WaferStatus.Unknown;
  866. WaferStatus st = (WaferStatus)waferState;
  867. if (st != WaferStatus.Empty)
  868. {
  869. WaferManager.Instance.CreateWafer(_currentMessage.Module, index-startIndex, st,(WaferSize)waferSize,waferType);
  870. if (st != WaferStatus.Normal)
  871. {
  872. result = false;
  873. }
  874. }
  875. else
  876. {
  877. WaferManager.Instance.DeleteWafer(_currentMessage.Module, index-startIndex);
  878. }
  879. }
  880. if (!result)
  881. {
  882. LOG.WriteLog(eEvent.ERROR_EFEM_ERROR_WAFER, Module.ToString(), $"{_currentMessage.Module} slot map failed {msg}");
  883. }
  884. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  885. {
  886. GetLoadPort(_currentMessage.Module).UpdateMapResult(result);
  887. }
  888. }
  889. private void OnErrorOccurred(string errorCode)
  890. {
  891. _status = RState.Failed;
  892. string description = errorCode;
  893. if (SumWayRobotErrorCode.ErrorCodeDescription.ContainsKey(errorCode))
  894. {
  895. description=SumWayRobotErrorCode.ErrorCodeDescription[errorCode];
  896. }
  897. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error, description);
  898. if (_currentMessage != null)
  899. {
  900. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"current operation {_currentMessage.Operation} failed,{description}");
  901. }
  902. _currentMessage=null;
  903. }
  904. private bool WriteCommand(string cmd)
  905. {
  906. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), cmd.Replace("\r", ""));
  907. return _socket.Write(cmd);
  908. }
  909. /// <summary>
  910. /// 获取模块Wafer尺寸
  911. /// </summary>
  912. /// <param name="moduleName"></param>
  913. /// <returns></returns>
  914. private int GetModuleNameWaferSize(ModuleName moduleName)
  915. {
  916. if (ModuleHelper.IsLoadPort(moduleName))
  917. {
  918. Loadport loadport = GetLoadPort(moduleName);
  919. if (!loadport.HasCassette)
  920. {
  921. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  922. return 0;
  923. }
  924. return (int)loadport.WaferSize;
  925. }
  926. else if (ModuleHelper.IsDummy(moduleName))
  927. {
  928. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(moduleName - ModuleName.Dummy1);
  929. if (!dummyDevice.HasCassette)
  930. {
  931. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  932. return 0;
  933. }
  934. return (int)dummyDevice.WaferSize;
  935. }
  936. return 0;
  937. }
  938. /// <summary>
  939. /// 获取模块尺寸
  940. /// </summary>
  941. /// <param name="moduleName"></param>
  942. /// <returns></returns>
  943. private int GetModuleSlotWaferSize(ModuleName moduleName,int slotNumber)
  944. {
  945. if(WaferManager.Instance.CheckHasWafer(moduleName,slotNumber))
  946. {
  947. WaferInfo waferInfo=WaferManager.Instance.GetWafer(moduleName, slotNumber);
  948. return (int)waferInfo.Size;
  949. }
  950. else
  951. {
  952. return 0;
  953. }
  954. }
  955. }
  956. }