JelRobotHandler.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using MECF.Framework.Common.Communications;
  4. using Newtonsoft.Json.Linq;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL
  9. {
  10. public abstract class JelRobotHandler:HandlerBase
  11. {
  12. public JelRobot Device { get; }
  13. protected string _command;
  14. protected string _parameter;
  15. protected JelRobotHandler(JelRobot device, string command, string parameter = null)
  16. : base(BuildMessage(device.BodyNumber, command, parameter))
  17. {
  18. Device = device;
  19. _command = command;
  20. _parameter = parameter;
  21. Name = command;
  22. }
  23. protected JelRobotHandler(string command)
  24. : base(command)
  25. {
  26. _command = command;
  27. }
  28. private static string BuildMessage(int bodyno, string command, string parameter)
  29. {
  30. return $"${bodyno}{command}{parameter}\r";
  31. }
  32. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  33. {
  34. JelRobotMessage response = msg as JelRobotMessage;
  35. ResponseMessage = msg;
  36. if (response.IsAck)
  37. {
  38. SetState(EnumHandlerState.Completed);
  39. transactionComplete = true;
  40. return true;
  41. }
  42. transactionComplete = false;
  43. return false;
  44. }
  45. }
  46. public class JelRobotReadHandler: JelRobotHandler
  47. {
  48. public JelRobotReadHandler(JelRobot device, string command, string parameter = null)
  49. : base(device, command, parameter)
  50. {
  51. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  52. LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
  53. }
  54. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  55. {
  56. JelRobotMessage response = msg as JelRobotMessage;
  57. ResponseMessage = msg;
  58. if (response.IsAck)
  59. {
  60. Device.ParseData(_command,_parameter,response.Data);
  61. SetState(EnumHandlerState.Completed);
  62. transactionComplete = true;
  63. return true;
  64. }
  65. transactionComplete = false;
  66. return false;
  67. }
  68. }
  69. public class JelRobotSetHandler : JelRobotHandler
  70. {
  71. public JelRobotSetHandler(JelRobot device, string command, string parameter = null)
  72. : base(device, command, parameter)
  73. {
  74. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  75. LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
  76. }
  77. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  78. {
  79. JelRobotMessage response = msg as JelRobotMessage;
  80. ResponseMessage = msg;
  81. if (response.IsAck)
  82. {
  83. SetState(EnumHandlerState.Completed);
  84. transactionComplete = true;
  85. return true;
  86. }
  87. transactionComplete = false;
  88. return false;
  89. }
  90. }
  91. public class JelRobotMoveHandler : JelRobotHandler
  92. {
  93. public JelRobotMoveHandler(JelRobot device, string command, string parameter = null)
  94. : base(device, command, parameter)
  95. {
  96. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  97. LOG.Write($"{device.Name} execute move command {command} {temp} in byte.");
  98. }
  99. }
  100. public class JelRobotRawCommandHandler : JelRobotHandler
  101. {
  102. public JelRobotRawCommandHandler(JelRobot device, string command)
  103. : base(command)
  104. {
  105. LOG.Write($"{device.Name} execute move command {command} in byte.");
  106. }
  107. }
  108. public class JelRobotCompaundCommandHandler : JelRobotHandler
  109. {
  110. public JelRobotCompaundCommandHandler(JelRobot device, string cmdNo, string parameter = null)
  111. : base(device, $"G{cmdNo}", parameter)
  112. {
  113. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  114. LOG.Write($"{device.Name} execute compaund command {cmdNo} {temp} in byte.");
  115. }
  116. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  117. {
  118. JelRobotMessage response = msg as JelRobotMessage;
  119. ResponseMessage = msg;
  120. if (response.IsAck)
  121. {
  122. //if (_command == "G")
  123. // Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
  124. SetState(EnumHandlerState.Acked);
  125. //transactionComplete = true;
  126. //return true;
  127. }
  128. if (response.IsResponse)
  129. {
  130. SetState(EnumHandlerState.Completed);
  131. if (response.Data.Contains("END"))
  132. {
  133. transactionComplete = true;
  134. return true;
  135. }
  136. if (response.Data.Contains("ERR"))
  137. {
  138. Device.HandlerError(response.Data);
  139. transactionComplete = true;
  140. return true;
  141. }
  142. if (response.Data.Contains("POK"))
  143. {
  144. transactionComplete = true;
  145. return true;
  146. }
  147. if (response.Data.Contains("PNG"))
  148. {
  149. Device.HandlerError(response.Data);
  150. transactionComplete = true;
  151. return true;
  152. }
  153. if (response.Data.Contains("GOK"))
  154. {
  155. transactionComplete = true;
  156. return true;
  157. }
  158. if (response.Data.Contains("GNG"))
  159. {
  160. Device.HandlerError(response.Data);
  161. transactionComplete = true;
  162. return true;
  163. }
  164. if (response.Data.Contains("OK"))
  165. {
  166. transactionComplete = true;
  167. return true;
  168. }
  169. if (response.Data.Contains("NG"))
  170. {
  171. Device.HandlerError(response.Data);
  172. transactionComplete = true;
  173. return true;
  174. }
  175. }
  176. transactionComplete = false;
  177. return false;
  178. }
  179. }
  180. public class JelRobotCheckWaferCommandHandler : JelRobotHandler
  181. {
  182. public JelRobotCheckWaferCommandHandler(JelRobot device, string cmdNo, RobotArmEnum arm, string parameter = null)
  183. : base(device, $"G{cmdNo}", parameter)
  184. {
  185. _arm = arm;
  186. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  187. LOG.Write($"{device.Name} execute compaund command {cmdNo} {temp} in byte.");
  188. }
  189. private RobotArmEnum _arm;
  190. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  191. {
  192. JelRobotMessage response = msg as JelRobotMessage;
  193. ResponseMessage = msg;
  194. if (response.IsAck)
  195. {
  196. //if (_command == "G")
  197. // Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
  198. SetState(EnumHandlerState.Acked);
  199. //transactionComplete = true;
  200. //return true;
  201. }
  202. if (response.IsResponse)
  203. {
  204. SetState(EnumHandlerState.Completed);
  205. if (response.Data.Contains("WCH0"))
  206. {
  207. Device.HandlerWaferCheckResult(false,_arm,false);
  208. transactionComplete = true;
  209. return true;
  210. }
  211. if (response.Data.Contains("WCH1"))
  212. {
  213. Device.HandlerWaferCheckResult(false, _arm, true);
  214. transactionComplete = true;
  215. return true;
  216. }
  217. if (response.Data.Contains("WCH9"))
  218. {
  219. Device.HandlerWaferCheckResult(true, _arm, true);
  220. transactionComplete = true;
  221. return true;
  222. }
  223. }
  224. transactionComplete = false;
  225. return false;
  226. }
  227. }
  228. }