| 1 | # modbus_close |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | modbus_close - close a Modbus connection |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | ```c |
| 10 | void modbus_close(modbus_t *ctx); |
| 11 | ``` |
| 12 | |
| 13 | ## Description |
| 14 | |
| 15 | The *modbus_close()* function shall close the connection established with the |
| 16 | backend set in the context. |
| 17 | |
| 18 | ## Return value |
| 19 | |
| 20 | There is no return value. |
| 21 | |
| 22 | ## Example |
| 23 | |
| 24 | ```c |
| 25 | modbus_t *ctx; |
| 26 | |
| 27 | ctx = modbus_new_tcp("127.0.0.1", 502); |
| 28 | if (modbus_connect(ctx) == -1) { |
| 29 | fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno)); |
| 30 | modbus_free(ctx); |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | modbus_close(ctx); |
| 35 | modbus_free(ctx); |
| 36 | ``` |
| 37 | |
| 38 | ## See also |
| 39 | |
| 40 | - [modbus_connect](modbus_connect.md) |