SunWayRobot.cs 37 KB

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