JelC5000RobotHandler.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL
  10. {
  11. public abstract class JelC5000RobotHandler:HandlerBase
  12. {
  13. public JelC5000Robot Device { get; }
  14. protected string _command;
  15. protected string _parameter;
  16. protected JelC5000RobotHandler(JelC5000Robot device, string command, string parameter = null)
  17. : base(BuildMessage(device.BodyNumber, command, parameter))
  18. {
  19. Device = device;
  20. _command = command;
  21. _parameter = parameter;
  22. Name = command;
  23. }
  24. protected JelC5000RobotHandler(string command)
  25. : base(command)
  26. {
  27. _command = command;
  28. }
  29. private static string BuildMessage(int bodyno, string command, string parameter)
  30. {
  31. return $"${bodyno}{command}{parameter}\r";
  32. }
  33. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  34. {
  35. JelC5000RobotMessage response = msg as JelC5000RobotMessage;
  36. ResponseMessage = msg;
  37. if (response.IsAck)
  38. {
  39. SetState(EnumHandlerState.Completed);
  40. transactionComplete = true;
  41. return true;
  42. }
  43. transactionComplete = false;
  44. return false;
  45. }
  46. }
  47. public class JelC5000RobotReadHandler: JelC5000RobotHandler
  48. {
  49. public JelC5000RobotReadHandler(JelC5000Robot device, string command, string parameter = null)
  50. : base(device, command, parameter)
  51. {
  52. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  53. LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
  54. }
  55. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  56. {
  57. JelC5000RobotMessage response = msg as JelC5000RobotMessage;
  58. ResponseMessage = msg;
  59. if (response.IsAck)
  60. {
  61. Device.ParseData(_command,_parameter,response.Data);
  62. SetState(EnumHandlerState.Completed);
  63. transactionComplete = true;
  64. return true;
  65. }
  66. transactionComplete = false;
  67. return false;
  68. }
  69. }
  70. public class JelC5000RobotSetHandler : JelC5000RobotHandler
  71. {
  72. public JelC5000RobotSetHandler(JelC5000Robot device, string command, string parameter = null)
  73. : base(device, command, parameter)
  74. {
  75. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  76. LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
  77. }
  78. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  79. {
  80. JelC5000RobotMessage response = msg as JelC5000RobotMessage;
  81. ResponseMessage = msg;
  82. if (response.IsAck)
  83. {
  84. switch(_command)
  85. {
  86. case "BC":
  87. Device.ReadBankNumber = _parameter;
  88. break;
  89. case "WCP":
  90. Device.ReadCassetNumber = Convert.ToInt32(_parameter);
  91. break;
  92. case "WCD":
  93. Device.ReadSlotNumber = Convert.ToInt32(_parameter);
  94. break;
  95. }
  96. SetState(EnumHandlerState.Completed);
  97. transactionComplete = true;
  98. return true;
  99. }
  100. transactionComplete = false;
  101. return false;
  102. }
  103. }
  104. public class JelC5000RobotMoveHandler : JelC5000RobotHandler
  105. {
  106. public JelC5000RobotMoveHandler(JelC5000Robot device, string command, string parameter = null)
  107. : base(device, command, parameter)
  108. {
  109. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  110. LOG.Write($"{device.Name} execute move command {command} {temp} in byte.");
  111. }
  112. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  113. {
  114. JelC5000RobotMessage response = msg as JelC5000RobotMessage;
  115. ResponseMessage = msg;
  116. if (response.IsAck)
  117. {
  118. //if (_command == "G")
  119. // Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
  120. SetState(EnumHandlerState.Completed);
  121. transactionComplete = true;
  122. return true;
  123. }
  124. transactionComplete = false;
  125. return false;
  126. }
  127. }
  128. public class JelC5000RobotRawCommandHandler : JelC5000RobotHandler
  129. {
  130. public JelC5000RobotRawCommandHandler(JelC5000Robot device, string command)
  131. : base(device,command)
  132. {
  133. LOG.Write($"{device.Name} execute move command {command} in byte.");
  134. }
  135. }
  136. public class JelC5000RobotCompaundCommandHandler : JelC5000RobotHandler
  137. {
  138. public JelC5000RobotCompaundCommandHandler(JelC5000Robot device, string cmdNo, string parameter = null)
  139. : base(device, $"G{cmdNo}", parameter)
  140. {
  141. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  142. LOG.Write($"{device.Name} execute compaund command {cmdNo} {temp} in byte.");
  143. }
  144. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  145. {
  146. JelC5000RobotMessage response = msg as JelC5000RobotMessage;
  147. ResponseMessage = msg;
  148. if (response.IsAck)
  149. {
  150. //if (_command == "G")
  151. // Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
  152. SetState(EnumHandlerState.Acked);
  153. //transactionComplete = true;
  154. //return true;
  155. }
  156. if(response.IsResponse)
  157. {
  158. SetState(EnumHandlerState.Completed);
  159. if(response.Data.Contains("END"))
  160. {
  161. transactionComplete = true;
  162. return true;
  163. }
  164. if(response.Data.Contains("ERR"))
  165. {
  166. Device.HandlerError(response.Data);
  167. transactionComplete = true;
  168. return true;
  169. }
  170. }
  171. transactionComplete = false;
  172. return false;
  173. }
  174. }
  175. }