Debian Codegraph @

docs/modbus_receive.md

raw symbols SCIP
1 # modbus_receive
2
3 ## Name
4
5 modbus_receive - receive an indication request
6
7 ## Synopsis
8
9 ```c
10 int modbus_receive(modbus_t *ctx, uint8_t *req);
11 ```
12
13 ## Description
14
15 The *modbus_receive()* function shall receive an indication request from the
16 socket of the context `ctx`. This function is used by a Modbus slave/server to
17 receive and analyze indication request sent by the masters/clients.
18
19 If you need to use another socket or file descriptor than the one defined in the
20 context `ctx`, see the function [modbus_set_socket](modbus_set_socket.md).
21
22 ## Return value
23
24 The function shall store the indication request in `req` and return the request
25 length if successful. The returned request length can be zero if the indication
26 request is ignored (eg. a query for another slave in RTU mode). Otherwise it
27 shall return -1 and set errno.
28
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
45 ## See also
46
47 - [modbus_set_socket](modbus_set_socket.md)
48 - [modbus_reply](modbus_reply.md)