RobotSiasun1500C800CHandler.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. using MECF.Framework.Common.Communications;
  2. using Newtonsoft.Json.Linq;
  3. using System.Linq;
  4. using System.Text;
  5. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Siasun1500C800C
  6. {
  7. public abstract class RobotSiasun1500C800CHandler : HandlerBase
  8. {
  9. public RobotSiasun1500C800C Device { get; }
  10. protected string _command;
  11. protected string _parameter;
  12. protected string _requestResponse = "";
  13. protected RobotSiasun1500C800CHandler(RobotSiasun1500C800C device, string command, string parameter = null)
  14. : base(BuildMessage(command, parameter))
  15. {
  16. Device = device;
  17. _command = command;
  18. _parameter = parameter;
  19. Name = command;
  20. }
  21. private static string BuildMessage( string command, string parameter)
  22. {
  23. string msg = parameter == null ? $"{command}" : $"{command} {parameter}";
  24. return msg + "\r";
  25. }
  26. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  27. {
  28. RobotSiasun1500C800CMessage response = msg as RobotSiasun1500C800CMessage;
  29. ResponseMessage = msg;
  30. if (response.IsError)
  31. {
  32. Device.NoteError(response.Data);
  33. }
  34. else
  35. {
  36. Device.NoteError(null);
  37. }
  38. if (response.IsComplete)
  39. {
  40. SetState(EnumHandlerState.Completed);
  41. transactionComplete = true;
  42. return true;
  43. }
  44. if(response.IsResponse)
  45. {
  46. _requestResponse = response.Data;
  47. }
  48. transactionComplete = false;
  49. return false;
  50. }
  51. }
  52. public class RobotSiasun1500C800CRawCommandHandler : RobotSiasun1500C800CHandler
  53. {
  54. public RobotSiasun1500C800CRawCommandHandler(RobotSiasun1500C800C device, string command, string parameter = null)
  55. : base(device, command, parameter)
  56. {
  57. }
  58. public override bool HandleMessage(MessageBase msg, out bool handled)
  59. {
  60. if(base.HandleMessage(msg, out handled))
  61. {
  62. var result = msg as RobotSiasun1500C800CMessage;
  63. var rawMsg = _requestResponse != null ? _requestResponse + "$" + result.RawMessage : result.RawMessage;
  64. Device.NoteRawCommandInfo(_command, rawMsg);
  65. }
  66. return true;
  67. }
  68. }
  69. public class RobotSiasun1500C800CGotoHandler : RobotSiasun1500C800CHandler
  70. {
  71. public RobotSiasun1500C800CGotoHandler(RobotSiasun1500C800C device, string jsonParameter)
  72. : base(device, "GOTO", BuildCommandParameter(jsonParameter))
  73. {
  74. }
  75. static string BuildCommandParameter(string jsonParameter)
  76. {
  77. JObject jsonObject = JObject.Parse(jsonParameter);
  78. StringBuilder paraBuilder = new StringBuilder();
  79. foreach (var item in jsonObject)
  80. {
  81. string key = item.Key;
  82. if (key == "station")
  83. key = "N";
  84. if (paraBuilder.Length == 0)
  85. {
  86. paraBuilder.Append(key.ToUpper() + " " + item.Value);
  87. }
  88. else
  89. {
  90. paraBuilder.Append(" " + key.ToUpper() + " " + item.Value);
  91. }
  92. }
  93. return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
  94. }
  95. public override bool HandleMessage(MessageBase msg, out bool handled)
  96. {
  97. var result = msg as RobotSiasun1500C800CMessage;
  98. if (result.IsError)
  99. {
  100. Device.NoteError(result.Data);
  101. }
  102. else
  103. {
  104. Device.NoteError(null);
  105. Device.NoteIsHalted(true);
  106. if (_parameter.Contains("ARM B"))
  107. {
  108. string position = _parameter.Replace(" ARM B", "");
  109. Device.NoteArmBPosition(position);
  110. }
  111. else
  112. {
  113. string position = _parameter;
  114. if (_parameter.Contains("ARM A"))
  115. {
  116. position = _parameter.Replace(" ARM A", "");
  117. }
  118. Device.NoteArmAPosition(position);
  119. }
  120. }
  121. ResponseMessage = msg;
  122. handled = true;
  123. return true;
  124. }
  125. }
  126. public class RobotSiasun1500C800CPickHandler : RobotSiasun1500C800CHandler
  127. {
  128. public RobotSiasun1500C800CPickHandler(RobotSiasun1500C800C device, string jsonParameter)
  129. : base(device, "PICK", BuildCommandParameter(jsonParameter))
  130. {
  131. }
  132. //N 2 R EX Z DOWN SLOT 1 ARM A
  133. static string BuildCommandParameter(string jsonParameter)
  134. {
  135. JObject jsonObject = JObject.Parse(jsonParameter);
  136. StringBuilder paraBuilder = new StringBuilder();
  137. foreach (var item in jsonObject)
  138. {
  139. if (paraBuilder.Length == 0)
  140. {
  141. paraBuilder.Append(item.Value);
  142. }
  143. else
  144. {
  145. if(item.Key == "Slot" || item.Key == "Arm")
  146. paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
  147. else
  148. paraBuilder.Append(" " + item.Value);
  149. }
  150. }
  151. return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
  152. }
  153. public override bool HandleMessage(MessageBase msg, out bool handled)
  154. {
  155. var result = msg as RobotSiasun1500C800CMessage;
  156. if (result.IsError)
  157. {
  158. Device.NoteError(result.Data);
  159. }
  160. else
  161. {
  162. Device.NoteError(null);
  163. Device.NoteLastPickInfo(SendText);
  164. }
  165. ResponseMessage = msg;
  166. handled = true;
  167. return true;
  168. }
  169. }
  170. public class RobotSiasun1500C800CPlaceHandler : RobotSiasun1500C800CHandler
  171. {
  172. public RobotSiasun1500C800CPlaceHandler(RobotSiasun1500C800C device, string jsonParameter)
  173. : base(device, "PLACE", BuildCommandParameter(jsonParameter))
  174. {
  175. }
  176. static string BuildCommandParameter(string jsonParameter)
  177. {
  178. JObject jsonObject = JObject.Parse(jsonParameter);
  179. StringBuilder paraBuilder = new StringBuilder();
  180. foreach (var item in jsonObject)
  181. {
  182. if (paraBuilder.Length == 0)
  183. {
  184. paraBuilder.Append(item.Value);
  185. }
  186. else
  187. {
  188. if (item.Key == "Slot" || item.Key == "Arm")
  189. paraBuilder.Append(" " + item.Key.ToUpper() + " " + item.Value);
  190. else
  191. paraBuilder.Append(" " + item.Value);
  192. }
  193. }
  194. return paraBuilder.Length > 0 ? paraBuilder.ToString() : null;
  195. }
  196. public override bool HandleMessage(MessageBase msg, out bool handled)
  197. {
  198. var result = msg as RobotSiasun1500C800CMessage;
  199. if (result.IsError)
  200. {
  201. Device.NoteError(result.Data);
  202. }
  203. else
  204. {
  205. Device.NoteError(null);
  206. Device.NoteLastPlaceInfo(SendText);
  207. }
  208. ResponseMessage = msg;
  209. handled = true;
  210. return true;
  211. }
  212. }
  213. public class RobotSiasun1500C800CTransferHandler : RobotSiasun1500C800CHandler
  214. {
  215. public RobotSiasun1500C800CTransferHandler(RobotSiasun1500C800C device, string fromStation, string toStation, string arm = null)
  216. : base(device, "XFER", arm == null? $"{fromStation} {toStation}" : $"ARM {arm} {fromStation} {toStation}")
  217. {
  218. }
  219. }
  220. public class RobotSiasun1500C800CRetractHandler : RobotSiasun1500C800CHandler
  221. {
  222. public RobotSiasun1500C800CRetractHandler(RobotSiasun1500C800C device)
  223. : base(device, "RETRACT")
  224. {
  225. }
  226. public override bool HandleMessage(MessageBase msg, out bool handled)
  227. {
  228. var result = msg as RobotSiasun1500C800CMessage;
  229. if (result.IsError)
  230. {
  231. Device.NoteError(result.Data);
  232. }
  233. else
  234. {
  235. Device.NoteError(null);
  236. Device.NoteRetracted(true);
  237. }
  238. ResponseMessage = msg;
  239. handled = true;
  240. return true;
  241. }
  242. }
  243. public class RobotSiasun1500C800CHaltHandler : RobotSiasun1500C800CHandler
  244. {
  245. public RobotSiasun1500C800CHaltHandler(RobotSiasun1500C800C device)
  246. : base(device, "HALT")
  247. {
  248. }
  249. public override bool HandleMessage(MessageBase msg, out bool handled)
  250. {
  251. var result = msg as RobotSiasun1500C800CMessage;
  252. if (result.IsError)
  253. {
  254. Device.NoteIsHalted(false);
  255. Device.NoteError(result.Data);
  256. }
  257. else
  258. {
  259. Device.NoteError(null);
  260. Device.NoteIsHalted(true);
  261. }
  262. ResponseMessage = msg;
  263. handled = true;
  264. return true;
  265. }
  266. }
  267. public class RobotSiasun1500C800CSetCommunicationEchoHandler : RobotSiasun1500C800CHandler
  268. {
  269. public RobotSiasun1500C800CSetCommunicationEchoHandler(RobotSiasun1500C800C device, string echoStaus)
  270. : base(device, "SET COMM ECHO", echoStaus)
  271. {
  272. }
  273. public override bool HandleMessage(MessageBase msg, out bool handled)
  274. {
  275. if (base.HandleMessage(msg, out handled))
  276. {
  277. Device.NoteSetCommEchoCompleted(true);
  278. }
  279. return true;
  280. }
  281. }
  282. public class RobotSiasun1500C800CSetLoadHandler : RobotSiasun1500C800CHandler
  283. {
  284. public RobotSiasun1500C800CSetLoadHandler(RobotSiasun1500C800C device, string arm, string status)
  285. : base(device, "SET LOAD", arm + " " + status)
  286. {
  287. }
  288. public override bool HandleMessage(MessageBase msg, out bool handled)
  289. {
  290. if (base.HandleMessage(msg, out handled))
  291. {
  292. Device.NoteSetLoadCompleted(true);
  293. }
  294. return true;
  295. }
  296. }
  297. public class RobotSiasun1500C800CSevoOnOffHandler : RobotSiasun1500C800CHandler
  298. {
  299. public RobotSiasun1500C800CSevoOnOffHandler(RobotSiasun1500C800C device, bool isOn)
  300. : base(device, isOn ? "SVON" : "SVOFF")
  301. {
  302. }
  303. public override bool HandleMessage(MessageBase msg, out bool handled)
  304. {
  305. var result = msg as RobotSiasun1500C800CMessage;
  306. if (result.IsError)
  307. {
  308. Device.NoteError(result.Data);
  309. }
  310. else
  311. {
  312. Device.NoteError(null);
  313. Device.NoteSevoOnOff(_command == "SVON");
  314. }
  315. ResponseMessage = msg;
  316. handled = true;
  317. return true;
  318. }
  319. }
  320. public class RobotSiasun1500C800CHomeAxisHandler : RobotSiasun1500C800CHandler
  321. {
  322. public RobotSiasun1500C800CHomeAxisHandler(RobotSiasun1500C800C device, string parameter)
  323. : base(device, "HOME", parameter)
  324. {
  325. }
  326. public override bool HandleMessage(MessageBase msg, out bool handled)
  327. {
  328. var result = msg as RobotSiasun1500C800CMessage;
  329. if (result.IsError)
  330. {
  331. Device.NoteError(result.Data);
  332. }
  333. else
  334. {
  335. Device.NoteError(null);
  336. Device.NoteAxisHomed(_parameter);
  337. }
  338. ResponseMessage = msg;
  339. handled = true;
  340. return true;
  341. }
  342. }
  343. public class RobotSiasun1500C800CQueryWaferOnOffHandler : RobotSiasun1500C800CHandler
  344. {
  345. public RobotSiasun1500C800CQueryWaferOnOffHandler(RobotSiasun1500C800C device, string jsonParameter)
  346. : base(device, "RQ LOAD", jsonParameter != null ? jsonParameter : "A")
  347. {
  348. }
  349. public override bool HandleMessage(MessageBase msg, out bool handled)
  350. {
  351. if (base.HandleMessage(msg, out handled))
  352. {
  353. var result = msg as RobotSiasun1500C800CMessage;
  354. if (_parameter != null && _parameter.Contains('B'))
  355. {
  356. Device.NoteWafeOnOff("B", _requestResponse.Contains("ON"));
  357. }
  358. else
  359. {
  360. Device.NoteWafeOnOff("A", _requestResponse.Contains("ON"));
  361. }
  362. }
  363. return true;
  364. }
  365. }
  366. public class RobotSiasun1500C800CRequestCommunicationEchoHandler : RobotSiasun1500C800CHandler
  367. {
  368. public RobotSiasun1500C800CRequestCommunicationEchoHandler(RobotSiasun1500C800C device)
  369. : base(device, "RQ COMM ECHO")
  370. {
  371. }
  372. public override bool HandleMessage(MessageBase msg, out bool handled)
  373. {
  374. if (base.HandleMessage(msg, out handled))
  375. {
  376. var result = msg as RobotSiasun1500C800CMessage;
  377. Device.NoteCommEchoStatus(_requestResponse.Contains("ON"));
  378. }
  379. return true;
  380. }
  381. }
  382. public class RobotSiasun1500C800CRequestWaferCentDataHandler : RobotSiasun1500C800CHandler
  383. {
  384. public RobotSiasun1500C800CRequestWaferCentDataHandler(RobotSiasun1500C800C device)
  385. : base(device, "RQ WAF_CEN DATA")
  386. {
  387. }
  388. public override bool HandleMessage(MessageBase msg, out bool handled)
  389. {
  390. if (base.HandleMessage(msg, out handled))
  391. {
  392. var result = msg as RobotSiasun1500C800CMessage;
  393. //WAF_CEN RT value1x value1y value4x value4y LFT value2x value2y value3x value3y offset_r offset_t
  394. Device.NoteWafeCenData(_requestResponse);
  395. }
  396. return true;
  397. }
  398. }
  399. }