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

insert image description here

1. 02 (0x02) read coil input

Use this function code to read the state of 1 to 2000 input coils from the remote address. The state of each coil can only be 0 or 1, and the number of read coils 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 number of coils + low number of coils, 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 + 1st coil status byte + ... + Nth coil status byte, a total of N+9 bytes, N is to be read The number of bytes occupied by all coil states (8 coils occupy one byte).

4. Case

Slave address: 1
Start address: 0

Guess you like

Origin blog.csdn.net/qq_34059233/article/details/131872244
Recommended