SunWayRobot.cs 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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 PunkHPX8_Core;
  8. using PunkHPX8_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 PunkHPX8_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 PunkHPX8_RT.Modules.LPs;
  28. using MECF.Framework.Common.ToolLayout;
  29. namespace PunkHPX8_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] = "B",
  52. [Hand.Blade2] = "A"
  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. private bool _isResumeRDYReceived = false;
  90. private bool _isPauseRDYReceived = false;
  91. private bool _isActionRDYReceived = false;
  92. private bool _isInPauseStatus = false;
  93. public override bool IsResumeRDYReceived { get { return _isResumeRDYReceived; } }
  94. public override bool IsPauseRDYReceived { get { return _isPauseRDYReceived; } }
  95. public override bool IsActionRDYReceived { get { return _isActionRDYReceived; } }
  96. public override bool IsInPauseStatus { get { return _isInPauseStatus; } }
  97. public SunWayRobot()
  98. {
  99. _socket = new AsyncSocket("","",DataType.Ascii,true);
  100. try
  101. {
  102. _address = SC.GetStringValue($"EFEM.IPAddress");
  103. _socket.Connect(_address);
  104. _socket.OnConnect += Socket_OnConnect;
  105. _socket.OnDataChanged += OnReceiveMessage;
  106. _socket.OnErrorHappened += OnErrorHappen;
  107. }
  108. catch(Exception ex)
  109. {
  110. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", ex.Message);
  111. }
  112. _status = RState.End;
  113. _IsHomed = false;
  114. _busyTrig.RST = true;
  115. InitializeModuleStation(ModuleName.LP1);
  116. InitializeModuleStation(ModuleName.LP2);
  117. InitializeModuleStation(ModuleName.LP3);
  118. InitializeModuleStation(ModuleName.Dummy1);
  119. InitializeModuleStation(ModuleName.Dummy2);
  120. InitializeModuleStation(ModuleName.Aligner1);
  121. InitializeModuleStation(ModuleName.SRD1);
  122. InitializeModuleStation(ModuleName.SRD2);
  123. InitializeVPWModuleStation(ModuleName.VPW1);
  124. InitializeVPWModuleStation(ModuleName.VPW2);
  125. InitializePlatingCellModuleStation(ModuleName.PlatingCell1);
  126. InitializePlatingCellModuleStation(ModuleName.PlatingCell2);
  127. InitializePlatingCellModuleStation(ModuleName.PlatingCell3);
  128. InitializePlatingCellModuleStation(ModuleName.PlatingCell4);
  129. CarrierManager.Instance.SubscribeLocation(ModuleName.LP1.ToString(), 1);
  130. CarrierManager.Instance.SubscribeLocation(ModuleName.LP2.ToString(), 1);
  131. CarrierManager.Instance.SubscribeLocation(ModuleName.LP3.ToString(), 1);
  132. WaferManager.Instance.SubscribeLocation(ModuleName.EfemRobot, 2);
  133. WaferManager.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  134. WaferManager.Instance.SubscribeLocation(ModuleName.LP1, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  135. WaferManager.Instance.SubscribeLocation(ModuleName.LP2, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  136. WaferManager.Instance.SubscribeLocation(ModuleName.LP3, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  137. Task.Run(() =>
  138. {
  139. foreach (var data in blockingCollection.GetConsumingEnumerable())
  140. {
  141. _robotMoveInfo.Action = data.Action;
  142. _robotMoveInfo.ArmTarget = data.Hand == Hand.Blade1 ? RobotArm.ArmA : (data.Hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
  143. _robotMoveInfo.BladeDirection = data.Flip;
  144. _robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{data.Target}.{data.Flip}";
  145. System.Threading.Thread.Sleep(600);
  146. }
  147. });
  148. }
  149. /// <summary>
  150. /// 初始化Module Station
  151. /// </summary>
  152. /// <param name="module"></param>
  153. private void InitializeModuleStation(ModuleName module)
  154. {
  155. int cassete200Station = SC.GetValue<int>($"EFEM.{module}.Cassete200Station_Blade1_Upper");
  156. _moduleStationNumberDictionary[$"{module}_200_Blade1_Upper"] = cassete200Station;
  157. int cassete150Station = SC.GetValue<int>($"EFEM.{module}.Cassete150Station_Blade1_Upper");
  158. _moduleStationNumberDictionary[$"{module}_150_Blade1_Upper"] = cassete150Station;
  159. int cassete100Station = SC.GetValue<int>($"EFEM.{module}.Cassete100Station_Blade1_Upper");
  160. _moduleStationNumberDictionary[$"{module}_100_Blade1_Upper"]=cassete100Station;
  161. }
  162. /// <summary>
  163. /// 初始化vpw module Station
  164. /// </summary>
  165. /// <param name="module"></param>
  166. private void InitializeVPWModuleStation(ModuleName module)
  167. {
  168. int cassete200Station_Blade1_Upper = SC.GetValue<int>($"EFEM.{module}.Cassete200Station_Blade1_Upper");
  169. _moduleStationNumberDictionary[$"{module}_200_Blade1_Upper"] = cassete200Station_Blade1_Upper;
  170. int cassete200Station_Blade2_Upper = SC.GetValue<int>($"EFEM.{module}.Cassete200Station_Blade2_Upper");
  171. _moduleStationNumberDictionary[$"{module}_200_Blade2_Upper"] = cassete200Station_Blade2_Upper;
  172. int cassete200Station_Blade2_Down = SC.GetValue<int>($"EFEM.{module}.Cassete200Station_Blade2_Down");
  173. _moduleStationNumberDictionary[$"{module}_200_Blade2_Down"] = cassete200Station_Blade2_Down;
  174. int cassete150Station_Blade1_Upper = SC.GetValue<int>($"EFEM.{module}.Cassete150Station_Blade1_Upper");
  175. _moduleStationNumberDictionary[$"{module}_150_Blade1_Upper"] = cassete150Station_Blade1_Upper;
  176. int cassete150Station_Blade2_Upper = SC.GetValue<int>($"EFEM.{module}.Cassete150Station_Blade2_Upper");
  177. _moduleStationNumberDictionary[$"{module}_150_Blade2_Upper"] = cassete150Station_Blade2_Upper;
  178. int cassete150Station_Blade2_Down = SC.GetValue<int>($"EFEM.{module}.Cassete150Station_Blade2_Down");
  179. _moduleStationNumberDictionary[$"{module}_150_Blade2_Down"] = cassete150Station_Blade2_Down;
  180. int cassete100Station_Blade1_Upper = SC.GetValue<int>($"EFEM.{module}.Cassete100Station_Blade1_Upper");
  181. _moduleStationNumberDictionary[$"{module}_100_Blade1_Upper"] = cassete100Station_Blade1_Upper;
  182. int cassete100Station_Blade2_Upper = SC.GetValue<int>($"EFEM.{module}.Cassete100Station_Blade2_Upper");
  183. _moduleStationNumberDictionary[$"{module}_100_Blade2_Upper"] = cassete100Station_Blade2_Upper;
  184. int cassete100Station_Blade2_Down = SC.GetValue<int>($"EFEM.{module}.Cassete100Station_Blade2_Down");
  185. _moduleStationNumberDictionary[$"{module}_100_Blade2_Down"] = cassete100Station_Blade2_Down;
  186. }
  187. /// <summary>
  188. /// 初始化Platingcell Module Station
  189. /// </summary>
  190. /// <param name="module"></param>
  191. private void InitializePlatingCellModuleStation(ModuleName module)
  192. {
  193. int cassete200Station = SC.GetValue<int>($"EFEM.{module}.Cassete200Station_Blade2_Down");
  194. _moduleStationNumberDictionary[$"{module}_200_Blade2_Down"] = cassete200Station;
  195. int cassete150Station = SC.GetValue<int>($"EFEM.{module}.Cassete150Station_Blade2_Down");
  196. _moduleStationNumberDictionary[$"{module}_150_Blade2_Down"] = cassete150Station;
  197. int cassete100Station = SC.GetValue<int>($"EFEM.{module}.Cassete100Station_Blade2_Down");
  198. _moduleStationNumberDictionary[$"{module}_100_Blade2_Down"] = cassete100Station;
  199. }
  200. private void Socket_OnConnect()
  201. {
  202. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
  203. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), $"connect {_address} success");
  204. }
  205. private void OnErrorHappen(ErrorEventArgs args)
  206. {
  207. _status = RState.Failed;
  208. if (_error != args.Reason)
  209. {
  210. _error = args.Reason;
  211. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"{Module} {_error}");
  212. }
  213. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  214. }
  215. public override void Monitor()
  216. {
  217. }
  218. public override void Terminate()
  219. {
  220. }
  221. public override void Reset()
  222. {
  223. _status = RState.End;
  224. _currentMessage = null;
  225. }
  226. public override void SetOnline(bool online)
  227. {
  228. }
  229. public override void SetOnline(ModuleName mod, bool online)
  230. {
  231. }
  232. public override void SetBusy(ModuleName mod, bool online)
  233. {
  234. _status = RState.Running;
  235. }
  236. public override bool HomeAll()
  237. {
  238. if (_status == RState.Running&&_currentMessage!=null)
  239. {
  240. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home All");
  241. return false;
  242. }
  243. //判断socket是否链接
  244. if (!_socket.IsConnected)
  245. {
  246. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  247. return false ;
  248. }
  249. _status = RState.Running;
  250. string data = "HOME ALL\r";
  251. _currentMessage =new EfemMessage(){
  252. Operation= EfemOperation.Home,
  253. Module=ModuleName.EFEM
  254. };
  255. //SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  256. return WriteCommand(data);
  257. }
  258. public override bool Home(ModuleName mod)
  259. {
  260. if (_status == RState.Running && _currentMessage!= null)
  261. {
  262. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home {mod}");
  263. return false;
  264. }
  265. if (mod != ModuleName.Aligner1&&mod!=ModuleName.EfemRobot)
  266. {
  267. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{mod} can not support home method");
  268. return false;
  269. }
  270. //判断socket是否链接
  271. if (!_socket.IsConnected)
  272. {
  273. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  274. return false;
  275. }
  276. if(mod == ModuleName.EfemRobot) SetRobotMovingInfo(RobotAction.Homing, Hand.Blade1, ModuleName.EfemRobot,Flip.Upper);
  277. _status = RState.Running;
  278. string cmd = "Home ALL\r";
  279. if (mod == ModuleName.Aligner1)
  280. {
  281. cmd = "ALIGNER HOME\r";
  282. }
  283. _currentMessage = new EfemMessage()
  284. {
  285. Operation = EfemOperation.Home,
  286. Module = ModuleName.Aligner1
  287. };
  288. return WriteCommand(cmd);
  289. }
  290. public override bool OriginalSearch(ModuleName mod)
  291. {
  292. return true;
  293. }
  294. public override bool CheckWaferPresence()
  295. {
  296. if (_status == RState.Running && _currentMessage != null)
  297. {
  298. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot check wafer");
  299. return false;
  300. }
  301. //判断socket是否链接
  302. if (!_socket.IsConnected)
  303. {
  304. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  305. return false;
  306. }
  307. if (!CheckEfemStatus())
  308. return false;
  309. _currentMessage = new EfemMessage()
  310. {
  311. Operation = EfemOperation.StateTrack,
  312. Module = ModuleName.EfemRobot
  313. };
  314. _status = RState.Running;
  315. string cmd = $"RQ LOAD {_armString[Hand.Blade1]}\r";
  316. return WriteCommand(cmd);
  317. }
  318. public override string GetWaferPresence()
  319. {
  320. return "";
  321. }
  322. public override bool Halt()
  323. {
  324. //判断socket是否链接
  325. if (!_socket.IsConnected)
  326. {
  327. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  328. return false;
  329. }
  330. _currentMessage = new EfemMessage()
  331. {
  332. Operation = EfemOperation.Abort,
  333. Module = ModuleName.EfemRobot
  334. };
  335. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EFEM,Flip.Upper);
  336. string cmd = "HALT\r";
  337. return WriteCommand(cmd);
  338. }
  339. public override bool Pause()
  340. {
  341. //判断socket是否链接
  342. if (!_socket.IsConnected)
  343. {
  344. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  345. return false;
  346. }
  347. string cmd = "PAUSE\r";
  348. bool result = WriteCommand(cmd);
  349. if (result)
  350. {
  351. _isInPauseStatus = true; //进入pause状态
  352. }
  353. else
  354. {
  355. _isInPauseStatus = false;
  356. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Send pause message error");
  357. }
  358. return result;
  359. }
  360. public override bool Resume()
  361. {
  362. _isActionRDYReceived = false; //把收到resume信号后执行resume动作成功的变量置false
  363. //判断socket是否链接
  364. if (!_socket.IsConnected)
  365. {
  366. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  367. return false;
  368. }
  369. string cmd = "RESUME\r";
  370. return WriteCommand(cmd);
  371. }
  372. public override bool ClearError()
  373. {
  374. return true;
  375. }
  376. public override bool CloseBuzzer()
  377. {
  378. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.TurnOffBuzzer]}");
  379. return false;
  380. }
  381. public override bool PickExtend(ModuleName chamber, int slot, Hand hand)
  382. {
  383. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  384. return false;
  385. }
  386. public override bool PickRetract(ModuleName chamber, int slot, Hand hand)
  387. {
  388. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  389. return false;
  390. }
  391. public override bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
  392. {
  393. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  394. return false;
  395. }
  396. public override bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
  397. {
  398. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  399. return false;
  400. }
  401. public override bool Pick(ModuleName station, int slot, Hand hand, Flip flip)
  402. {
  403. if (_status == RState.Running && _currentMessage != null)
  404. {
  405. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot pick");
  406. return false;
  407. }
  408. //判断socket是否链接
  409. if (!_socket.IsConnected)
  410. {
  411. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  412. return false;
  413. }
  414. //判断Loadport的门是否打开
  415. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  416. //{
  417. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  418. // return false;
  419. //}
  420. if (!CheckEfemStatus())
  421. return false;
  422. int waferSize = GetModuleSlotWaferSize(station,slot);
  423. if (waferSize == 0)
  424. {
  425. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Pick Action");
  426. return false;
  427. }
  428. string strModuleWaferSize = $"{station}_{waferSize}_{hand}_{flip}";
  429. if (!_moduleStationNumberDictionary.ContainsKey(strModuleWaferSize))
  430. {
  431. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s number is not exist, Cannot Execute Pick Action");
  432. return false;
  433. }
  434. int stationNumber= _moduleStationNumberDictionary[strModuleWaferSize];
  435. string strFlip = flip == Flip.Down ? " FLIP" : "";
  436. string cmd = $"PICK {stationNumber} SLOT {slot+1} ARM {_armString[hand]}{strFlip}\r";
  437. if(ModuleHelper.IsAligner(station)||ModuleHelper.IsSRD(station)||ModuleHelper.IsVPWCell(station) || ModuleHelper.IsPlatingCell(station))
  438. {
  439. cmd = $"PICK {stationNumber} SLOT 1 ARM {_armString[hand]}{strFlip}\r";
  440. }
  441. _currentMessage = new EfemMessage()
  442. {
  443. Operation=EfemOperation.Pick,
  444. Flip = flip
  445. };
  446. _status = RState.Running;
  447. SetRobotMovingInfo(RobotAction.Picking, hand, station, flip);
  448. return WriteCommand(cmd);
  449. }
  450. private Loadport GetLoadPort(ModuleName station)
  451. {
  452. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  453. return loadPortModule.LPDevice;
  454. }
  455. public override bool Place(ModuleName station, int slot, Hand hand,Flip flip)
  456. {
  457. if (_status == RState.Running && _currentMessage != null)
  458. {
  459. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot place");
  460. return false;
  461. }
  462. //判断socket是否链接
  463. if (!_socket.IsConnected)
  464. {
  465. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  466. return false;
  467. }
  468. //判断Loadport的门是否打开
  469. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  470. //{
  471. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  472. // return false;
  473. //}
  474. if (!CheckEfemStatus())
  475. return false;
  476. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, (int)hand);
  477. if (waferSize == 0)
  478. {
  479. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Place Action");
  480. return false;
  481. }
  482. string strModuleWaferSize = $"{station}_{waferSize}_{hand}_{flip}";
  483. _currentMessage = new EfemMessage()
  484. {
  485. Operation = EfemOperation.Place,
  486. Flip = flip
  487. };
  488. _status = RState.Running;
  489. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  490. string strFlip = flip == Flip.Down ? " FLIP" : "";
  491. string cmd = $"PLACE {stationNumber} SLOT {slot+1} ARM {_armString[hand]}{strFlip}\r";
  492. if (ModuleHelper.IsSRD(station) || ModuleHelper.IsVPWCell(station) || ModuleHelper.IsPlatingCell(station))
  493. {
  494. cmd = $"PLACE {stationNumber} SLOT 1 ARM {_armString[hand]}{strFlip}\r";
  495. }
  496. if (ModuleHelper.IsAligner(station))
  497. {
  498. cmd = $"PLACE {stationNumber} PHOME\r";
  499. }
  500. SetRobotMovingInfo(RobotAction.Placing, hand, station, flip);
  501. return WriteCommand(cmd);
  502. }
  503. public override bool Goto(ModuleName station, Hand hand, string updown = "Upper")
  504. {
  505. if (_status == RState.Running && _currentMessage != null)
  506. {
  507. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto");
  508. return false;
  509. }
  510. if (!CheckEfemStatus())
  511. return false;
  512. //判断socket是否链接
  513. if (!_socket.IsConnected)
  514. {
  515. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  516. return false;
  517. }
  518. _currentMessage = new EfemMessage()
  519. {
  520. Operation = EfemOperation.Goto
  521. };
  522. int waferSize = GetModuleNameWaferSize(station);
  523. if (waferSize == 0)
  524. {
  525. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  526. return false;
  527. }
  528. string strModuleWaferSize = $"{station}_{waferSize}";
  529. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  530. string cmd = $"GOTO N {stationNumber} R EX Z {updown} ARM SLOT 1 {_armString[hand]}\r";
  531. _status = RState.Running;
  532. return WriteCommand(cmd);
  533. }
  534. public override bool Grip(Hand blade, bool isGrip)
  535. {
  536. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Grip]}");
  537. return false;
  538. }
  539. public override bool GotoMap(ModuleName mod,Hand hand,string extend="EX")
  540. {
  541. if (_status == RState.Running && _currentMessage != null)
  542. {
  543. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto map");
  544. return false;
  545. }
  546. //判断socket是否链接
  547. if (!_socket.IsConnected)
  548. {
  549. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  550. return false;
  551. }
  552. if (!CheckEfemStatus())
  553. return false;
  554. int waferSize = GetModuleNameWaferSize(mod);
  555. if (waferSize == 0)
  556. {
  557. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  558. return false;
  559. }
  560. string strModuleWaferSize = $"{mod}_{waferSize}_{hand}_Upper";
  561. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  562. string cmd = $"GOTO N {stationNumber} MAP {extend} ARM {_armString[hand]}\r";
  563. _currentMessage = new EfemMessage()
  564. {
  565. Operation = EfemOperation.Goto,
  566. Module= mod
  567. };
  568. _status = RState.Running;
  569. return WriteCommand(cmd);
  570. }
  571. public override bool Map(ModuleName mod)
  572. {
  573. if (_status == RState.Running && _currentMessage != null)
  574. {
  575. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot map");
  576. return false;
  577. }
  578. //判断socket是否链接
  579. if (!_socket.IsConnected)
  580. {
  581. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  582. return false;
  583. }
  584. if (!CheckEfemStatus())
  585. return false;
  586. int waferSize = GetModuleNameWaferSize(mod);
  587. if (waferSize == 0)
  588. {
  589. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  590. return false;
  591. }
  592. string strModuleWaferSize = $"{mod}_{waferSize}_Blade1_Upper";
  593. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  594. _currentMessage = new EfemMessage()
  595. {
  596. Operation = EfemOperation.Map,
  597. Module = mod
  598. };
  599. string cmd = $"MAP {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  600. _status = RState.Running;
  601. return WriteCommand(cmd);
  602. }
  603. public override bool RequestMapResult(ModuleName mod)
  604. {
  605. if (_status == RState.Running && _currentMessage != null)
  606. {
  607. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot request map");
  608. return false;
  609. }
  610. //判断socket是否链接
  611. if (!_socket.IsConnected)
  612. {
  613. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  614. return false;
  615. }
  616. if (!CheckEfemStatus())
  617. return false;
  618. int waferSize = GetModuleNameWaferSize(mod);
  619. if (waferSize == 0)
  620. {
  621. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  622. return false;
  623. }
  624. string strModuleWaferSize = $"{mod}_{waferSize}_Blade1_Upper";
  625. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  626. _currentMessage = new EfemMessage()
  627. {
  628. Operation = EfemOperation.RequestMapResult,
  629. Module = mod
  630. };
  631. string cmd = $"RSR {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  632. _status = RState.Running;
  633. return WriteCommand(cmd);
  634. }
  635. public override bool Vacuum(ModuleName mod,bool VacuumState)
  636. {
  637. if (_status == RState.Running && _currentMessage != null)
  638. {
  639. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot vacuum");
  640. return false;
  641. }
  642. //判断socket是否链接
  643. if (!_socket.IsConnected)
  644. {
  645. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  646. return false;
  647. }
  648. _currentMessage = new EfemMessage()
  649. {
  650. Operation = EfemOperation.Vacuum,
  651. Module = mod
  652. };
  653. _status = RState.Running;
  654. string strVacuum = VacuumState ? "ON" : "OFF";
  655. string cmd = "";
  656. if (ModuleName.Aligner1 == mod)
  657. {
  658. cmd = $"ALIGNER VAC {strVacuum}\r";
  659. }
  660. else
  661. {
  662. cmd = $"VAC {strVacuum} ARM {_armString[Hand.Blade1]}\r";
  663. }
  664. return WriteCommand(cmd);
  665. }
  666. public override bool GetWaferSize(ModuleName mod)
  667. {
  668. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support GetWaferSize");
  669. return false;
  670. }
  671. public override bool SetWaferSize(ModuleName mod, int WaferSize)
  672. {
  673. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support SetWaferSize");
  674. return false;
  675. }
  676. public override bool SetPinUp(ModuleName mod)
  677. {
  678. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  679. return false;
  680. }
  681. public override bool SetPinDown(ModuleName mod)
  682. {
  683. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  684. return false;
  685. }
  686. public override bool SetAlignWaferSize()
  687. {
  688. if (_status == RState.Running && _currentMessage != null)
  689. {
  690. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Wafer Size");
  691. return false;
  692. }
  693. if (!CheckEfemStatus())
  694. return false;
  695. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  696. {
  697. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} has no wafer, Cannot Execute Set aligner wafersize");
  698. return false;
  699. }
  700. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, 0);
  701. if (waferSize == 0)
  702. {
  703. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} wafer size is 0, Cannot Execute Set aligner wafersize");
  704. return false;
  705. }
  706. //判断socket是否链接
  707. if (!_socket.IsConnected)
  708. {
  709. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  710. return false;
  711. }
  712. _currentMessage = new EfemMessage()
  713. {
  714. Operation = EfemOperation.AlignWaferSize
  715. };
  716. string cmd = $"SET ALIGNER WAFERSIZE {waferSize}\r";
  717. _status = RState.Running;
  718. return WriteCommand(cmd);
  719. }
  720. public override bool SetAlignFlatType(int flatType)
  721. {
  722. if (_status == RState.Running && _currentMessage != null)
  723. {
  724. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align flat type");
  725. return false;
  726. }
  727. if (!CheckEfemStatus())
  728. return false;
  729. //判断socket是否链接
  730. if (!_socket.IsConnected)
  731. {
  732. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  733. return false;
  734. }
  735. _currentMessage = new EfemMessage()
  736. {
  737. Operation = EfemOperation.AlignFlatType
  738. };
  739. string cmd = $"SET ALIGNER WAFERTYPE {flatType}\r";
  740. _status = RState.Running;
  741. return WriteCommand(cmd);
  742. }
  743. public override bool SetAlignDistance()
  744. {
  745. int distance200 = SC.GetValue<int>("EFEM.Aligner1.Aligner200Distance");
  746. int distance150 = SC.GetValue<int>("EFEM.Aligner1.Aligner150Distance");
  747. int distance100 = SC.GetValue<int>("EFEM.Aligner1.Aligner100Distance");
  748. if (_status == RState.Running && _currentMessage != null)
  749. {
  750. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align flat type");
  751. return false;
  752. }
  753. if (!CheckEfemStatus())
  754. return false;
  755. //判断socket是否链接
  756. if (!_socket.IsConnected)
  757. {
  758. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  759. return false;
  760. }
  761. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  762. {
  763. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} has no wafer, Cannot Execute Set aligner wafersize");
  764. return false;
  765. }
  766. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, 0);
  767. if (waferSize == 0)
  768. {
  769. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} wafer size is 0, Cannot Execute Set aligner wafersize");
  770. return false;
  771. }
  772. _currentMessage = new EfemMessage()
  773. {
  774. Operation = EfemOperation.AlignDistance
  775. };
  776. int distance = distance200;
  777. if (waferSize == (int)WaferSize.WS6)
  778. {
  779. distance = distance150;
  780. }
  781. else if (waferSize == (int)WaferSize.WS4)
  782. {
  783. distance = distance100;
  784. }
  785. string cmd = $"SET ALIGNER WAFERDISTANCE {distance}\r";
  786. _status = RState.Running;
  787. return WriteCommand(cmd);
  788. }
  789. public override bool SetAlignAngle(ModuleName mod, double angle)
  790. {
  791. if (_status == RState.Running && _currentMessage != null)
  792. {
  793. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Angle");
  794. return false;
  795. }
  796. if (!CheckEfemStatus())
  797. return false;
  798. //判断socket是否链接
  799. if (!_socket.IsConnected)
  800. {
  801. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  802. return false;
  803. }
  804. _currentMessage = new EfemMessage()
  805. {
  806. Operation = EfemOperation.Align,
  807. };
  808. string cmd = $"SET ALIGNER POSTPOS 1 POS {angle*1000}\r";
  809. _status = RState.Running;
  810. return WriteCommand(cmd);
  811. }
  812. public override bool SetRobotSpeed(ModuleName mod, int speed)
  813. {
  814. if (_status == RState.Running && _currentMessage != null)
  815. {
  816. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Speed");
  817. return false;
  818. }
  819. //判断socket是否链接
  820. if (!_socket.IsConnected)
  821. {
  822. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  823. return false;
  824. }
  825. _currentMessage = new EfemMessage()
  826. {
  827. Operation = EfemOperation.Speed
  828. };
  829. string cmd = $"SET ACTION SPEEDS {speed}\r";
  830. _status = RState.Running;
  831. return WriteCommand(cmd);
  832. }
  833. public override bool RobotPowerOn(ModuleName mod, bool Status)
  834. {
  835. if (_status == RState.Running && _currentMessage != null)
  836. {
  837. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot PowerOn");
  838. return false;
  839. }
  840. //判断socket是否链接
  841. if (!_socket.IsConnected)
  842. {
  843. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  844. return false;
  845. }
  846. string status = Status? "ON":"OFF";
  847. _currentMessage = new EfemMessage()
  848. {
  849. Operation = EfemOperation.PowerOn
  850. };
  851. string cmd = $"SET SERVOS {status}\r";
  852. _status = RState.Running;
  853. return WriteCommand(cmd);
  854. }
  855. public override bool Align(ModuleName mod, double angle, float delayTime, WaferSize size)
  856. {
  857. if (_status == RState.Running && _currentMessage != null)
  858. {
  859. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align");
  860. return false;
  861. }
  862. //判断socket是否链接
  863. if (!_socket.IsConnected)
  864. {
  865. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  866. return false;
  867. }
  868. if (!CheckEfemStatus())
  869. return false;
  870. _currentMessage = new EfemMessage()
  871. {
  872. Operation = EfemOperation.Align
  873. };
  874. _status = RState.Running;
  875. string cmd = "ALIGNER ALGN\r";
  876. return WriteCommand(cmd);
  877. }
  878. public override bool SetLamp(LightType light, LightStatus status)
  879. {
  880. return false;
  881. }
  882. public override bool Load(ModuleName mod)
  883. {
  884. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Load");
  885. return false;
  886. }
  887. public override bool Unload(ModuleName mod)
  888. {
  889. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unload");
  890. return false;
  891. }
  892. public override bool ReadCarrierId(ModuleName mod)
  893. {
  894. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support ReadCarrierId");
  895. return false;
  896. }
  897. public override bool WriteCarrierId(ModuleName mod, string id)
  898. {
  899. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support WriteCarrierId");
  900. return false;
  901. }
  902. public override bool ReadTagData(ModuleName mod)
  903. {
  904. return ReadCarrierId(mod);
  905. }
  906. public override bool WriteTagData(ModuleName mod, string tagData)
  907. {
  908. return WriteCarrierId(mod, tagData);
  909. }
  910. public override bool Dock(ModuleName mod)
  911. {
  912. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Dock");
  913. return false;
  914. }
  915. public override bool Undock(ModuleName mod)
  916. {
  917. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Undock");
  918. return false;
  919. }
  920. public override bool Clamp(ModuleName mod, bool isUnloadClamp)
  921. {
  922. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Clamp");
  923. return false;
  924. }
  925. public override bool Unclamp(ModuleName mod)
  926. {
  927. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unclamp");
  928. return false;
  929. }
  930. public override bool SetThickness(ModuleName mod, string thickness)
  931. {
  932. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.SetThickness]}");
  933. return false;
  934. }
  935. public override void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target,Flip flip)
  936. {
  937. blockingCollection.Add(new RobotAnimationData(action, hand, target,flip));
  938. }
  939. private void OnReceiveMessage(string msg)
  940. {
  941. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), msg.Replace("\r",""));
  942. if (_currentMessage == null)
  943. {
  944. return;
  945. }
  946. if(msg.Contains("_ERR"))
  947. {
  948. string error = msg.Replace("_ERR", "").Trim();
  949. OnErrorOccurred(error);
  950. _currentMessage = null;
  951. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EFEM, Flip.Upper);
  952. return;
  953. }
  954. else if (msg.StartsWith("ACTION _RDY"))
  955. {
  956. _status = RState.End;
  957. _isResumeRDYReceived = false;
  958. _isPauseRDYReceived = false;
  959. _isActionRDYReceived = true;
  960. }
  961. else if (msg.StartsWith("_RDY"))
  962. {
  963. _status = RState.End;
  964. switch (_currentMessage.Operation)
  965. {
  966. case EfemOperation.Home:
  967. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM, Flip.Upper);
  968. break;
  969. case EfemOperation.Map:
  970. case EfemOperation.GotoMap:
  971. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  972. {
  973. GetLoadPort(_currentMessage.Module).OnMaped();
  974. }
  975. break;
  976. case EfemOperation.Pick:
  977. case EfemOperation.Place:
  978. if(_currentMessage.Flip == Flip.Down)
  979. {
  980. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot, Flip.Down);
  981. }
  982. else
  983. {
  984. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot, Flip.Upper);
  985. }
  986. break;
  987. }
  988. }
  989. else if (msg.Contains("PAUSE _RDY"))
  990. {
  991. _isPauseRDYReceived = true;
  992. _isResumeRDYReceived = false; //收到pause把收到resume的信号置false
  993. LOG.WriteLog(eEvent.INFO_TM_ROBOT, Module.ToString(), $"PAUSE_RDY was received, robot pause status is true");
  994. }
  995. else if (msg.Contains("RESUME _RDY"))
  996. {
  997. _isResumeRDYReceived = true;
  998. _isPauseRDYReceived = false; //收到Resume把收到pause的信号置false
  999. _isInPauseStatus = false; //取消pause状态
  1000. LOG.WriteLog(eEvent.INFO_TM_ROBOT, Module.ToString(), $"RESUME _RDY was received, robot pause status is false");
  1001. }
  1002. else
  1003. {
  1004. switch (_currentMessage.Operation)
  1005. {
  1006. case EfemOperation.StateTrack:
  1007. DealStateTrack(msg);
  1008. break;
  1009. case EfemOperation.RequestMapResult:
  1010. DealMapResult(msg);
  1011. break;
  1012. }
  1013. _status = RState.End;
  1014. _currentMessage = null;
  1015. }
  1016. }
  1017. /// <summary>
  1018. /// 处理StateTrack结果
  1019. /// </summary>
  1020. /// <param name="msg"></param>
  1021. private void DealStateTrack(string msg)
  1022. {
  1023. if (msg.StartsWith("LOAD"))
  1024. {
  1025. string[] strAry = msg.Trim().Split(' ');
  1026. if (strAry.Length >= 2)
  1027. {
  1028. bool hasWafer = strAry[2] == "ON" ? true : false;
  1029. if (strAry[1] == _armString[Hand.Blade1])
  1030. {
  1031. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)&& hasWafer)
  1032. {
  1033. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 0, WaferStatus.Normal);
  1034. }
  1035. }
  1036. else if (strAry[1] == _armString[Hand.Blade2])
  1037. {
  1038. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && hasWafer)
  1039. {
  1040. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 1, WaferStatus.Normal);
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }
  1046. /// <summary>
  1047. /// 处理Map结果
  1048. /// </summary>
  1049. /// <param name="msg"></param>
  1050. private void DealMapResult(string msg)
  1051. {
  1052. if (_currentMessage.Operation != EfemOperation.RequestMapResult)
  1053. {
  1054. return;
  1055. }
  1056. if(!msg.StartsWith("MAP"))
  1057. {
  1058. return;
  1059. }
  1060. string[] sWaferInfo = msg.Split(new char[] { ' ', '\r', '\n' });
  1061. if (sWaferInfo.Length <= 2)
  1062. {
  1063. return;
  1064. }
  1065. int slotMap = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
  1066. WaferType waferType = WaferType.Production;
  1067. if (ModuleHelper.IsDummy(_currentMessage.Module))
  1068. {
  1069. DummyCassetteItem item = DummyCasseteItemManager.Instance.GetDummyCassetteItem(_currentMessage.Module.ToString());
  1070. if (item != null)
  1071. {
  1072. slotMap = item.MaxNumberOfSlots;
  1073. }
  1074. waferType = WaferType.Assit;
  1075. }
  1076. int waferSize = GetModuleNameWaferSize(_currentMessage.Module);
  1077. //Map 结果(1 1 1 1 1 1 1 ...0)
  1078. int startIndex = 1;
  1079. int count = slotMap >= sWaferInfo.Length-startIndex? sWaferInfo.Length-startIndex : slotMap;
  1080. bool result = true;
  1081. for (int index = startIndex; index <= count; index++)
  1082. {
  1083. string strState = sWaferInfo[index];
  1084. int waferState = 0;
  1085. //合理的映射到内部支持的叠片/交叉片
  1086. if (strState == "1") waferState = (int)WaferStatus.Normal;
  1087. else if (strState == "2") waferState = (int)WaferStatus.Double;
  1088. else if (strState == "3") waferState = (int)WaferStatus.Crossed;
  1089. else if (strState == "5") waferState = (int)WaferStatus.Thin;
  1090. else if(strState=="?") waferState=(int)WaferStatus.Unknown;
  1091. WaferStatus st = (WaferStatus)waferState;
  1092. if (st != WaferStatus.Empty)
  1093. {
  1094. WaferManager.Instance.CreateWafer(_currentMessage.Module, index-startIndex, st,(WaferSize)waferSize,waferType);
  1095. if (st != WaferStatus.Normal)
  1096. {
  1097. result = false;
  1098. }
  1099. }
  1100. else
  1101. {
  1102. WaferManager.Instance.DeleteWafer(_currentMessage.Module, index-startIndex);
  1103. }
  1104. }
  1105. if (!result)
  1106. {
  1107. LOG.WriteLog(eEvent.ERROR_EFEM_ERROR_WAFER, Module.ToString(), $"{_currentMessage.Module} slot map failed {msg}");
  1108. }
  1109. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  1110. {
  1111. GetLoadPort(_currentMessage.Module).UpdateMapResult(result);
  1112. }
  1113. }
  1114. private void OnErrorOccurred(string errorCode)
  1115. {
  1116. _status = RState.Failed;
  1117. string description = errorCode;
  1118. if (SumWayRobotErrorCode.ErrorCodeDescription.ContainsKey(errorCode))
  1119. {
  1120. description=SumWayRobotErrorCode.ErrorCodeDescription[errorCode];
  1121. }
  1122. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error, description);
  1123. if (_currentMessage != null)
  1124. {
  1125. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"current operation {_currentMessage.Operation} failed,{description}");
  1126. }
  1127. _currentMessage=null;
  1128. }
  1129. private bool WriteCommand(string cmd)
  1130. {
  1131. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), cmd.Replace("\r", ""));
  1132. return _socket.Write(cmd);
  1133. }
  1134. /// <summary>
  1135. /// 获取模块Wafer尺寸
  1136. /// </summary>
  1137. /// <param name="moduleName"></param>
  1138. /// <returns></returns>
  1139. private int GetModuleNameWaferSize(ModuleName moduleName)
  1140. {
  1141. if (ModuleHelper.IsLoadPort(moduleName))
  1142. {
  1143. Loadport loadport = GetLoadPort(moduleName);
  1144. if (!loadport.HasCassette)
  1145. {
  1146. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  1147. return 0;
  1148. }
  1149. return (int)loadport.WaferSize;
  1150. }
  1151. else if (ModuleHelper.IsDummy(moduleName))
  1152. {
  1153. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(moduleName - ModuleName.Dummy1);
  1154. if (!dummyDevice.HasCassette)
  1155. {
  1156. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  1157. return 0;
  1158. }
  1159. return (int)dummyDevice.WaferSize;
  1160. }
  1161. return 0;
  1162. }
  1163. /// <summary>
  1164. /// 获取模块尺寸
  1165. /// </summary>
  1166. /// <param name="moduleName"></param>
  1167. /// <returns></returns>
  1168. private int GetModuleSlotWaferSize(ModuleName moduleName,int slotNumber)
  1169. {
  1170. if(WaferManager.Instance.CheckHasWafer(moduleName,slotNumber))
  1171. {
  1172. WaferInfo waferInfo=WaferManager.Instance.GetWafer(moduleName, slotNumber);
  1173. return (int)waferInfo.Size;
  1174. }
  1175. else
  1176. {
  1177. return 0;
  1178. }
  1179. }
  1180. }
  1181. }