Handler.cs 42 KB

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