Modbus Common Function Code protocol detailed 01h-read coil status
1) Description: Read slave coil register, bit operation, readable single or multiple;
2) Send command:
Assuming slave address bit 0x01, register start address 0x0023, register end resists 0x0038, a total of 21 coils are read. The agreement diagram is as follows:
3) Response:
Each bit of the returned data corresponds to the coil state, 1-on,0-off, such as;
In the table above, data1 represents the 0x0023-0x002a coil state, data1 the lowest bit represents the lowest address of the coil state, can be understood as the small-end mode;
The DATA2 represents the coil state of the address 0x002b-0x0033, as shown in the following table:
The DATA3 represents the coil state of the address 0x0034-0x0038, not enough 8 bits, the byte high is filled with 0, as in the following table:
02h-Read discrete input state
1): Read discrete input register, bit operation, readable single or multiple, protocol similar function code 0X01 protocol, here Province;
03h-Read hold Register
1) Description: Read hold register, byte instruction operation, readable single or multiple;
2) Send command:
Slave address 0x01, hold register start address 0x0032, read 2 hold Register
3) Response:
Data storage Order
04h-Read Input Register
1) Description: Read input register, byte instruction operation, readable single or multiple;
2) Send command: with 03H;
3) Response: with 03H;
05h-Write a single coil
1) Description: Write a single coil, bit operation, can only write one, write 0xff00 indicates set coil status on, write 0x0000 to set the coil status is off
2) Send command:
Set the 0x0032 coil to on;
3) Response:
with the sending instruction;
06h-Write a single hold register
1) Description: Write a single hold register, byte instruction operation, can only write one;
2) Send command:
Write 0x0032 hold register as 0x1232;
3) Response: with the sending instructions;
0fh-Write multiple coils
1) Description: Write multiple coil registers. If the data area has a bit value of "1" indicates that the requested corresponding coil status is on, if a bit value is "0", then the status is off.
2) Send command:
The coil address is 0x04a5, write 12 coils,
The DATA1 is 0x0c, indicating:
DATA2 is 0x02, not enough 8 bits, byte high fill 0:
3) Response:
10h-Write multiple hold Registers
1) Description: Write multiple hold register, byte instruction operation, can write multiple;
2) Send command:
Hold register start address is 0x0034, write 2 registers 4 bytes of data;
3) Response:
Modbus Common Function Code Protocol detailed