AEOR4000THandler.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Collections.Generic;
  2. using MECF.Framework.Common.Communications;
  3. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temperatures.AEs
  4. {
  5. public class AEOR4000THandler : HandlerBase
  6. {
  7. public AEOR4000T Device { get; }
  8. public string _command;
  9. protected string _parameter;
  10. protected AEOR4000THandler(AEOR4000T device, string command, string parameter)
  11. : base(BuildMessage(command, parameter))
  12. {
  13. Device = device;
  14. _command = command;
  15. _parameter = parameter;
  16. Name = command;
  17. }
  18. private static string _CH = "\t";
  19. private static string _endLine = "\r";
  20. private static string BuildMessage(string command, string parameter)
  21. {
  22. if (string.IsNullOrEmpty(parameter))
  23. return command + _endLine;
  24. else
  25. return command +_CH + parameter + _endLine;
  26. }
  27. public override bool HandleMessage(MessageBase msg, out bool handled)
  28. {
  29. AETempAsciiMessage response = msg as AETempAsciiMessage;
  30. ResponseMessage = msg;
  31. if (response.IsAck)
  32. {
  33. SetState(EnumHandlerState.Acked);
  34. if (msg.IsError)
  35. {
  36. //Device.NoteError($"Command '{_command}' Error: {response.Data}:{ErrorString(response.ErrorText)}");
  37. }
  38. else
  39. {
  40. SetState(EnumHandlerState.Completed);
  41. handled = true;
  42. //Device.NoteError(null);
  43. return true;
  44. }
  45. }
  46. handled = false;
  47. return false;
  48. }
  49. private static Dictionary<string, string> ErrorDict = new Dictionary<string, string>()
  50. {
  51. {"1","Invalid message" },
  52. {"2","Number not found" },
  53. {"3","Number Invalid" },
  54. {"4","Parameter’s value not received" },
  55. {"5","Command not possible" }
  56. };
  57. private static string ErrorString(string errorCode)
  58. {
  59. if (ErrorDict.ContainsKey(errorCode))
  60. return ErrorDict[errorCode];
  61. else
  62. return "NotDefined error";
  63. }
  64. }
  65. public class AETempReadCommandHandler : AEOR4000THandler
  66. {
  67. public AETempReadCommandHandler(AEOR4000T device, string command, string parameter)
  68. : base(device, command, parameter)
  69. {
  70. }
  71. public override bool HandleMessage(MessageBase msg, out bool handled)
  72. {
  73. if (base.HandleMessage(msg, out handled))
  74. {
  75. var result = msg as AETempAsciiMessage;
  76. Device.ParseCommandInfo(_command, result.Data);
  77. }
  78. return true;
  79. }
  80. }
  81. }