SunWayRobot.cs 37 KB

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