Figure 26 - MODBUS function codes 5.3.1.4.1.1 - Using Function Code 3 Request: Size Range Table 8 - Function Code 1 0x03 Starting Address 2 0x0000 to 0xFFFF Number of Registers 2 1 to 125 Function code 3 request breakdown Response: Size Function Code 1 0x03 Byte Count 1 (no. of registers) x 2 Register Value (no. of registers) x 2 9 - Function code 3 response breakdown Function code 3 is used to read the contents of the holding registers. The registers can be read only in a continuous order. For example registers 1, 2, and 3 can be all be read at once; however, registers 1, 5, and 8 could not be read at once. In order to use the function, its function code (3) is specified in the first byte and then the starting address is specified in the next 2 bytes. The last 2 bytes will specify how many registers will be read (must be at least 1 to read a register). The response generated will include the function code (3), then will contain the total bytes in the next byte. The remainder of the message will include values in the registers by allocating 1 byte for the hi value and 1 byte for the low value (each register holds 16 bits) An example of this be requesting to read the registers 5-8. The following message would be sent: 0x0300040004. The total message size is 5 bytes. The first byte is the function code 0x03 (each hex value is 4bits or a half of a byte). The next two bytes 0x0004 specify the starting address (starting address 0 holds the first register (register 1)). The Last two bytes 0x0004 hold the number of registers to be read. The response from to this request will return the data stored in registers 5, 6, 7, and 8. Each register holds two 2 bytes of data.
Figure 26 - MODBUS function codes 5.3.1.4.1.1 - Using Function Code 3 Request: Size Range Function Code 1 0x03 Starting Address 2 0x0000 to 0xFFFF Number of Registers 2 1 to 125 Table 8 - Function code 3 request breakdown Response: Size Function Code 1 0x03 Byte Count 1 (no. of registers) x 2 Register Value (no. of registers) x 2 9 - Function code 3 response breakdown Function code 3 is used to read the contents of the holding registers. The registers can be read only in a continuous order. For example registers 1, 2, and 3 can be all be read at once; however, registers 1, 5, and 8 could not be read at once. In order to use the function, its function code (3) is specified in the first byte and then the starting address is specified in the next 2 bytes. The last 2 bytes will specify how many registers will be read (must be at least 1 to read a register). The response generated will include the function code (3), then will contain the total bytes in the next byte. The remainder of the message will include values in the registers by allocating 1 byte for the hi value and 1 byte for the low value (each register holds 16 bits) An example of this be requesting to read the registers 5-8. The following message would be sent: 0x0300040004. The total message size is 5 bytes. The first byte is the function code 0x03 (each hex value is 4bits or a half of a byte). The next two bytes 0x0004 specify the starting address (starting address 0 holds the first register (register 1)). The Last two bytes 0x0004 hold the number of registers to be read. The response from to this request will return the data stored in registers 5, 6, 7, and 8. Each register holds two 2 bytes of data.