SiasunVCEHandler.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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.VCE.SiasunVCE
  6. {
  7. public abstract class SiasunVCEHandler : HandlerBase
  8. {
  9. public SiasunVCE Device { get; set; }
  10. protected string _commandType;
  11. protected string _command;
  12. protected string _parameter;
  13. public bool IsSendText(string commandType, string command, string commandArgumen)
  14. {
  15. return _commandType == commandType && _command == command && _parameter == commandArgumen;
  16. }
  17. protected SiasunVCEHandler(SiasunVCE device, string commandType, string command, string parameter = null)
  18. : base(BuildMessage(device.Address, commandType, command, parameter))
  19. {
  20. Device = device;
  21. _commandType = commandType;
  22. _command = command;
  23. _parameter = parameter;
  24. Name = command;
  25. }
  26. private static string BuildMessage(string address, string commandType, string command, string parameter)
  27. {
  28. string strCommand = $"{address},{commandType}";
  29. if (!string.IsNullOrEmpty(command))
  30. {
  31. strCommand += "," + command;
  32. }
  33. if (!string.IsNullOrEmpty(parameter))
  34. {
  35. strCommand += "," + parameter;
  36. }
  37. return strCommand + "\r";
  38. }
  39. public override bool HandleMessage(MessageBase msg, out bool handled)
  40. {
  41. var result = msg as SiasunVCEMessage;
  42. handled = msg.IsComplete;
  43. if (result.IsError)
  44. {
  45. Device.NoteError(result.Data);
  46. }
  47. else
  48. {
  49. Device.NoteError(null);
  50. }
  51. if (result.IsComplete)
  52. {
  53. SetState(EnumHandlerState.Completed);
  54. }
  55. if (result.IsAck)
  56. {
  57. SetState(EnumHandlerState.Acked);
  58. }
  59. if (result.IsRDY)
  60. {
  61. if (IsAcked)
  62. {
  63. SetState(EnumHandlerState.Completed);
  64. handled = true;
  65. }
  66. else
  67. {
  68. SetState(EnumHandlerState.Acked);
  69. }
  70. }
  71. ResponseMessage = msg;
  72. return handled;
  73. }
  74. }
  75. public class SiasunVCERawCommandHandler : SiasunVCEHandler
  76. {
  77. public SiasunVCERawCommandHandler(SiasunVCE device, string commandType, string command, string parameter = null)
  78. : base(device, commandType, command, parameter)
  79. {
  80. }
  81. public override bool HandleMessage(MessageBase msg, out bool handled)
  82. {
  83. base.HandleMessage(msg, out handled);
  84. var result = msg as SiasunVCEMessage;
  85. Device.NoteRawCommandInfo(_commandType, _command, result.RawMessage);
  86. return true;
  87. }
  88. }
  89. public class SiasunVCEAbortHandler : SiasunVCEHandler
  90. {
  91. public SiasunVCEAbortHandler(SiasunVCE device)
  92. : base(device, "E", "")
  93. {
  94. }
  95. public override bool HandleMessage(MessageBase msg, out bool handled)
  96. {
  97. if (base.HandleMessage(msg, out handled))
  98. {
  99. Device.NoteIsHalted(true);
  100. }
  101. return true;
  102. }
  103. }
  104. public class SiasunVCECommonActionHandler : SiasunVCEHandler
  105. {
  106. public SiasunVCECommonActionHandler(SiasunVCE device, string command)
  107. : base(device, "A", command)
  108. {
  109. }
  110. public override bool HandleMessage(MessageBase msg, out bool handled)
  111. {
  112. if (base.HandleMessage(msg, out handled))
  113. {
  114. Device.NoteCommonActionResult(_command);
  115. }
  116. return true;
  117. }
  118. }
  119. public class SiasunVCEMoveHandler : SiasunVCEHandler
  120. {
  121. public SiasunVCEMoveHandler(SiasunVCE device, string axis, string type, string value)
  122. : base(device, "A", "MOVE", axis + "," + type + "," + value)
  123. {
  124. }
  125. public override bool HandleMessage(MessageBase msg, out bool handled)
  126. {
  127. if (base.HandleMessage(msg, out handled))
  128. {
  129. Device.NoteMoveResult(_parameter);
  130. }
  131. return true;
  132. }
  133. }
  134. public class SiasunVCECloseDoorHandler : SiasunVCEHandler
  135. {
  136. public SiasunVCECloseDoorHandler(SiasunVCE device)
  137. : base(device, "A", "DC")
  138. {
  139. }
  140. public override bool HandleMessage(MessageBase msg, out bool handled)
  141. {
  142. if (base.HandleMessage(msg, out handled))
  143. {
  144. Device.NoteDoorClosed(true);
  145. }
  146. return true;
  147. }
  148. }
  149. public class SiasunVCEOpenDoorHandler : SiasunVCEHandler
  150. {
  151. public SiasunVCEOpenDoorHandler(SiasunVCE device)
  152. : base(device, "A", "DO")
  153. {
  154. }
  155. public override bool HandleMessage(MessageBase msg, out bool handled)
  156. {
  157. if (base.HandleMessage(msg, out handled))
  158. {
  159. Device.NoteDoorClosed(false);
  160. }
  161. return true;
  162. }
  163. }
  164. public class SiasunVCEHomeHandler : SiasunVCEHandler
  165. {
  166. public SiasunVCEHomeHandler(SiasunVCE device)
  167. : base(device, "A", "HM", "")
  168. {
  169. }
  170. public override bool HandleMessage(MessageBase msg, out bool handled)
  171. {
  172. if (base.HandleMessage(msg, out handled))
  173. {
  174. Device.NoteHomed(true);
  175. }
  176. return true;
  177. }
  178. }
  179. public class SiasunVCEGotoZHandler : SiasunVCEHandler
  180. {
  181. public SiasunVCEGotoZHandler(SiasunVCE device, int slot)
  182. : base(device, "A", "GOTO", slot.ToString())
  183. {
  184. }
  185. public override bool HandleMessage(MessageBase msg, out bool handled)
  186. {
  187. if (base.HandleMessage(msg, out handled))
  188. {
  189. Device.NoteZAxisPosition(_parameter.Split(',')[2]);
  190. }
  191. return true;
  192. }
  193. }
  194. public class SiasunVCESetCommunicationModeHandler : SiasunVCEHandler
  195. {
  196. public SiasunVCESetCommunicationModeHandler(SiasunVCE device, string commMode)
  197. : base(device, "S", "COMM", "FLOW," + commMode)
  198. {
  199. }
  200. public override bool HandleMessage(MessageBase msg, out bool handled)
  201. {
  202. if (base.HandleMessage(msg, out handled))
  203. {
  204. var result = msg as SiasunVCEMessage;
  205. if (result.IsComplete)
  206. {
  207. Device.NoteCommunicationMode(this._parameter.Split(',')[2]);
  208. }
  209. }
  210. return true;
  211. }
  212. }
  213. public class BrooksACERequestArmRPositonHandler : SiasunVCEHandler
  214. {
  215. public BrooksACERequestArmRPositonHandler(SiasunVCE device, string axisPosition)
  216. : base(device, "R", "ARM", "R," + axisPosition)
  217. {
  218. }
  219. public override bool HandleMessage(MessageBase msg, out bool handled)
  220. {
  221. if (base.HandleMessage(msg, out handled))
  222. {
  223. var result = msg as SiasunVCEMessage;
  224. Device.NoteArmRPositon(result.Data.Split(',')[2]);
  225. }
  226. return true;
  227. }
  228. }
  229. public class BrooksACERequestArmZPositonHandler : SiasunVCEHandler
  230. {
  231. public BrooksACERequestArmZPositonHandler(SiasunVCE device, string axisPosition)
  232. : base(device, "R", "ARM", "Z," + axisPosition)
  233. {
  234. }
  235. public override bool HandleMessage(MessageBase msg, out bool handled)
  236. {
  237. if (base.HandleMessage(msg, out handled))
  238. {
  239. var result = msg as SiasunVCEMessage;
  240. Device.NoteArmZPositon(result.Data.Split(',')[2]);
  241. }
  242. return true;
  243. }
  244. }
  245. public class BrooksACERequestCommModeHandler : SiasunVCEHandler
  246. {
  247. public BrooksACERequestCommModeHandler(SiasunVCE device)
  248. : base(device, "R", "COMM", "FLOW")
  249. {
  250. }
  251. public override bool HandleMessage(MessageBase msg, out bool handled)
  252. {
  253. if (base.HandleMessage(msg, out handled))
  254. {
  255. var result = msg as SiasunVCEMessage;
  256. Device.NoteCurrentCommunicationMode(result.Data);
  257. }
  258. return true;
  259. }
  260. }
  261. public class BrooksACERequestErrorStatusHandler : SiasunVCEHandler
  262. {
  263. public BrooksACERequestErrorStatusHandler(SiasunVCE device)
  264. : base(device, "R", "ER")
  265. {
  266. }
  267. public override bool HandleMessage(MessageBase msg, out bool handled)
  268. {
  269. if (base.HandleMessage(msg, out handled))
  270. {
  271. var result = msg as SiasunVCEMessage;
  272. Device.NoteCurrentErrorStatus(result.Data);
  273. }
  274. return true;
  275. }
  276. }
  277. public class BrooksACERequestVCEStatusHandler : SiasunVCEHandler
  278. {
  279. public BrooksACERequestVCEStatusHandler(SiasunVCE device)
  280. : base(device, "R", "STAT", "ALL")
  281. {
  282. }
  283. public override bool HandleMessage(MessageBase msg, out bool handled)
  284. {
  285. if (base.HandleMessage(msg, out handled))
  286. {
  287. var result = msg as SiasunVCEMessage;
  288. Device.NoteCurrentACEStatus(result.Data);
  289. }
  290. return true;
  291. }
  292. }
  293. public class BrooksACERequestLoadPositionHandler : SiasunVCEHandler
  294. {
  295. public BrooksACERequestLoadPositionHandler(SiasunVCE device)
  296. : base(device, "R", "LP")
  297. {
  298. }
  299. public override bool HandleMessage(MessageBase msg, out bool handled)
  300. {
  301. if (base.HandleMessage(msg, out handled))
  302. {
  303. var result = msg as SiasunVCEMessage;
  304. Device.NoteIsLoadPositon(result.Data);
  305. }
  306. return true;
  307. }
  308. }
  309. public class BrooksACERequestMappingInfoHandler : SiasunVCEHandler
  310. {
  311. public BrooksACERequestMappingInfoHandler(SiasunVCE device)
  312. : base(device, "R", "MI")
  313. {
  314. }
  315. public override bool HandleMessage(MessageBase msg, out bool handled)
  316. {
  317. if (base.HandleMessage(msg, out handled))
  318. {
  319. var result = msg as SiasunVCEMessage;
  320. Device.NoteCurrentMappingInfo(result.Data);
  321. }
  322. return true;
  323. }
  324. }
  325. public class BrooksACERequestPlatformPositionHandler : SiasunVCEHandler
  326. {
  327. public BrooksACERequestPlatformPositionHandler(SiasunVCE device)
  328. : base(device, "R", "LP")
  329. {
  330. }
  331. public override bool HandleMessage(MessageBase msg, out bool handled)
  332. {
  333. if (base.HandleMessage(msg, out handled))
  334. {
  335. var result = msg as SiasunVCEMessage;
  336. Device.NoteIsPlatformPosition(result.Data);
  337. }
  338. return true;
  339. }
  340. }
  341. }