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

insert image description here

1. 0F (0x0F) write multiple coil output

Use this function code to write the value of multiple coils into the remote address.

2. Send message format

insert image description here

The more detailed format is as follows:
MBAP message header + function code + high bit of coil start address + low bit of coil start address + high bit of coil number + low bit of coil number + byte count of coil + coil output status, a total of N+13 words Festival.

3. Return message format

insert image description here

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

4. Case

Slave station address: 1
Coil start address: 0
Coil number: 10
Suppose you want to set the value of a total of 10 coils with the slave station address as 1 and the start address as 0, and set the address 0 to 4 to ON, and the address 5 to 0. 9 set to OFF

4.1 Send the message as follows:

0x00、0x0a、0x00、0x00、0x00、0x09、0x01、0x0f、0x00、0x00、0x00、0x

Guess you like

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