SunWayRobot.cs 52 KB

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