01H-Read coil status
1) Description: Read slave coil register, bit operation, read single or multiple;
2) Send command:
Assuming slave address bit 0x01, register start address 0x0023, register end resist 0x0038, a total of 21 coils are read. The protocol diagram is as follows:
3) Response:
each bit of the returned data corresponds to the coil state, 1-ON, 0-OFF, as shown in the figure below;
In the above table, data1 represents the coil state of 0x0023-0x002a, and the lowest bit of data1 represents the coil state of the lowest address, which can be understood as little-endian mode;
data2 represents the coil status of addresses 0x002b-0x0033, as shown in the following table:
data3 represents the coil status of the address 0x0034-0x0038, which is not enough for 8 bits, and the high byte of the byte is filled with 0, as shown in the following table:
02H-Read discrete input status
1): Read discrete input register, bit operation, read single or multiple, the protocol is similar to the function code 0X01 protocol, which is omitted here;
03H - Read Holding Register
1) Description: read holding register, byte command operation, read single or multiple;
2) Send command:
slave address 0x01, starting address of holding register 0x0032, read 2 holding registers
3) Response:
Data storage order
04H - read input register
1) Description: read input register, byte command operation, read single or multiple;
2) Send command: same as 03H;
3) Response: same as 03H;
05H-Write a single coil
1) Description: write a single coil, bit operation, only one can be written, write 0xff00 means set the coil state to ON, write 0x0000 means set the coil state to OFF
2) Send command:
set the 0x0032 coil to ON;
3) Response:
same as sending command;
06H - Write a single holding register
1) Description: write a single holding register, byte command operation, only one can be written;
2) Send command:
write 0x0032 holding register to 0x1232;
3) Response: same as sending command;
0FH - write multiple coils
1) Description: Write multiple coil registers. If the value of a bit in the data area is "1", it means that the requested corresponding coil state is ON; if the value of a bit is "0", the state is OFF.
2) Send command:
the coil address is 0x04a5, write 12 coils,
In the above figure, DATA1 is 0x0c, which means:
DATA2 is 0x02, which is not enough for 8 bits, and the high byte of the byte is filled with 0:
3) Response:
10H - write multiple holding registers
1) Description: Write multiple holding registers, byte instruction operation, multiple can be written;
2) Send instruction:
The starting address of the holding register is 0x0034, and the data of 4 bytes of 2 registers is written;
3) Response:
01H-Read coil status
1) Description: Read slave coil register, bit operation, read single or multiple;
2) Send command:
Assuming slave address bit 0x01, register start address 0x0023, register end resist 0x0038, a total of 21 coils are read. The protocol diagram is as follows:
3) Response:
each bit of the returned data corresponds to the coil state, 1-ON, 0-OFF, as shown in the figure below;
In the above table, data1 represents the coil state of 0x0023-0x002a, and the lowest bit of data1 represents the coil state of the lowest address, which can be understood as little-endian mode;
data2 represents the coil status of addresses 0x002b-0x0033, as shown in the following table:
data3 represents the coil status of the address 0x0034-0x0038, which is not enough for 8 bits, and the high byte of the byte is filled with 0, as shown in the following table:
02H-Read discrete input status
1): Read discrete input register, bit operation, read single or multiple, the protocol is similar to the function code 0X01 protocol, which is omitted here;
03H - Read Holding Register
1) Description: read holding register, byte command operation, read single or multiple;
2) Send command:
slave address 0x01, starting address of holding register 0x0032, read 2 holding registers
3) Response:
Data storage order
04H - read input register
1) Description: read input register, byte command operation, read single or multiple;
2) Send command: same as 03H;
3) Response: same as 03H;
05H-Write a single coil
1) Description: write a single coil, bit operation, only one can be written, write 0xff00 means set the coil state to ON, write 0x0000 means set the coil state to OFF
2) Send command:
set the 0x0032 coil to ON;
3) Response:
same as sending command;
06H - Write a single holding register
1) Description: write a single holding register, byte command operation, only one can be written;
2) Send command:
write 0x0032 holding register to 0x1232;
3) Response: same as sending command;
0FH - write multiple coils
1) Description: Write multiple coil registers. If the value of a bit in the data area is "1", it means that the requested corresponding coil state is ON; if the value of a bit is "0", the state is OFF.
2) Send command:
the coil address is 0x04a5, write 12 coils,
In the above figure, DATA1 is 0x0c, which means:
DATA2 is 0x02, which is not enough for 8 bits, and the high byte of the byte is filled with 0:
3) Response:
10H - write multiple holding registers
1) Description: Write multiple holding registers, byte instruction operation, multiple can be written;
2) Send instruction:
The starting address of the holding register is 0x0034, and the data of 4 bytes of 2 registers is written;
3) Response: