Robot.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.DataCenter;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using TSC = Aitex.Sorter.Common;
  10. using Aitex.Core.RT.Device;
  11. using Aitex.Core.RT.SCCore;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using Aitex.Core.RT.OperationCenter;
  15. using MECF.Framework.Common.Communications;
  16. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot
  17. {
  18. public enum RobotType
  19. {
  20. SR100,
  21. NX100,
  22. MAG7,
  23. }
  24. public class Robot : BaseDevice, IDevice, IConnection
  25. {
  26. public event Action<ModuleName, string> OnSlotMapRead;
  27. public string Address
  28. {
  29. get { return _addr; }
  30. }
  31. public bool IsConnected
  32. {
  33. get { return _socket.IsConnected; }
  34. }
  35. public bool Disconnect()
  36. {
  37. return true;
  38. }
  39. public const string delimiter = "\r";
  40. public int LastErrorCode { get; set; }
  41. public int Status { get; set; }
  42. public int ErrorCode { get; set; }
  43. public int ElapseTime { get; set; }
  44. public int Speed { get; set; }
  45. public int Rotation { get; set; }
  46. public int Extension { get; set; }
  47. public int Wrist1 { get; set; }
  48. public int Wrist2 { get; set; }
  49. public int Evevation { get; set; }
  50. public bool StateWaferOnBlade1 { get; set; }
  51. public bool StateWaferOnBlade2 { get; set; }
  52. public bool StateBlade1Gripped { get; set; }
  53. public bool StateBlade2Gripped { get; set; }
  54. public bool StateInterlock1 { get; set; }
  55. public bool StateInterlock2 { get; set; }
  56. public bool StateInterlock3 { get; set; }
  57. public bool StateInterlock4 { get; set; }
  58. public bool StateInterlock5 { get; set; }
  59. public bool StateInterlock6 { get; set; }
  60. public bool StateInterlock7 { get; set; }
  61. public bool StateInterlock8 { get; set; }
  62. public bool Swap { get; set; }
  63. public Hand PlaceBalde { get; set; }
  64. public ModuleName Blade1Target
  65. {
  66. get;
  67. set;
  68. }
  69. public ModuleName Blade2Target { get; set; }
  70. //naming follow PM1.A LL1.A PM2.B
  71. public string CmdBladeTarget { get; set; }
  72. //naming follow 0 1
  73. public string CmdBlade1Extend { get; set; }
  74. //naming follow 0 1
  75. public string CmdBlade2Extend { get; set; }
  76. public bool Blade1Enable
  77. {
  78. get
  79. {
  80. if (SC.ContainsItem($"{Name}.Blade1Enable"))
  81. {
  82. return SC.GetValue<bool>($"{Name}.Blade1Enable");
  83. }
  84. return SC.GetValue<bool>($"Robot.Blade1Enable");
  85. }
  86. set
  87. {
  88. if (SC.ContainsItem($"{Name}.Blade1Enable"))
  89. {
  90. SC.SetItemValue($"{Name}.Blade1Enable", value);
  91. }else if (SC.ContainsItem($"Robot.Blade1Enable"))
  92. {
  93. SC.SetItemValue($"Robot.Blade1Enable", value);
  94. }
  95. }
  96. }
  97. public bool Blade2Enable
  98. {
  99. get
  100. {
  101. if (SC.ContainsItem($"{Name}.Blade2Enable"))
  102. {
  103. return SC.GetValue<bool>($"{Name}.Blade2Enable");
  104. }
  105. return SC.GetValue<bool>($"Robot.Blade2Enable");
  106. }
  107. set
  108. {
  109. if (SC.ContainsItem($"{Name}.Blade2Enable"))
  110. {
  111. SC.SetItemValue($"{Name}.Blade2Enable", value);
  112. }
  113. else if (SC.ContainsItem($"Robot.Blade2Enable"))
  114. {
  115. SC.SetItemValue($"Robot.Blade2Enable", value);
  116. }
  117. }
  118. }
  119. public int Blade2Slots
  120. {
  121. get
  122. {
  123. if (SC.ContainsItem($"{Name}.Blade2Slots"))
  124. {
  125. return Math.Max(SC.GetValue<int>($"{Name}.Blade2Slots"), 1);
  126. }
  127. if (SC.ContainsItem($"Robot.Blade2Slots"))
  128. {
  129. return Math.Max(SC.GetValue<int>($"Robot.Blade2Slots"), 1);
  130. }
  131. return 1;
  132. }
  133. }
  134. public bool Initalized { get; set; }
  135. public bool Communication
  136. {
  137. get
  138. {
  139. return !_commErr;
  140. }
  141. }
  142. public bool Busy
  143. {
  144. get { return _backgroundHandler != null || _foregroundHandler != null; }
  145. }
  146. public bool Moving
  147. {
  148. get { return _backgroundHandler != null; }
  149. }
  150. public bool Error
  151. {
  152. get
  153. {
  154. return ErrorCode > 0 || _commErr || _exceuteErr;
  155. }
  156. }
  157. public DeviceState State
  158. {
  159. get
  160. {
  161. if (!Initalized)
  162. {
  163. return DeviceState.Unknown;
  164. }
  165. if (Error)
  166. {
  167. return DeviceState.Error;
  168. }
  169. if (Busy)
  170. return DeviceState.Busy;
  171. return DeviceState.Idle;
  172. }
  173. }
  174. //public string ErrorMessage
  175. //{
  176. // get
  177. // {
  178. // return _factory.GetError(LastErrorCode);
  179. // }
  180. //}
  181. public bool WaferOnBlade1 { get { return (Status & (int)StateBit.WaferOnBlade1) > 0; } }
  182. public bool WaferOnBlade2 { get { return (Status & (int)StateBit.WaferOnBlade2) > 0; } }
  183. public bool WaferPresentOnBlade1 { get; set; }
  184. public bool WaferPresentOnBlade2 { get; set; }
  185. public Hand TransferBlade {
  186. get
  187. {
  188. if (!Blade1Enable) return Hand.Blade2;
  189. if (!Blade2Enable) return Hand.Blade1;
  190. return Hand.Both;
  191. }
  192. }
  193. protected static Object _locker = new Object();
  194. protected AsyncSocket _socket;
  195. protected IHandler _eventHandler = null;
  196. protected IHandler _backgroundHandler = null; //moving
  197. protected IHandler _foregroundHandler = null; //current handler
  198. private IRobotHandlerFactory _factory = null;
  199. private DeviceTimer _timerQuery = new DeviceTimer();
  200. //private int _queryPeriod = 5000; //ms
  201. //private bool _queryState = true;
  202. protected bool _exceuteErr = false;
  203. protected bool _commErr = false;
  204. protected string _addr;
  205. protected RobotType _type = RobotType.SR100;
  206. private string AlarmRobotError = "RobotError";
  207. public Robot(string module, string name, string display, string deviceId, string address, RobotType type = RobotType.SR100)
  208. : base(module, name, display, deviceId)
  209. {
  210. _addr = address;
  211. _socket = new AsyncSocket(address);
  212. _type = type;
  213. _socket.OnDataChanged += new AsyncSocket.MessageHandler(OnDataChanged);
  214. _socket.OnErrorHappened += new AsyncSocket.ErrorHandler(OnErrorHandler);
  215. Initalized = false;
  216. WaferManager.Instance.SubscribeLocation(name, 1+ Blade2Slots);
  217. }
  218. public Robot(string module, string name, string address, RobotType type = RobotType.SR100)
  219. : this(module, name, name, name, address, type)
  220. {
  221. }
  222. public bool Initialize()
  223. {
  224. switch (_type)
  225. {
  226. case RobotType.NX100:
  227. _factory = new NX100.NX100RobotHandlerFactory(this);
  228. break;
  229. case RobotType.SR100:
  230. _factory = new SR100.SR100RobotHandlerFactory(this);
  231. break;
  232. case RobotType.MAG7:
  233. _factory = new MAG7.Mag7RobotHandlerFactory(this);
  234. break;
  235. }
  236. ConnectionManager.Instance.Subscribe(Name, this);
  237. Connect();
  238. DEVICE.Register(String.Format("{0}.{1}", ModuleName.Robot.ToString(), "Init"), (out string reason, int time, object[] param) =>
  239. {
  240. bool ret = Init(out reason);
  241. if (ret)
  242. {
  243. reason = string.Format("{0} {1}", Name, "Initializing");
  244. return true;
  245. }
  246. return false;
  247. });
  248. DEVICE.Register(String.Format("{0}.{1}", ModuleName.Robot.ToString(), "Home"), (out string reason, int time, object[] param) =>
  249. {
  250. bool ret = Home(out reason);
  251. if (ret)
  252. {
  253. reason = string.Format("{0} {1}", Name, "Homing");
  254. return true;
  255. }
  256. return false;
  257. });
  258. DEVICE.Register(String.Format("{0}.{1}", ModuleName.Robot.ToString(), "RobotHome"), (out string reason, int time, object[] param) =>
  259. {
  260. bool ret = Home(out reason);
  261. if (ret)
  262. {
  263. reason = string.Format("{0} {1}", Name, "Homing");
  264. return true;
  265. }
  266. return false;
  267. });
  268. DEVICE.Register(String.Format("{0}.{1}", Name, "Reset"), (out string reason, int time, object[] param) =>
  269. {
  270. bool ret = Clear(out reason);
  271. if (ret)
  272. {
  273. reason = string.Format("{0} {1}", Name, "Reset");
  274. return true;
  275. }
  276. return false;
  277. });
  278. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotReset"), (out string reason, int time, object[] param) =>
  279. {
  280. bool ret = Clear(out reason);
  281. if (ret)
  282. {
  283. reason = string.Format("{0} {1}", Name, "Reset");
  284. return true;
  285. }
  286. return false;
  287. });
  288. DEVICE.Register(String.Format("{0}.{1}", Name, "Grip"), (out string reason, int time, object[] param) =>
  289. {
  290. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  291. bool ret = Grip(hand,out reason);
  292. //bool ret = WaferMapping(ModuleName.LP1, out reason);
  293. if (ret)
  294. {
  295. reason = string.Format("{0} {1}", Name, "Grip");
  296. return true;
  297. }
  298. return false;
  299. });
  300. DEVICE.Register(String.Format("{0}.{1}", Name, "Release"), (out string reason, int time, object[] param) =>
  301. {
  302. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  303. bool ret = Release(hand, out reason);
  304. //bool ret = QueryWaferMap(ModuleName.LP1, out reason);
  305. if (ret)
  306. {
  307. reason = string.Format("{0} {1}", Name, "Release");
  308. return true;
  309. }
  310. return false;
  311. });
  312. DEVICE.Register(String.Format("{0}.{1}", Name, "Stop"), (out string reason, int time, object[] param) =>
  313. {
  314. bool ret = Stop(false, out reason);
  315. if (ret)
  316. {
  317. reason = string.Format("{0} {1}", Name, "Stopping");
  318. return true;
  319. }
  320. return false;
  321. });
  322. DEVICE.Register(String.Format("{0}.{1}", Name, "Pick"), (out string reason, int time, object[] param) =>
  323. {
  324. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  325. int slot = int.Parse((string)param[1]);
  326. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  327. bool ret = Pick(chamber, slot, hand, out reason);
  328. if (ret)
  329. {
  330. reason = string.Format("{0} {1}", Name, "Pick wafer");
  331. return true;
  332. }
  333. return false;
  334. });
  335. DEVICE.Register(String.Format("{0}.{1}", Name, "Place"), (out string reason, int time, object[] param) =>
  336. {
  337. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  338. int slot = int.Parse((string)param[1]);
  339. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  340. bool ret = Place(chamber, slot, hand, out reason);
  341. if (ret)
  342. {
  343. reason = string.Format("{0} {1}", Name, "Place wafer");
  344. return true;
  345. }
  346. return false;
  347. });
  348. DEVICE.Register(String.Format("{0}.{1}", Name, "Exchange"), (out string reason, int time, object[] param) =>
  349. {
  350. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  351. int slot = int.Parse((string)param[1]);
  352. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  353. bool ret = Exchange(chamber, slot, hand, out reason);
  354. if (ret)
  355. {
  356. reason = string.Format("{0} {1}", Name, "Swap wafer");
  357. return true;
  358. }
  359. return false;
  360. });
  361. DEVICE.Register(String.Format("{0}.{1}", Name, "Goto"), (out string reason, int time, object[] param) =>
  362. {
  363. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  364. int slot = int.Parse((string)param[1]);
  365. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  366. Motion next = (Motion)Enum.Parse(typeof(Motion), (string)param[3], true);
  367. int x = int.Parse((string)param[4]);
  368. int y = int.Parse((string)param[5]);
  369. int z = int.Parse((string)param[6]);
  370. bool ret = Goto(chamber, slot, next, hand, x,y,z, out reason);
  371. if (ret)
  372. {
  373. reason = string.Format("{0}{1}", Name, "Goto");
  374. return true;
  375. }
  376. return false;
  377. });
  378. DEVICE.Register(String.Format("{0}.{1}", Name, "BladeEnable"), (out string reason, int time, object[] param) =>
  379. {
  380. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  381. bool bEnable = bool.Parse((string)param[1]);
  382. bool ret = Enable(hand, bEnable, out reason);
  383. if (ret)
  384. {
  385. reason = string.Format("{0}{1}", Name, "Disable robot arm");
  386. return true;
  387. }
  388. return false;
  389. });
  390. OP.Subscribe($"{Name}.Reconnect", (string cmd, object[] args) =>
  391. {
  392. return Connect();
  393. });
  394. DATA.Subscribe($"{Name}.State", () => State);
  395. DATA.Subscribe($"{Name}.Busy", () => Busy);
  396. DATA.Subscribe($"{Name}.ErrorCode", () => ErrorCode);
  397. DATA.Subscribe($"{Name}.Blade1Target", () => Blade1Target);
  398. DATA.Subscribe($"{Name}.Blade2Target", () => Blade2Target);
  399. DATA.Subscribe($"{Name}.Blade1Enable", () => Blade1Enable);
  400. DATA.Subscribe($"{Name}.Blade2Enable", () => Blade2Enable);
  401. DATA.Subscribe($"{Name}.Swap", () => Swap);
  402. DATA.Subscribe($"{Name}.PlaceBalde", () => PlaceBalde);
  403. DATA.Subscribe($"{Name}.Speed", () => Speed);
  404. DATA.Subscribe($"{Name}.RobotSpeed", () => Speed.ToString());
  405. DATA.Subscribe($"{Name}.RobotState", () => State.ToString());
  406. DATA.Subscribe($"{Name}.Rotation", () => Rotation);
  407. DATA.Subscribe($"{Name}.Extension", () => Extension);
  408. DATA.Subscribe($"{Name}.Wrist1", () => Wrist1);
  409. DATA.Subscribe($"{Name}.Wrist2", () => Wrist2);
  410. DATA.Subscribe($"{Name}.Evevation", () => Evevation);
  411. DATA.Subscribe($"{Name}.CmdBladeTarget", () => CmdBladeTarget);
  412. DATA.Subscribe($"{Name}.CmdBlade1Extend", () => CmdBlade1Extend);
  413. DATA.Subscribe($"{Name}.CmdBlade2Extend", () => CmdBlade2Extend);
  414. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotBusy", () => Busy);
  415. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotError", () => ErrorCode);
  416. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotBlade1Traget", () => Blade1Target);
  417. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotBlade2Traget", () => Blade2Target);
  418. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotBlade1Enabled", () => Blade1Enable);
  419. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotBlade2Enabled", () => Blade2Enable);
  420. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotSwap", () => Swap);
  421. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotSwapPlaceBalde", () => PlaceBalde);
  422. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotPosRotationAxis", () => Rotation);
  423. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotPosExtensionAxis", () => Extension);
  424. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotPosWrist1Axis", () => Wrist1);
  425. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotPosWrist2Axis", () => Wrist2);
  426. DATA.Subscribe(ModuleName.Robot.ToString(), "RobotPosEvevationAxis", () => Evevation);
  427. DATA.Subscribe($"{Name}.CommunicationStatus", () => _socket == null ? false : _socket.IsConnected);
  428. EV.Subscribe(new EventItem("Event", AlarmRobotError, "Robot error", EventLevel.Alarm, Aitex.Core.RT.Event.EventType.HostNotification));
  429. Reset();
  430. string str = string.Empty;
  431. _eventHandler = _factory.Event();
  432. return true;
  433. }
  434. public void Terminate()
  435. {
  436. }
  437. public void Monitor()
  438. {
  439. }
  440. public void Reset()
  441. {
  442. lock (_locker)
  443. {
  444. _foregroundHandler = null;
  445. _backgroundHandler = null;
  446. }
  447. _exceuteErr = false;
  448. if (_commErr)
  449. {
  450. Connect();
  451. }
  452. Swap = false;
  453. }
  454. public bool Enable(Hand hand, bool bEnable, out string reason)
  455. {
  456. reason = string.Empty;
  457. if (hand == Hand.Blade1)
  458. {
  459. Blade2Enable = bEnable;
  460. }
  461. else if (hand == Hand.Blade2)
  462. {
  463. Blade2Enable = bEnable;
  464. }
  465. else
  466. {
  467. reason = "Can't disable all blade";
  468. return false;
  469. }
  470. return true;
  471. }
  472. public virtual bool Connect()
  473. {
  474. _commErr = false;
  475. _socket.Connect(this._addr);
  476. return true;
  477. }
  478. #region Command
  479. public bool Init(out string reason)
  480. {
  481. lock (_locker)
  482. {
  483. _foregroundHandler = null;
  484. _backgroundHandler = null;
  485. }
  486. reason = string.Empty;
  487. return execute(_factory.Init(), out reason);
  488. }
  489. public bool Home(out string reason)
  490. {
  491. lock (_locker)
  492. {
  493. _foregroundHandler = null;
  494. _backgroundHandler = null;
  495. }
  496. reason = string.Empty;
  497. return execute(_factory.Home(), out reason);
  498. }
  499. public bool Grip(Hand hand,out string reason)
  500. {
  501. reason = string.Empty;
  502. return execute(_factory.Grip(hand), out reason);
  503. }
  504. public bool Release(Hand hand, out string reason)
  505. {
  506. reason = string.Empty;
  507. return execute(_factory.Release(hand), out reason);
  508. }
  509. public bool WaferMapping(ModuleName loadport, out string reason)
  510. {
  511. reason = string.Empty;
  512. return execute(_factory.WaferMapping(loadport), out reason);
  513. }
  514. public bool QueryWaferMap(ModuleName loadport, out string reason)
  515. {
  516. reason = string.Empty;
  517. return execute(_factory.QueryWaferMap(loadport), out reason);
  518. }
  519. public bool QueryState(out string reason)
  520. {
  521. reason = string.Empty;
  522. return execute(_factory.QueryState(), out reason);
  523. }
  524. public bool QueryPosition(out string reason)
  525. {
  526. reason = string.Empty;
  527. return execute(_factory.QueryPosition(), out reason);
  528. }
  529. public bool Clear(out string reason)
  530. {
  531. reason = string.Empty;
  532. return execute(_factory.Clear(), out reason);
  533. }
  534. public bool Stop(bool isEmergency, out string reason)
  535. {
  536. reason = string.Empty;
  537. lock (_locker)
  538. {
  539. _foregroundHandler = null;
  540. _backgroundHandler = null;
  541. }
  542. return execute(_factory.Stop(isEmergency), out reason);
  543. }
  544. public bool Resume( out string reason)
  545. {
  546. reason = string.Empty;
  547. return execute(_factory.Resume(), out reason);
  548. }
  549. public bool SetSpeed(int speed, out string reason)
  550. {
  551. reason = string.Empty;
  552. return execute(_factory.SetSpeed(speed), out reason);
  553. }
  554. public bool SetCommunication( out string reason)
  555. {
  556. reason = string.Empty;
  557. return execute(_factory.SetCommunication(), out reason);
  558. }
  559. public bool SetLoad(Hand hand, out string reason)
  560. {
  561. reason = string.Empty;
  562. return execute(_factory.SetLoad(hand), out reason);
  563. }
  564. public bool CheckLoad(ModuleName chamber, int slot, out string reason)
  565. {
  566. reason = string.Empty;
  567. return execute(_factory.CheckLoad(chamber, slot), out reason);
  568. }
  569. public bool RequestWaferPresent( out string reason)
  570. {
  571. reason = string.Empty;
  572. return execute(_factory.RequestWaferPresent(), out reason);
  573. }
  574. public bool Goto(ModuleName chamber, int slot, Motion motion,Hand hand, int x, int y, int z,out string reason)
  575. {
  576. reason = string.Empty;
  577. if (chamber == ModuleName.Robot)
  578. {
  579. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  580. return false;
  581. }
  582. if (ModuleHelper.IsLoadPort(chamber))
  583. {
  584. if (hand == Hand.Both)
  585. {
  586. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  587. {
  588. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  589. return false;
  590. }
  591. }
  592. else if(hand == Hand.Blade2)
  593. {
  594. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  595. {
  596. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  597. return false;
  598. }
  599. }
  600. else
  601. {
  602. if (!checkslot(0, 25, slot))
  603. {
  604. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  605. return false;
  606. }
  607. }
  608. }
  609. else
  610. {
  611. if (hand == Hand.Both)
  612. {
  613. reason = string.Format("Pick invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  614. return false;
  615. }
  616. }
  617. return execute(_factory.Goto( chamber, slot, motion, hand, x,y,z), out reason);
  618. }
  619. public bool MoveTo(ModuleName chamber, int slot, Hand hand, bool isPick, int x, int y, int z,out string reason)
  620. {
  621. reason = string.Empty;
  622. if (chamber == ModuleName.Robot)
  623. {
  624. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  625. return false;
  626. }
  627. if (ModuleHelper.IsLoadPort(chamber))
  628. {
  629. if (hand == Hand.Both)
  630. {
  631. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  632. {
  633. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  634. return false;
  635. }
  636. }
  637. else if(hand == Hand.Blade2)
  638. {
  639. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  640. {
  641. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  642. return false;
  643. }
  644. }
  645. else
  646. {
  647. if (!checkslot(0, 25, slot))
  648. {
  649. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  650. return false;
  651. }
  652. }
  653. }
  654. else
  655. {
  656. if (hand == Hand.Both)
  657. {
  658. reason = string.Format("Pick invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  659. return false;
  660. }
  661. }
  662. return execute(_factory.MoveTo( chamber, slot, hand, isPick, x,y,z), out reason);
  663. }
  664. public bool Extend(ModuleName chamber, int slot, Hand hand, out string reason)
  665. {
  666. reason = string.Empty;
  667. if (chamber == ModuleName.Robot)
  668. {
  669. reason = string.Format("Extend invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  670. return false;
  671. }
  672. if (ModuleHelper.IsLoadPort(chamber))
  673. {
  674. if (hand == Hand.Both)
  675. {
  676. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  677. {
  678. reason = string.Format("Extend invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  679. return false;
  680. }
  681. }
  682. else if (hand == Hand.Blade2)
  683. {
  684. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  685. {
  686. reason = string.Format("Extend invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  687. return false;
  688. }
  689. }
  690. else
  691. {
  692. if (!checkslot(0, 25, slot))
  693. {
  694. reason = string.Format("Extend invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  695. return false;
  696. }
  697. }
  698. }
  699. else
  700. {
  701. if (hand == Hand.Both)
  702. {
  703. reason = string.Format("Extend invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  704. return false;
  705. }
  706. }
  707. return execute(_factory.Extend(chamber, slot, hand), out reason);
  708. }
  709. public bool Retract(ModuleName chamber, int slot, Hand hand, out string reason)
  710. {
  711. reason = string.Empty;
  712. if (chamber == ModuleName.Robot)
  713. {
  714. reason = string.Format("Retract invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  715. return false;
  716. }
  717. if (ModuleHelper.IsLoadPort(chamber))
  718. {
  719. if (hand == Hand.Both)
  720. {
  721. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  722. {
  723. reason = string.Format("Retract invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  724. return false;
  725. }
  726. }
  727. else if (hand == Hand.Blade2)
  728. {
  729. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  730. {
  731. reason = string.Format("Retract invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  732. return false;
  733. }
  734. }
  735. else
  736. {
  737. if (!checkslot(0, 25, slot))
  738. {
  739. reason = string.Format("Retract invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  740. return false;
  741. }
  742. }
  743. }
  744. else
  745. {
  746. if (hand == Hand.Both)
  747. {
  748. reason = string.Format("Retract invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  749. return false;
  750. }
  751. }
  752. return execute(_factory.Retract(chamber, slot, hand), out reason);
  753. }
  754. public bool PickExtend(ModuleName chamber, int slot, Hand hand, out string reason)
  755. {
  756. reason = string.Empty;
  757. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber) || ModuleHelper.IsBuffer(chamber))
  758. {
  759. reason = $"Pick extend target not support, chamber is {chamber.ToString()}, slot is {slot}";
  760. return false;
  761. }
  762. if (hand == Hand.Both)
  763. {
  764. reason = string.Format("Pick extend invalid parameter, do not support double arm extend ,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  765. return false;
  766. }
  767. return execute(_factory.PickExtend(chamber, slot, hand), out reason);
  768. }
  769. public bool PickRetract(ModuleName chamber, int slot, Hand hand, out string reason)
  770. {
  771. reason = string.Empty;
  772. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber) || ModuleHelper.IsBuffer(chamber))
  773. {
  774. reason = $"Pick retract target not support, chamber is {chamber.ToString()}, slot is {slot}";
  775. return false;
  776. }
  777. if (hand == Hand.Both)
  778. {
  779. reason = string.Format("Pick retract invalid parameter, do not support double arm retract ,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  780. return false;
  781. }
  782. return execute(_factory.PickRetract(chamber, slot, hand), out reason);
  783. }
  784. public bool Pick(ModuleName chamber, int slot, Hand hand, out string reason)
  785. {
  786. reason = string.Empty;
  787. if (chamber == ModuleName.Robot)
  788. {
  789. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  790. return false;
  791. }
  792. if (ModuleHelper.IsLoadPort(chamber))
  793. {
  794. if (hand == Hand.Both)
  795. {
  796. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  797. {
  798. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  799. return false;
  800. }
  801. }
  802. else if (hand == Hand.Blade2)
  803. {
  804. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  805. {
  806. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  807. return false;
  808. }
  809. }
  810. else
  811. {
  812. if (!checkslot(0, 25, slot))
  813. {
  814. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  815. return false;
  816. }
  817. }
  818. }
  819. else if(ModuleHelper.IsBuffer(chamber))
  820. {
  821. if (hand == Hand.Both)
  822. {
  823. if (!checkslot(0, 6 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  824. {
  825. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  826. return false;
  827. }
  828. }
  829. else if (hand == Hand.Blade2)
  830. {
  831. if (!checkslot(0, 6 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  832. {
  833. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  834. return false;
  835. }
  836. }
  837. else
  838. {
  839. if (!checkslot(0, 6, slot))
  840. {
  841. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  842. return false;
  843. }
  844. }
  845. }
  846. else
  847. {
  848. if (hand == Hand.Both)
  849. {
  850. reason = string.Format("Pick invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  851. return false;
  852. }
  853. }
  854. return execute(_factory.Pick(chamber, slot, hand), out reason);
  855. }
  856. public bool Place(ModuleName chamber, int slot, Hand hand, out string reason)
  857. {
  858. reason = string.Empty;
  859. if (chamber == ModuleName.Robot)
  860. {
  861. reason = string.Format("Place invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  862. return false;
  863. }
  864. if (ModuleHelper.IsLoadPort(chamber))
  865. {
  866. if (hand == Hand.Both)
  867. {
  868. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  869. {
  870. reason = string.Format("Place invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  871. return false;
  872. }
  873. }
  874. else if (hand == Hand.Blade2)
  875. {
  876. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  877. {
  878. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  879. return false;
  880. }
  881. }
  882. else
  883. {
  884. if (!checkslot(0, 25, slot))
  885. {
  886. reason = string.Format("Place invalid parameter,place, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  887. return false;
  888. }
  889. }
  890. }
  891. else if (ModuleHelper.IsBuffer(chamber))
  892. {
  893. if (hand == Hand.Both)
  894. {
  895. if (!checkslot(0, 6 - Blade2Slots, slot)) //0-6
  896. {
  897. reason = string.Format("Place invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  898. return false;
  899. }
  900. }
  901. else if (hand == Hand.Blade2)
  902. {
  903. if (!checkslot(0, 6 - Blade2Slots + 1, slot)) //0 - 6
  904. {
  905. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  906. return false;
  907. }
  908. }
  909. else
  910. {
  911. if (!checkslot(0, 6, slot))
  912. {
  913. reason = string.Format("Place invalid parameter,place, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  914. return false;
  915. }
  916. }
  917. }
  918. else
  919. {
  920. if (hand == Hand.Both)
  921. {
  922. reason = string.Format("Place invalid parameter, double place,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  923. return false;
  924. }
  925. }
  926. return execute(_factory.Place(chamber, slot, hand), out reason);
  927. }
  928. public bool PlaceExtend(ModuleName chamber, int slot, Hand hand, out string reason)
  929. {
  930. reason = string.Empty;
  931. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber) || ModuleHelper.IsBuffer(chamber))
  932. {
  933. reason = $"Place extend target not support, chamber is {chamber.ToString()}, slot is {slot}";
  934. return false;
  935. }
  936. if (hand == Hand.Both)
  937. {
  938. reason =
  939. $"Place extend invalid parameter, do not support double arm extend ,chamber is {chamber.ToString()}, slot is {slot}";
  940. return false;
  941. }
  942. return execute(_factory.PlaceExtend(chamber, slot, hand), out reason);
  943. }
  944. public bool PlaceRetract(ModuleName chamber, int slot, Hand hand, out string reason)
  945. {
  946. reason = string.Empty;
  947. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber) ||ModuleHelper.IsBuffer(chamber) )
  948. {
  949. reason = $"Place retract target not support, chamber is {chamber.ToString()}, slot is {slot}";
  950. return false;
  951. }
  952. if (hand == Hand.Both)
  953. {
  954. reason =
  955. $"Place retract invalid parameter, do not support double arm extend ,chamber is {chamber.ToString()}, slot is {slot}";
  956. return false;
  957. }
  958. return execute(_factory.PlaceRetract(chamber, slot, hand), out reason);
  959. }
  960. public bool Exchange(ModuleName chamber, int slot, Hand hand, out string reason)
  961. {
  962. reason = string.Empty;
  963. if (chamber == ModuleName.Robot)
  964. {
  965. reason = string.Format("Exchange invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  966. return false;
  967. }
  968. if (Blade2Slots > 1)
  969. {
  970. reason = string.Format("this robot don't support exchange operation.");
  971. return false;
  972. }
  973. if (hand == Hand.Both)
  974. {
  975. reason = string.Format("Exchange invalid parameter,double hand");
  976. return false;
  977. }
  978. if (ModuleHelper.IsLoadPort(chamber))
  979. {
  980. if (!checkslot(0, 25, slot))
  981. {
  982. reason = string.Format("Exchange invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  983. return false;
  984. }
  985. }
  986. return execute(_factory.Exchange(chamber, slot, hand), out reason);
  987. }
  988. public bool PickEx(ModuleName chamber, int slot, Hand hand, int x, int y, int z, out string reason)
  989. {
  990. reason = string.Empty;
  991. if (chamber == ModuleName.Robot)
  992. {
  993. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  994. return false;
  995. }
  996. if (ModuleHelper.IsLoadPort(chamber))
  997. {
  998. if (hand == Hand.Both)
  999. {
  1000. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  1001. {
  1002. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1003. return false;
  1004. }
  1005. }
  1006. else if (hand == Hand.Blade2)
  1007. {
  1008. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  1009. {
  1010. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1011. return false;
  1012. }
  1013. }
  1014. else
  1015. {
  1016. if (!checkslot(0, 25, slot))
  1017. {
  1018. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1019. return false;
  1020. }
  1021. }
  1022. }
  1023. else
  1024. {
  1025. if (hand == Hand.Both)
  1026. {
  1027. reason = string.Format("Pick invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1028. return false;
  1029. }
  1030. }
  1031. return execute(_factory.PickEx(chamber, slot, hand, x,y,z), out reason);
  1032. }
  1033. public bool PlaceEx(ModuleName chamber, int slot, Hand hand, int x, int y, int z, out string reason)
  1034. {
  1035. reason = string.Empty;
  1036. if (chamber == ModuleName.Robot)
  1037. {
  1038. reason = string.Format("Place invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1039. return false;
  1040. }
  1041. if (ModuleHelper.IsLoadPort(chamber))
  1042. {
  1043. if (hand == Hand.Both)
  1044. {
  1045. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  1046. {
  1047. reason = string.Format("Place invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1048. return false;
  1049. }
  1050. }
  1051. else if (hand == Hand.Blade2)
  1052. {
  1053. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  1054. {
  1055. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1056. return false;
  1057. }
  1058. }
  1059. else
  1060. {
  1061. if (!checkslot(0, 25, slot))
  1062. {
  1063. reason = string.Format("Place invalid parameter,place, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1064. return false;
  1065. }
  1066. }
  1067. }
  1068. else
  1069. {
  1070. if (hand == Hand.Both)
  1071. {
  1072. reason = string.Format("Place invalid parameter, double place,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1073. return false;
  1074. }
  1075. }
  1076. return execute(_factory.PlaceEx(chamber, slot, hand,x,y,z), out reason);
  1077. }
  1078. public bool ExchangeEx(ModuleName chamber, int slot, Hand hand, int x, int y, int z, out string reason)
  1079. {
  1080. reason = string.Empty;
  1081. if (chamber == ModuleName.Robot)
  1082. {
  1083. reason = string.Format("Exchange invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1084. return false;
  1085. }
  1086. if (Blade2Slots > 1)
  1087. {
  1088. reason = string.Format("this robot don't support exchange operation.");
  1089. return false;
  1090. }
  1091. if (hand == Hand.Both)
  1092. {
  1093. reason = string.Format("Exchange invalid parameter,double hand");
  1094. return false;
  1095. }
  1096. if (ModuleHelper.IsLoadPort(chamber))
  1097. {
  1098. if (!checkslot(0, 25, slot))
  1099. {
  1100. reason = string.Format("Exchange invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  1101. return false;
  1102. }
  1103. }
  1104. return execute(_factory.ExchangeEx(chamber, slot, hand, x, y, z), out reason);
  1105. }
  1106. #endregion
  1107. public virtual bool execute(IHandler handler, out string reason)
  1108. {
  1109. reason = string.Empty;
  1110. lock (_locker)
  1111. {
  1112. if (_foregroundHandler != null)
  1113. {
  1114. reason = "System busy, please wait or reset system.";
  1115. EV.PostMessage(Name, EventEnum.DefaultWarning, string.Format("{0} {1} {2}", this.DeviceID, handler.ToString(), reason));
  1116. return false;
  1117. }
  1118. if (_backgroundHandler != null && handler.IsBackground)
  1119. {
  1120. reason = "System busy,one background command is running, please wait or reset system.";
  1121. EV.PostMessage(Name, EventEnum.DefaultWarning, string.Format("{0} {1} {2}", this.DeviceID, handler.ToString(), reason)); reason = "系统忙,后台命令正在处理,暂时不能处理新的后台命令";
  1122. return false;
  1123. }
  1124. handler.Unit = (int)Unit.Robot;
  1125. if(!handler.Execute(ref _socket))
  1126. {
  1127. reason = "Communication error,please check it.";
  1128. return false;
  1129. }
  1130. if (handler.IsBackground)
  1131. _backgroundHandler = handler;
  1132. else
  1133. _foregroundHandler = handler;
  1134. }
  1135. return true;
  1136. }
  1137. public virtual void OnDataChanged(string package)
  1138. {
  1139. try
  1140. {
  1141. if (!package.Contains("Gb") && !package.Contains("Pb"))
  1142. package = package.ToUpper();
  1143. string[] msgs = Regex.Split(package, delimiter);
  1144. foreach (string msg in msgs)
  1145. {
  1146. if (msg.Length > 0)
  1147. {
  1148. bool completed = false;
  1149. string resp = msg;
  1150. lock (_locker)
  1151. {
  1152. if (_foregroundHandler != null && _foregroundHandler.OnMessage(ref _socket, resp, out completed))
  1153. {
  1154. _foregroundHandler = null;
  1155. }
  1156. else if (_backgroundHandler != null && _backgroundHandler.OnMessage(ref _socket, resp, out completed))
  1157. {
  1158. if (completed)
  1159. {
  1160. string reason = string.Empty;
  1161. QueryState(out reason);
  1162. _backgroundHandler = null;
  1163. }
  1164. }
  1165. else
  1166. {
  1167. if (_eventHandler != null)
  1168. {
  1169. if (_eventHandler.OnMessage(ref _socket, resp, out completed))
  1170. {
  1171. if (completed)
  1172. {
  1173. EV.PostMessage("Robot", EventEnum.DefaultWarning, string.Format(" has error. {0:X}", ErrorCode));
  1174. _exceuteErr = true;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. catch (ExcuteFailedException e)
  1184. {
  1185. EV.PostMessage("Robot", EventEnum.DefaultWarning, string.Format("executed failed. {0}",e.Message));
  1186. OnError();
  1187. _exceuteErr = false;
  1188. }
  1189. catch (InvalidPackageException e)
  1190. {
  1191. EV.PostMessage("Robot", EventEnum.DefaultWarning, string.Format("receive invalid package. {0}", e.Message));
  1192. OnError();
  1193. }
  1194. catch (System.Exception ex)
  1195. {
  1196. _commErr = true;
  1197. LOG.Write("Robot failed:" + ex.ToString());
  1198. }
  1199. }
  1200. private void OnErrorHandler(ErrorEventArgs args)
  1201. {
  1202. _commErr = true;
  1203. Initalized = false;
  1204. EV.PostMessage(Module, EventEnum.CommunicationError, Display, args.Reason);
  1205. OnError();
  1206. }
  1207. private bool checkslot(int min, int max, int slot)
  1208. {
  1209. return slot >= min && slot < max;
  1210. }
  1211. public void NotifySlotMapResult(ModuleName module, string slotMap)
  1212. {
  1213. if (OnSlotMapRead != null)
  1214. {
  1215. OnSlotMapRead(module, slotMap);
  1216. }
  1217. }
  1218. public void OnError()
  1219. {
  1220. EV.Notify(AlarmRobotError);
  1221. }
  1222. public void NotifyWaferPresent(Hand hand, WaferStatus status)
  1223. {
  1224. if (status == WaferStatus.Empty)
  1225. {
  1226. if (hand == Hand.Blade1)
  1227. {
  1228. WaferPresentOnBlade1 = status == WaferStatus.Empty;
  1229. }
  1230. if (hand == Hand.Blade2)
  1231. {
  1232. WaferPresentOnBlade2 = status == WaferStatus.Empty;
  1233. }
  1234. }
  1235. if (status == WaferStatus.Unknown)
  1236. {
  1237. EV.PostWarningLog(Module, "Wafer present unknown");
  1238. return;
  1239. }
  1240. if (hand == Hand.Blade1)
  1241. {
  1242. WaferPresentOnBlade1 = status == WaferStatus.Normal;
  1243. }
  1244. if (hand == Hand.Blade2)
  1245. {
  1246. WaferPresentOnBlade2 = status == WaferStatus.Normal;
  1247. }
  1248. }
  1249. }
  1250. }