JelAlignerHandler.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.Aligners.JelAligner
  9. {
  10. public abstract class JelAlignerHandler : HandlerBase
  11. {
  12. public JelAligner Device { get; }
  13. protected string _command;
  14. protected string _parameter;
  15. protected JelAlignerHandler(JelAligner 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 JelAlignerHandler(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. JelAlignerMessage response = msg as JelAlignerMessage;
  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 JelAlignerReadHandler : JelAlignerHandler
  47. {
  48. public JelAlignerReadHandler(JelAligner 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. JelAlignerMessage response = msg as JelAlignerMessage;
  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 JelAlignerSetHandler : JelAlignerHandler
  70. {
  71. public JelAlignerSetHandler(JelAligner 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 set command {command} {temp} in byte.");
  76. }
  77. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  78. {
  79. JelAlignerMessage response = msg as JelAlignerMessage;
  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 JelAlignerMoveHandler : JelAlignerHandler
  92. {
  93. public JelAlignerMoveHandler(JelAligner 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 JelAlignerRawCommandHandler : JelAlignerHandler
  101. {
  102. public JelAlignerRawCommandHandler(JelAligner device, string command)
  103. : base(command)
  104. {
  105. LOG.Write($"{device.Name} execute move command {command} in byte.");
  106. }
  107. }
  108. }