C# Modbus communication from entry to proficiency (25) - Modbus TCP (0x04 function code and C# code implementation)

insert image description here

1. 04 (0x04) read input register

Use this function code to read the value of 1 to 125 input registers from the remote address, each input register occupies two bytes, and the number of input registers to be read is specified by the master station when reading.

2. Send message format

insert image description here

The format of the MBAP header is as follows:
insert image description here

The more detailed format is as follows:
MBAP message header + function code + high start address + low start address + high register quantity + low register quantity, a total of 12 bytes.

3. Return message format

insert image description here

The more detailed format is as follows:
MBAP message header + function code + byte count + high byte of the first register + low byte of the first register + ... + high byte of the value of the Nth register + low byte of the Nth register Bytes, a total of 2*N+9 bytes, N is the number of input registers that need to be read

4. Case

Slave address: 1
Start address: 0

Guess you like

Origin blog.csdn.net/qq_34059233/article/details/131875468