| 1 | # modbus_reply |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | modbus_reply - send a response to the received request |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | ```c |
| 10 | int modbus_reply(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_mapping); |
| 11 | ``` |
| 12 | |
| 13 | ## Description |
| 14 | |
| 15 | The *modbus_reply()* function shall send a response to received request. The |
| 16 | request `req` given in argument is analyzed, a response is then built and sent |
| 17 | by using the information of the modbus context `ctx`. |
| 18 | |
| 19 | If the request indicates to read or write a value the operation will done in the |
| 20 | modbus mapping `mb_mapping` according to the type of the manipulated data. |
| 21 | |
| 22 | If an error occurs, an exception response will be sent. |
| 23 | |
| 24 | This function is designed for Modbus servers. |
| 25 | |
| 26 | ## Return value |
| 27 | |
| 28 | The function shall return the length of the response sent if |
| 29 | successful. Otherwise it shall return -1 and set errno. |
| 30 | |
| 31 | ## Errors |
| 32 | |
| 33 | - *EMBMDATA*, sending has failed |
| 34 | |
| 35 | See also the errors returned by the syscall used to send the response (eg. send or write). |
| 36 | |
| 37 | ## See also |
| 38 | |
| 39 | - [modbus_reply_exception](modbus_reply_exception.md) |