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

1. 01 (0x01) read coil output

Use this function code to read the state of 1 to 2000 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 message header is as follows:
insert image description here
the more detailed format is as follows:
MBAP message header + function code + high byte of start address + low byte of start address + high byte of coil quantity + low byte of coil 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 + low byte of coil status + ... + high byte of coil status, a total of N+9 bytes, N is the occupation of all coil statuses that need to be read The number of bytes (8 coils occupy one byte).

4. Case

Slave address: 1
Start address: 0
Number of coils: 10
Suppose you want to read 10 coil status values ​​with slave address 1 and start address 0, then

4.1 Send the message as follows:

Guess you like

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