Skip to content

Commit b7ee556

Browse files
committed
Document required buffer size of modbus_receive
The documentation for modbus_receive() did not mention the required buffer size for the req parameter. Add a "Buffer size" section recommending MODBUS_MAX_ADU_LENGTH, consistent with the existing documentation of modbus_receive_confirmation().
1 parent 031293d commit b7ee556

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

docs/modbus_receive.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ length if successful. The returned request length can be zero if the indication
2626
request is ignored (eg. a query for another slave in RTU mode). Otherwise it
2727
shall return -1 and set errno.
2828
29+
## Buffer size
30+
31+
The maximum size of the request depends on the used backend, in RTU the `req`
32+
array must be `MODBUS_RTU_MAX_ADU_LENGTH` bytes and in TCP it must be
33+
`MODBUS_TCP_MAX_ADU_LENGTH` bytes. If you want to write code compatible with
34+
both, you can use the constant `MODBUS_MAX_ADU_LENGTH` (maximum value of all
35+
libmodbus backends). Take care to allocate enough memory to store requests to
36+
avoid crashes of your server.
37+
38+
## Example
39+
40+
```c
41+
uint8_t req[MODBUS_MAX_ADU_LENGTH];
42+
rc = modbus_receive(ctx, req);
43+
```
44+
2945
## See also
3046

3147
- [modbus_set_socket](modbus_set_socket.md)

0 commit comments

Comments
 (0)