SiasunVCEHandler.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. using MECF.Framework.Common.Communications;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Linq;
  5. using System.Text;
  6. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.VCE.SiasunVCEII
  7. {
  8. public abstract class SiasunVCEHandler : HandlerBase
  9. {
  10. public SiasunVCE Device { get; set; }
  11. protected string _commandType;
  12. protected string _command;
  13. protected string _parameter;
  14. public bool IsSendText(string commandType, string command, string commandArgumen)
  15. {
  16. return _commandType == commandType && _command == command && _parameter == commandArgumen;
  17. }
  18. protected SiasunVCEHandler(SiasunVCE device, string commandType, string command, string parameter = null)
  19. : base(BuildMessage(commandType, command, parameter))
  20. {
  21. Device = device;
  22. _commandType = commandType;
  23. _command = command;
  24. _parameter = parameter;
  25. Name = command;
  26. }
  27. private static string BuildMessage(string commandType, string command, string parameter)
  28. {
  29. string strCommand = $"{commandType}";
  30. if (!string.IsNullOrEmpty(command))
  31. {
  32. strCommand += "," + command;
  33. }
  34. if (!string.IsNullOrEmpty(parameter))
  35. {
  36. strCommand += "," + parameter;
  37. }
  38. return strCommand + "\r";
  39. }
  40. public override bool HandleMessage(MessageBase msg, out bool handled)
  41. {
  42. var result = msg as SiasunVCEMessage;
  43. handled = msg.IsComplete;
  44. if (result.IsError)
  45. {
  46. Device.NoteError(result.Data);
  47. }
  48. else
  49. {
  50. Device.NoteError(null);
  51. }
  52. if (result.IsComplete)
  53. {
  54. SetState(EnumHandlerState.Completed);
  55. }
  56. if (result.IsAck)
  57. {
  58. SetState(EnumHandlerState.Acked);
  59. }
  60. ResponseMessage = msg;
  61. return handled;
  62. }
  63. }
  64. public class SiasunVCERawCommandHandler : SiasunVCEHandler
  65. {
  66. public SiasunVCERawCommandHandler(SiasunVCE device, string commandType, string command, string parameter = null)
  67. : base(device, commandType, command, parameter)
  68. {
  69. }
  70. public override bool HandleMessage(MessageBase msg, out bool handled)
  71. {
  72. base.HandleMessage(msg, out handled);
  73. var result = msg as SiasunVCEMessage;
  74. Device.NoteRawCommandInfo(_commandType, _command, result.RawMessage);
  75. return true;
  76. }
  77. }
  78. public class SiasunVCEAbortHandler : SiasunVCEHandler
  79. {
  80. public SiasunVCEAbortHandler(SiasunVCE device)
  81. : base(device, "E", "")
  82. {
  83. }
  84. public override bool HandleMessage(MessageBase msg, out bool handled)
  85. {
  86. if (base.HandleMessage(msg, out handled))
  87. {
  88. Device.IsIdle = true;
  89. }
  90. return true;
  91. }
  92. }
  93. public class SiasunVCEMoveHandler : SiasunVCEHandler
  94. {
  95. public SiasunVCEMoveHandler(SiasunVCE device, string axis, string type, string value)
  96. : base(device, "A", "MOVE", axis + "," + type + "," + value)
  97. {
  98. }
  99. public override bool HandleMessage(MessageBase msg, out bool handled)
  100. {
  101. if (base.HandleMessage(msg, out handled))
  102. {
  103. Device.NoteMoveResult(_parameter);
  104. Device.IsIdle = true;
  105. }
  106. return true;
  107. }
  108. }
  109. public class SiasunVCEZAxisMoveToLoadPositionHandler : SiasunVCEHandler
  110. {
  111. public SiasunVCEZAxisMoveToLoadPositionHandler(SiasunVCE device, int timeout)
  112. : base(device, "A", "LP")
  113. {
  114. AckTimeout = TimeSpan.FromSeconds(timeout);
  115. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  116. }
  117. public override bool HandleMessage(MessageBase msg, out bool handled)
  118. {
  119. if (base.HandleMessage(msg, out handled))
  120. {
  121. Device.IsZAxisAtLoadPostion = true;
  122. Device.IsIdle = true;
  123. }
  124. return true;
  125. }
  126. }
  127. public class SiasunVCEPlatformInHandler : SiasunVCEHandler
  128. {
  129. public SiasunVCEPlatformInHandler(SiasunVCE device, int timeout)
  130. : base(device, "A", "PI")
  131. {
  132. AckTimeout = TimeSpan.FromSeconds(timeout);
  133. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  134. }
  135. public override bool HandleMessage(MessageBase msg, out bool handled)
  136. {
  137. if (base.HandleMessage(msg, out handled))
  138. {
  139. Device.IsPlatformIn = true;
  140. Device.IsPlatformOut = false;
  141. Device.IsIdle = true;
  142. }
  143. return true;
  144. }
  145. }
  146. public class SiasunVCEMappingHandler : SiasunVCEHandler
  147. {
  148. public SiasunVCEMappingHandler(SiasunVCE device, int timeout)
  149. : base(device, "A", "MP")
  150. {
  151. AckTimeout = TimeSpan.FromSeconds(timeout);
  152. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  153. }
  154. public override bool HandleMessage(MessageBase msg, out bool handled)
  155. {
  156. if (base.HandleMessage(msg, out handled))
  157. {
  158. Device.IsIdle = true;
  159. Device.IsMapped = true;
  160. }
  161. return true;
  162. }
  163. }
  164. public class SiasunVCEPlatformOutHandler : SiasunVCEHandler
  165. {
  166. public SiasunVCEPlatformOutHandler(SiasunVCE device, int timeout)
  167. : base(device, "A", "PO")
  168. {
  169. AckTimeout = TimeSpan.FromSeconds(timeout);
  170. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  171. }
  172. public override bool HandleMessage(MessageBase msg, out bool handled)
  173. {
  174. if (base.HandleMessage(msg, out handled))
  175. {
  176. Device.IsPlatformOut = true;
  177. Device.IsPlatformIn = false;
  178. Device.IsIdle = true;
  179. }
  180. return true;
  181. }
  182. }
  183. public class SiasunVCECloseDoorHandler : SiasunVCEHandler
  184. {
  185. public SiasunVCECloseDoorHandler(SiasunVCE device, int timeout)
  186. : base(device, "A", "DC")
  187. {
  188. AckTimeout = TimeSpan.FromSeconds(timeout);
  189. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  190. }
  191. public override bool HandleMessage(MessageBase msg, out bool handled)
  192. {
  193. if (base.HandleMessage(msg, out handled))
  194. {
  195. Device.IsDoorClosed = true;
  196. Device.IsDoorOpened = false;
  197. Device.IsIdle = true;
  198. }
  199. return true;
  200. }
  201. }
  202. public class SiasunVCEOpenDoorHandler : SiasunVCEHandler
  203. {
  204. public SiasunVCEOpenDoorHandler(SiasunVCE device, int timeout)
  205. : base(device, "A", "DO")
  206. {
  207. AckTimeout = TimeSpan.FromSeconds(timeout);
  208. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  209. }
  210. public override bool HandleMessage(MessageBase msg, out bool handled)
  211. {
  212. if (base.HandleMessage(msg, out handled))
  213. {
  214. Device.IsDoorOpened = true;
  215. Device.IsDoorClosed = false;
  216. Device.IsMapped = false;
  217. Device.IsIdle = true;
  218. }
  219. return true;
  220. }
  221. }
  222. public class SiasunVCEHomeHandler : SiasunVCEHandler
  223. {
  224. public SiasunVCEHomeHandler(SiasunVCE device, int timeout)
  225. : base(device, "A", "HM", "ALL")
  226. {
  227. AckTimeout = TimeSpan.FromSeconds(timeout);
  228. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  229. }
  230. public override bool HandleMessage(MessageBase msg, out bool handled)
  231. {
  232. if (base.HandleMessage(msg, out handled))
  233. {
  234. Device.NoteHomed(true);
  235. Device.IsIdle = true;
  236. }
  237. return true;
  238. }
  239. }
  240. public class SiasunVCEHomeRAxisHandler : SiasunVCEHandler
  241. {
  242. public SiasunVCEHomeRAxisHandler(SiasunVCE device, int timeout)
  243. : base(device, "A", "HM", "R")
  244. {
  245. AckTimeout = TimeSpan.FromSeconds(timeout);
  246. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  247. }
  248. public override bool HandleMessage(MessageBase msg, out bool handled)
  249. {
  250. if (base.HandleMessage(msg, out handled))
  251. {
  252. Device.IsIdle = true;
  253. }
  254. return true;
  255. }
  256. }
  257. public class SiasunVCEHomeZAxisHandler : SiasunVCEHandler
  258. {
  259. public SiasunVCEHomeZAxisHandler(SiasunVCE device, int timeout)
  260. : base(device, "A", "HM", "Z")
  261. {
  262. AckTimeout = TimeSpan.FromSeconds(timeout);
  263. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  264. }
  265. public override bool HandleMessage(MessageBase msg, out bool handled)
  266. {
  267. if (base.HandleMessage(msg, out handled))
  268. {
  269. Device.NoteHomed(true);
  270. Device.IsIdle = true;
  271. }
  272. return true;
  273. }
  274. }
  275. public class SiasunVCEZAxisGotoSlotHandler : SiasunVCEHandler
  276. {
  277. public SiasunVCEZAxisGotoSlotHandler(SiasunVCE device, int slot, int timeout)
  278. : base(device, "A", "GO", (slot + 1).ToString())
  279. {
  280. AckTimeout = TimeSpan.FromSeconds(timeout);
  281. CompleteTimeout = TimeSpan.FromSeconds(timeout);
  282. }
  283. public override bool HandleMessage(MessageBase msg, out bool handled)
  284. {
  285. if (base.HandleMessage(msg, out handled))
  286. {
  287. Device.NoteZAxisPosition(_parameter);
  288. Device.IsIdle = true;
  289. }
  290. return true;
  291. }
  292. }
  293. //motor motion scope
  294. public class SiasunVCERequestZAxisMotionScopenHandler : SiasunVCEHandler
  295. {
  296. public SiasunVCERequestZAxisMotionScopenHandler(SiasunVCE device, bool isUp)
  297. : base(device, "R", "ARM", "Z," + (isUp ? "UP" : "DN"))
  298. {
  299. }
  300. public override bool HandleMessage(MessageBase msg, out bool handled)
  301. {
  302. if (base.HandleMessage(msg, out handled))
  303. {
  304. var result = msg as SiasunVCEMessage;
  305. Device.NoteArmRPositon(result.Data.Split(',')[2]);
  306. }
  307. return true;
  308. }
  309. }
  310. public class SiasunVCEResetErrorHandler : SiasunVCEHandler
  311. {
  312. public SiasunVCEResetErrorHandler(SiasunVCE device)
  313. : base(device, "S", "ER")
  314. {
  315. }
  316. public override bool HandleMessage(MessageBase msg, out bool handled)
  317. {
  318. if (base.HandleMessage(msg, out handled))
  319. {
  320. Device.IsAlarm = false;
  321. }
  322. return true;
  323. }
  324. }
  325. public class SiasunVCECassetteInterlockHandler : SiasunVCEHandler
  326. {
  327. public SiasunVCECassetteInterlockHandler(SiasunVCE device, bool isEnable)
  328. : base(device, "S", "CE", isEnable ? "Y" : "N")
  329. {
  330. }
  331. public override bool HandleMessage(MessageBase msg, out bool handled)
  332. {
  333. if (base.HandleMessage(msg, out handled))
  334. {
  335. Device.IsAlarm = false;
  336. }
  337. return true;
  338. }
  339. }
  340. public class SiasunVCEDoorInterlockHandler : SiasunVCEHandler
  341. {
  342. public SiasunVCEDoorInterlockHandler(SiasunVCE device, bool isEnable)
  343. : base(device, "S", "ZD", isEnable ? "Y" : "N")
  344. {
  345. }
  346. public override bool HandleMessage(MessageBase msg, out bool handled)
  347. {
  348. if (base.HandleMessage(msg, out handled))
  349. {
  350. Device.IsAlarm = false;
  351. }
  352. return true;
  353. }
  354. }
  355. public class SiasunVCERequestErrorInfoHandler : SiasunVCEHandler
  356. {
  357. public SiasunVCERequestErrorInfoHandler(SiasunVCE device)
  358. : base(device, "R", "ER")
  359. {
  360. }
  361. public override bool HandleMessage(MessageBase msg, out bool handled)
  362. {
  363. if (base.HandleMessage(msg, out handled))
  364. {
  365. var result = msg as SiasunVCEMessage;
  366. Device.NoteCurrentErrorStatus(result.Data.Replace("ER", ""));//X,ERcode
  367. Device.IsIdle = true;
  368. }
  369. return true;
  370. }
  371. }
  372. public class SiasunVCERequestWaferSlideOutHandler : SiasunVCEHandler
  373. {
  374. public SiasunVCERequestWaferSlideOutHandler(SiasunVCE device)
  375. : base(device, "R", "SO")
  376. {
  377. }
  378. public override bool HandleMessage(MessageBase msg, out bool handled)
  379. {
  380. if (base.HandleMessage(msg, out handled))
  381. {
  382. var result = msg as SiasunVCEMessage;
  383. Device.IsWaferSlideOut = result.Data.Replace("SO", "").ToUpper() == "Y";
  384. Device.IsIdle = true;
  385. }
  386. return true;
  387. }
  388. }
  389. public class SiasunVCERequestCassettePresentHandler : SiasunVCEHandler
  390. {
  391. public SiasunVCERequestCassettePresentHandler(SiasunVCE device)
  392. : base(device, "R", "W2")
  393. {
  394. }
  395. public override bool HandleMessage(MessageBase msg, out bool handled)
  396. {
  397. if (base.HandleMessage(msg, out handled))
  398. {
  399. var result = msg as SiasunVCEMessage;
  400. Device.IsCassettePresent = result.Data.Replace("W2", "").ToUpper() == "Y";
  401. Device.IsIdle = true;
  402. }
  403. return true;
  404. }
  405. }
  406. // R,STAT,DOOR
  407. public class SiasunVCERequestDoorStatusHandler : SiasunVCEHandler
  408. {
  409. public SiasunVCERequestDoorStatusHandler(SiasunVCE device)
  410. : base(device, "R", "STAT", "DOOR")
  411. {
  412. }
  413. // X,STATC
  414. public override bool HandleMessage(MessageBase msg, out bool handled)
  415. {
  416. if (base.HandleMessage(msg, out handled))
  417. {
  418. var result = msg as SiasunVCEMessage;
  419. string resp = result.Data.Replace("STAT", "").ToUpper();
  420. Device.IsDoorOpened = resp.Last() == 'O';
  421. Device.IsDoorClosed = resp.Last() == 'C';
  422. Device.IsIdle = true;
  423. }
  424. return true;
  425. }
  426. }
  427. public class SiasunVCERequestArmPositionHandler : SiasunVCEHandler
  428. {
  429. public SiasunVCERequestArmPositionHandler(SiasunVCE device)
  430. : base(device, "R", "STAT", "ARM")
  431. {
  432. }
  433. public override bool HandleMessage(MessageBase msg, out bool handled)
  434. {
  435. if (base.HandleMessage(msg, out handled))
  436. {
  437. var result = msg as SiasunVCEMessage;
  438. var pos = result.Data.Replace("STAT", "").ToUpper();
  439. if (int.TryParse(pos, out int slot) && slot > 0)
  440. {
  441. //slot
  442. Device.IsZAxisAtLoadPostion = false;
  443. Device.IsZAxisAtHomePostion = false;
  444. Device.ZAxisAtSlot = slot - 1;
  445. }
  446. else if (pos == "M")
  447. {
  448. //Mapping end position
  449. Device.IsZAxisAtLoadPostion = false;
  450. Device.IsZAxisAtHomePostion = false;
  451. Device.ZAxisAtSlot = -1;
  452. }
  453. else if (pos == "H")
  454. {
  455. //Home position
  456. Device.IsZAxisAtLoadPostion = false;
  457. Device.IsZAxisAtHomePostion = true;
  458. Device.ZAxisAtSlot = -1;
  459. }
  460. else if (pos == "L")
  461. {
  462. //Home position
  463. Device.IsZAxisAtLoadPostion = true;
  464. Device.IsZAxisAtHomePostion = false;
  465. Device.ZAxisAtSlot = -1;
  466. }
  467. else
  468. {
  469. //unknown position
  470. Device.IsZAxisAtLoadPostion = false;
  471. Device.IsZAxisAtHomePostion = false;
  472. Device.ZAxisAtSlot = -1;
  473. }
  474. Device.IsIdle = true;
  475. }
  476. return true;
  477. }
  478. }
  479. public class SiasunVCERequestMappingInfoHandler : SiasunVCEHandler
  480. {
  481. //S:single wafer
  482. //O;no wafer
  483. //T:double wafer
  484. //C:cross wafer
  485. //?:slot spare
  486. //X,MI****
  487. public SiasunVCERequestMappingInfoHandler(SiasunVCE device)
  488. : base(device, "R", "MI")
  489. {
  490. }
  491. public override bool HandleMessage(MessageBase msg, out bool handled)
  492. {
  493. if (base.HandleMessage(msg, out handled))
  494. {
  495. var result = msg as SiasunVCEMessage;
  496. var arr = result.Data.Replace("MI", "").Replace("?", "").ToCharArray();
  497. Array.Reverse(arr);// slot25->slot1 to slot1->slot25
  498. Device.NoteCurrentMappingInfo(new string(arr));
  499. Device.IsIdle = true;
  500. }
  501. return true;
  502. }
  503. }
  504. public class SiasunVCESetCassetteSlotNumberHandler : SiasunVCEHandler
  505. {
  506. // slot number [1, 25]
  507. public SiasunVCESetCassetteSlotNumberHandler(SiasunVCE device, int slotNum)
  508. : base(device, "S", "CF,NS", slotNum.ToString())
  509. {
  510. }
  511. public override bool HandleMessage(MessageBase msg, out bool handled)
  512. {
  513. if (base.HandleMessage(msg, out handled))
  514. {
  515. }
  516. return true;
  517. }
  518. }
  519. public class SiasunVCESetMappingTeachFlagHandler : SiasunVCEHandler
  520. {
  521. public SiasunVCESetMappingTeachFlagHandler(SiasunVCE device, bool isMappingTeach)
  522. : base(device, "S", "MP", (isMappingTeach ? 1 : 0).ToString())
  523. {
  524. }
  525. public override bool HandleMessage(MessageBase msg, out bool handled)
  526. {
  527. if (base.HandleMessage(msg, out handled))
  528. {
  529. }
  530. return true;
  531. }
  532. }
  533. public class SiasunVCESetZAxisSpeedHandler : SiasunVCEHandler
  534. {
  535. //speed range (0,99] %
  536. public SiasunVCESetZAxisSpeedHandler(SiasunVCE device, int speed)
  537. : base(device, "S", "SPEED,Z", speed.ToString())
  538. {
  539. }
  540. public override bool HandleMessage(MessageBase msg, out bool handled)
  541. {
  542. if (base.HandleMessage(msg, out handled))
  543. {
  544. }
  545. return true;
  546. }
  547. }
  548. public class SiasunVCESetWaferDetectHandler : SiasunVCEHandler
  549. {
  550. public SiasunVCESetWaferDetectHandler(SiasunVCE device, bool isDetect)
  551. : base(device, "S", "WS", isDetect ? "Y" : "N")
  552. {
  553. }
  554. public override bool HandleMessage(MessageBase msg, out bool handled)
  555. {
  556. if (base.HandleMessage(msg, out handled))
  557. {
  558. }
  559. return true;
  560. }
  561. }
  562. }