Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

35 rader
888 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. namespace ModbusDemo.Uitls
  8. {
  9. public static class CheckData
  10. {
  11. public static void CheckResponse(byte[] response)
  12. {
  13. // 检查数组长度是否足够
  14. if (response.Length > 1)
  15. {
  16. byte secondByte = response[1]; // 获取第二个字节(索引为1)
  17. // 使用掩码0xF0获取高4位,并右移4位
  18. int highNibble = (secondByte & 0xF0) >> 4;
  19. // 判断高4位是否等于8
  20. if (highNibble == 8)
  21. {
  22. MessageBox.Show($"数据错误:错误码为:0x{response[2]:X2}");
  23. return;
  24. }
  25. }
  26. }
  27. }
  28. }