25개 이상의 토픽을 선택하실 수 없습니다.
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
-
- namespace ModbusDemo.Uitls
- {
- public static class CheckData
- {
-
- public static void CheckResponse(byte[] response)
- {
- // 检查数组长度是否足够
- if (response.Length > 1)
- {
- byte secondByte = response[1]; // 获取第二个字节(索引为1)
-
- // 使用掩码0xF0获取高4位,并右移4位
- int highNibble = (secondByte & 0xF0) >> 4;
-
- // 判断高4位是否等于8
- if (highNibble == 8)
- {
- MessageBox.Show($"数据错误:错误码为:0x{response[2]:X2}");
- return;
- }
-
- }
- }
-
- }
- }
|