JelC5000RobotFlippeHandler.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 JelC5000RobotFlippeHandler : HandlerBase
  11. {
  12. public JelC5000RobotFlippe Device { get; }
  13. protected string _command;
  14. protected string _parameter;
  15. protected JelC5000RobotFlippeHandler(JelC5000RobotFlippe device, string command, string parameter = null,int bodynumber=-1)
  16. : base(BuildMessage((bodynumber == -1? device.BodyNumber:bodynumber), command, parameter))
  17. {
  18. Device = device;
  19. _command = command;
  20. _parameter = parameter;
  21. Name = command;
  22. }
  23. protected JelC5000RobotFlippeHandler(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. JelC5000RobotFlippeMessage response = msg as JelC5000RobotFlippeMessage;
  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 JelC5000RobotFlippeReadHandler : JelC5000RobotFlippeHandler
  47. {
  48. public JelC5000RobotFlippeReadHandler(JelC5000RobotFlippe device, string command, string parameter = null,int bodynumber=-1)
  49. : base(device, command, parameter,bodynumber)
  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. JelC5000RobotFlippeMessage response = msg as JelC5000RobotFlippeMessage;
  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 JelC5000RobotFlippeSetHandler : JelC5000RobotFlippeHandler
  70. {
  71. public JelC5000RobotFlippeSetHandler(JelC5000RobotFlippe 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. JelC5000RobotFlippeMessage response = msg as JelC5000RobotFlippeMessage;
  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 JelC5000RobotFlippeMoveHandler : JelC5000RobotFlippeHandler
  92. {
  93. public JelC5000RobotFlippeMoveHandler(JelC5000RobotFlippe 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. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  100. {
  101. JelC5000RobotFlippeMessage response = msg as JelC5000RobotFlippeMessage;
  102. ResponseMessage = msg;
  103. if (response.IsAck)
  104. {
  105. //if (_command == "G")
  106. // Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
  107. SetState(EnumHandlerState.Completed);
  108. transactionComplete = true;
  109. return true;
  110. }
  111. transactionComplete = false;
  112. return false;
  113. }
  114. }
  115. public class JelC5000RobotFlippeRawCommandHandler : JelC5000RobotFlippeHandler
  116. {
  117. public JelC5000RobotFlippeRawCommandHandler(JelC5000RobotFlippe device, string command)
  118. : base(device,command)
  119. {
  120. LOG.Write($"{device.Name} execute move command {command} in byte.");
  121. }
  122. }
  123. public class JelC5000RobotFlippeCompaundCommandHandler : JelC5000RobotFlippeHandler
  124. {
  125. public JelC5000RobotFlippeCompaundCommandHandler(JelC5000RobotFlippe device, string cmdNo, string parameter = null)
  126. : base(device, $"G{cmdNo}", parameter)
  127. {
  128. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  129. LOG.Write($"{device.Name} execute compaund command {cmdNo} {temp} in byte.");
  130. }
  131. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  132. {
  133. JelC5000RobotFlippeMessage response = msg as JelC5000RobotFlippeMessage;
  134. ResponseMessage = msg;
  135. if (response.IsAck)
  136. {
  137. //if (_command == "G")
  138. // Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
  139. SetState(EnumHandlerState.Acked);
  140. //transactionComplete = true;
  141. //return true;
  142. }
  143. if(response.IsResponse)
  144. {
  145. SetState(EnumHandlerState.Completed);
  146. if(response.Data.Contains("END"))
  147. {
  148. transactionComplete = true;
  149. return true;
  150. }
  151. if(response.Data.Contains("ERR"))
  152. {
  153. Device.HandlerError(response.Data);
  154. transactionComplete = true;
  155. return true;
  156. }
  157. }
  158. transactionComplete = false;
  159. return false;
  160. }
  161. }
  162. }