SunWayRobot.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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 PunkHPX8_Core;
  8. using PunkHPX8_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 PunkHPX8_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 PunkHPX8_RT.Modules.LPs;
  28. using MECF.Framework.Common.ToolLayout;
  29. namespace PunkHPX8_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. private bool _isResumeRDYReceived = false;
  90. private bool _isPauseRDYReceived = false;
  91. private bool _isActionRDYReceived = false;
  92. private bool _isInPauseStatus = false;
  93. public override bool IsResumeRDYReceived { get { return _isResumeRDYReceived; } }
  94. public override bool IsPauseRDYReceived { get { return _isPauseRDYReceived; } }
  95. public override bool IsActionRDYReceived { get { return _isActionRDYReceived; } }
  96. public override bool IsInPauseStatus { get { return _isInPauseStatus; } }
  97. public SunWayRobot()
  98. {
  99. _socket = new AsyncSocket("","",DataType.Ascii,true);
  100. try
  101. {
  102. _address = SC.GetStringValue($"EFEM.IPAddress");
  103. _socket.Connect(_address);
  104. _socket.OnConnect += Socket_OnConnect;
  105. _socket.OnDataChanged += OnReceiveMessage;
  106. _socket.OnErrorHappened += OnErrorHappen;
  107. }
  108. catch(Exception ex)
  109. {
  110. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", ex.Message);
  111. }
  112. _status = RState.Init;
  113. _IsHomed = false;
  114. _busyTrig.RST = true;
  115. InitializeModuleStation(ModuleName.LP1);
  116. InitializeModuleStation(ModuleName.LP2);
  117. InitializeModuleStation(ModuleName.LP3);
  118. InitializeModuleStation(ModuleName.Dummy1);
  119. InitializeModuleStation(ModuleName.Dummy2);
  120. InitializeModuleStation(ModuleName.Aligner1);
  121. InitializeModuleStation(ModuleName.SRD1);
  122. InitializeModuleStation(ModuleName.SRD2);
  123. InitializeModuleStation(ModuleName.VPW1);
  124. InitializeModuleStation(ModuleName.VPW2);
  125. InitializeModuleStation(ModuleName.PlatingCell1);
  126. InitializeModuleStation(ModuleName.PlatingCell2);
  127. InitializeModuleStation(ModuleName.PlatingCell3);
  128. InitializeModuleStation(ModuleName.PlatingCell4);
  129. CarrierManager.Instance.SubscribeLocation(ModuleName.LP1.ToString(), 1);
  130. CarrierManager.Instance.SubscribeLocation(ModuleName.LP2.ToString(), 1);
  131. CarrierManager.Instance.SubscribeLocation(ModuleName.LP3.ToString(), 1);
  132. WaferManager.Instance.SubscribeLocation(ModuleName.EfemRobot, 2);
  133. WaferManager.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  134. WaferManager.Instance.SubscribeLocation(ModuleName.LP1, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  135. WaferManager.Instance.SubscribeLocation(ModuleName.LP2, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  136. WaferManager.Instance.SubscribeLocation(ModuleName.LP3, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
  137. Task.Run(() =>
  138. {
  139. foreach (var data in blockingCollection.GetConsumingEnumerable())
  140. {
  141. _robotMoveInfo.Action = data.Action;
  142. _robotMoveInfo.ArmTarget = data.Hand == Hand.Blade1 ? RobotArm.ArmA : (data.Hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
  143. _robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{data.Target}";
  144. System.Threading.Thread.Sleep(600);
  145. }
  146. });
  147. }
  148. /// <summary>
  149. /// 初始化Module Station
  150. /// </summary>
  151. /// <param name="module"></param>
  152. private void InitializeModuleStation(ModuleName module)
  153. {
  154. int cassete200Station = SC.GetValue<int>($"EFEM.{module}.Cassete200Station");
  155. _moduleStationNumberDictionary[$"{module}_200"] = cassete200Station;
  156. int cassete150Station = SC.GetValue<int>($"EFEM.{module}.Cassete150Station");
  157. _moduleStationNumberDictionary[$"{module}_150"] = cassete150Station;
  158. int cassete100Station = SC.GetValue<int>($"EFEM.{module}.Cassete100Station");
  159. _moduleStationNumberDictionary[$"{module}_100"]=cassete100Station;
  160. }
  161. private void Socket_OnConnect()
  162. {
  163. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
  164. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), $"connect {_address} success");
  165. }
  166. private void OnErrorHappen(ErrorEventArgs args)
  167. {
  168. _status = RState.Failed;
  169. if (_error != args.Reason)
  170. {
  171. _error = args.Reason;
  172. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"{Module} {_error}");
  173. }
  174. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
  175. }
  176. public override void Monitor()
  177. {
  178. }
  179. public override void Terminate()
  180. {
  181. }
  182. public override void Reset()
  183. {
  184. _status = RState.End;
  185. _currentMessage = null;
  186. }
  187. public override void SetOnline(bool online)
  188. {
  189. }
  190. public override void SetOnline(ModuleName mod, bool online)
  191. {
  192. }
  193. public override void SetBusy(ModuleName mod, bool online)
  194. {
  195. _status = RState.Running;
  196. }
  197. public override bool HomeAll()
  198. {
  199. if (_status == RState.Running&&_currentMessage!=null)
  200. {
  201. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home All");
  202. return false;
  203. }
  204. //判断socket是否链接
  205. if (!_socket.IsConnected)
  206. {
  207. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  208. return false ;
  209. }
  210. _status = RState.Running;
  211. string data = "HOME ALL\r";
  212. _currentMessage =new EfemMessage(){
  213. Operation= EfemOperation.Home,
  214. Module=ModuleName.EFEM
  215. };
  216. //SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  217. return WriteCommand(data);
  218. }
  219. public override bool Home(ModuleName mod)
  220. {
  221. if (_status == RState.Running && _currentMessage!= null)
  222. {
  223. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home {mod}");
  224. return false;
  225. }
  226. if (mod != ModuleName.Aligner1&&mod!=ModuleName.EfemRobot)
  227. {
  228. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{mod} can not support home method");
  229. return false;
  230. }
  231. //判断socket是否链接
  232. if (!_socket.IsConnected)
  233. {
  234. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  235. return false;
  236. }
  237. if(mod == ModuleName.EfemRobot) SetRobotMovingInfo(RobotAction.Homing, Hand.Blade1, ModuleName.EfemRobot);
  238. _status = RState.Running;
  239. string cmd = "Home ALL\r";
  240. if (mod == ModuleName.Aligner1)
  241. {
  242. cmd = "ALIGNER HOME\r";
  243. }
  244. _currentMessage = new EfemMessage()
  245. {
  246. Operation = EfemOperation.Home,
  247. Module = ModuleName.Aligner1
  248. };
  249. return WriteCommand(cmd);
  250. }
  251. public override bool OriginalSearch(ModuleName mod)
  252. {
  253. return true;
  254. }
  255. public override bool CheckWaferPresence()
  256. {
  257. if (_status == RState.Running && _currentMessage != null)
  258. {
  259. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot check wafer");
  260. return false;
  261. }
  262. //判断socket是否链接
  263. if (!_socket.IsConnected)
  264. {
  265. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  266. return false;
  267. }
  268. if (!CheckEfemStatus())
  269. return false;
  270. _currentMessage = new EfemMessage()
  271. {
  272. Operation = EfemOperation.StateTrack,
  273. Module = ModuleName.EfemRobot
  274. };
  275. _status = RState.Running;
  276. string cmd = $"RQ LOAD {_armString[Hand.Blade1]}\r";
  277. return WriteCommand(cmd);
  278. }
  279. public override string GetWaferPresence()
  280. {
  281. return "";
  282. }
  283. public override bool Halt()
  284. {
  285. //判断socket是否链接
  286. if (!_socket.IsConnected)
  287. {
  288. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  289. return false;
  290. }
  291. _currentMessage = new EfemMessage()
  292. {
  293. Operation = EfemOperation.Abort,
  294. Module = ModuleName.EfemRobot
  295. };
  296. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EFEM);
  297. string cmd = "HALT\r";
  298. return WriteCommand(cmd);
  299. }
  300. public override bool Pause()
  301. {
  302. //判断socket是否链接
  303. if (!_socket.IsConnected)
  304. {
  305. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  306. return false;
  307. }
  308. string cmd = "PAUSE\r";
  309. bool result = WriteCommand(cmd);
  310. if (result)
  311. {
  312. _isInPauseStatus = true; //进入pause状态
  313. }
  314. else
  315. {
  316. _isInPauseStatus = false;
  317. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Send pause message error");
  318. }
  319. return result;
  320. }
  321. public override bool Resume()
  322. {
  323. _isActionRDYReceived = false; //把收到resume信号后执行resume动作成功的变量置false
  324. //判断socket是否链接
  325. if (!_socket.IsConnected)
  326. {
  327. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  328. return false;
  329. }
  330. string cmd = "RESUME\r";
  331. return WriteCommand(cmd);
  332. }
  333. public override bool ClearError()
  334. {
  335. return true;
  336. }
  337. public override bool CloseBuzzer()
  338. {
  339. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.TurnOffBuzzer]}");
  340. return false;
  341. }
  342. public override bool PickExtend(ModuleName chamber, int slot, Hand hand)
  343. {
  344. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  345. return false;
  346. }
  347. public override bool PickRetract(ModuleName chamber, int slot, Hand hand)
  348. {
  349. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  350. return false;
  351. }
  352. public override bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
  353. {
  354. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  355. return false;
  356. }
  357. public override bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
  358. {
  359. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
  360. return false;
  361. }
  362. public override bool Pick(ModuleName station, int slot, Hand hand, Flip flip)
  363. {
  364. if (_status == RState.Running && _currentMessage != null)
  365. {
  366. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot pick");
  367. return false;
  368. }
  369. //判断socket是否链接
  370. if (!_socket.IsConnected)
  371. {
  372. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  373. return false;
  374. }
  375. //判断Loadport的门是否打开
  376. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  377. //{
  378. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  379. // return false;
  380. //}
  381. if (!CheckEfemStatus())
  382. return false;
  383. int waferSize = GetModuleSlotWaferSize(station,slot);
  384. if (waferSize == 0)
  385. {
  386. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Pick Action");
  387. return false;
  388. }
  389. string strModuleWaferSize = $"{station}_{waferSize}";
  390. if (!_moduleStationNumberDictionary.ContainsKey(strModuleWaferSize))
  391. {
  392. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s number is not exist, Cannot Execute Pick Action");
  393. return false;
  394. }
  395. int stationNumber= _moduleStationNumberDictionary[strModuleWaferSize];
  396. string strFlip = flip == Flip.Down ? " FLIP" : "";
  397. string cmd = $"PICK {stationNumber} SLOT {slot+1} ARM {_armString[hand]}{strFlip}\r";
  398. if(ModuleHelper.IsAligner(station)||ModuleHelper.IsSRD(station)||ModuleHelper.IsVPWCell(station) || ModuleHelper.IsPlatingCell(station))
  399. {
  400. cmd = $"PICK {stationNumber} SLOT 1 ARM {_armString[hand]}{strFlip}\r";
  401. }
  402. _currentMessage = new EfemMessage()
  403. {
  404. Operation=EfemOperation.Pick
  405. };
  406. _status = RState.Running;
  407. SetRobotMovingInfo(RobotAction.Picking, hand, station);
  408. return WriteCommand(cmd);
  409. }
  410. private Loadport GetLoadPort(ModuleName station)
  411. {
  412. LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
  413. return loadPortModule.LPDevice;
  414. }
  415. public override bool Place(ModuleName station, int slot, Hand hand,Flip flip)
  416. {
  417. if (_status == RState.Running && _currentMessage != null)
  418. {
  419. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot place");
  420. return false;
  421. }
  422. //判断socket是否链接
  423. if (!_socket.IsConnected)
  424. {
  425. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  426. return false;
  427. }
  428. //判断Loadport的门是否打开
  429. //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
  430. //{
  431. // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
  432. // return false;
  433. //}
  434. if (!CheckEfemStatus())
  435. return false;
  436. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, (int)hand);
  437. if (waferSize == 0)
  438. {
  439. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station} slot {slot} wafer size is 0, Cannot Execute Place Action");
  440. return false;
  441. }
  442. string strModuleWaferSize = $"{station}_{waferSize}";
  443. _currentMessage = new EfemMessage()
  444. {
  445. Operation = EfemOperation.Place
  446. };
  447. _status = RState.Running;
  448. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  449. string strFlip = flip == Flip.Down ? " FLIP" : "";
  450. string cmd = $"PLACE {stationNumber} SLOT {slot+1} ARM {_armString[hand]}{strFlip}\r";
  451. if (ModuleHelper.IsSRD(station) || ModuleHelper.IsVPWCell(station) || ModuleHelper.IsPlatingCell(station))
  452. {
  453. cmd = $"PLACE {stationNumber} SLOT 1 ARM {_armString[hand]}{strFlip}\r";
  454. }
  455. if (ModuleHelper.IsAligner(station))
  456. {
  457. cmd = $"PLACE {stationNumber} PHOME\r";
  458. }
  459. SetRobotMovingInfo(RobotAction.Placing, hand, station);
  460. return WriteCommand(cmd);
  461. }
  462. public override bool Goto(ModuleName station, Hand hand, string updown = "UP")
  463. {
  464. if (_status == RState.Running && _currentMessage != null)
  465. {
  466. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto");
  467. return false;
  468. }
  469. if (!CheckEfemStatus())
  470. return false;
  471. //判断socket是否链接
  472. if (!_socket.IsConnected)
  473. {
  474. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  475. return false;
  476. }
  477. _currentMessage = new EfemMessage()
  478. {
  479. Operation = EfemOperation.Goto
  480. };
  481. int waferSize = GetModuleNameWaferSize(station);
  482. if (waferSize == 0)
  483. {
  484. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  485. return false;
  486. }
  487. string strModuleWaferSize = $"{station}_{waferSize}";
  488. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  489. string cmd = $"GOTO N {stationNumber} R EX Z {updown} ARM SLOT 1 {_armString[hand]}\r";
  490. _status = RState.Running;
  491. return WriteCommand(cmd);
  492. }
  493. public override bool Grip(Hand blade, bool isGrip)
  494. {
  495. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Grip]}");
  496. return false;
  497. }
  498. public override bool GotoMap(ModuleName mod,Hand hand,string extend="EX")
  499. {
  500. if (_status == RState.Running && _currentMessage != null)
  501. {
  502. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto map");
  503. return false;
  504. }
  505. //判断socket是否链接
  506. if (!_socket.IsConnected)
  507. {
  508. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  509. return false;
  510. }
  511. if (!CheckEfemStatus())
  512. return false;
  513. int waferSize = GetModuleNameWaferSize(mod);
  514. if (waferSize == 0)
  515. {
  516. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  517. return false;
  518. }
  519. string strModuleWaferSize = $"{mod}_{waferSize}";
  520. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  521. string cmd = $"GOTO N {stationNumber} MAP {extend} ARM {_armString[hand]}\r";
  522. _currentMessage = new EfemMessage()
  523. {
  524. Operation = EfemOperation.Goto,
  525. Module= mod
  526. };
  527. _status = RState.Running;
  528. return WriteCommand(cmd);
  529. }
  530. public override bool Map(ModuleName mod)
  531. {
  532. if (_status == RState.Running && _currentMessage != null)
  533. {
  534. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot map");
  535. return false;
  536. }
  537. //判断socket是否链接
  538. if (!_socket.IsConnected)
  539. {
  540. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  541. return false;
  542. }
  543. if (!CheckEfemStatus())
  544. return false;
  545. int waferSize = GetModuleNameWaferSize(mod);
  546. if (waferSize == 0)
  547. {
  548. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  549. return false;
  550. }
  551. string strModuleWaferSize = $"{mod}_{waferSize}";
  552. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  553. _currentMessage = new EfemMessage()
  554. {
  555. Operation = EfemOperation.Map,
  556. Module = mod
  557. };
  558. string cmd = $"MAP {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  559. _status = RState.Running;
  560. return WriteCommand(cmd);
  561. }
  562. public override bool RequestMapResult(ModuleName mod)
  563. {
  564. if (_status == RState.Running && _currentMessage != null)
  565. {
  566. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot request map");
  567. return false;
  568. }
  569. //判断socket是否链接
  570. if (!_socket.IsConnected)
  571. {
  572. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  573. return false;
  574. }
  575. if (!CheckEfemStatus())
  576. return false;
  577. int waferSize = GetModuleNameWaferSize(mod);
  578. if (waferSize == 0)
  579. {
  580. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"wafersize is 0");
  581. return false;
  582. }
  583. string strModuleWaferSize = $"{mod}_{waferSize}";
  584. int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
  585. _currentMessage = new EfemMessage()
  586. {
  587. Operation = EfemOperation.RequestMapResult,
  588. Module = mod
  589. };
  590. string cmd = $"RSR {stationNumber} ARM {_armString[Hand.Blade1]}\r";
  591. _status = RState.Running;
  592. return WriteCommand(cmd);
  593. }
  594. public override bool Vacuum(ModuleName mod,bool VacuumState)
  595. {
  596. if (_status == RState.Running && _currentMessage != null)
  597. {
  598. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot vacuum");
  599. return false;
  600. }
  601. //判断socket是否链接
  602. if (!_socket.IsConnected)
  603. {
  604. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  605. return false;
  606. }
  607. _currentMessage = new EfemMessage()
  608. {
  609. Operation = EfemOperation.Vacuum,
  610. Module = mod
  611. };
  612. _status = RState.Running;
  613. string strVacuum = VacuumState ? "ON" : "OFF";
  614. string cmd = "";
  615. if (ModuleName.Aligner1 == mod)
  616. {
  617. cmd = $"ALIGNER VAC {strVacuum}\r";
  618. }
  619. else
  620. {
  621. cmd = $"VAC {strVacuum} ARM {_armString[Hand.Blade1]}\r";
  622. }
  623. return WriteCommand(cmd);
  624. }
  625. public override bool GetWaferSize(ModuleName mod)
  626. {
  627. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support GetWaferSize");
  628. return false;
  629. }
  630. public override bool SetWaferSize(ModuleName mod, int WaferSize)
  631. {
  632. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support SetWaferSize");
  633. return false;
  634. }
  635. public override bool SetPinUp(ModuleName mod)
  636. {
  637. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  638. return false;
  639. }
  640. public override bool SetPinDown(ModuleName mod)
  641. {
  642. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
  643. return false;
  644. }
  645. public override bool SetAlignWaferSize()
  646. {
  647. if (_status == RState.Running && _currentMessage != null)
  648. {
  649. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Wafer Size");
  650. return false;
  651. }
  652. if (!CheckEfemStatus())
  653. return false;
  654. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  655. {
  656. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} has no wafer, Cannot Execute Set aligner wafersize");
  657. return false;
  658. }
  659. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, 0);
  660. if (waferSize == 0)
  661. {
  662. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} wafer size is 0, Cannot Execute Set aligner wafersize");
  663. return false;
  664. }
  665. //判断socket是否链接
  666. if (!_socket.IsConnected)
  667. {
  668. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  669. return false;
  670. }
  671. _currentMessage = new EfemMessage()
  672. {
  673. Operation = EfemOperation.AlignWaferSize
  674. };
  675. string cmd = $"SET ALIGNER WAFERSIZE {waferSize}\r";
  676. _status = RState.Running;
  677. return WriteCommand(cmd);
  678. }
  679. public override bool SetAlignFlatType(int flatType)
  680. {
  681. if (_status == RState.Running && _currentMessage != null)
  682. {
  683. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align flat type");
  684. return false;
  685. }
  686. if (!CheckEfemStatus())
  687. return false;
  688. //判断socket是否链接
  689. if (!_socket.IsConnected)
  690. {
  691. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  692. return false;
  693. }
  694. _currentMessage = new EfemMessage()
  695. {
  696. Operation = EfemOperation.AlignFlatType
  697. };
  698. string cmd = $"SET ALIGNER WAFERTYPE {flatType}\r";
  699. _status = RState.Running;
  700. return WriteCommand(cmd);
  701. }
  702. public override bool SetAlignDistance()
  703. {
  704. int distance200 = SC.GetValue<int>("EFEM.Aligner1.Aligner200Distance");
  705. int distance150 = SC.GetValue<int>("EFEM.Aligner1.Aligner150Distance");
  706. int distance100 = SC.GetValue<int>("EFEM.Aligner1.Aligner100Distance");
  707. if (_status == RState.Running && _currentMessage != null)
  708. {
  709. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align flat type");
  710. return false;
  711. }
  712. if (!CheckEfemStatus())
  713. return false;
  714. //判断socket是否链接
  715. if (!_socket.IsConnected)
  716. {
  717. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  718. return false;
  719. }
  720. if (!WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  721. {
  722. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} has no wafer, Cannot Execute Set aligner wafersize");
  723. return false;
  724. }
  725. int waferSize = GetModuleSlotWaferSize(ModuleName.EfemRobot, 0);
  726. if (waferSize == 0)
  727. {
  728. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{ModuleName.EfemRobot} wafer size is 0, Cannot Execute Set aligner wafersize");
  729. return false;
  730. }
  731. _currentMessage = new EfemMessage()
  732. {
  733. Operation = EfemOperation.AlignDistance
  734. };
  735. int distance = distance200;
  736. if (waferSize == (int)WaferSize.WS6)
  737. {
  738. distance = distance150;
  739. }
  740. else if (waferSize == (int)WaferSize.WS4)
  741. {
  742. distance = distance100;
  743. }
  744. string cmd = $"SET ALIGNER WAFERDISTANCE {distance}\r";
  745. _status = RState.Running;
  746. return WriteCommand(cmd);
  747. }
  748. public override bool SetAlignAngle(ModuleName mod, double angle)
  749. {
  750. if (_status == RState.Running && _currentMessage != null)
  751. {
  752. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Angle");
  753. return false;
  754. }
  755. if (!CheckEfemStatus())
  756. return false;
  757. //判断socket是否链接
  758. if (!_socket.IsConnected)
  759. {
  760. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  761. return false;
  762. }
  763. _currentMessage = new EfemMessage()
  764. {
  765. Operation = EfemOperation.Align,
  766. };
  767. string cmd = $"SET ALIGNER POSTPOS 1 POS {angle*1000}\r";
  768. _status = RState.Running;
  769. return WriteCommand(cmd);
  770. }
  771. public override bool SetRobotSpeed(ModuleName mod, int speed)
  772. {
  773. if (_status == RState.Running && _currentMessage != null)
  774. {
  775. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Speed");
  776. return false;
  777. }
  778. //判断socket是否链接
  779. if (!_socket.IsConnected)
  780. {
  781. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  782. return false;
  783. }
  784. _currentMessage = new EfemMessage()
  785. {
  786. Operation = EfemOperation.Speed
  787. };
  788. string cmd = $"SET ACTION SPEEDS {speed}\r";
  789. _status = RState.Running;
  790. return WriteCommand(cmd);
  791. }
  792. public override bool RobotPowerOn(ModuleName mod, bool Status)
  793. {
  794. if (_status == RState.Running && _currentMessage != null)
  795. {
  796. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot PowerOn");
  797. return false;
  798. }
  799. //判断socket是否链接
  800. if (!_socket.IsConnected)
  801. {
  802. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  803. return false;
  804. }
  805. string status = Status? "ON":"OFF";
  806. _currentMessage = new EfemMessage()
  807. {
  808. Operation = EfemOperation.PowerOn
  809. };
  810. string cmd = $"SET SERVOS {status}\r";
  811. _status = RState.Running;
  812. return WriteCommand(cmd);
  813. }
  814. public override bool Align(ModuleName mod, double angle, float delayTime, WaferSize size)
  815. {
  816. if (_status == RState.Running && _currentMessage != null)
  817. {
  818. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align");
  819. return false;
  820. }
  821. //判断socket是否链接
  822. if (!_socket.IsConnected)
  823. {
  824. LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
  825. return false;
  826. }
  827. if (!CheckEfemStatus())
  828. return false;
  829. _currentMessage = new EfemMessage()
  830. {
  831. Operation = EfemOperation.Align
  832. };
  833. _status = RState.Running;
  834. string cmd = "ALIGNER ALGN\r";
  835. return WriteCommand(cmd);
  836. }
  837. public override bool SetLamp(LightType light, LightStatus status)
  838. {
  839. return false;
  840. }
  841. public override bool Load(ModuleName mod)
  842. {
  843. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Load");
  844. return false;
  845. }
  846. public override bool Unload(ModuleName mod)
  847. {
  848. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unload");
  849. return false;
  850. }
  851. public override bool ReadCarrierId(ModuleName mod)
  852. {
  853. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support ReadCarrierId");
  854. return false;
  855. }
  856. public override bool WriteCarrierId(ModuleName mod, string id)
  857. {
  858. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support WriteCarrierId");
  859. return false;
  860. }
  861. public override bool ReadTagData(ModuleName mod)
  862. {
  863. return ReadCarrierId(mod);
  864. }
  865. public override bool WriteTagData(ModuleName mod, string tagData)
  866. {
  867. return WriteCarrierId(mod, tagData);
  868. }
  869. public override bool Dock(ModuleName mod)
  870. {
  871. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Dock");
  872. return false;
  873. }
  874. public override bool Undock(ModuleName mod)
  875. {
  876. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Undock");
  877. return false;
  878. }
  879. public override bool Clamp(ModuleName mod, bool isUnloadClamp)
  880. {
  881. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Clamp");
  882. return false;
  883. }
  884. public override bool Unclamp(ModuleName mod)
  885. {
  886. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unclamp");
  887. return false;
  888. }
  889. public override bool SetThickness(ModuleName mod, string thickness)
  890. {
  891. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.SetThickness]}");
  892. return false;
  893. }
  894. public override void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target)
  895. {
  896. blockingCollection.Add(new RobotAnimationData(action, hand, target));
  897. }
  898. private void OnReceiveMessage(string msg)
  899. {
  900. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), msg.Replace("\r",""));
  901. if (_currentMessage == null)
  902. {
  903. return;
  904. }
  905. if(msg.Contains("_ERR"))
  906. {
  907. string error = msg.Replace("_ERR", "").Trim();
  908. OnErrorOccurred(error);
  909. _currentMessage = null;
  910. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EFEM);
  911. return;
  912. }
  913. else if (msg.StartsWith("ACTION _RDY"))
  914. {
  915. _status = RState.End;
  916. _isResumeRDYReceived = false;
  917. _isPauseRDYReceived = false;
  918. _isActionRDYReceived = true;
  919. }
  920. else if (msg.StartsWith("_RDY"))
  921. {
  922. _status = RState.End;
  923. switch (_currentMessage.Operation)
  924. {
  925. case EfemOperation.Home:
  926. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
  927. break;
  928. case EfemOperation.Map:
  929. case EfemOperation.GotoMap:
  930. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  931. {
  932. GetLoadPort(_currentMessage.Module).OnMaped();
  933. }
  934. break;
  935. case EfemOperation.Pick:
  936. case EfemOperation.Place:
  937. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.EfemRobot);
  938. break;
  939. }
  940. }
  941. else if (msg.Contains("PAUSE _RDY"))
  942. {
  943. _isPauseRDYReceived = true;
  944. _isResumeRDYReceived = false; //收到pause把收到resume的信号置false
  945. LOG.WriteLog(eEvent.INFO_TM_ROBOT, Module.ToString(), $"PAUSE_RDY was received, robot pause status is true");
  946. }
  947. else if (msg.Contains("RESUME _RDY"))
  948. {
  949. _isResumeRDYReceived = true;
  950. _isPauseRDYReceived = false; //收到Resume把收到pause的信号置false
  951. _isInPauseStatus = false; //取消pause状态
  952. LOG.WriteLog(eEvent.INFO_TM_ROBOT, Module.ToString(), $"RESUME _RDY was received, robot pause status is false");
  953. }
  954. else
  955. {
  956. switch (_currentMessage.Operation)
  957. {
  958. case EfemOperation.StateTrack:
  959. DealStateTrack(msg);
  960. break;
  961. case EfemOperation.RequestMapResult:
  962. DealMapResult(msg);
  963. break;
  964. }
  965. _status = RState.End;
  966. _currentMessage = null;
  967. }
  968. }
  969. /// <summary>
  970. /// 处理StateTrack结果
  971. /// </summary>
  972. /// <param name="msg"></param>
  973. private void DealStateTrack(string msg)
  974. {
  975. if (msg.StartsWith("LOAD"))
  976. {
  977. string[] strAry = msg.Trim().Split(' ');
  978. if (strAry.Length >= 2)
  979. {
  980. bool hasWafer = strAry[2] == "ON" ? true : false;
  981. if (strAry[1] == _armString[Hand.Blade1])
  982. {
  983. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)&& hasWafer)
  984. {
  985. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 0, WaferStatus.Normal);
  986. }
  987. }
  988. else if (strAry[1] == _armString[Hand.Blade2])
  989. {
  990. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && hasWafer)
  991. {
  992. WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 1, WaferStatus.Normal);
  993. }
  994. }
  995. }
  996. }
  997. }
  998. /// <summary>
  999. /// 处理Map结果
  1000. /// </summary>
  1001. /// <param name="msg"></param>
  1002. private void DealMapResult(string msg)
  1003. {
  1004. if (_currentMessage.Operation != EfemOperation.RequestMapResult)
  1005. {
  1006. return;
  1007. }
  1008. if(!msg.StartsWith("MAP"))
  1009. {
  1010. return;
  1011. }
  1012. string[] sWaferInfo = msg.Split(new char[] { ' ', '\r', '\n' });
  1013. if (sWaferInfo.Length <= 2)
  1014. {
  1015. return;
  1016. }
  1017. int slotMap = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
  1018. WaferType waferType = WaferType.Production;
  1019. if (ModuleHelper.IsDummy(_currentMessage.Module))
  1020. {
  1021. DummyCassetteItem item = DummyCasseteItemManager.Instance.GetDummyCassetteItem(_currentMessage.Module.ToString());
  1022. if (item != null)
  1023. {
  1024. slotMap = item.MaxNumberOfSlots;
  1025. }
  1026. waferType = WaferType.Assit;
  1027. }
  1028. int waferSize = GetModuleNameWaferSize(_currentMessage.Module);
  1029. //Map 结果(1 1 1 1 1 1 1 ...0)
  1030. int startIndex = 1;
  1031. int count = slotMap >= sWaferInfo.Length-startIndex? sWaferInfo.Length-startIndex : slotMap;
  1032. bool result = true;
  1033. for (int index = startIndex; index <= count; index++)
  1034. {
  1035. string strState = sWaferInfo[index];
  1036. int waferState = 0;
  1037. //合理的映射到内部支持的叠片/交叉片
  1038. if (strState == "1") waferState = (int)WaferStatus.Normal;
  1039. else if (strState == "2") waferState = (int)WaferStatus.Double;
  1040. else if (strState == "3") waferState = (int)WaferStatus.Crossed;
  1041. else if (strState == "5") waferState = (int)WaferStatus.Thin;
  1042. else if(strState=="?") waferState=(int)WaferStatus.Unknown;
  1043. WaferStatus st = (WaferStatus)waferState;
  1044. if (st != WaferStatus.Empty)
  1045. {
  1046. WaferManager.Instance.CreateWafer(_currentMessage.Module, index-startIndex, st,(WaferSize)waferSize,waferType);
  1047. if (st != WaferStatus.Normal)
  1048. {
  1049. result = false;
  1050. }
  1051. }
  1052. else
  1053. {
  1054. WaferManager.Instance.DeleteWafer(_currentMessage.Module, index-startIndex);
  1055. }
  1056. }
  1057. if (!result)
  1058. {
  1059. LOG.WriteLog(eEvent.ERROR_EFEM_ERROR_WAFER, Module.ToString(), $"{_currentMessage.Module} slot map failed {msg}");
  1060. }
  1061. if (ModuleHelper.IsLoadPort(_currentMessage.Module))
  1062. {
  1063. GetLoadPort(_currentMessage.Module).UpdateMapResult(result);
  1064. }
  1065. }
  1066. private void OnErrorOccurred(string errorCode)
  1067. {
  1068. _status = RState.Failed;
  1069. string description = errorCode;
  1070. if (SumWayRobotErrorCode.ErrorCodeDescription.ContainsKey(errorCode))
  1071. {
  1072. description=SumWayRobotErrorCode.ErrorCodeDescription[errorCode];
  1073. }
  1074. Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error, description);
  1075. if (_currentMessage != null)
  1076. {
  1077. LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"current operation {_currentMessage.Operation} failed,{description}");
  1078. }
  1079. _currentMessage=null;
  1080. }
  1081. private bool WriteCommand(string cmd)
  1082. {
  1083. LOG.WriteLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), cmd.Replace("\r", ""));
  1084. return _socket.Write(cmd);
  1085. }
  1086. /// <summary>
  1087. /// 获取模块Wafer尺寸
  1088. /// </summary>
  1089. /// <param name="moduleName"></param>
  1090. /// <returns></returns>
  1091. private int GetModuleNameWaferSize(ModuleName moduleName)
  1092. {
  1093. if (ModuleHelper.IsLoadPort(moduleName))
  1094. {
  1095. Loadport loadport = GetLoadPort(moduleName);
  1096. if (!loadport.HasCassette)
  1097. {
  1098. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  1099. return 0;
  1100. }
  1101. return (int)loadport.WaferSize;
  1102. }
  1103. else if (ModuleHelper.IsDummy(moduleName))
  1104. {
  1105. DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(moduleName - ModuleName.Dummy1);
  1106. if (!dummyDevice.HasCassette)
  1107. {
  1108. LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
  1109. return 0;
  1110. }
  1111. return (int)dummyDevice.WaferSize;
  1112. }
  1113. return 0;
  1114. }
  1115. /// <summary>
  1116. /// 获取模块尺寸
  1117. /// </summary>
  1118. /// <param name="moduleName"></param>
  1119. /// <returns></returns>
  1120. private int GetModuleSlotWaferSize(ModuleName moduleName,int slotNumber)
  1121. {
  1122. if(WaferManager.Instance.CheckHasWafer(moduleName,slotNumber))
  1123. {
  1124. WaferInfo waferInfo=WaferManager.Instance.GetWafer(moduleName, slotNumber);
  1125. return (int)waferInfo.Size;
  1126. }
  1127. else
  1128. {
  1129. return 0;
  1130. }
  1131. }
  1132. }
  1133. }