Handler.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. using System;
  2. using System.Text;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Sorter.Common;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using System.Text.RegularExpressions;
  8. using Aitex.Core.RT.Log;
  9. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot.SR100
  10. {
  11. public class handler<T> : IHandler where T : ITransferMsg, new()
  12. {
  13. public int ID { get; set; }
  14. public int Unit { get; set; }
  15. public bool IsBackground { get { return _imp.background; } }
  16. private static int retry_time = 3;
  17. private int retry_count = retry_time;
  18. private object[] _objs = null;
  19. private TokenGenerator _generator;
  20. private T _imp = new T();
  21. public handler(IDevice device)
  22. {
  23. _imp.Robot = device;
  24. }
  25. public handler(IDevice device, ref TokenGenerator gen, params object[] objs)
  26. {
  27. _imp.Robot = device;
  28. this._generator = gen;
  29. this._objs = objs;
  30. }
  31. public bool Execute<TPort>(ref TPort port) where TPort : ICommunication
  32. {
  33. retry_count = retry_time;
  34. ID = _generator.create();
  35. return port.Write(string.Format("{0}{1}{2}", ProtocolTag.tag_cmd_start, package(), ProtocolTag.tag_end));
  36. }
  37. /// <summary>
  38. /// return value: bhandle
  39. /// </summary>
  40. /// <typeparam name="TPort"></typeparam>
  41. /// <param name="port"></param>
  42. /// <param name="msg"></param>
  43. /// <param name="completed"></param>
  44. /// <returns></returns>
  45. ///
  46. public bool OnMessage<TPort>(ref TPort port, string message, out bool completed) where TPort : ICommunication
  47. {
  48. //message = ">,1,EVNT,100,2018/11/16 17:01:06,2BA0,A1";
  49. // >,1,EVNT,100,2019/10/11 17:27:32,1930,8B
  50. //message = " !,1,36,40,2BA0,MTRS,002200,-0011931,-0610171,00179995,00049818,00186336,57";
  51. //message = "!,1,16,40,0000,MTCH,000483,-0011862,00000000,00179516,00090369,00172882,0A";
  52. try
  53. {
  54. completed = false;
  55. string package = message;
  56. string[] words = Regex.Split(package, ProtocolTag.cmd_token);
  57. string type = words[0];
  58. int unit = int.Parse(words[1]);
  59. string sum = words[words.Length - 1];
  60. string check = Checksum(package);
  61. if (sum != check)
  62. {
  63. throw (new InvalidPackageException(string.Format("check sum error{0}", package)));
  64. }
  65. if (type != ProtocolTag.resp_tag_event && type != ProtocolTag.resp_tag_error)
  66. {
  67. int seq = int.Parse(words[2]);
  68. if (seq != ID)
  69. return false;
  70. if (unit != Unit)
  71. {
  72. throw (new InvalidPackageException(string.Format("invalid unit {0}", package)));
  73. }
  74. }
  75. if (type == ProtocolTag.resp_tag_error)
  76. {
  77. string error = words[1];
  78. //‘1’: Warning 1 (W1), ‘2’: Warning 2 (W2), ‘3’: Important alarm 1 (A1), ‘4’: Important alarm 2 (A2),
  79. //‘5’: Serious alarm (F)
  80. if (error[0] != '1' && error[0] != '2')
  81. {
  82. string warning = string.Format("can't execute retry, {0}", error);
  83. LOG.Warning(warning);
  84. throw (new ExcuteFailedException(warning));
  85. }
  86. if (retry_count-- <= 0)
  87. {
  88. string warning = string.Format("retry over {0} times", retry_time);
  89. LOG.Warning(warning);
  90. throw (new ExcuteFailedException(warning));
  91. }
  92. port.Write(string.Format("{0}{1}{2}", ProtocolTag.tag_cmd_start, this.package(), ProtocolTag.tag_end));
  93. return true;
  94. }
  95. else if (type == ProtocolTag.resp_tag_event)
  96. {
  97. string evtType = words[3];
  98. string evtInfo = words[5];
  99. if (_imp.evt)
  100. completed = _imp.unpackage(type, words);
  101. return _imp.evt;
  102. }
  103. else
  104. {
  105. completed = _imp.unpackage(type, words);
  106. if (completed)
  107. {
  108. _generator.release(ID);
  109. if (_imp.background)
  110. {
  111. ID = this._generator.create();
  112. port.Write(string.Format("{0}{1}{2}", ProtocolTag.tag_cmd_start, ackn(), ProtocolTag.tag_end));
  113. _generator.release(ID);
  114. }
  115. //wait 2ms
  116. return true;
  117. }
  118. return true;
  119. }
  120. }
  121. catch (ExcuteFailedException e)
  122. {
  123. throw (e);
  124. }
  125. catch (InvalidPackageException e)
  126. {
  127. throw e;
  128. }
  129. catch (Exception ex)
  130. {
  131. LOG.Write(ex);
  132. throw (new InvalidPackageException(message));
  133. }
  134. }
  135. private string Checksum(string package)
  136. {
  137. int start = package.IndexOf(ProtocolTag.cmd_token);
  138. int end = package.LastIndexOf(ProtocolTag.cmd_token);
  139. int len = end - start + 1;
  140. if (len > 1)
  141. {
  142. string data = package.Substring(start, len);
  143. return Checksum(Encoding.Default.GetBytes(data));
  144. }
  145. return "";
  146. }
  147. private string Checksum(byte[] bytes)
  148. {
  149. int sum = 0;
  150. foreach (byte code in bytes)
  151. {
  152. sum += code;
  153. }
  154. string hex = String.Format("{0:X2}", sum % 256);
  155. return hex;
  156. }
  157. private string package()
  158. {
  159. //$,<UNo>(,<SeqNo>),<Command>,<Parameter>(,<Sum>)<CR>
  160. string data = string.Empty;
  161. data = string.Format(",{0:D1},{1:D2}{2}", Unit, ID, _imp.package(this._objs));
  162. string sum = Checksum(Encoding.ASCII.GetBytes(data));
  163. return data + sum;
  164. }
  165. private string ackn()
  166. {
  167. //$,<UNo>(,<SeqNo>),ACKN(,<Sum>)<CR>
  168. string data = string.Empty;
  169. data = string.Format(",{0:D1},{1:D2},ACKN,", Unit, ID);
  170. string sum = Checksum(Encoding.ASCII.GetBytes(data));
  171. return data + sum;
  172. }
  173. }
  174. public class RobotMotionHandler : ITransferMsg
  175. {
  176. public bool background { get; protected set; }
  177. public bool evt { get { return false; } }
  178. public string deviceID { private get; set; }
  179. public string _cmd = string.Empty;
  180. public IDevice Robot { set { _device = (Robot)value; } }
  181. protected Robot _device;
  182. public RobotMotionHandler()
  183. {
  184. background = false;
  185. }
  186. public virtual string package(params object[] args)
  187. {
  188. return "";
  189. }
  190. public bool unpackage(string type, string[] items)
  191. {
  192. int value = Convert.ToInt32(items[3],16);
  193. _device.Status = value;
  194. int error = Convert.ToInt32(items[4], 16);
  195. _device.ErrorCode = error;
  196. if (error > 0)
  197. _device.LastErrorCode = error;
  198. if (type.Equals(ProtocolTag.resp_tag_excute))
  199. {
  200. if (items.Length > 7)
  201. _device.ElapseTime = int.Parse(items[6]);
  202. if (items.Length > 8)
  203. _device.Rotation = int.Parse(items[7]);
  204. if (items.Length > 9)
  205. _device.Extension = int.Parse(items[8]);
  206. if (items.Length > 10)
  207. _device.Wrist1= int.Parse(items[9]);
  208. if (items.Length > 11)
  209. _device.Wrist2= int.Parse(items[10]);
  210. if (items.Length > 12)
  211. _device.Evevation = int.Parse(items[11]);
  212. if (error == 0)
  213. {
  214. update(items);
  215. }
  216. return true;
  217. }
  218. return !background;
  219. }
  220. protected virtual void update(string[] data)
  221. {
  222. }
  223. }
  224. public class RbInitHandler : RobotMotionHandler
  225. {
  226. public RbInitHandler()
  227. {
  228. background = true;
  229. }
  230. //$,<UNo>(,<SeqNo>),CCLR,<CMode>(,<Sum>)<CR>
  231. public override string package(params object[] args)
  232. {
  233. return ",CCLR,E,";
  234. }
  235. }
  236. public class RbHomeHandler : RobotMotionHandler
  237. {
  238. public RbHomeHandler()
  239. {
  240. background = true;
  241. }
  242. public override string package(params object[] args)
  243. {
  244. updateBefore();
  245. return ",INIT,1,1,G,";
  246. }
  247. protected void updateBefore()
  248. {
  249. _device.Blade1Target = ModuleHelper.Converter(_device.Name);
  250. _device.Blade2Target = ModuleHelper.Converter(_device.Name);
  251. }
  252. protected override void update(string[] data)
  253. {
  254. _device.Initalized = true;
  255. _device.Swap = false;
  256. }
  257. }
  258. public class RbClearErrorHandler : RobotMotionHandler
  259. {
  260. public RbClearErrorHandler()
  261. {
  262. background = true;
  263. }
  264. //$,<UNo>(,<SeqNo>),CCLR,<CMode>(,<Sum>)<CR>
  265. public override string package(params object[] args)
  266. {
  267. return ",CCLR,E,";
  268. }
  269. }
  270. public class RbGripHandler : RobotMotionHandler
  271. {
  272. Hand _hand;
  273. public RbGripHandler()
  274. {
  275. background = true;
  276. }
  277. //$,<UNo>(,<SeqNo>),CSOL,<Sol>,<Sw>,<Wait>(,<Sum>)<CR>
  278. //sol Solenoid control specification (1 byte) • ‘1’ : Blade 1. • ‘2’ : Blade 2. • ‘F’ : Blade 1 + Blade 2.
  279. // Solenoid command (1 byte) • ‘0’ : Wafer release. / Lifter down. • ‘1’ : Wafer hold. / Lifter up.
  280. public override string package(params object[] args)
  281. {
  282. _hand = (Hand)args[0];
  283. bool bHold = (bool)args[1];
  284. if(bHold)
  285. return string.Format(",CSOL,{0},1,0,",RobotConvertor.hand2string(_hand));
  286. return string.Format(",CSOL,{0},0,0,", RobotConvertor.hand2string(_hand));
  287. }
  288. }
  289. public class RbStopHandler : RobotMotionHandler
  290. {
  291. public RbStopHandler()
  292. {
  293. background = true;
  294. }
  295. //$,<UNo>(,<SeqNo>),CSTP,<Sw>(,<Sum>)<CR>
  296. //• ‘H’ : Deceleration to a stop.
  297. //• ‘E’ : Emergency stop.
  298. public override string package(params object[] args)
  299. {
  300. bool isEmergency = (bool)args[0];
  301. if (isEmergency)
  302. return ",CSTP,E,";
  303. return ",CSTP,H,";
  304. }
  305. }
  306. public class RbResumeHandler : RobotMotionHandler
  307. {
  308. public RbResumeHandler()
  309. {
  310. background = true;
  311. }
  312. //[Command Message] $,<UNo>(,<SeqNo>),CRSM(,<Sum>)<CR>
  313. //• UNo : Unit number(1 byte)
  314. // • ‘1’ : Manipulator.
  315. // • ‘2’ : Pre-aligner.
  316. //• SeqNo : Sequence number(None / 2 bytes)
  317. public override string package(params object[] args)
  318. {
  319. return ",CRSM,";
  320. }
  321. }
  322. public class PickExtendHandler : RobotMotionHandler
  323. {
  324. private ModuleName _chamber;
  325. private int _slot;
  326. private Hand _hand;
  327. public PickExtendHandler()
  328. {
  329. background = true;
  330. }
  331. public override string package(params object[] args)
  332. {
  333. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  334. _chamber = (ModuleName)args[0];
  335. _slot = (int)args[1];
  336. _hand = (Hand)args[2];
  337. updateBefore();
  338. return string.Format(",MTRS,G,{0},{1:D2},A,{2},Gb,",
  339. RobotConvertor.chamber2staion(_chamber),
  340. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  341. RobotConvertor.hand2string(_hand));
  342. }
  343. private void updateBefore()
  344. {
  345. _device.Blade1Target = _chamber;
  346. _device.Blade2Target = _chamber;
  347. string arm = _hand == Hand.Blade1 ? "A" : "B";
  348. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  349. _device.CmdBlade1Extend = _hand == Hand.Blade1 ? "1" : "0";
  350. _device.CmdBlade2Extend = _hand == Hand.Blade1 ? "0" : "1";
  351. }
  352. }
  353. public class PickRetractHandler : RobotMotionHandler
  354. {
  355. private ModuleName _chamber;
  356. private int _slot;
  357. private Hand _hand;
  358. public PickRetractHandler()
  359. {
  360. background = true;
  361. }
  362. public override string package(params object[] args)
  363. {
  364. //$,<UNo>(,<SeqNo>),MPNT,<TrsPnt>(,<Sum>)<CR>
  365. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  366. _chamber = (ModuleName)args[0];
  367. _slot = (int)args[1];
  368. _hand = (Hand)args[2];
  369. updateBefore();
  370. return ",MPNT,G4,";
  371. }
  372. private void updateBefore()
  373. {
  374. _device.Blade1Target = _chamber;
  375. _device.Blade2Target = _chamber;
  376. string arm = _hand == Hand.Blade1 ? "A" : "B";
  377. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  378. _device.CmdBlade1Extend = _hand == Hand.Blade1 ? "1" : "0";
  379. _device.CmdBlade2Extend = _hand == Hand.Blade1 ? "0" : "1";
  380. }
  381. protected override void update(string[] data)
  382. {
  383. if (_hand == Hand.Both)
  384. {
  385. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleHelper.Converter(_device.Name), (int)Hand.Blade1);
  386. WaferManager.Instance.WaferMoved(_chamber, _slot + 1, ModuleHelper.Converter(_device.Name), (int)Hand.Blade2);
  387. }
  388. else
  389. {
  390. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleHelper.Converter(_device.Name), (int)_hand);
  391. }
  392. string arm = _hand == Hand.Blade1 ? "A" : "B";
  393. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  394. _device.CmdBlade1Extend = "0";
  395. _device.CmdBlade2Extend = "0";
  396. _device.Blade1Target = ModuleHelper.Converter(_device.Name);
  397. _device.Blade2Target = ModuleHelper.Converter(_device.Name);
  398. }
  399. }
  400. public class PickHandler : RobotMotionHandler
  401. {
  402. private ModuleName _chamber;
  403. private int _slot;
  404. private Hand _hand;
  405. public PickHandler()
  406. {
  407. background = true;
  408. }
  409. public override string package(params object[] args)
  410. {
  411. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  412. _chamber = (ModuleName)args[0];
  413. _slot = (int)args[1];
  414. _hand = (Hand)args[2];
  415. updateBefore();
  416. return string.Format(",MTRS,G,{0},{1:D2},A,{2},G4,",
  417. RobotConvertor.chamber2staion(_chamber),
  418. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  419. RobotConvertor.hand2string(_hand));
  420. }
  421. private void updateBefore()
  422. {
  423. _device.Blade1Target = _chamber;
  424. _device.Blade2Target = _chamber;
  425. string arm = _hand == Hand.Blade1 ? "A" : "B";
  426. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  427. _device.CmdBlade1Extend = _hand == Hand.Blade1 ? "1" : "0";
  428. _device.CmdBlade2Extend = _hand == Hand.Blade1 ? "0" : "1";
  429. }
  430. protected override void update(string[] data)
  431. {
  432. if (_hand == Hand.Both)
  433. {
  434. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleHelper.Converter(_device.Name), (int)Hand.Blade1);
  435. WaferManager.Instance.WaferMoved(_chamber, _slot + 1, ModuleHelper.Converter(_device.Name), (int)Hand.Blade2);
  436. }
  437. else
  438. {
  439. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleHelper.Converter(_device.Name), (int)_hand);
  440. }
  441. string arm = _hand == Hand.Blade1 ? "A" : "B";
  442. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  443. _device.CmdBlade1Extend = "0";
  444. _device.CmdBlade2Extend = "0";
  445. _device.Blade1Target = ModuleHelper.Converter(_device.Name);
  446. _device.Blade2Target = ModuleHelper.Converter(_device.Name);
  447. }
  448. }
  449. public class PlaceHandler : RobotMotionHandler
  450. {
  451. private ModuleName _chamber;
  452. private int _slot;
  453. private Hand _hand;
  454. public PlaceHandler()
  455. {
  456. background = true;
  457. }
  458. public override string package(params object[] args)
  459. {
  460. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  461. _chamber = (ModuleName)args[0];
  462. _slot = (int)args[1];
  463. _hand = (Hand)args[2];
  464. updateBefore();
  465. return string.Format(",MTRS,P,{0},{1:D2},A,{2},P4,",
  466. RobotConvertor.chamber2staion(_chamber),
  467. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  468. RobotConvertor.hand2string(_hand));
  469. }
  470. private void updateBefore()
  471. {
  472. _device.Blade1Target = _chamber;
  473. _device.Blade2Target = _chamber;
  474. string arm = _hand == Hand.Blade1 ? "A" : "B";
  475. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  476. _device.CmdBlade1Extend = _hand == Hand.Blade1 ? "1" : "0";
  477. _device.CmdBlade2Extend = _hand == Hand.Blade1 ? "0" : "1";
  478. }
  479. protected override void update(string[] data)
  480. {
  481. if (_hand == Hand.Both)
  482. {
  483. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)Hand.Blade1, _chamber, _slot);
  484. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)Hand.Blade2, _chamber, _slot + 1);
  485. }
  486. else
  487. {
  488. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)_hand, _chamber, _slot);
  489. }
  490. string arm = _hand == Hand.Blade1 ? "A" : "B";
  491. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  492. _device.CmdBlade1Extend = "0";
  493. _device.CmdBlade2Extend = "0";
  494. _device.Blade1Target = ModuleHelper.Converter(_device.Name);
  495. _device.Blade2Target = ModuleHelper.Converter(_device.Name);
  496. }
  497. }
  498. public class PlaceExtendHandler : RobotMotionHandler
  499. {
  500. private ModuleName _chamber;
  501. private int _slot;
  502. private Hand _hand;
  503. public PlaceExtendHandler()
  504. {
  505. background = true;
  506. }
  507. public override string package(params object[] args)
  508. {
  509. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  510. _chamber = (ModuleName)args[0];
  511. _slot = (int)args[1];
  512. _hand = (Hand)args[2];
  513. updateBefore();
  514. return string.Format(",MTRS,P,{0},{1:D2},A,{2},Pb,",
  515. RobotConvertor.chamber2staion(_chamber),
  516. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  517. RobotConvertor.hand2string(_hand));
  518. }
  519. private void updateBefore()
  520. {
  521. _device.Blade1Target = _chamber;
  522. _device.Blade2Target = _chamber;
  523. string arm = _hand == Hand.Blade1 ? "A" : "B";
  524. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  525. _device.CmdBlade1Extend = _hand == Hand.Blade1 ? "1" : "0";
  526. _device.CmdBlade2Extend = _hand == Hand.Blade1 ? "0" : "1";
  527. }
  528. }
  529. public class PlaceRetractHandler : RobotMotionHandler
  530. {
  531. private ModuleName _chamber;
  532. private int _slot;
  533. private Hand _hand;
  534. public PlaceRetractHandler()
  535. {
  536. background = true;
  537. }
  538. public override string package(params object[] args)
  539. {
  540. //$,<UNo>(,<SeqNo>),MPNT,<TrsPnt>(,<Sum>)<CR>
  541. // $,<UNo>(,<SeqNo>),MPNT,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  542. _chamber = (ModuleName)args[0];
  543. _slot = (int)args[1];
  544. _hand = (Hand)args[2];
  545. updateBefore();
  546. return ",MPNT,P4,";
  547. }
  548. private void updateBefore()
  549. {
  550. _device.Blade1Target = _chamber;
  551. _device.Blade2Target = _chamber;
  552. string arm = _hand == Hand.Blade1 ? "A" : "B";
  553. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  554. _device.CmdBlade1Extend = _hand == Hand.Blade1 ? "1" : "0";
  555. _device.CmdBlade2Extend = _hand == Hand.Blade1 ? "0" : "1";
  556. }
  557. protected override void update(string[] data)
  558. {
  559. if (_hand == Hand.Both)
  560. {
  561. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)Hand.Blade1, _chamber, _slot);
  562. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)Hand.Blade2, _chamber, _slot + 1);
  563. }
  564. else
  565. {
  566. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)_hand, _chamber, _slot);
  567. }
  568. string arm = _hand == Hand.Blade1 ? "A" : "B";
  569. _device.CmdBladeTarget = $"{_chamber}.{arm}";
  570. _device.CmdBlade1Extend = "0";
  571. _device.CmdBlade2Extend = "0";
  572. _device.Blade1Target = ModuleHelper.Converter(_device.Name);
  573. _device.Blade2Target = ModuleHelper.Converter(_device.Name);
  574. }
  575. }
  576. public class ExchangHandler : RobotMotionHandler
  577. {
  578. private ModuleName _chamber;
  579. private int _slot;
  580. private Hand _hand;
  581. public ExchangHandler()
  582. {
  583. background = true;
  584. }
  585. public override string package(params object[] args)
  586. {
  587. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  588. _chamber = (ModuleName)args[0];
  589. _slot = (int)args[1];
  590. _hand = (Hand)args[2];
  591. if (_hand == Hand.Blade1)
  592. _hand = Hand.Blade2;
  593. else
  594. _hand = Hand.Blade1;
  595. updateBefore();
  596. return string.Format(",MTRS,E,{0},{1:D2},A,{2},P4,",
  597. RobotConvertor.chamber2staion(_chamber),
  598. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  599. RobotConvertor.hand2string(_hand));
  600. }
  601. private void updateBefore()
  602. {
  603. _device.Blade1Target = _chamber;
  604. _device.Blade2Target = _chamber;
  605. _device.Swap = true;
  606. _device.PlaceBalde = _hand;
  607. }
  608. protected override void update(string[] data)
  609. {
  610. if (_hand == Hand.Blade2)
  611. {
  612. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleHelper.Converter(_device.Name), (int)Hand.Blade2);
  613. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)Hand.Blade1, _chamber, _slot);
  614. }
  615. else
  616. {
  617. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleHelper.Converter(_device.Name), (int)Hand.Blade1);
  618. WaferManager.Instance.WaferMoved(ModuleHelper.Converter(_device.Name), (int)Hand.Blade2, _chamber, _slot);
  619. }
  620. _device.Swap = false;
  621. _device.Blade1Target = ModuleHelper.Converter(_device.Name);
  622. _device.Blade2Target = ModuleHelper.Converter(_device.Name);
  623. }
  624. }
  625. public class GotoHandler : RobotMotionHandler
  626. {
  627. private ModuleName _chamber;
  628. private int _slot;
  629. private Hand _hand;
  630. public GotoHandler()
  631. {
  632. background = true;
  633. }
  634. public override string package(params object[] args)
  635. {
  636. // $,<UNo>(,<SeqNo>),MTCH,<TrsSt>,<Slot>,<Posture>,<Hand>,<PMode> (,< OfstX >,< OfstY >,< OfstZ >)(,< Sum >)< CR >
  637. //• ‘M’ : Intermediate position (position with XYZ direction offset value applied).
  638. //• ‘R’ : Ready position (position with XYZ direction offset value applied).
  639. // • ‘O’ : Offset position (position with XYZ direction offset values applied).
  640. //// • ‘S’ : Registered position.
  641. /// • ‘B’ : Mapping start position.
  642. // • ‘E’ : Mapping finish position.
  643. _chamber = (ModuleName)args[0];
  644. _slot = (int)args[1];
  645. _hand = (Hand)args[2];
  646. updateBefore();
  647. return string.Format(",MTCH,{0},{1:D2},A,{2},R,",
  648. RobotConvertor.chamber2staion(_chamber),
  649. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  650. RobotConvertor.hand2string(_hand));
  651. }
  652. private void updateBefore()
  653. {
  654. _device.Blade1Target = _chamber;
  655. _device.Blade2Target = _chamber;
  656. }
  657. }
  658. public class MoveToHandler : RobotMotionHandler
  659. {
  660. private ModuleName _chamber;
  661. private int _slot;
  662. private Hand _hand;
  663. private bool _isPick;
  664. public MoveToHandler()
  665. {
  666. background = true;
  667. }
  668. public override string package(params object[] args)
  669. {
  670. // $,<UNo>(,<SeqNo>),MTCH,<TrsSt>,<Slot>,<Posture>,<Hand>,<PMode> (,< OfstX >,< OfstY >,< OfstZ >)(,< Sum >)< CR >
  671. _chamber = (ModuleName)args[0];
  672. _slot = (int)args[1];
  673. _hand = (Hand)args[2];
  674. _isPick = (bool)args[3];
  675. updateBefore();
  676. return string.Format(",MTRS,G,{0},{1:D2},A,{2},G4,",
  677. RobotConvertor.chamber2staion(_chamber),
  678. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  679. RobotConvertor.IsPick2Position(_isPick));
  680. }
  681. private void updateBefore()
  682. {
  683. _device.Blade1Target = _chamber;
  684. _device.Blade2Target = _chamber;
  685. }
  686. }
  687. public class PickHandlerEx : RobotMotionHandler
  688. {
  689. private ModuleName _chamber;
  690. private int _slot;
  691. private Hand _hand;
  692. public PickHandlerEx()
  693. {
  694. background = true;
  695. }
  696. public override string package(params object[] args)
  697. {
  698. // Move to ready position and get wafer with adjustment offset(MTRO+MGET)
  699. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt> (,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  700. // UNo: Unit number (1 byte)
  701. // • ‘1’ : Manipulator.
  702. // • SeqNo : Sequence number (None / 2 bytes)
  703. // • Mtn : Motion mode (1 byte)
  704. // • ‘G’ : Get motion.
  705. // • ‘P’ : Put motion.
  706. // • ‘E’ : Exchange motion.
  707. // • TrsSt : Transfer station (3 bytes)
  708. // • “C01” - “C08” : Cassette stage.
  709. // • “S01” - “S12” : Transfer stage.
  710. // • “P01” : P/A stage.
  711. // • Slot : Slot number (2 bytes)
  712. // <Cassette stage>
  713. // • “01” - “30” : When cassette stage specified.
  714. // <Transfer stage, Pre-aligner stage>
  715. // • “00” : Fixed slot(because this type of station does not have multiple slots.).
  716. // Note) If value is less than 2 digits, fill the higher digit with ‘0’ so that the field always has 2 digits.
  717. // Note) If <Hand> is ‘F’(Blade 1 + Blade 2), specifies the slot accessed by Blade 1.
  718. // Note) If <TrsST> is “S01”-“S12” or “P01”, the slot no. is ignored.
  719. // • Posture : Arm Posture (1 byte)
  720. // • ‘L’ : Left elbow.
  721. // • ‘R’ : Right elbow.
  722. // • ‘A’ : Automatic (Automatically selected posture with the proper path).
  723. // • Hand : Blade (1 byte)
  724. // • ‘1’ : Blade 1.
  725. // • ‘2’ : Blade 2.
  726. // • ‘F’ : Blade 1 + Blade 2 (WGet/WPut operation).
  727. // Note) Except for <TrsPnt> is [C01-C08: Cassette stage], ‘F’(Blade 1 + Blade 2) cannot be
  728. // specified.
  729. // Note) If <Mtn> is ‘E’( Exchange motion), ‘F’(Blade 1 + Blade 2) cannot be specified.
  730. _chamber = (ModuleName)args[0];
  731. _slot = (int)args[1];
  732. _hand = (Hand)args[2];
  733. int x = (int)args[3];
  734. int y = (int)args[4];
  735. int z = (int)args[5];
  736. updateBefore();
  737. return string.Format(",MTRS,G,{0},{1:D2},A,{2},G4,{3},{4},{5},",
  738. RobotConvertor.chamber2staion(_chamber),
  739. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  740. RobotConvertor.hand2string(_hand),
  741. RobotConvertor.Offset2String(x),
  742. RobotConvertor.Offset2String(y),
  743. RobotConvertor.Offset2String(z)
  744. );
  745. }
  746. private void updateBefore()
  747. {
  748. _device.Blade1Target = _chamber;
  749. _device.Blade2Target = _chamber;
  750. }
  751. protected override void update(string[] data)
  752. {
  753. if (_hand == Hand.Both)
  754. {
  755. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleName.Robot, (int)Hand.Blade1);
  756. WaferManager.Instance.WaferMoved(_chamber, _slot + 1, ModuleName.Robot, (int)Hand.Blade2);
  757. }
  758. else
  759. {
  760. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleName.Robot, (int)_hand);
  761. }
  762. _device.Blade1Target = ModuleName.Robot;
  763. _device.Blade2Target = ModuleName.Robot;
  764. }
  765. }
  766. public class PlaceHandlerEx : RobotMotionHandler
  767. {
  768. private ModuleName _chamber;
  769. private int _slot;
  770. private Hand _hand;
  771. public PlaceHandlerEx()
  772. {
  773. background = true;
  774. }
  775. public override string package(params object[] args)
  776. {
  777. _chamber = (ModuleName)args[0];
  778. _slot = (int)args[1];
  779. _hand = (Hand)args[2];
  780. int x = (int)args[3];
  781. int y = (int)args[4];
  782. int z = (int)args[5];
  783. updateBefore();
  784. return string.Format(",MTRS,P,{0},{1:D2},A,{2},P4,{3},{4},{5},",
  785. RobotConvertor.chamber2staion(_chamber),
  786. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  787. RobotConvertor.hand2string(_hand),
  788. RobotConvertor.Offset2String(x),
  789. RobotConvertor.Offset2String(y),
  790. RobotConvertor.Offset2String(z)
  791. );
  792. }
  793. private void updateBefore()
  794. {
  795. _device.Blade1Target = _chamber;
  796. _device.Blade2Target = _chamber;
  797. }
  798. protected override void update(string[] data)
  799. {
  800. if (_hand == Hand.Both)
  801. {
  802. WaferManager.Instance.WaferMoved(ModuleName.Robot, (int)Hand.Blade1, _chamber, _slot);
  803. WaferManager.Instance.WaferMoved(ModuleName.Robot, (int)Hand.Blade2, _chamber, _slot + 1);
  804. }
  805. else
  806. {
  807. WaferManager.Instance.WaferMoved(ModuleName.Robot, (int)_hand, _chamber, _slot);
  808. }
  809. _device.Blade1Target = ModuleName.Robot;
  810. _device.Blade2Target = ModuleName.Robot;
  811. }
  812. }
  813. public class ExchangeHandlerEx : RobotMotionHandler
  814. {
  815. private ModuleName _chamber;
  816. private int _slot;
  817. private Hand _hand;
  818. public ExchangeHandlerEx()
  819. {
  820. background = true;
  821. }
  822. public override string package(params object[] args)
  823. {
  824. // $,<UNo>(,<SeqNo>),MTRS,<Mtn>,<TrsSt>,<Slot>,<Posture>,<Hand>,<TrsPnt>(,<OfstX>,<OfstY>,<OfstZ>)(,<Angle>)(,<Sum>)<CR>
  825. _chamber = (ModuleName)args[0];
  826. _slot = (int)args[1];
  827. _hand = (Hand)args[2];
  828. if (_hand == Hand.Blade1)
  829. _hand = Hand.Blade2;
  830. else
  831. _hand = Hand.Blade1;
  832. int x = (int)args[3];
  833. int y = (int)args[4];
  834. int z = (int)args[5];
  835. updateBefore();
  836. return string.Format(",MTRS,E,{0},{1:D2},A,{2},P4,{3},{4},{5},",
  837. RobotConvertor.chamber2staion(_chamber),
  838. RobotConvertor.chamberSlot2Slot(_chamber, _slot),
  839. RobotConvertor.hand2string(_hand),
  840. RobotConvertor.Offset2String(x),
  841. RobotConvertor.Offset2String(y),
  842. RobotConvertor.Offset2String(z));
  843. }
  844. private void updateBefore()
  845. {
  846. _device.Blade1Target = _chamber;
  847. _device.Blade2Target = _chamber;
  848. _device.Swap = true;
  849. _device.PlaceBalde = _hand;
  850. }
  851. protected override void update(string[] data)
  852. {
  853. if (_hand == Hand.Blade2)
  854. {
  855. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleName.Robot, (int)Hand.Blade2);
  856. WaferManager.Instance.WaferMoved(ModuleName.Robot, (int)Hand.Blade1, _chamber, _slot);
  857. }
  858. else
  859. {
  860. WaferManager.Instance.WaferMoved(_chamber, _slot, ModuleName.Robot, (int)Hand.Blade1);
  861. WaferManager.Instance.WaferMoved(ModuleName.Robot, (int)Hand.Blade2, _chamber, _slot);
  862. }
  863. _device.Swap = false;
  864. _device.Blade1Target = ModuleName.Robot;
  865. _device.Blade2Target = ModuleName.Robot;
  866. }
  867. }
  868. public class RBWaferMappingHandler : RobotMotionHandler
  869. {
  870. private ModuleName _chamber;
  871. //private int _slot;
  872. //private Hand _hand;
  873. public RBWaferMappingHandler()
  874. {
  875. background = true;
  876. }
  877. public override string package(params object[] args)
  878. {
  879. //$,<UNo>(,<SeqNo>),MMAP,<TrsSt>,<Slot>(,<Safe>)(,<Sum>)<CR>
  880. //TrsSt : Transfer station (3 bytes)
  881. //“C01” - “C08” : Cassette stage.
  882. //“S01” - “S12” : Transfer stage.
  883. //“P01” : P/A stage.
  884. //• Slot : Slot number (2 bytes)
  885. //<Cassette stage>
  886. //• “01” - “30” : When specifying individual cassette stage slot.
  887. //• “00” : When specifying all slots.
  888. //<Transfer stage, P/A stage>
  889. //• “00” : Fixed value t(because this type of station does not have multiple slots.)
  890. //Note) If value is less than 2 digits, fill the higher digit with ‘0’ so that the field always has 8 digits.
  891. //Note) If <TrsST> is “S01”-“S12” or “P01”, the slot no. is ignored.
  892. //• Safe : Specifies wafer protrusion detection operation yes/no (1 byte)
  893. //• ‘0’ : No wafer protrusion detection operation.
  894. //• ‘1’ : Wafer protrusion detection operation performed.
  895. _chamber = (ModuleName)args[0];
  896. //_slot = (int)args[1];
  897. //_hand = (Hand)args[2];
  898. updateBefore();
  899. return string.Format(",MMAP,{0},00,1,",
  900. RobotConvertor.chamber2staion(_chamber));
  901. }
  902. private void updateBefore()
  903. {
  904. _device.Blade1Target = _chamber;
  905. _device.Blade2Target = _chamber;
  906. }
  907. }
  908. public class RBQueryWaferMapHandler : ITransferMsg
  909. {
  910. public bool background { get; protected set; }
  911. public bool evt { get { return false; } }
  912. public string deviceID { private get; set; }
  913. public string _cmd = string.Empty;
  914. private ModuleName _chamber;
  915. public IDevice Robot { set { _device = (Robot)value; } }
  916. protected Robot _device;
  917. public RBQueryWaferMapHandler()
  918. {
  919. background = false;
  920. }
  921. //$,<UNo>(,<SeqNo>),RMAP,<TrsSt>,<Slot>(,<Sum>)<CR>
  922. public string package(params object[] args)
  923. {
  924. _chamber = (ModuleName)args[0];
  925. return string.Format(",RMAP,{0},00,",
  926. RobotConvertor.chamber2staion(_chamber));
  927. }
  928. public bool unpackage(string type, string[] items)
  929. {
  930. //$,<UNo>(,<SeqNo>),<Sts>,<Ackcd>,RMAP,<TrsSt>,<Slot>,
  931. //01:<Result1>…,N:<ResultN>(,<Sum>)<CR>
  932. //• UNo : Unit number (1 byte)
  933. //• SeqNo : Sequence number (None / 2 bytes)
  934. //• Sts : Status (2 bytes)
  935. //• Ackcd : Response code (4 bytes)
  936. //• TrsSt : Transfer station (3 bytes)
  937. //• Slot : Slot number (2 bytes)
  938. //• Result* : Mapping result (2 bytes each)
  939. //• “--” : No wafer detected.
  940. //• “OK” : Wafer inserted correctly.
  941. //• “CW” : Wafer inserted incorrectly (inclined).
  942. //• “DW” : Wafer inserted incorrectly (duplicated).
  943. //Note) Responds with the number of slots of the specified transfer station.
  944. //$,1,00,0000,RMAP,C02,00,
  945. //01:OK,02:DW,03:OK,04:CW,05:CW,06:OK,07:OK,08:--,09:OK,10:OK
  946. // No wafer: "0", Wafer: "1", Crossed:"2", Undefined: "?", Overlapping wafers: "W"
  947. if (items.Length > 7)
  948. {
  949. StringBuilder sb = new StringBuilder();
  950. for (int i = 8; i < items.Length-1; i++)
  951. {
  952. string value = items[i].Substring(3);
  953. switch (value)
  954. {
  955. case "--":
  956. sb.Append("0");
  957. break;
  958. case "OK":
  959. sb.Append("1");
  960. break;
  961. case "CW":
  962. sb.Append("2");
  963. break;
  964. case "DW":
  965. sb.Append("W");
  966. break;
  967. }
  968. }
  969. _device.NotifySlotMapResult(_chamber, sb.ToString());
  970. return true;
  971. }
  972. return !background;
  973. }
  974. }
  975. public class RbSetSpeedHandler : RobotMotionHandler
  976. {
  977. private int _speed = 0;
  978. public RbSetSpeedHandler()
  979. {
  980. background = false;
  981. }
  982. public override string package(params object[] args)
  983. {
  984. _speed = (int)args[0];
  985. return string.Format(",SSLV,{0},", _speed);
  986. }
  987. }
  988. public class RBQueryStateHandler : ITransferMsg
  989. {
  990. public bool background { get; protected set; }
  991. public bool evt { get { return false; } }
  992. public string deviceID { private get; set; }
  993. public string _cmd = string.Empty;
  994. public IDevice Robot { set { _device = (Robot)value; } }
  995. protected Robot _device;
  996. public RBQueryStateHandler()
  997. {
  998. background = false;
  999. }
  1000. //$,<UNo>(,<SeqNo>),RSTS(,<Sum>)<CR>
  1001. public string package(params object[] args)
  1002. {
  1003. return ",RSTS,";
  1004. }
  1005. public bool unpackage(string type, string[] items)
  1006. {
  1007. /*
  1008. (Positive Response Message)
  1009. $,<UNo>(,<SeqNo>),<Sts>,<Ackcd>,RSTS,<Errcd>,<Status>(,<Sum>)<CR>
  1010. • UNo : Unit number (1 byte)
  1011. • SeqNo : Sequence number (None / 2 bytes)
  1012. • Sts : Status (2 bytes)
  1013. • Ackcd : Response code (4 bytes)
  1014. • Errcd : Error code (4 bytes)
  1015. Note) Responds with the currently occurring error for the specified unit.
  1016. (When there is no error, responds “0000”)
  1017. • Status : Status information (4 bytes)
  1018. • Refer to the supplementary explanation.
  1019. (Negative Response Message)
  1020. $,<UNo>(,<SeqNo>),<Sts>,<Ackcd>,RSTS(,<Sum>)<CR>
  1021. • UNo : Unit number (1 byte)
  1022. • SeqNo : Sequence number (None / 2 bytes)
  1023. • Sts : Status (2 bytes)
  1024. • Ackcd : Response code (4 bytes)
  1025. */
  1026. if (items.Length > 7)
  1027. {
  1028. int errorCode = Convert.ToInt32(items[6], 16);
  1029. _device.ErrorCode = errorCode;
  1030. }
  1031. if (items.Length > 8)
  1032. {
  1033. int status = Convert.ToInt32(items[7], 16);
  1034. _device.StateWaferOnBlade1 = (status & 0x01) == 0x01;
  1035. _device.StateWaferOnBlade2 = (status & 0x02) == 0x02;
  1036. _device.StateBlade1Gripped = (status & 0x04) == 0x04;
  1037. _device.StateBlade2Gripped = (status & 0x08) == 0x08;
  1038. _device.StateInterlock1 = (status & 0x0100) == 0x0100;
  1039. _device.StateInterlock2 = (status & 0x0200) == 0x0200;
  1040. _device.StateInterlock3 = (status & 0x0400) == 0x0400;
  1041. _device.StateInterlock4 = (status & 0x0800) == 0x0800;
  1042. _device.StateInterlock5 = (status & 0x010000) == 0x010000;
  1043. _device.StateInterlock6 = (status & 0x020000) == 0x020000;
  1044. _device.StateInterlock7 = (status & 0x040000) == 0x040000;
  1045. _device.StateInterlock8 = (status & 0x080000) == 0x080000;
  1046. }
  1047. return !background;
  1048. }
  1049. }
  1050. public class RbEventHandler : ITransferMsg
  1051. {
  1052. public bool background { get { return false; } }
  1053. public bool evt { get { return true; } }
  1054. public string deviceID { private get; set; }
  1055. public string _cmd = string.Empty;
  1056. public IDevice Robot { set { _device = (Robot)value; } }
  1057. protected Robot _device;
  1058. public RbEventHandler()
  1059. {
  1060. }
  1061. //$,<UNo>(,<SeqNo>),RSTS(,<Sum>)<CR>
  1062. public string package(params object[] args)
  1063. {
  1064. return "";
  1065. }
  1066. public bool unpackage(string type, string[] items)
  1067. {
  1068. string evtType = items[3];
  1069. if (evtType.Equals(ProtocolTag.resp_evt_error))
  1070. {
  1071. int error = Convert.ToInt32(items[5], 16);
  1072. _device.ErrorCode = error;
  1073. if (error > 0)
  1074. _device.LastErrorCode = error;
  1075. return true;
  1076. }
  1077. return false;
  1078. }
  1079. }
  1080. public class RBQueryPositionHandler : ITransferMsg
  1081. {
  1082. public bool background { get; protected set; }
  1083. public bool evt { get { return false; } }
  1084. public string deviceID { private get; set; }
  1085. public string _cmd = string.Empty;
  1086. public IDevice Robot { set { _device = (Robot)value; } }
  1087. protected Robot _device;
  1088. public RBQueryPositionHandler()
  1089. {
  1090. background = false;
  1091. }
  1092. //$,<UNo>(,<SeqNo>),RPOS,<PType>(,<Sum>)<CR>
  1093. //• ‘R’ : Command position.• ‘F’ : Feedback position.
  1094. public string package(params object[] args)
  1095. {
  1096. return ",RPOS,F,";
  1097. }
  1098. public bool unpackage(string type, string[] items)
  1099. {
  1100. //Positive $,<UNo>(,<SeqNo>),<Sts>,<Ackcd>,RPOS,<PType>,<Value1>…,<ValueN>(,<Sum>)<CR>
  1101. //Negative $,<UNo>(,<SeqNo>),<Sts>,<Ackcd>,RPOS,<PType>(,<Sum>)<CR>
  1102. if (items.Length > 7)
  1103. {
  1104. _device.Rotation = int.Parse(items[7]);
  1105. _device.Extension = int.Parse(items[8]);
  1106. _device.Wrist1 = int.Parse(items[9]);
  1107. _device.Wrist2 = int.Parse(items[10]);
  1108. _device.Evevation = int.Parse(items[11]);
  1109. return true;
  1110. }
  1111. return !background;
  1112. }
  1113. }
  1114. }