SunWayRobot.cs 49 KB

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