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

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 more detailed format is as follows:
start character + slave station address + function code + high start address + low start address + high number of registers + low number of registers + LRC + end character, a total of 17 bytes, of which the LRC calculation excludes Start character, end character.

3. Return message format

72bdbbb181f4ef19b5744e92702dae7.png)

The more detailed format is as follows:
start character + slave station address + function code + number of bytes occupied by the register + low byte of register value + ... + high byte of register value + LRC + terminator, assuming that the number of registers is N, a total of 4N+11 bytes

4. Case

Slave address: 1
Start address: 0
Number of registers: 3
Suppose you want to read the values ​​of 3 registers whose slave address is 1 and start address is 0, then

4.1 Send the message as follows:

0x3a、0x30、0x31、0x30、0x34、0x30、0x30、0x30、0x30

Guess you like

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