SunWayRobot.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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)
  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 = "ALIGNER HOME\r";
  227. _currentMessage = new EfemMessage()
  228. {
  229. Operation = EfemOperation.Home,
  230. Module = ModuleName.Aligner1
  231. };
  232. return WriteCommand(cmd);
  233. }
  234. public override bool OriginalSearch(ModuleName mod)
  235. {
  236. return true;
  237. }
  238. public override bool CheckWaferPresence()
  239. {
  240. if (_status == RState.Running && _currentMessage != null)
  241. {
  242. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot check wafer");
  243. return false;
  244. }
  245. //判断socket是否链接
  246. if (!_socket.IsConnected)
  247. {
  248. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  249. return false;
  250. }
  251. if (!CheckEfemStatus())
  252. return false;
  253. _currentMessage = new EfemMessage()
  254. {
  255. Operation = EfemOperation.StateTrack,
  256. Module = ModuleName.EfemRobot
  257. };
  258. _status = RState.Running;
  259. string cmd = $"RQ LOAD {_armString[Hand.Blade1]}\r";
  260. return WriteCommand(cmd);
  261. }
  262. public override string GetWaferPresence()
  263. {
  264. return "";
  265. }
  266. public override bool Halt()
  267. {
  268. if (_status == RState.Running && _currentMessage != null)
  269. {
  270. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot halt");
  271. return false;
  272. }
  273. //判断socket是否链接
  274. if (!_socket.IsConnected)
  275. {
  276. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  277. return false;
  278. }
  279. _currentMessage = new EfemMessage()
  280. {
  281. Operation = EfemOperation.Abort,
  282. Module = ModuleName.EfemRobot
  283. };
  284. string cmd = "HALT\r";
  285. return WriteCommand(cmd);
  286. }
  287. public override bool ClearError()
  288. {
  289. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.ClearError]}");
  290. return false;
  291. }
  292. public override bool CloseBuzzer()
  293. {
  294. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.TurnOffBuzzer]}");
  295. return false;
  296. }
  297. public override bool PickExtend(ModuleName chamber, int slot, Hand hand)
  298. {
  299. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  300. return false;
  301. }
  302. public override bool PickRetract(ModuleName chamber, int slot, Hand hand)
  303. {
  304. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  305. return false;
  306. }
  307. public override bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
  308. {
  309. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  310. return false;
  311. }
  312. public override bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
  313. {
  314. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  315. return false;
  316. }
  317. public override bool Pick(ModuleName station, int slot, Hand hand)
  318. {
  319. if (_status == RState.Running && _currentMessage != null)
  320. {
  321. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot pick");
  322. return false;
  323. }
  324. //判断socket是否链接
  325. if (!_socket.IsConnected)
  326. {
  327. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  328. return false;
  329. }
  330. //判断Loadport的门是否打开
  331. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  332. //{
  333. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  334. // return false;
  335. //}
  336. if (!CheckEfemStatus())
  337. return false;
  338. int waferSize = GetModuleSlotWaferSize(station,slot);
  339. if (waferSize == 0)
  340. {
  341. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Pick Action");
  342. return false;
  343. }
  344. string strModuleWaferSize = $"{station}_{waferSize}";
  345. if (!_moduleStationNumberDictionary.ContainsKey(strModuleWaferSize))
  346. {
  347. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s number is not exist, Cannot Execute Pick Action");
  348. return false;
  349. }
  350. int stationNumber= _moduleStationNumberDictionary[strModuleWaferSize];
  351. string cmd = $"PICK {stationNumber} SLOT {slot+1} ARM {_armString[hand]}\r";
  352. _currentMessage = new EfemMessage()
  353. {
  354. Operation=EfemOperation.Pick
  355. };
  356. _status = RState.Running;
  357. SetRobotMovingInfo(RobotAction.Picking, hand, station);
  358. return WriteCommand(cmd);
  359. }
  360. private Loadport GetLoadPort(ModuleName station)
  361. {
  362. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  363. return loadPortModule.LPDevice;
  364. }
  365. public override bool Place(ModuleName station, int slot, Hand hand)
  366. {
  367. if (_status == RState.Running && _currentMessage != null)
  368. {
  369. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot place");
  370. return false;
  371. }
  372. //判断socket是否链接
  373. if (!_socket.IsConnected)
  374. {
  375. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  376. return false;
  377. }
  378. //判断Loadport的门是否打开
  379. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  380. //{
  381. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  382. // return false;
  383. //}
  384. if (!CheckEfemStatus())
  385. return false;
  386. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, (int)hand);
  387. if (waferSize == 0)
  388. {
  389. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Place Action");
  390. return false;
  391. }
  392. string strModuleWaferSize = $"{station}_{waferSize}";
  393. _currentMessage = new EfemMessage()
  394. {
  395. Operation = EfemOperation.Place
  396. };
  397. _status = RState.Running;
  398. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  399. string cmd = $"PLACE {stationNumber} SLOT {slot+1} ARM {_armString[hand]}\r";
  400. SetRobotMovingInfo(RobotAction.Placing, hand, station);
  401. return WriteCommand(cmd);
  402. }
  403. public override bool Goto(ModuleName station, Hand hand, string updown = "UP")
  404. {
  405. if (_status == RState.Running && _currentMessage != null)
  406. {
  407. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto");
  408. return false;
  409. }
  410. if (!CheckEfemStatus())
  411. return false;
  412. //判断socket是否链接
  413. if (!_socket.IsConnected)
  414. {
  415. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  416. return false;
  417. }
  418. _currentMessage = new EfemMessage()
  419. {
  420. Operation = EfemOperation.Goto
  421. };
  422. int waferSize = GetModuleNameWaferSize(station);
  423. if (waferSize == 0)
  424. {
  425. return false;
  426. }
  427. string strModuleWaferSize = $"{station}_{waferSize}";
  428. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  429. string cmd = $"GOTO N {stationNumber} R EX Z {updown} ARM SLOT 1 {_armString[hand]}\r";
  430. _status = RState.Running;
  431. return WriteCommand(cmd);
  432. }
  433. public override bool Grip(Hand blade, bool isGrip)
  434. {
  435. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Grip]}");
  436. return false;
  437. }
  438. public override bool GotoMap(ModuleName mod,Hand hand,string extend="EX")
  439. {
  440. if (_status == RState.Running && _currentMessage != null)
  441. {
  442. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto map");
  443. return false;
  444. }
  445. //判断socket是否链接
  446. if (!_socket.IsConnected)
  447. {
  448. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  449. return false;
  450. }
  451. if (!CheckEfemStatus())
  452. return false;
  453. int waferSize = GetModuleNameWaferSize(mod);
  454. if (waferSize == 0)
  455. {
  456. return false;
  457. }
  458. string strModuleWaferSize = $"{mod}_{waferSize}";
  459. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  460. string cmd = $"GOTO N {stationNumber} MAP {extend} ARM {_armString[hand]}\r";
  461. _currentMessage = new EfemMessage()
  462. {
  463. Operation = EfemOperation.Goto,
  464. Module= mod
  465. };
  466. _status = RState.Running;
  467. return WriteCommand(cmd);
  468. }
  469. public override bool Map(ModuleName mod)
  470. {
  471. if (_status == RState.Running && _currentMessage != null)
  472. {
  473. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot map");
  474. return false;
  475. }
  476. //判断socket是否链接
  477. if (!_socket.IsConnected)
  478. {
  479. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  480. return false;
  481. }
  482. if (!CheckEfemStatus())
  483. return false;
  484. int waferSize = GetModuleNameWaferSize(mod);
  485. if (waferSize == 0)
  486. {
  487. return false;
  488. }
  489. string strModuleWaferSize = $"{mod}_{waferSize}";
  490. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  491. _currentMessage = new EfemMessage()
  492. {
  493. Operation = EfemOperation.Home,
  494. Module = mod
  495. };
  496. string cmd = $"MAP {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  497. _status = RState.Running;
  498. return WriteCommand(cmd);
  499. }
  500. public override bool RequestMapResult(ModuleName mod)
  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 request map");
  505. return false;
  506. }
  507. //判断socket是否链接
  508. if (!_socket.IsConnected)
  509. {
  510. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  511. return false;
  512. }
  513. if (!CheckEfemStatus())
  514. return false;
  515. int waferSize = GetModuleNameWaferSize(mod);
  516. if (waferSize == 0)
  517. {
  518. return false;
  519. }
  520. string strModuleWaferSize = $"{mod}_{waferSize}";
  521. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  522. _currentMessage = new EfemMessage()
  523. {
  524. Operation = EfemOperation.RequestMapResult,
  525. Module = mod
  526. };
  527. string cmd = $"RSR {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  528. _status = RState.Running;
  529. return WriteCommand(cmd);
  530. }
  531. public override bool Vacuum(ModuleName mod,bool VacuumState)
  532. {
  533. if (_status == RState.Running && _currentMessage != null)
  534. {
  535. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot vacuum");
  536. return false;
  537. }
  538. //判断socket是否链接
  539. if (!_socket.IsConnected)
  540. {
  541. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  542. return false;
  543. }
  544. _currentMessage = new EfemMessage()
  545. {
  546. Operation = EfemOperation.Vacuum,
  547. Module = mod
  548. };
  549. _status = RState.Running;
  550. string strVacuum = VacuumState ? "ON" : "OFF";
  551. string cmd = $"VAC {strVacuum} ARM {_armString[Hand.Blade1]}\r";
  552. return WriteCommand(cmd);
  553. }
  554. public override bool GetWaferSize(ModuleName mod)
  555. {
  556. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support GetWaferSize");
  557. return false;
  558. }
  559. public override bool SetWaferSize(ModuleName mod, int WaferSize)
  560. {
  561. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support SetWaferSize");
  562. return false;
  563. }
  564. public override bool SetPinUp(ModuleName mod)
  565. {
  566. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  567. return false;
  568. }
  569. public override bool SetPinDown(ModuleName mod)
  570. {
  571. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  572. return false;
  573. }
  574. public override bool SetAlignAngle(ModuleName mod, double angle)
  575. {
  576. if (_status == RState.Running && _currentMessage != null)
  577. {
  578. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Angle");
  579. return false;
  580. }
  581. if (!CheckEfemStatus())
  582. return false;
  583. //判断socket是否链接
  584. if (!_socket.IsConnected)
  585. {
  586. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  587. return false;
  588. }
  589. _currentMessage = new EfemMessage()
  590. {
  591. Operation = EfemOperation.Align,
  592. };
  593. string cmd = $"SET ALIGNER CCDPOS {angle}\r";
  594. _status = RState.Running;
  595. return WriteCommand(cmd);
  596. }
  597. public override bool SetRobotSpeed(ModuleName mod, int speed)
  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 Speed");
  602. return false;
  603. }
  604. //判断socket是否链接
  605. if (!_socket.IsConnected)
  606. {
  607. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  608. return false;
  609. }
  610. _currentMessage = new EfemMessage()
  611. {
  612. Operation = EfemOperation.Speed
  613. };
  614. string cmd = $"SET ACTION SPEEDS {speed}\r";
  615. _status = RState.Running;
  616. return WriteCommand(cmd);
  617. }
  618. public override bool RobotPowerOn(ModuleName mod, bool Status)
  619. {
  620. if (_status == RState.Running && _currentMessage != null)
  621. {
  622. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot PowerOn");
  623. return false;
  624. }
  625. //判断socket是否链接
  626. if (!_socket.IsConnected)
  627. {
  628. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  629. return false;
  630. }
  631. string status = "ON";
  632. if (!Status)
  633. {
  634. status = "OFF";
  635. }
  636. _currentMessage = new EfemMessage()
  637. {
  638. Operation = EfemOperation.PowerOn
  639. };
  640. string cmd = $"SET SERVOS {status}\r";
  641. _status = RState.Running;
  642. return WriteCommand(cmd);
  643. }
  644. public override bool Align(ModuleName mod, double angle, float delayTime, WaferSize size)
  645. {
  646. if (_status == RState.Running && _currentMessage != null)
  647. {
  648. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align");
  649. return false;
  650. }
  651. //判断socket是否链接
  652. if (!_socket.IsConnected)
  653. {
  654. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  655. return false;
  656. }
  657. if (!CheckEfemStatus())
  658. return false;
  659. _currentMessage = new EfemMessage()
  660. {
  661. Operation = EfemOperation.Align
  662. };
  663. _status = RState.Running;
  664. string cmd = "ALIGNER ALGN\r";
  665. return WriteCommand(cmd);
  666. }
  667. public override bool SetLamp(LightType light, LightStatus status)
  668. {
  669. return false;
  670. }
  671. public override bool Load(ModuleName mod)
  672. {
  673. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Load");
  674. return false;
  675. }
  676. public override bool Unload(ModuleName mod)
  677. {
  678. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unload");
  679. return false;
  680. }
  681. public override bool ReadCarrierId(ModuleName mod)
  682. {
  683. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support ReadCarrierId");
  684. return false;
  685. }
  686. public override bool WriteCarrierId(ModuleName mod, string id)
  687. {
  688. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support WriteCarrierId");
  689. return false;
  690. }
  691. public override bool ReadTagData(ModuleName mod)
  692. {
  693. return ReadCarrierId(mod);
  694. }
  695. public override bool WriteTagData(ModuleName mod, string tagData)
  696. {
  697. return WriteCarrierId(mod, tagData);
  698. }
  699. public override bool Dock(ModuleName mod)
  700. {
  701. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Dock");
  702. return false;
  703. }
  704. public override bool Undock(ModuleName mod)
  705. {
  706. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Undock");
  707. return false;
  708. }
  709. public override bool Clamp(ModuleName mod, bool isUnloadClamp)
  710. {
  711. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Clamp");
  712. return false;
  713. }
  714. public override bool Unclamp(ModuleName mod)
  715. {
  716. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unclamp");
  717. return false;
  718. }
  719. public override bool SetThickness(ModuleName mod, string thickness)
  720. {
  721. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.SetThickness]}");
  722. return false;
  723. }
  724. public override void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target)
  725. {
  726. blockingCollection.Add(new RobotAnimationData(action, hand, target));
  727. }
  728. private void OnReceiveMessage(string msg)
  729. {
  730. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), msg.Replace("\r",""));
  731. if (_currentMessage == null)
  732. {
  733. return;
  734. }
  735. if(msg.StartsWith("_ERR"))
  736. {
  737. string error = msg.Replace("_ERR", "").Trim();
  738. OnErrorOccurred(error);
  739. _currentMessage = null;
  740. return;
  741. }
  742. else if(msg.StartsWith("_RDY"))
  743. {
  744. _status = RState.End;
  745. switch (_currentMessage.Operation)
  746. {
  747. case EfemOperation.Home:
  748. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  749. break;
  750. case EfemOperation.Map:
  751. case EfemOperation.GotoMap:
  752. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  753. {
  754. GetLoadPort(_currentMessage.Module).OnMaped();
  755. }
  756. break;
  757. case EfemOperation.Pick:
  758. case EfemOperation.Place:
  759. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot);
  760. break;
  761. }
  762. }
  763. else
  764. {
  765. switch (_currentMessage.Operation)
  766. {
  767. case EfemOperation.StateTrack:
  768. DealStateTrack(msg);
  769. break;
  770. case EfemOperation.RequestMapResult:
  771. DealMapResult(msg);
  772. break;
  773. }
  774. _status = RState.End;
  775. _currentMessage = null;
  776. }
  777. }
  778. /// <summary>
  779. /// 处理StateTrack结果
  780. /// </summary>
  781. /// <param name="msg"></param>
  782. private void DealStateTrack(string msg)
  783. {
  784. if (msg.StartsWith("LOAD"))
  785. {
  786. string[] strAry = msg.Trim().Split(' ');
  787. if (strAry.Length >= 2)
  788. {
  789. bool hasWafer = strAry[2] == "ON" ? true : false;
  790. if (strAry[1] == _armString[Hand.Blade1])
  791. {
  792. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)&& hasWafer)
  793. {
  794. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 0, WaferStatus.Normal);
  795. }
  796. }
  797. else if (strAry[1] == _armString[Hand.Blade2])
  798. {
  799. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && hasWafer)
  800. {
  801. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 1, WaferStatus.Normal);
  802. }
  803. }
  804. }
  805. }
  806. }
  807. /// <summary>
  808. /// 处理Map结果
  809. /// </summary>
  810. /// <param name="msg"></param>
  811. private void DealMapResult(string msg)
  812. {
  813. if (_currentMessage.Operation != EfemOperation.RequestMapResult)
  814. {
  815. return;
  816. }
  817. if(!msg.StartsWith("MAP"))
  818. {
  819. return;
  820. }
  821. string[] sWaferInfo = msg.Split(new char[] { ' ', '\r', '\n' });
  822. if (sWaferInfo.Length <= 2)
  823. {
  824. return;
  825. }
  826. int slotMap = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
  827. WaferType waferType = WaferType.Production;
  828. if (ModuleHelper.IsDummy(_currentMessage.Module))
  829. {
  830. DummyCassetteItem item = DummyCasseteItemManager.Instance.GetDummyCassetteItem(_currentMessage.Module.ToString());
  831. if (item != null)
  832. {
  833. slotMap = item.MaxNumberOfSlots;
  834. }
  835. waferType = WaferType.Assit;
  836. }
  837. int waferSize = GetModuleNameWaferSize(_currentMessage.Module);
  838. //Map 结果(1 1 1 1 1 1 1 ...0)
  839. int startIndex = 1;
  840. int count = slotMap >= sWaferInfo.Length-startIndex? sWaferInfo.Length-startIndex : slotMap;
  841. bool result = true;
  842. for (int index = startIndex; index <= count; index++)
  843. {
  844. int waferState = int.Parse(sWaferInfo[index]);
  845. //合理的映射到内部支持的叠片/交叉片
  846. if (waferState >= 7) waferState = 7;
  847. else if (waferState >= 2) waferState = 3;
  848. WaferStatus st = (WaferStatus)waferState;
  849. if (st != WaferStatus.Empty)
  850. {
  851. WaferManager.Instance.CreateWafer(_currentMessage.Module, index-startIndex, st,(WaferSize)waferSize,waferType);
  852. if (st != WaferStatus.Normal)
  853. {
  854. result = false;
  855. }
  856. }
  857. else
  858. {
  859. WaferManager.Instance.DeleteWafer(_currentMessage.Module, index-startIndex);
  860. }
  861. }
  862. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  863. {
  864. GetLoadPort(_currentMessage.Module).UpdateMapResult(result);
  865. }
  866. }
  867. private void OnErrorOccurred(string errorCode)
  868. {
  869. _status = RState.Failed;
  870. string description = errorCode;
  871. if (SumWayRobotErrorCode.ErrorCodeDescription.ContainsKey(errorCode))
  872. {
  873. description=SumWayRobotErrorCode.ErrorCodeDescription[errorCode];
  874. }
  875. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error, description);
  876. if (_currentMessage != null)
  877. {
  878. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"current operation {_currentMessage.Operation} failed,{description}");
  879. }
  880. _currentMessage=null;
  881. }
  882. private bool WriteCommand(string cmd)
  883. {
  884. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), cmd.Replace("\r", ""));
  885. return _socket.Write(cmd);
  886. }
  887. /// <summary>
  888. /// 获取模块Wafer尺寸
  889. /// </summary>
  890. /// <param name="moduleName"></param>
  891. /// <returns></returns>
  892. private int GetModuleNameWaferSize(ModuleName moduleName)
  893. {
  894. if (ModuleHelper.IsLoadPort(moduleName))
  895. {
  896. Loadport loadport = GetLoadPort(moduleName);
  897. if (!loadport.HasCassette)
  898. {
  899. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  900. return 0;
  901. }
  902. return (int)loadport.WaferSize;
  903. }
  904. else if (ModuleHelper.IsDummy(moduleName))
  905. {
  906. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(moduleName - ModuleName.Dummy1);
  907. if (!dummyDevice.HasCassette)
  908. {
  909. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  910. return 0;
  911. }
  912. return (int)dummyDevice.WaferSize;
  913. }
  914. return 0;
  915. }
  916. /// <summary>
  917. /// 获取模块尺寸
  918. /// </summary>
  919. /// <param name="moduleName"></param>
  920. /// <returns></returns>
  921. private int GetModuleSlotWaferSize(ModuleName moduleName,int slotNumber)
  922. {
  923. if(WaferManager.Instance.CheckHasWafer(moduleName,slotNumber))
  924. {
  925. WaferInfo waferInfo=WaferManager.Instance.GetWafer(moduleName, slotNumber);
  926. return (int)waferInfo.Size;
  927. }
  928. else
  929. {
  930. return 0;
  931. }
  932. }
  933. }
  934. }