RequestMessageBase.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ProGauge_StartItaliana_Probe.MessageEntity.Outgoing
  6. {
  7. public enum RequestType
  8. {
  9. MeasureRequest,
  10. DiagnostiRequest,
  11. TemperatureRequest,
  12. VersionRequest,
  13. ResetSW,
  14. SetAlarmPointInDmm,
  15. }
  16. public abstract class RequestMessageBase : MessageBase
  17. {
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. /// <param name="address">55555 is a broadcast address.</param>
  22. /// <param name="type"></param>
  23. public RequestMessageBase(string address, RequestType type)
  24. {
  25. if (string.IsNullOrEmpty(address)) throw new ArgumentException("address");
  26. if (address.Length > 5) throw new ArgumentException("address value length should <=5");
  27. address = address.PadLeft(5, '0');
  28. string requestMsg = "";
  29. switch (type)
  30. {
  31. case RequestType.MeasureRequest:
  32. requestMsg = "M";
  33. break;
  34. case RequestType.DiagnostiRequest:
  35. requestMsg = "D";
  36. break;
  37. case RequestType.TemperatureRequest:
  38. requestMsg = "T";
  39. break;
  40. case RequestType.VersionRequest:
  41. requestMsg = "V";
  42. break;
  43. case RequestType.ResetSW:
  44. requestMsg = "X";
  45. break;
  46. case RequestType.SetAlarmPointInDmm:
  47. requestMsg = "A";
  48. break;
  49. }
  50. requestMsg += address + "\r\n";
  51. base.RawContent = Encoding.ASCII.GetBytes(requestMsg).ToList();
  52. }
  53. }
  54. }