SkySGMPumpHandler.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using MECF.Framework.Common.Communications;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Pumps.SkySGMPump
  8. {
  9. public class SkySGMPumpHandler : HandlerBase
  10. {
  11. public SkySGMPump Device { get; }
  12. public string _command;
  13. protected string _completeEvent;
  14. protected SkySGMPumpHandler(SkySGMPump device, string command, string completeEvent) : base(BuildMessage(device.Address, command))
  15. {
  16. Device = device;
  17. _command = command;
  18. _completeEvent = completeEvent;
  19. Name = command;
  20. }
  21. private static string _startLine = "@00";
  22. private static string _endLine = "\r\n";
  23. private static string BuildMessage(string address, string command)
  24. {
  25. return _startLine + address + command + _endLine;
  26. }
  27. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  28. {
  29. SkySGMPumpMessage response = msg as SkySGMPumpMessage;
  30. if (response.IsAck)
  31. {
  32. SetState(EnumHandlerState.Completed);
  33. transactionComplete = true;
  34. Device.NoteError(null);
  35. return true;
  36. }
  37. transactionComplete = false;
  38. return false;
  39. }
  40. }
  41. public class SkySGMPumpRawCommandHandler : SkySGMPumpHandler
  42. {
  43. public SkySGMPumpRawCommandHandler(SkySGMPump device, string command, string completeEvent)
  44. : base(device, command, completeEvent)
  45. {
  46. }
  47. public override bool HandleMessage(MessageBase msg, out bool handled)
  48. {
  49. if (base.HandleMessage(msg, out handled))
  50. {
  51. var result = msg as SkySGMPumpMessage;
  52. Device.NoteRawCommandInfo(_command, result.RawMessage);
  53. }
  54. return true;
  55. }
  56. }
  57. public class SkySGMPumpStartHandler : SkySGMPumpHandler
  58. {
  59. public SkySGMPumpStartHandler(SkySGMPump device)
  60. : base(device, "CON_FDP_ON", "FDP_ONOK")
  61. {
  62. }
  63. public override bool HandleMessage(MessageBase msg, out bool handled)
  64. {
  65. if (base.HandleMessage(msg, out handled))
  66. {
  67. Device.NoteStart(true);
  68. }
  69. return true;
  70. }
  71. }
  72. public class SkySGMPumpStopHandler : SkySGMPumpHandler
  73. {
  74. public SkySGMPumpStopHandler(SkySGMPump device)
  75. : base(device, "CON_FDP_OFF", "FDP_OFFOK")
  76. {
  77. }
  78. public override bool HandleMessage(MessageBase msg, out bool handled)
  79. {
  80. if (base.HandleMessage(msg, out handled))
  81. {
  82. Device.NoteStart(false);
  83. }
  84. return true;
  85. }
  86. }
  87. public class SkySGMPumpReadRunParaHandler : SkySGMPumpHandler
  88. {
  89. public SkySGMPumpReadRunParaHandler(SkySGMPump device)
  90. : base(device, "READ_RUN_PARA", "RUN_PARA")
  91. {
  92. }
  93. public override bool HandleMessage(MessageBase msg, out bool handled)
  94. {
  95. if (base.HandleMessage(msg, out handled))
  96. {
  97. var result = msg as SkySGMPumpMessage;
  98. if (result.Data.Length != 40)
  99. {
  100. Device.NoteError("Invalid 'RunParameter'response, the length is not 40");
  101. }
  102. else
  103. {
  104. Device.NoteRunPara(result.Data);
  105. }
  106. }
  107. return true;
  108. }
  109. }
  110. }