Robot.cs 52 KB

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