SunWayRobot.cs 38 KB

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