SunWayRobot.cs 40 KB

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