1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| ushort startAddr = 0; ushort readLen = 2;
List<byte> command = new List<byte>();
command.Add(0x01);
command.Add(0x03);
command.Add(BitConverter.GetBytes(startAddr)[1]); command.Add(BitConverter.GetBytes(startAddr)[0]);
command.Add(BitConverter.GetBytes(readLen)[1]); command.Add(BitConverter.GetBytes(readLen)[0]);
command = CRC16(command);
serialPort.Write(command.ToArray(), 0, command.Count);
Task.Run(() => { byte[] respBytes1 = {0x01, 0x03, 0x4e, 0x20, 0x00, 0x0A, 0xd3, 0x25}; byte[] respBytes2 = {0x02, 0x03, 0x4e, 0x20, 0x00, 0x0A, 0xd3, 0x25}; serialPort1.Write(respBytes1, 0, 8); Thread.Sleep(1000); serialPort1.Write(respBytes2, 0, 8); Thread.Sleep(1000); });
|