PresetVolumeRequest.cs 1.2 KB

1234567891011121314151617181920212223242526272829
  1. using Edge.Core.Parser.BinaryParser.Util;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace LanTian_Pump_664_Or_886.MessageEntity.Outgoing
  8. {
  9. public class PresetVolumeRequest : MessageBase
  10. {
  11. public PresetVolumeRequest(int volumeWithoutDecimalPoint, byte volumeFieldLength)
  12. {
  13. if (volumeFieldLength != 3 && volumeFieldLength != 4)
  14. throw new ArgumentException("预置字段长度应为 3 or 4");
  15. if (volumeFieldLength == 3
  16. && (volumeWithoutDecimalPoint > 999999 || volumeWithoutDecimalPoint <= 0))
  17. throw new ArgumentException("664机型预置金额区为3字节, so should range from 0 to 999999");
  18. if (volumeFieldLength == 4
  19. && (volumeWithoutDecimalPoint > 99999999 || volumeWithoutDecimalPoint <= 0))
  20. throw new ArgumentException("886机型预置金额区为4字节, so should range from 0 to 99999999");
  21. this.BodyAndXRL = volumeWithoutDecimalPoint.GetBCDBytes(volumeFieldLength).ToList();
  22. // cmd byte
  23. this.BodyAndXRL.Add(0xB9);
  24. // add a place hold for XRL
  25. this.BodyAndXRL.Add(0);
  26. }
  27. }
  28. }