SunWayRobot.cs 56 KB

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