SunWayRobot.cs 38 KB

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