SunWayRobot.cs 37 KB

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