MessageBase.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using Edge.Core.Parser.BinaryParser.MessageEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace PressureGage_3051.MessageEntity
  6. {
  7. public enum FunctionCode
  8. {
  9. /// <summary>
  10. /// Read Holding Registers
  11. /// </summary>
  12. READ_HOLDING_REGISTERS = 0x03,
  13. /// <summary>
  14. /// Read Input Registers
  15. /// </summary>
  16. READ_INPUT_REGISTERS = 0x04,
  17. /// <summary>
  18. /// Preset Single Register
  19. /// </summary>
  20. PRESET_SINGLE_REGISTER = 0x06,
  21. /// <summary>
  22. /// Preset Multiple Registers
  23. /// </summary>
  24. PRESET_MULTIPLE_REGISTER = 0x10,
  25. }
  26. public abstract class MessageBase : MessageTemplateBase
  27. {
  28. [Format(1, EncodingType.BIN, -9990)]
  29. public byte Address { get; set; }
  30. [Format(1, EncodingType.BIN, -9980)]
  31. public FunctionCode FunctionCode { get; set; }
  32. [EnumerableFormat("%cascade", -9970)]
  33. public List<byte> RawDataField { get; set; }
  34. public static float BytesToFloat(byte[] hexBytes)
  35. {
  36. for (int i = 1; i < hexBytes.Length;)
  37. {
  38. var t = hexBytes[i - 1];
  39. hexBytes[i - 1] = hexBytes[i];
  40. hexBytes[i] = t;
  41. i += 2;
  42. }
  43. return BitConverter.ToSingle(hexBytes, 0);
  44. }
  45. }
  46. }