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

insert image description here

1. 06 (0x06) write a single register

Use this function code to write the value of a holding register to 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 register address + low bit of register address + high bit of output value + low bit of output value, 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 + high bit of register address + low bit of register address + high bit of output value + low bit of output value, a total of 12 bytes.

4. Case

Slave station address: 1
Holding register address: 8
Output value: 1000
Suppose you want to set the value of the holding register with slave station address 1 and address 8 as 1000

4.1 Send the message as follows:

0x00, 0x04
, 0x00, 0x00, 0x00, 0x06, 0x01, 0x06, 0x00, 0x08, 0x03, 0xe8 The meaning of each byte is as follows:
the first byte 0x00 is the high byte of the transaction processing flag

Guess you like

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