| 1 | # modbus_receive_confirmation |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | modbus_receive_confirmation - receive a confirmation request |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | ```c |
| 10 | int modbus_receive_confirmation(modbus_t *ctx, uint8_t *rsp); |
| 11 | ``` |
| 12 | |
| 13 | ## Description |
| 14 | |
| 15 | The *modbus_receive_confirmation()* function shall receive a request via the |
| 16 | socket of the context `ctx`. This function must be used for debugging purposes |
| 17 | because the received response isn't checked against the initial request. This |
| 18 | function can be used to receive request not handled by the library. |
| 19 | |
| 20 | The maximum size of the response depends on the used backend, in RTU the `rsp` |
| 21 | array must be `MODBUS_RTU_MAX_ADU_LENGTH` bytes and in TCP it must be |
| 22 | `MODBUS_TCP_MAX_ADU_LENGTH` bytes. If you want to write code compatible with |
| 23 | both, you can use the constant `MODBUS_MAX_ADU_LENGTH` (maximum value of all |
| 24 | libmodbus backends). Take care to allocate enough memory to store responses to |
| 25 | avoid crashes of your server. |
| 26 | |
| 27 | ## Return value |
| 28 | |
| 29 | The function shall store the confirmation request in `rsp` and return the |
| 30 | response length if successful. The returned request length can be zero if the |
| 31 | indication request is ignored (eg. a query for another slave in RTU |
| 32 | mode). Otherwise it shall return -1 and set errno. |
| 33 | |
| 34 | ## Example |
| 35 | |
| 36 | ```c |
| 37 | uint8_t rsp[MODBUS_MAX_ADU_LENGTH]; |
| 38 | rc = modbus_receive_confirmation(ctx, rsp); |
| 39 | ``` |
| 40 | |
| 41 | ## See also |
| 42 | |
| 43 | - [modbus_send_raw_request](modbus_send_raw_request.md) |