8. Modbus protocol
8. 9. Read/Write Multiple Registers (23 = 16#17)
Request:
Slave no. | 17 | No. of 1st word to be | Number of words to be | No. of 1st word to be | Number of words to be | |||||||||
|
|
| read |
| read |
| written |
| written |
| ||||
|
| Hi |
| Lo | Hi |
| Lo | Hi |
| Lo | Hi |
| Lo | |
|
|
|
|
|
| |||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 byte | 1 byte |
| 2 bytes |
| 2 bytes |
| 2 bytes |
| 2 bytes |
|
Number of bytes to be | Value of 1st word to be | ||
written |
| written | |
| Hi |
| Lo |
|
| ||
|
|
|
|
1 byte |
| 2 bytes |
Value of last word to be written | CRC16 | ||||
Hi |
| Lo | Lo |
| Hi |
|
| ||||
|
|
|
|
|
|
| 2 bytes | 2 bytes |
Response:
Slave no. | 17 | Number of bytes | Value of 1st word read | ||
|
| read |
|
|
|
|
|
| Hi |
| Lo |
|
|
|
| ||
|
|
|
|
|
|
1 byte | 1 byte | 1 byte |
| 2 bytes |
Value of last word read | CRC16 | ||||
Hi |
| Lo | Lo |
| Hi |
|
| ||||
|
|
|
|
|
|
| 2 bytes | 2 bytes |
Example: This example combines the two examples for functions 3 and 16. With function 23, the line is less busy than with these two functions. However, the number of words that can be read and written is restricted.
•Write the values 20 (16#14) and 30 (16#1E) respectively to the 2 logic address words 9001 and 9002 on slave 2.
•Read the 4 logic address words 3102 to 3105 on the same slave (values read = 16#0028, 16#0258, 16#01F4, and 16#0000).
Request:
Slave no. |
| Request code | No. of 1st word to be | No. of words to be | No. of 1st word to be |
| No. of words to be |
|
| |||||||||||||||||||||||||
|
|
|
|
|
| read |
|
|
|
|
| read |
|
|
|
|
| written |
|
|
|
| written |
|
|
|
| |||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
| Hi |
| Lo | Hi |
|
|
|
| Lo | Hi |
|
|
| Lo |
| Hi |
|
|
| Lo |
|
|
| ||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
02 |
| 17 |
|
| 0C |
| 1E | 00 |
|
|
|
| 04 | 23 |
|
|
| 29 | 00 |
|
| 02 |
|
|
| |||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||
No. of bytes to be written |
| Value of 1st word to be written |
|
|
| Value of 2nd word to be written |
| CRC |
| CRC |
| |||||||||||||||||||||||
|
|
|
|
| Hi |
|
|
| Lo |
|
|
|
| Hi |
|
|
|
| Lo |
|
|
| Lo |
|
|
|
| Hi |
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
| 04 |
|
| 00 |
|
|
|
| 14 |
|
|
|
| 00 |
|
|
|
| 1E |
|
|
| D2 |
|
|
|
| F5 |
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Response: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||||||||||||||
|
|
|
|
|
|
|
|
| Value of 1st |
| Value of 2nd | Value of 3rd |
| Value of 4th |
|
| CRC | CRC |
| |||||||||||||||
Slave no. | Response code |
| No. of bytes |
| word read |
| word read | word read |
| word read |
|
|
|
|
|
|
|
| ||||||||||||||||
|
|
|
|
|
| read |
| Hi |
| Lo |
| Hi |
| Lo | Hi |
| Lo |
| Hi |
| Lo |
|
| Lo |
| Hi |
| |||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||||||||
02 | 17 |
|
| 08 |
| 00 |
| 28 |
| 02 |
| 58 | 01 |
|
| F4 |
| 00 |
| 00 |
| 12 |
| F0 |
| |||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31