SunWayRobot.cs 41 KB

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