PresetSingleRegister_Request.cs 903 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace PressureGage_3051.MessageEntity.Outgoing
  5. {
  6. public class PresetSingleRegister_Request : MessageBase
  7. {
  8. private Dictionary<string, byte> unitMapper = new Dictionary<string, byte>();
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. public PresetSingleRegister_Request(byte deviceAddress, short dataAddress, string writeValue)
  13. {
  14. unitMapper["Pa"] = 11;
  15. unitMapper["KPa"] = 12;
  16. unitMapper["MPa"] = 237;
  17. base.Address = deviceAddress;
  18. base.FunctionCode = FunctionCode.PRESET_SINGLE_REGISTER;
  19. base.RawDataField = new List<byte>();
  20. base.RawDataField.AddRange(BitConverter.GetBytes(dataAddress).Reverse());
  21. base.RawDataField.AddRange(new byte[] { 0, unitMapper[writeValue] });
  22. }
  23. }
  24. }