Robot.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot
  15. {
  16. public enum RobotType
  17. {
  18. SR100,
  19. NX100,
  20. MAG7,
  21. }
  22. public class Robot : BaseDevice, IDevice
  23. {
  24. public event Action<ModuleName, string> OnSlotMapRead;
  25. public const string delimiter = "\r";
  26. public int LastErrorCode { get; set; }
  27. public int Status { get; set; }
  28. public int ErrorCode { get; set; }
  29. public int ElapseTime { get; set; }
  30. public int Speed { get; set; }
  31. public int Rotation { get; set; }
  32. public int Extension { get; set; }
  33. public int Wrist1 { get; set; }
  34. public int Wrist2 { get; set; }
  35. public int Evevation { get; set; }
  36. public bool Swap { get; set; }
  37. public Hand PlaceBalde { get; set; }
  38. public ModuleName Blade1Target
  39. {
  40. get;
  41. set;
  42. }
  43. public ModuleName Blade2Target { get; set; }
  44. //naming follow PM1.A LL1.A PM2.B
  45. public string CmdBladeTarget { get; set; }
  46. //naming follow 0 1
  47. public string CmdBlade1Extend { get; set; }
  48. //naming follow 0 1
  49. public string CmdBlade2Extend { get; set; }
  50. public bool Blade1Enable
  51. {
  52. get
  53. {
  54. if (SC.ContainsItem($"{Name}.Blade1Enable"))
  55. {
  56. return SC.GetValue<bool>($"{Name}.Blade1Enable");
  57. }
  58. return SC.GetValue<bool>($"Robot.Blade1Enable");
  59. }
  60. set
  61. {
  62. if (SC.ContainsItem($"{Name}.Blade1Enable"))
  63. {
  64. SC.SetItemValue($"{Name}.Blade1Enable", value);
  65. }else if (SC.ContainsItem($"Robot.Blade1Enable"))
  66. {
  67. SC.SetItemValue($"Robot.Blade1Enable", value);
  68. }
  69. }
  70. }
  71. public bool Blade2Enable
  72. {
  73. get
  74. {
  75. if (SC.ContainsItem($"{Name}.Blade2Enable"))
  76. {
  77. return SC.GetValue<bool>($"{Name}.Blade2Enable");
  78. }
  79. return SC.GetValue<bool>($"Robot.Blade2Enable");
  80. }
  81. set
  82. {
  83. if (SC.ContainsItem($"{Name}.Blade2Enable"))
  84. {
  85. SC.SetItemValue($"{Name}.Blade2Enable", value);
  86. }
  87. else if (SC.ContainsItem($"Robot.Blade2Enable"))
  88. {
  89. SC.SetItemValue($"Robot.Blade2Enable", value);
  90. }
  91. }
  92. }
  93. public int Blade2Slots
  94. {
  95. get
  96. {
  97. if (SC.ContainsItem($"{Name}.Blade2Slots"))
  98. {
  99. return Math.Max(SC.GetValue<int>($"{Name}.Blade2Slots"), 1);
  100. }
  101. if (SC.ContainsItem($"Robot.Blade2Slots"))
  102. {
  103. return Math.Max(SC.GetValue<int>($"Robot.Blade2Slots"), 1);
  104. }
  105. return 1;
  106. }
  107. }
  108. public bool Initalized { get; set; }
  109. public bool Communication
  110. {
  111. get
  112. {
  113. return !_commErr;
  114. }
  115. }
  116. public bool Busy
  117. {
  118. get { return _backgroundHandler != null || _foregroundHandler != null; }
  119. }
  120. public bool Moving
  121. {
  122. get { return _backgroundHandler != null; }
  123. }
  124. public bool Error
  125. {
  126. get
  127. {
  128. return ErrorCode > 0 || _commErr || _exceuteErr;
  129. }
  130. }
  131. public DeviceState State
  132. {
  133. get
  134. {
  135. if (!Initalized)
  136. {
  137. return DeviceState.Unknown;
  138. }
  139. if (Error)
  140. {
  141. return DeviceState.Error;
  142. }
  143. if (Busy)
  144. return DeviceState.Busy;
  145. return DeviceState.Idle;
  146. }
  147. }
  148. //public string ErrorMessage
  149. //{
  150. // get
  151. // {
  152. // return _factory.GetError(LastErrorCode);
  153. // }
  154. //}
  155. public bool WaferOnBlade1 { get { return (Status & (int)StateBit.WaferOnBlade1) > 0; } }
  156. public bool WaferOnBlade2 { get { return (Status & (int)StateBit.WaferOnBlade2) > 0; } }
  157. public bool WaferPresentOnBlade1 { get; set; }
  158. public bool WaferPresentOnBlade2 { get; set; }
  159. public Hand TransferBlade {
  160. get
  161. {
  162. if (!Blade1Enable) return Hand.Blade2;
  163. if (!Blade2Enable) return Hand.Blade1;
  164. return Hand.Both;
  165. }
  166. }
  167. protected static Object _locker = new Object();
  168. protected AsyncSocket _socket;
  169. protected IHandler _eventHandler = null;
  170. protected IHandler _backgroundHandler = null; //moving
  171. protected IHandler _foregroundHandler = null; //current handler
  172. private IRobotHandlerFactory _factory = null;
  173. private DeviceTimer _timerQuery = new DeviceTimer();
  174. //private int _queryPeriod = 5000; //ms
  175. //private bool _queryState = true;
  176. protected bool _exceuteErr = false;
  177. protected bool _commErr = false;
  178. protected string _addr;
  179. protected RobotType _type = RobotType.SR100;
  180. public Robot(string module, string name, string display, string deviceId, string address, RobotType type = RobotType.SR100)
  181. : base(module, name, display, deviceId)
  182. {
  183. _addr = address;
  184. _socket = new AsyncSocket(address);
  185. _type = type;
  186. _socket.OnDataChanged += new AsyncSocket.MessageHandler(OnDataChanged);
  187. _socket.OnErrorHappened += new AsyncSocket.ErrorHandler(OnErrorHandler);
  188. Initalized = false;
  189. WaferManager.Instance.SubscribeLocation(name, 1+ Blade2Slots);
  190. }
  191. public Robot(string module, string name, string address, RobotType type = RobotType.SR100)
  192. : this(module, name, name, name, address, type)
  193. {
  194. }
  195. public bool Initialize()
  196. {
  197. switch (_type)
  198. {
  199. case RobotType.NX100:
  200. _factory = new NX100.NX100RobotHandlerFactory(this);
  201. break;
  202. case RobotType.SR100:
  203. _factory = new SR100.SR100RobotHandlerFactory(this);
  204. break;
  205. case RobotType.MAG7:
  206. _factory = new MAG7.Mag7RobotHandlerFactory(this);
  207. break;
  208. }
  209. _commErr = false;
  210. _socket.Connect(this._addr);
  211. DEVICE.Register(String.Format("{0}.{1}", ModuleName.Robot.ToString(), "Init"), (out string reason, int time, object[] param) =>
  212. {
  213. bool ret = Init(out reason);
  214. if (ret)
  215. {
  216. reason = string.Format("{0} {1}", Name, "Initializing");
  217. return true;
  218. }
  219. return false;
  220. });
  221. DEVICE.Register(String.Format("{0}.{1}", ModuleName.Robot.ToString(), "Home"), (out string reason, int time, object[] param) =>
  222. {
  223. bool ret = Home(out reason);
  224. if (ret)
  225. {
  226. reason = string.Format("{0} {1}", Name, "Homing");
  227. return true;
  228. }
  229. return false;
  230. });
  231. DEVICE.Register(String.Format("{0}.{1}", Name, "Reset"), (out string reason, int time, object[] param) =>
  232. {
  233. bool ret = Clear(out reason);
  234. if (ret)
  235. {
  236. reason = string.Format("{0} {1}", Name, "Reset");
  237. return true;
  238. }
  239. return false;
  240. });
  241. DEVICE.Register(String.Format("{0}.{1}", Name, "Grip"), (out string reason, int time, object[] param) =>
  242. {
  243. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  244. bool ret = Grip(hand,out reason);
  245. //bool ret = WaferMapping(ModuleName.LP1, out reason);
  246. if (ret)
  247. {
  248. reason = string.Format("{0} {1}", Name, "Grip");
  249. return true;
  250. }
  251. return false;
  252. });
  253. DEVICE.Register(String.Format("{0}.{1}", Name, "Release"), (out string reason, int time, object[] param) =>
  254. {
  255. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  256. bool ret = Release(hand, out reason);
  257. //bool ret = QueryWaferMap(ModuleName.LP1, out reason);
  258. if (ret)
  259. {
  260. reason = string.Format("{0} {1}", Name, "Release");
  261. return true;
  262. }
  263. return false;
  264. });
  265. DEVICE.Register(String.Format("{0}.{1}", Name, "Stop"), (out string reason, int time, object[] param) =>
  266. {
  267. bool ret = Stop(out reason);
  268. if (ret)
  269. {
  270. reason = string.Format("{0} {1}", Name, "Stopping");
  271. return true;
  272. }
  273. return false;
  274. });
  275. DEVICE.Register(String.Format("{0}.{1}", Name, "Pick"), (out string reason, int time, object[] param) =>
  276. {
  277. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  278. int slot = int.Parse((string)param[1]);
  279. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  280. bool ret = Pick(chamber, slot, hand, out reason);
  281. if (ret)
  282. {
  283. reason = string.Format("{0} {1}", Name, "Pick wafer");
  284. return true;
  285. }
  286. return false;
  287. });
  288. DEVICE.Register(String.Format("{0}.{1}", Name, "Place"), (out string reason, int time, object[] param) =>
  289. {
  290. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  291. int slot = int.Parse((string)param[1]);
  292. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  293. bool ret = Place(chamber, slot, hand, out reason);
  294. if (ret)
  295. {
  296. reason = string.Format("{0} {1}", Name, "Place wafer");
  297. return true;
  298. }
  299. return false;
  300. });
  301. DEVICE.Register(String.Format("{0}.{1}", Name, "Exchange"), (out string reason, int time, object[] param) =>
  302. {
  303. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  304. int slot = int.Parse((string)param[1]);
  305. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  306. bool ret = Exchange(chamber, slot, hand, out reason);
  307. if (ret)
  308. {
  309. reason = string.Format("{0} {1}", Name, "Swap wafer");
  310. return true;
  311. }
  312. return false;
  313. });
  314. DEVICE.Register(String.Format("{0}.{1}", Name, "Goto"), (out string reason, int time, object[] param) =>
  315. {
  316. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  317. int slot = int.Parse((string)param[1]);
  318. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  319. Motion next = (Motion)Enum.Parse(typeof(Motion), (string)param[3], true);
  320. int x = int.Parse((string)param[4]);
  321. int y = int.Parse((string)param[5]);
  322. int z = int.Parse((string)param[6]);
  323. bool ret = Goto(chamber, slot, next, hand, x,y,z, out reason);
  324. if (ret)
  325. {
  326. reason = string.Format("{0}{1}", Name, "Goto");
  327. return true;
  328. }
  329. return false;
  330. });
  331. DEVICE.Register(String.Format("{0}.{1}", Name, "BladeEnable"), (out string reason, int time, object[] param) =>
  332. {
  333. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  334. bool bEnable = bool.Parse((string)param[1]);
  335. bool ret = Enable(hand, bEnable, out reason);
  336. if (ret)
  337. {
  338. reason = string.Format("{0}{1}", Name, "Disable robot arm");
  339. return true;
  340. }
  341. return false;
  342. });
  343. DATA.Subscribe($"{Name}.State", () => State);
  344. DATA.Subscribe($"{Name}.Busy", () => Busy);
  345. DATA.Subscribe($"{Name}.ErrorCode", () => ErrorCode);
  346. DATA.Subscribe($"{Name}.Blade1Target", () => Blade1Target);
  347. DATA.Subscribe($"{Name}.Blade2Target", () => Blade2Target);
  348. DATA.Subscribe($"{Name}.Blade1Enable", () => Blade1Enable);
  349. DATA.Subscribe($"{Name}.Blade2Enable", () => Blade2Enable);
  350. DATA.Subscribe($"{Name}.Swap", () => Swap);
  351. DATA.Subscribe($"{Name}.PlaceBalde", () => PlaceBalde);
  352. DATA.Subscribe($"{Name}.Speed", () => Speed);
  353. DATA.Subscribe($"{Name}.Rotation", () => Rotation);
  354. DATA.Subscribe($"{Name}.Extension", () => Extension);
  355. DATA.Subscribe($"{Name}.Wrist1", () => Wrist1);
  356. DATA.Subscribe($"{Name}.Wrist2", () => Wrist2);
  357. DATA.Subscribe($"{Name}.Evevation", () => Evevation);
  358. DATA.Subscribe($"{Name}.CmdBladeTarget", () => CmdBladeTarget);
  359. DATA.Subscribe($"{Name}.CmdBlade1Extend", () => CmdBlade1Extend);
  360. DATA.Subscribe($"{Name}.CmdBlade2Extend", () => CmdBlade2Extend);
  361. Reset();
  362. string str = string.Empty;
  363. _eventHandler = _factory.Event();
  364. return true;
  365. }
  366. public void Terminate()
  367. {
  368. }
  369. public void Monitor()
  370. {
  371. }
  372. public void Reset()
  373. {
  374. lock (_locker)
  375. {
  376. _foregroundHandler = null;
  377. _backgroundHandler = null;
  378. }
  379. _exceuteErr = false;
  380. if (_commErr)
  381. {
  382. _commErr = false;
  383. _socket.Connect(this._addr);
  384. }
  385. Swap = false;
  386. }
  387. public bool Enable(Hand hand, bool bEnable, out string reason)
  388. {
  389. reason = string.Empty;
  390. if (hand == Hand.Blade1)
  391. {
  392. Blade2Enable = bEnable;
  393. }
  394. else if (hand == Hand.Blade2)
  395. {
  396. Blade2Enable = bEnable;
  397. }
  398. else
  399. {
  400. reason = "Can't disable all blade";
  401. return false;
  402. }
  403. return true;
  404. }
  405. #region Command
  406. public bool Init(out string reason)
  407. {
  408. lock (_locker)
  409. {
  410. _foregroundHandler = null;
  411. _backgroundHandler = null;
  412. }
  413. reason = string.Empty;
  414. return execute(_factory.Init(), out reason);
  415. }
  416. public bool Home(out string reason)
  417. {
  418. lock (_locker)
  419. {
  420. _foregroundHandler = null;
  421. _backgroundHandler = null;
  422. }
  423. reason = string.Empty;
  424. return execute(_factory.Home(), out reason);
  425. }
  426. public bool Grip(Hand hand,out string reason)
  427. {
  428. reason = string.Empty;
  429. return execute(_factory.Grip(hand), out reason);
  430. }
  431. public bool Release(Hand hand, out string reason)
  432. {
  433. reason = string.Empty;
  434. return execute(_factory.Release(hand), out reason);
  435. }
  436. public bool WaferMapping(ModuleName loadport, out string reason)
  437. {
  438. reason = string.Empty;
  439. return execute(_factory.WaferMapping(loadport), out reason);
  440. }
  441. public bool QueryWaferMap(ModuleName loadport, out string reason)
  442. {
  443. reason = string.Empty;
  444. return execute(_factory.QueryWaferMap(loadport), out reason);
  445. }
  446. public bool QueryState(out string reason)
  447. {
  448. reason = string.Empty;
  449. return execute(_factory.QueryState(), out reason);
  450. }
  451. public bool QueryPosition(out string reason)
  452. {
  453. reason = string.Empty;
  454. return execute(_factory.QueryPosition(), out reason);
  455. }
  456. public bool Clear(out string reason)
  457. {
  458. reason = string.Empty;
  459. return execute(_factory.Clear(), out reason);
  460. }
  461. public bool Stop(out string reason)
  462. {
  463. reason = string.Empty;
  464. lock (_locker)
  465. {
  466. _foregroundHandler = null;
  467. _backgroundHandler = null;
  468. }
  469. return execute(_factory.Stop(), out reason);
  470. }
  471. public bool SetSpeed(int speed, out string reason)
  472. {
  473. reason = string.Empty;
  474. return execute(_factory.SetSpeed(speed), out reason);
  475. }
  476. public bool SetCommunication( out string reason)
  477. {
  478. reason = string.Empty;
  479. return execute(_factory.SetCommunication(), out reason);
  480. }
  481. public bool SetLoad(Hand hand, out string reason)
  482. {
  483. reason = string.Empty;
  484. return execute(_factory.SetLoad(hand), out reason);
  485. }
  486. public bool CheckLoad(ModuleName chamber, int slot, out string reason)
  487. {
  488. reason = string.Empty;
  489. return execute(_factory.CheckLoad(chamber, slot), out reason);
  490. }
  491. public bool RequestWaferPresent( out string reason)
  492. {
  493. reason = string.Empty;
  494. return execute(_factory.RequestWaferPresent(), out reason);
  495. }
  496. public bool Goto(ModuleName chamber, int slot, Motion motion,Hand hand, int x, int y, int z,out string reason)
  497. {
  498. reason = string.Empty;
  499. if (chamber == ModuleName.Robot)
  500. {
  501. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  502. return false;
  503. }
  504. if (ModuleHelper.IsLoadPort(chamber))
  505. {
  506. if (hand == Hand.Both)
  507. {
  508. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  509. {
  510. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  511. return false;
  512. }
  513. }
  514. else if(hand == Hand.Blade2)
  515. {
  516. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  517. {
  518. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  519. return false;
  520. }
  521. }
  522. else
  523. {
  524. if (!checkslot(0, 25, slot))
  525. {
  526. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  527. return false;
  528. }
  529. }
  530. }
  531. else
  532. {
  533. if (hand == Hand.Both)
  534. {
  535. reason = string.Format("Pick invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  536. return false;
  537. }
  538. }
  539. return execute(_factory.Goto( chamber, slot, motion, hand, x,y,z), out reason);
  540. }
  541. public bool Extend(ModuleName chamber, int slot, Hand hand, out string reason)
  542. {
  543. reason = string.Empty;
  544. if (chamber == ModuleName.Robot)
  545. {
  546. reason = string.Format("Extend invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  547. return false;
  548. }
  549. if (ModuleHelper.IsLoadPort(chamber))
  550. {
  551. if (hand == Hand.Both)
  552. {
  553. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  554. {
  555. reason = string.Format("Extend invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  556. return false;
  557. }
  558. }
  559. else if (hand == Hand.Blade2)
  560. {
  561. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  562. {
  563. reason = string.Format("Extend invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  564. return false;
  565. }
  566. }
  567. else
  568. {
  569. if (!checkslot(0, 25, slot))
  570. {
  571. reason = string.Format("Extend invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  572. return false;
  573. }
  574. }
  575. }
  576. else
  577. {
  578. if (hand == Hand.Both)
  579. {
  580. reason = string.Format("Extend invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  581. return false;
  582. }
  583. }
  584. return execute(_factory.Extend(chamber, slot, hand), out reason);
  585. }
  586. public bool Retract(ModuleName chamber, int slot, Hand hand, out string reason)
  587. {
  588. reason = string.Empty;
  589. if (chamber == ModuleName.Robot)
  590. {
  591. reason = string.Format("Retract invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  592. return false;
  593. }
  594. if (ModuleHelper.IsLoadPort(chamber))
  595. {
  596. if (hand == Hand.Both)
  597. {
  598. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  599. {
  600. reason = string.Format("Retract invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  601. return false;
  602. }
  603. }
  604. else if (hand == Hand.Blade2)
  605. {
  606. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  607. {
  608. reason = string.Format("Retract invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  609. return false;
  610. }
  611. }
  612. else
  613. {
  614. if (!checkslot(0, 25, slot))
  615. {
  616. reason = string.Format("Retract invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  617. return false;
  618. }
  619. }
  620. }
  621. else
  622. {
  623. if (hand == Hand.Both)
  624. {
  625. reason = string.Format("Retract invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  626. return false;
  627. }
  628. }
  629. return execute(_factory.Retract(chamber, slot, hand), out reason);
  630. }
  631. public bool PickExtend(ModuleName chamber, int slot, Hand hand, out string reason)
  632. {
  633. reason = string.Empty;
  634. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber))
  635. {
  636. reason = $"Pick extend target not support, chamber is {chamber.ToString()}, slot is {slot}";
  637. return false;
  638. }
  639. if (hand == Hand.Both)
  640. {
  641. reason = string.Format("Pick extend invalid parameter, do not support double arm extend ,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  642. return false;
  643. }
  644. return execute(_factory.PickExtend(chamber, slot, hand), out reason);
  645. }
  646. public bool PickRetract(ModuleName chamber, int slot, Hand hand, out string reason)
  647. {
  648. reason = string.Empty;
  649. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber))
  650. {
  651. reason = $"Pick retract target not support, chamber is {chamber.ToString()}, slot is {slot}";
  652. return false;
  653. }
  654. if (hand == Hand.Both)
  655. {
  656. reason = string.Format("Pick retract invalid parameter, do not support double arm retract ,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  657. return false;
  658. }
  659. return execute(_factory.PickRetract(chamber, slot, hand), out reason);
  660. }
  661. public bool Pick(ModuleName chamber, int slot, Hand hand, out string reason)
  662. {
  663. reason = string.Empty;
  664. if (chamber == ModuleName.Robot)
  665. {
  666. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  667. return false;
  668. }
  669. if (ModuleHelper.IsLoadPort(chamber))
  670. {
  671. if (hand == Hand.Both)
  672. {
  673. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  674. {
  675. reason = string.Format("Pick invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  676. return false;
  677. }
  678. }
  679. else if (hand == Hand.Blade2)
  680. {
  681. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  682. {
  683. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  684. return false;
  685. }
  686. }
  687. else
  688. {
  689. if (!checkslot(0, 25, slot))
  690. {
  691. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  692. return false;
  693. }
  694. }
  695. }
  696. else
  697. {
  698. if (hand == Hand.Both)
  699. {
  700. reason = string.Format("Pick invalid parameter, double pick,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  701. return false;
  702. }
  703. }
  704. return execute(_factory.Pick(chamber, slot, hand), out reason);
  705. }
  706. public bool Place(ModuleName chamber, int slot, Hand hand, out string reason)
  707. {
  708. reason = string.Empty;
  709. if (chamber == ModuleName.Robot)
  710. {
  711. reason = string.Format("Place invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  712. return false;
  713. }
  714. if (ModuleHelper.IsLoadPort(chamber))
  715. {
  716. if (hand == Hand.Both)
  717. {
  718. if (!checkslot(0, 25 - Blade2Slots, slot)) //0-20 | 20,21,22,23,24
  719. {
  720. reason = string.Format("Place invalid parameter,double hand, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  721. return false;
  722. }
  723. }
  724. else if (hand == Hand.Blade2)
  725. {
  726. if (!checkslot(0, 25 - Blade2Slots + 1, slot)) //0 - 21| 21,22,23,24
  727. {
  728. reason = string.Format("Pick invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  729. return false;
  730. }
  731. }
  732. else
  733. {
  734. if (!checkslot(0, 25, slot))
  735. {
  736. reason = string.Format("Place invalid parameter,place, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  737. return false;
  738. }
  739. }
  740. }
  741. else
  742. {
  743. if (hand == Hand.Both)
  744. {
  745. reason = string.Format("Place invalid parameter, double place,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  746. return false;
  747. }
  748. }
  749. return execute(_factory.Place(chamber, slot, hand), out reason);
  750. }
  751. public bool PlaceExtend(ModuleName chamber, int slot, Hand hand, out string reason)
  752. {
  753. reason = string.Empty;
  754. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber))
  755. {
  756. reason = $"Place extend target not support, chamber is {chamber.ToString()}, slot is {slot}";
  757. return false;
  758. }
  759. if (hand == Hand.Both)
  760. {
  761. reason =
  762. $"Place extend invalid parameter, do not support double arm extend ,chamber is {chamber.ToString()}, slot is {slot}";
  763. return false;
  764. }
  765. return execute(_factory.PlaceExtend(chamber, slot, hand), out reason);
  766. }
  767. public bool PlaceRetract(ModuleName chamber, int slot, Hand hand, out string reason)
  768. {
  769. reason = string.Empty;
  770. if (chamber.ToString() == Name || chamber == ModuleName.System || ModuleHelper.IsLoadPort(chamber))
  771. {
  772. reason = $"Place retract target not support, chamber is {chamber.ToString()}, slot is {slot}";
  773. return false;
  774. }
  775. if (hand == Hand.Both)
  776. {
  777. reason =
  778. $"Place retract invalid parameter, do not support double arm extend ,chamber is {chamber.ToString()}, slot is {slot}";
  779. return false;
  780. }
  781. return execute(_factory.PlaceRetract(chamber, slot, hand), out reason);
  782. }
  783. public bool Exchange(ModuleName chamber, int slot, Hand hand, out string reason)
  784. {
  785. reason = string.Empty;
  786. if (chamber == ModuleName.Robot)
  787. {
  788. reason = string.Format("Exchange invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  789. return false;
  790. }
  791. if (Blade2Slots > 1)
  792. {
  793. reason = string.Format("this robot don't support exchange operation.");
  794. return false;
  795. }
  796. if (hand == Hand.Both)
  797. {
  798. reason = string.Format("Exchange invalid parameter,double hand");
  799. return false;
  800. }
  801. if (ModuleHelper.IsLoadPort(chamber))
  802. {
  803. if (!checkslot(0, 25, slot))
  804. {
  805. reason = string.Format("Exchange invalid parameter,pick, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  806. return false;
  807. }
  808. }
  809. return execute(_factory.Exchange(chamber, slot, hand), out reason);
  810. }
  811. public bool PickEx(ModuleName chamber, int slot, Hand hand, int x, int y, int z, out string reason)
  812. {
  813. reason = string.Empty;
  814. if (chamber == ModuleName.Robot)
  815. {
  816. reason = string.Format("Pick invalid parameter, chamber is {0}, slot is {1}", chamber.ToString(), slot);
  817. return false;
  818. }
  819. if (ModuleHelper.IsLoadPort(chamber))
  820. {
  821. if (hand == Hand.Both)
  822. {
  823. if (!checkslot(0, 25 - 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, 25 - 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, 25, 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.PickEx(chamber, slot, hand, x,y,z), out reason);
  855. }
  856. public bool PlaceEx(ModuleName chamber, int slot, Hand hand, int x, int y, int z, 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
  892. {
  893. if (hand == Hand.Both)
  894. {
  895. reason = string.Format("Place invalid parameter, double place,chamber is {0}, slot is {1}", chamber.ToString(), slot);
  896. return false;
  897. }
  898. }
  899. return execute(_factory.PlaceEx(chamber, slot, hand,x,y,z), out reason);
  900. }
  901. #endregion
  902. public virtual bool execute(IHandler handler, out string reason)
  903. {
  904. reason = string.Empty;
  905. lock (_locker)
  906. {
  907. if (_foregroundHandler != null)
  908. {
  909. reason = "System busy, please wait or reset system.";
  910. EV.PostMessage(Name, EventEnum.DefaultWarning, string.Format("{0} {1} {2}", this.DeviceID, handler.ToString(), reason));
  911. return false;
  912. }
  913. if (_backgroundHandler != null && handler.IsBackground)
  914. {
  915. reason = "System busy,one background command is running, please wait or reset system.";
  916. EV.PostMessage(Name, EventEnum.DefaultWarning, string.Format("{0} {1} {2}", this.DeviceID, handler.ToString(), reason)); reason = "系统忙,后台命令正在处理,暂时不能处理新的后台命令";
  917. return false;
  918. }
  919. handler.Unit = (int)Unit.Robot;
  920. if(!handler.Execute(ref _socket))
  921. {
  922. reason = "Communication error,please check it.";
  923. return false;
  924. }
  925. if (handler.IsBackground)
  926. _backgroundHandler = handler;
  927. else
  928. _foregroundHandler = handler;
  929. }
  930. return true;
  931. }
  932. public virtual void OnDataChanged(string package)
  933. {
  934. try
  935. {
  936. if (!package.Contains("Gb") && !package.Contains("Pb"))
  937. package = package.ToUpper();
  938. string[] msgs = Regex.Split(package, delimiter);
  939. foreach (string msg in msgs)
  940. {
  941. if (msg.Length > 0)
  942. {
  943. bool completed = false;
  944. string resp = msg;
  945. lock (_locker)
  946. {
  947. if (_foregroundHandler != null && _foregroundHandler.OnMessage(ref _socket, resp, out completed))
  948. {
  949. _foregroundHandler = null;
  950. }
  951. else if (_backgroundHandler != null && _backgroundHandler.OnMessage(ref _socket, resp, out completed))
  952. {
  953. if (completed)
  954. {
  955. string reason = string.Empty;
  956. QueryState(out reason);
  957. _backgroundHandler = null;
  958. }
  959. }
  960. else
  961. {
  962. if (_eventHandler != null)
  963. {
  964. if (_eventHandler.OnMessage(ref _socket, resp, out completed))
  965. {
  966. if (completed)
  967. {
  968. EV.PostMessage("Robot", EventEnum.DefaultWarning, string.Format(" has error. {0:X}", ErrorCode));
  969. _exceuteErr = true;
  970. }
  971. }
  972. }
  973. }
  974. }
  975. }
  976. }
  977. }
  978. catch (ExcuteFailedException e)
  979. {
  980. EV.PostMessage("Robot", EventEnum.DefaultWarning, string.Format("executed failed. {0}",e.Message));
  981. _exceuteErr = false;
  982. }
  983. catch (InvalidPackageException e)
  984. {
  985. EV.PostMessage("Robot", EventEnum.DefaultWarning, string.Format("recive invalid package. {0}", e.Message));
  986. }
  987. catch (System.Exception ex)
  988. {
  989. _commErr = true;
  990. LOG.Write("Eobot failed:" + ex.ToString());
  991. }
  992. }
  993. private void OnErrorHandler(ErrorEventArgs args)
  994. {
  995. _commErr = true;
  996. Initalized = false;
  997. EV.PostMessage(Module, EventEnum.CommunicationError, Display, args.Reason);
  998. //LOG.Error(string.Format("{0} communication failed,检查通讯连接.{1}", Name, args.Reason));
  999. }
  1000. private bool checkslot(int min, int max, int slot)
  1001. {
  1002. return slot >= min && slot < max;
  1003. }
  1004. public void NotifySlotMapResult(ModuleName module, string slotMap)
  1005. {
  1006. if (OnSlotMapRead != null)
  1007. {
  1008. OnSlotMapRead(module, slotMap);
  1009. }
  1010. }
  1011. public void NotifyWaferPresent(Hand hand, WaferStatus status)
  1012. {
  1013. if (status == WaferStatus.Empty)
  1014. {
  1015. if (hand == Hand.Blade1)
  1016. {
  1017. WaferPresentOnBlade1 = status == WaferStatus.Empty;
  1018. }
  1019. if (hand == Hand.Blade2)
  1020. {
  1021. WaferPresentOnBlade2 = status == WaferStatus.Empty;
  1022. }
  1023. }
  1024. if (status == WaferStatus.Unknown)
  1025. {
  1026. EV.PostWarningLog(Module, "Wafer present unknown");
  1027. return;
  1028. }
  1029. if (hand == Hand.Blade1)
  1030. {
  1031. WaferPresentOnBlade1 = status == WaferStatus.Normal;
  1032. }
  1033. if (hand == Hand.Blade2)
  1034. {
  1035. WaferPresentOnBlade2 = status == WaferStatus.Normal;
  1036. }
  1037. }
  1038. }
  1039. }