public bool Motor5(int index, ushort id1, int value) { const int function = 4; try { var byteList = new List { // 地址 1个字节,取低位 (byte)(id1 % 256), // 功能码 1个字节 取低位 (byte)(function % 256), // 起始地址2个字节 高位 0x00, 0x02, 0x00, 0x02 }; // 校验码 byteList = CRC16(byteList); // 发送报文 port.Write(byteList.ToArray(), 0, byteList.Count); Thread.Sleep(50); var buffer = new byte[port.BytesToRead]; port.Read(buffer, 0, buffer.Length); if (RecordTimes > 30) { RecordTimes = 0; return true; } RecordTimes++; if (buffer[2] == 04) { var value3 = value <= 65535 ? buffer[3] * 256 + buffer[4] : 65535 + buffer[3] * 256 + buffer[4] + buffer[6]; if (value == value3) { RecordTimes = 0; return true; } } return false; } catch (Exception) { return false; } }

public bool Motor5int index ushort id1 int value int function = 4; try Listbyte byteList = new Listbyte 地址 1个字节取低位

原文地址: https://www.cveoy.top/t/topic/b75i 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录