rodbus (C API) 1.3.1
Loading...
Searching...
No Matches
rodbus.h
Go to the documentation of this file.
1// This library is provided under the terms of a non-commercial license.
2//
3// Please refer to the source repository for details:
4//
5// https://github.com/stepfunc/rodbus/blob/master/LICENSE.txt
6//
7// Please contact Step Function I/O if you are interested in commercial license:
8//
9// info@stepfunc.io
10#pragma once
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#define RODBUS_VERSION_MAJOR 1
17#define RODBUS_VERSION_MINOR 3
18#define RODBUS_VERSION_PATCH 1
19#define RODBUS_VERSION_STRING "1.3.1"
20
21#include <stdbool.h>
22#include <stdint.h>
23
43
46{
88
93{
94 switch (value)
95 {
96 case RODBUS_PARAM_ERROR_OK: return "ok";
97 case RODBUS_PARAM_ERROR_NO_SUPPORT: return "no_support";
98 case RODBUS_PARAM_ERROR_NULL_PARAMETER: return "null_parameter";
99 case RODBUS_PARAM_ERROR_LOGGING_ALREADY_CONFIGURED: return "logging_already_configured";
100 case RODBUS_PARAM_ERROR_RUNTIME_CREATION_FAILURE: return "runtime_creation_failure";
101 case RODBUS_PARAM_ERROR_RUNTIME_DESTROYED: return "runtime_destroyed";
102 case RODBUS_PARAM_ERROR_RUNTIME_CANNOT_BLOCK_WITHIN_ASYNC: return "runtime_cannot_block_within_async";
103 case RODBUS_PARAM_ERROR_INVALID_IP_ADDRESS: return "invalid_ip_address";
104 case RODBUS_PARAM_ERROR_INVALID_RANGE: return "invalid_range";
105 case RODBUS_PARAM_ERROR_INVALID_REQUEST: return "invalid_request";
106 case RODBUS_PARAM_ERROR_INVALID_INDEX: return "invalid_index";
107 case RODBUS_PARAM_ERROR_SERVER_BIND_ERROR: return "server_bind_error";
108 case RODBUS_PARAM_ERROR_INVALID_UNIT_ID: return "invalid_unit_id";
109 case RODBUS_PARAM_ERROR_INVALID_PEER_CERTIFICATE: return "invalid_peer_certificate";
110 case RODBUS_PARAM_ERROR_INVALID_LOCAL_CERTIFICATE: return "invalid_local_certificate";
111 case RODBUS_PARAM_ERROR_INVALID_PRIVATE_KEY: return "invalid_private_key";
112 case RODBUS_PARAM_ERROR_INVALID_DNS_NAME: return "invalid_dns_name";
113 case RODBUS_PARAM_ERROR_BAD_TLS_CONFIG: return "bad_tls_config";
114 case RODBUS_PARAM_ERROR_SHUTDOWN: return "shutdown";
115 case RODBUS_PARAM_ERROR_INVALID_UTF8: return "invalid_utf8";
116 default: return "unknown param_error value";
117 }
118}
119
120
123{
127
132{
133 switch (value)
134 {
135 case RODBUS_NOTHING_NOTHING: return "nothing";
136 default: return "unknown nothing value";
137 }
138}
139
144{
154
159{
160 switch (value)
161 {
162 case RODBUS_APP_DECODE_LEVEL_NOTHING: return "nothing";
163 case RODBUS_APP_DECODE_LEVEL_FUNCTION_CODE: return "function_code";
164 case RODBUS_APP_DECODE_LEVEL_DATA_HEADERS: return "data_headers";
165 case RODBUS_APP_DECODE_LEVEL_DATA_VALUES: return "data_values";
166 default: return "unknown app_decode_level value";
167 }
168}
169
176{
184
189{
190 switch (value)
191 {
192 case RODBUS_FRAME_DECODE_LEVEL_NOTHING: return "nothing";
193 case RODBUS_FRAME_DECODE_LEVEL_HEADER: return "header";
194 case RODBUS_FRAME_DECODE_LEVEL_PAYLOAD: return "payload";
195 default: return "unknown frame_decode_level value";
196 }
197}
198
201{
209
214{
215 switch (value)
216 {
217 case RODBUS_PHYS_DECODE_LEVEL_NOTHING: return "nothing";
218 case RODBUS_PHYS_DECODE_LEVEL_LENGTH: return "length";
219 case RODBUS_PHYS_DECODE_LEVEL_DATA: return "data";
220 default: return "unknown phys_decode_level value";
221 }
222}
223
225
228{
236
243{
244 rodbus_decode_level_t _return_value = {
245 app,
246 frame,
247 physical
248 };
249 return _return_value;
250}
251
261{
262 rodbus_decode_level_t _return_value = {
266 };
267 return _return_value;
268}
269
270
272
274typedef struct rodbus_bit_value_t
275{
277 uint16_t index;
279 bool value;
281
286static rodbus_bit_value_t rodbus_bit_value_init(uint16_t index, bool value)
287{
288 rodbus_bit_value_t _return_value = {
289 index,
290 value
291 };
292 return _return_value;
293}
294
295
297
300{
302 uint16_t index;
304 uint16_t value;
306
311static rodbus_register_value_t rodbus_register_value_init(uint16_t index, uint16_t value)
312{
313 rodbus_register_value_t _return_value = {
314 index,
315 value
316 };
317 return _return_value;
318}
319
320
323
325
328{
334
342{
343 rodbus_runtime_config_t _return_value = {
344 0
345 };
346 return _return_value;
347}
348
349
357
363
372
373
378{
420
425{
426 switch (value)
427 {
428 case RODBUS_REQUEST_ERROR_OK: return "ok";
429 case RODBUS_REQUEST_ERROR_SHUTDOWN: return "shutdown";
430 case RODBUS_REQUEST_ERROR_NO_CONNECTION: return "no_connection";
431 case RODBUS_REQUEST_ERROR_RESPONSE_TIMEOUT: return "response_timeout";
432 case RODBUS_REQUEST_ERROR_BAD_REQUEST: return "bad_request";
433 case RODBUS_REQUEST_ERROR_BAD_RESPONSE: return "bad_response";
434 case RODBUS_REQUEST_ERROR_IO_ERROR: return "io_error";
435 case RODBUS_REQUEST_ERROR_BAD_FRAMING: return "bad_framing";
436 case RODBUS_REQUEST_ERROR_INTERNAL_ERROR: return "internal_error";
437 case RODBUS_REQUEST_ERROR_BAD_ARGUMENT: return "bad_argument";
438 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_FUNCTION: return "modbus_exception_illegal_function";
439 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS: return "modbus_exception_illegal_data_address";
440 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE: return "modbus_exception_illegal_data_value";
441 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE: return "modbus_exception_server_device_failure";
442 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ACKNOWLEDGE: return "modbus_exception_acknowledge";
443 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY: return "modbus_exception_server_device_busy";
444 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR: return "modbus_exception_memory_parity_error";
445 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE: return "modbus_exception_gateway_path_unavailable";
446 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: return "modbus_exception_gateway_target_device_failed_to_respond";
447 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_UNKNOWN: return "modbus_exception_unknown";
448 default: return "unknown request_error value";
449 }
450}
451
452
454
457{
459 uint16_t start;
461 uint16_t count;
463
468static rodbus_address_range_t rodbus_address_range_init(uint16_t start, uint16_t count)
469{
470 rodbus_address_range_t _return_value = {
471 start,
472 count
473 };
474 return _return_value;
475}
476
477
479
482{
484 uint8_t unit_id;
487 uint64_t timeout;
489
494static rodbus_request_param_t rodbus_request_param_init(uint8_t unit_id, uint64_t timeout)
495{
496 rodbus_request_param_t _return_value = {
497 unit_id,
498 timeout
499 };
500 return _return_value;
501}
502
503
506
511
512
515
520
521
524{
546
551{
552 switch (value)
553 {
554 case RODBUS_MODBUS_EXCEPTION_ILLEGAL_FUNCTION: return "illegal_function";
555 case RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS: return "illegal_data_address";
556 case RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE: return "illegal_data_value";
557 case RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE: return "server_device_failure";
558 case RODBUS_MODBUS_EXCEPTION_ACKNOWLEDGE: return "acknowledge";
559 case RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY: return "server_device_busy";
560 case RODBUS_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR: return "memory_parity_error";
561 case RODBUS_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE: return "gateway_path_unavailable";
562 case RODBUS_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: return "gateway_target_device_failed_to_respond";
563 case RODBUS_MODBUS_EXCEPTION_UNKNOWN: return "unknown";
564 default: return "unknown modbus_exception value";
565 }
566}
567
570{
580
585{
586 switch (value)
587 {
588 case RODBUS_DATA_BITS_FIVE: return "five";
589 case RODBUS_DATA_BITS_SIX: return "six";
590 case RODBUS_DATA_BITS_SEVEN: return "seven";
591 case RODBUS_DATA_BITS_EIGHT: return "eight";
592 default: return "unknown data_bits value";
593 }
594}
595
598{
606
611{
612 switch (value)
613 {
614 case RODBUS_FLOW_CONTROL_NONE: return "none";
615 case RODBUS_FLOW_CONTROL_SOFTWARE: return "software";
616 case RODBUS_FLOW_CONTROL_HARDWARE: return "hardware";
617 default: return "unknown flow_control value";
618 }
619}
620
622typedef enum rodbus_parity_t
623{
631
636{
637 switch (value)
638 {
639 case RODBUS_PARITY_NONE: return "none";
640 case RODBUS_PARITY_ODD: return "odd";
641 case RODBUS_PARITY_EVEN: return "even";
642 default: return "unknown parity value";
643 }
644}
645
648{
654
659{
660 switch (value)
661 {
662 case RODBUS_STOP_BITS_ONE: return "one";
663 case RODBUS_STOP_BITS_TWO: return "two";
664 default: return "unknown stop_bits value";
665 }
666}
667
669
672{
674 uint32_t baud_rate;
684
696{
697 rodbus_serial_port_settings_t _return_value = {
698 9600,
703 };
704 return _return_value;
705}
706
707
710{
716
721{
722 switch (value)
723 {
724 case RODBUS_MIN_TLS_VERSION_V12: return "v12";
725 case RODBUS_MIN_TLS_VERSION_V13: return "v13";
726 default: return "unknown min_tls_version value";
727 }
728}
729
734{
746
751{
752 switch (value)
753 {
754 case RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED: return "authority_based";
755 case RODBUS_CERTIFICATE_MODE_SELF_SIGNED: return "self_signed";
756 default: return "unknown certificate_mode value";
757 }
758}
759
761
766{
769 uint64_t min_delay;
772 uint64_t max_delay;
774
783{
784 rodbus_retry_strategy_t _return_value = {
785 1000,
786 10000
787 };
788 return _return_value;
789}
790
791
796{
808
813{
814 switch (value)
815 {
816 case RODBUS_LOG_LEVEL_ERROR: return "error";
817 case RODBUS_LOG_LEVEL_WARN: return "warn";
818 case RODBUS_LOG_LEVEL_INFO: return "info";
819 case RODBUS_LOG_LEVEL_DEBUG: return "debug";
820 case RODBUS_LOG_LEVEL_TRACE: return "trace";
821 default: return "unknown log_level value";
822 }
823}
824
826
829{
835
840{
841 switch (value)
842 {
843 case RODBUS_LOG_OUTPUT_FORMAT_TEXT: return "text";
844 case RODBUS_LOG_OUTPUT_FORMAT_JSON: return "json";
845 default: return "unknown log_output_format value";
846 }
847}
848
851{
859
864{
865 switch (value)
866 {
867 case RODBUS_TIME_FORMAT_NONE: return "none";
868 case RODBUS_TIME_FORMAT_RFC_3339: return "rfc_3339";
869 case RODBUS_TIME_FORMAT_SYSTEM: return "system";
870 default: return "unknown time_format value";
871 }
872}
873
876{
888
900{
901 rodbus_logging_config_t _return_value = {
905 true,
906 false
907 };
908 return _return_value;
909}
910
911
913typedef struct rodbus_logger_t
914{
915
920 void (*on_message)(rodbus_log_level_t, const char*, void*);
923 void (*on_destroy)(void* arg);
925 void* ctx;
927
937
938
943
945
948{
950 const char* dns_name;
952 const char* peer_cert_path;
954 const char* local_cert_path;
956 const char* private_key_path;
962 const char* password;
970
984static rodbus_tls_client_config_t rodbus_tls_client_config_init(const char* dns_name, const char* peer_cert_path, const char* local_cert_path, const char* private_key_path, const char* password)
985{
986 rodbus_tls_client_config_t _return_value = {
987 dns_name,
988 peer_cert_path,
989 local_cert_path,
990 private_key_path,
991 password,
994 false
995 };
996 return _return_value;
997}
998
999
1004{
1018
1023{
1024 switch (value)
1025 {
1026 case RODBUS_CLIENT_STATE_DISABLED: return "disabled";
1027 case RODBUS_CLIENT_STATE_CONNECTING: return "connecting";
1028 case RODBUS_CLIENT_STATE_CONNECTED: return "connected";
1029 case RODBUS_CLIENT_STATE_WAIT_AFTER_FAILED_CONNECT: return "wait_after_failed_connect";
1030 case RODBUS_CLIENT_STATE_WAIT_AFTER_DISCONNECT: return "wait_after_disconnect";
1031 case RODBUS_CLIENT_STATE_SHUTDOWN: return "shutdown";
1032 default: return "unknown client_state value";
1033 }
1034}
1035
1038{
1039
1046 void (*on_destroy)(void* arg);
1048 void* ctx;
1050
1055{
1065
1070{
1071 switch (value)
1072 {
1073 case RODBUS_PORT_STATE_DISABLED: return "disabled";
1074 case RODBUS_PORT_STATE_WAIT: return "wait";
1075 case RODBUS_PORT_STATE_OPEN: return "open";
1076 case RODBUS_PORT_STATE_SHUTDOWN: return "shutdown";
1077 default: return "unknown port_state value";
1078 }
1079}
1080
1083{
1084
1091 void (*on_destroy)(void* arg);
1093 void* ctx;
1095
1106rodbus_param_error_t rodbus_client_channel_create_tcp(rodbus_runtime_t* runtime, const char* host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t** out);
1107
1119
1131rodbus_param_error_t rodbus_client_channel_create_tls(rodbus_runtime_t* runtime, const char* host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_tls_client_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t** out);
1132
1136
1139{
1140
1145
1152 void (*on_destroy)(void* arg);
1154 void* ctx;
1156
1159{
1160
1165
1172 void (*on_destroy)(void* arg);
1174 void* ctx;
1176
1179{
1180
1185
1192 void (*on_destroy)(void* arg);
1194 void* ctx;
1196
1204
1212
1220
1228
1236
1244
1247
1252
1256
1260void rodbus_bit_list_add(rodbus_bit_list_t* instance, bool value);
1261
1262
1271
1274
1279
1283
1287void rodbus_register_list_add(rodbus_register_list_t* instance, uint16_t value);
1288
1289
1298
1304
1311
1318
1319
1322
1328bool rodbus_database_add_coil(rodbus_database_t* instance, uint16_t index, bool value);
1329
1335bool rodbus_database_add_discrete_input(rodbus_database_t* instance, uint16_t index, bool value);
1336
1342bool rodbus_database_add_holding_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1343
1349bool rodbus_database_add_input_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1350
1357
1364
1371
1378
1384bool rodbus_database_update_coil(rodbus_database_t* instance, uint16_t index, bool value);
1385
1391bool rodbus_database_update_discrete_input(rodbus_database_t* instance, uint16_t index, bool value);
1392
1398bool rodbus_database_update_holding_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1399
1405bool rodbus_database_update_input_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1406
1411bool rodbus_database_delete_coil(rodbus_database_t* instance, uint16_t index);
1412
1418
1424
1430
1431
1434{
1435
1439 void (*callback)(rodbus_database_t*, void*);
1442 void (*on_destroy)(void* arg);
1444 void* ctx;
1446
1448
1455{
1463
1473{
1474 rodbus_write_result_t _return_value = {
1475 true,
1477 0
1478 };
1479 return _return_value;
1480}
1481
1491{
1492 rodbus_write_result_t _return_value = {
1493 false,
1494 exception,
1495 0
1496 };
1497 return _return_value;
1498}
1499
1509{
1510 rodbus_write_result_t _return_value = {
1511 false,
1513 raw_exception
1514 };
1515 return _return_value;
1516}
1517
1518
1521{
1522
1530
1538
1546
1556 void (*on_destroy)(void* arg);
1558 void* ctx;
1560
1563
1567
1571
1579
1580
1582
1585{
1587 const char* peer_cert_path;
1589 const char* local_cert_path;
1591 const char* private_key_path;
1597 const char* password;
1603
1615static rodbus_tls_server_config_t rodbus_tls_server_config_init(const char* peer_cert_path, const char* local_cert_path, const char* private_key_path, const char* password)
1616{
1617 rodbus_tls_server_config_t _return_value = {
1618 peer_cert_path,
1619 local_cert_path,
1620 private_key_path,
1621 password,
1624 };
1625 return _return_value;
1626}
1627
1628
1631{
1637
1642{
1643 switch (value)
1644 {
1645 case RODBUS_AUTHORIZATION_ALLOW: return "allow";
1646 case RODBUS_AUTHORIZATION_DENY: return "deny";
1647 default: return "unknown authorization value";
1648 }
1649}
1650
1653{
1654
1662
1670
1678
1686
1693 rodbus_authorization_t (*write_single_coil)(uint8_t, uint16_t, const char*, void*);
1694
1701 rodbus_authorization_t (*write_single_register)(uint8_t, uint16_t, const char*, void*);
1702
1710
1720 void (*on_destroy)(void* arg);
1722 void* ctx;
1724
1727
1731
1741
1749
1753
1754
1757
1772rodbus_param_error_t rodbus_server_create_tcp(rodbus_runtime_t* runtime, const char* address, uint16_t port, rodbus_address_filter_t* filter, uint16_t max_sessions, rodbus_device_map_t* endpoints, rodbus_decode_level_t decode_level, rodbus_server_t** out);
1773
1784
1803rodbus_param_error_t rodbus_server_create_tls_with_authz(rodbus_runtime_t* runtime, const char* address, uint16_t port, rodbus_address_filter_t* filter, uint16_t max_sessions, rodbus_device_map_t* endpoints, rodbus_tls_server_config_t tls_config, rodbus_authorization_handler_t authorization_handler, rodbus_decode_level_t decode_level, rodbus_server_t** out);
1804
1820rodbus_param_error_t rodbus_server_create_tls(rodbus_runtime_t* runtime, const char* address, uint16_t port, rodbus_address_filter_t* filter, uint16_t max_sessions, rodbus_device_map_t* endpoints, rodbus_tls_server_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_server_t** out);
1821
1825
1832
1838
1839
1842const char* rodbus_version();
1843
1844#ifdef __cplusplus
1845}
1846#endif
static rodbus_bit_value_t rodbus_bit_value_init(uint16_t index, bool value)
Fully construct rodbus_bit_value_t specifying the value of each field.
Definition: rodbus.h:286
static const char * rodbus_request_error_to_string(rodbus_request_error_t value)
Converts the enum to a string.
Definition: rodbus.h:424
rodbus_param_error_t rodbus_server_create_tls(rodbus_runtime_t *runtime, const char *address, uint16_t port, rodbus_address_filter_t *filter, uint16_t max_sessions, rodbus_device_map_t *endpoints, rodbus_tls_server_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Create a TLS server that does NOT require the client role extension.
rodbus_port_state_t
State of the serial port.
Definition: rodbus.h:1055
@ RODBUS_PORT_STATE_OPEN
Port is open.
Definition: rodbus.h:1061
@ RODBUS_PORT_STATE_DISABLED
Disabled until enabled.
Definition: rodbus.h:1057
@ RODBUS_PORT_STATE_WAIT
Waiting to perform an open retry.
Definition: rodbus.h:1059
@ RODBUS_PORT_STATE_SHUTDOWN
Task has been shut down.
Definition: rodbus.h:1063
rodbus_register_list_t * rodbus_register_list_create(uint32_t reserve_size)
Creates an instance of the collection.
rodbus_log_output_format_t
Describes how each log event is formatted.
Definition: rodbus.h:829
@ RODBUS_LOG_OUTPUT_FORMAT_TEXT
A simple text-based format.
Definition: rodbus.h:831
@ RODBUS_LOG_OUTPUT_FORMAT_JSON
Output formatted as JSON.
Definition: rodbus.h:833
void rodbus_register_list_add(rodbus_register_list_t *instance, uint16_t value)
Add a value to the collection.
rodbus_param_error_t rodbus_client_channel_write_multiple_registers(rodbus_client_channel_t *instance, rodbus_request_param_t param, uint16_t start, rodbus_register_list_t *items, rodbus_write_callback_t callback)
Write multiple registers.
void rodbus_runtime_destroy(rodbus_runtime_t *instance)
Destroy a runtime.
bool rodbus_database_update_holding_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Update the current value of a holding register in the database.
static const char * rodbus_certificate_mode_to_string(rodbus_certificate_mode_t value)
Converts the enum to a string.
Definition: rodbus.h:750
rodbus_min_tls_version_t
Minimum TLS version to allow.
Definition: rodbus.h:710
@ RODBUS_MIN_TLS_VERSION_V13
TLS 1.3.
Definition: rodbus.h:714
@ RODBUS_MIN_TLS_VERSION_V12
TLS 1.2.
Definition: rodbus.h:712
static rodbus_address_range_t rodbus_address_range_init(uint16_t start, uint16_t count)
Fully construct rodbus_address_range_t specifying the value of each field.
Definition: rodbus.h:468
rodbus_param_error_t rodbus_client_channel_read_coils(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_bit_read_callback_t callback)
Start an asynchronous request to read coils.
rodbus_param_error_t rodbus_configure_logging(rodbus_logging_config_t config, rodbus_logger_t logger)
Set the callback that will receive all the log messages.
static const char * rodbus_modbus_exception_to_string(rodbus_modbus_exception_t value)
Converts the enum to a string.
Definition: rodbus.h:550
static rodbus_request_param_t rodbus_request_param_init(uint8_t unit_id, uint64_t timeout)
Fully construct rodbus_request_param_t specifying the value of each field.
Definition: rodbus.h:494
rodbus_param_error_t rodbus_client_channel_write_single_register(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_register_value_t value, rodbus_write_callback_t callback)
Write a single register.
struct rodbus_runtime_t rodbus_runtime_t
Handle to the underlying runtime.
Definition: rodbus.h:322
void rodbus_bit_list_add(rodbus_bit_list_t *instance, bool value)
Add a value to the collection.
void rodbus_runtime_set_shutdown_timeout(rodbus_runtime_t *instance, uint64_t timeout)
By default, when the runtime shuts down, it does so without a timeout and waits indefinitely for all ...
static const char * rodbus_data_bits_to_string(rodbus_data_bits_t value)
Converts the enum to a string.
Definition: rodbus.h:584
rodbus_flow_control_t
Flow control modes.
Definition: rodbus.h:598
@ RODBUS_FLOW_CONTROL_SOFTWARE
Flow control using XON/XOFF bytes.
Definition: rodbus.h:602
@ RODBUS_FLOW_CONTROL_HARDWARE
Flow control using RTS/CTS signals.
Definition: rodbus.h:604
@ RODBUS_FLOW_CONTROL_NONE
No flow control.
Definition: rodbus.h:600
static rodbus_write_result_t rodbus_write_result_exception_init(rodbus_modbus_exception_t exception)
Initialize a rodbus_write_result_t to indicate a standard Modbus exception.
Definition: rodbus.h:1490
rodbus_param_error_t rodbus_database_get_coil(rodbus_database_t *instance, uint16_t index, bool *out)
Get the current coil value of the database.
void rodbus_bit_list_destroy(rodbus_bit_list_t *instance)
Destroys an instance of the collection.
rodbus_param_error_t rodbus_database_get_input_register(rodbus_database_t *instance, uint16_t index, uint16_t *out)
Get the current input register value of the database.
rodbus_bit_list_t * rodbus_bit_list_create(uint32_t reserve_size)
Creates an instance of the collection.
rodbus_frame_decode_level_t
Controls how the transmitted and received frames are decoded at the INFO log level.
Definition: rodbus.h:176
@ RODBUS_FRAME_DECODE_LEVEL_PAYLOAD
Decode the header and the raw payload as hexadecimal.
Definition: rodbus.h:182
@ RODBUS_FRAME_DECODE_LEVEL_NOTHING
Log nothing.
Definition: rodbus.h:178
@ RODBUS_FRAME_DECODE_LEVEL_HEADER
Decode the header.
Definition: rodbus.h:180
bool rodbus_database_add_coil(rodbus_database_t *instance, uint16_t index, bool value)
Add a new coil to the database.
struct rodbus_server_t rodbus_server_t
Handle to the running server. The server runs on a background task until this class is destroyed.
Definition: rodbus.h:1756
rodbus_param_error_t rodbus_client_channel_write_multiple_coils(rodbus_client_channel_t *instance, rodbus_request_param_t param, uint16_t start, rodbus_bit_list_t *items, rodbus_write_callback_t callback)
Write multiple coils.
static const char * rodbus_parity_to_string(rodbus_parity_t value)
Converts the enum to a string.
Definition: rodbus.h:635
static const char * rodbus_flow_control_to_string(rodbus_flow_control_t value)
Converts the enum to a string.
Definition: rodbus.h:610
static rodbus_decode_level_t rodbus_decode_level_build(rodbus_app_decode_level_t app, rodbus_frame_decode_level_t frame, rodbus_phys_decode_level_t physical)
Fully construct rodbus_decode_level_t specifying the value of each field.
Definition: rodbus.h:242
bool rodbus_database_delete_coil(rodbus_database_t *instance, uint16_t index)
Remove a coil address from the database.
static const char * rodbus_frame_decode_level_to_string(rodbus_frame_decode_level_t value)
Converts the enum to a string.
Definition: rodbus.h:188
bool rodbus_database_add_holding_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Add a new holding register to the database.
rodbus_request_error_t
Error information returned from asynchronous functions calls.
Definition: rodbus.h:378
@ RODBUS_REQUEST_ERROR_NO_CONNECTION
No connection could be made to the server.
Definition: rodbus.h:384
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_UNKNOWN
The status code is not defined in the Modbus specification, refer to the raw exception code to see wh...
Definition: rodbus.h:418
@ RODBUS_REQUEST_ERROR_BAD_REQUEST
The request was invalid.
Definition: rodbus.h:388
@ RODBUS_REQUEST_ERROR_OK
Success, i.e. no error occurred.
Definition: rodbus.h:380
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE
An unrecoverable error occurred while the server was attempting to perform the requested action.
Definition: rodbus.h:406
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR
Specialized use in conjunction with function codes 20 and 21 and reference type 6,...
Definition: rodbus.h:412
@ RODBUS_REQUEST_ERROR_SHUTDOWN
The channel was shutdown before the operation could complete.
Definition: rodbus.h:382
@ RODBUS_REQUEST_ERROR_RESPONSE_TIMEOUT
No valid response was received before the timeout.
Definition: rodbus.h:386
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY
Specialized use in conjunction with programming commands. The server is engaged in processing a long-...
Definition: rodbus.h:410
@ RODBUS_REQUEST_ERROR_BAD_ARGUMENT
An invalid argument was supplied and the request could not be performed.
Definition: rodbus.h:398
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_FUNCTION
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:400
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ACKNOWLEDGE
Specialized use in conjunction with programming commands. The server has accepted the request and is ...
Definition: rodbus.h:408
@ RODBUS_REQUEST_ERROR_BAD_RESPONSE
The response from the server was received but was improperly formatted.
Definition: rodbus.h:390
@ RODBUS_REQUEST_ERROR_INTERNAL_ERROR
An unspecified internal error occurred while performing the request.
Definition: rodbus.h:396
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
Specialized use in conjunction with gateways, indicates that no response was obtained from the target...
Definition: rodbus.h:416
@ RODBUS_REQUEST_ERROR_IO_ERROR
An I/O error occurred on the underlying stream while performing the request.
Definition: rodbus.h:392
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:402
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE
Specialized use in conjunction with gateways, indicates that the gateway was unable to allocate an in...
Definition: rodbus.h:414
@ RODBUS_REQUEST_ERROR_BAD_FRAMING
A framing error was detected while performing the request.
Definition: rodbus.h:394
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE
A value contained in the request is not an allowable value for server.
Definition: rodbus.h:404
struct rodbus_address_filter_t rodbus_address_filter_t
Filter used to restrict which IP addresses may communicate with a server.
Definition: rodbus.h:1726
static rodbus_tls_client_config_t rodbus_tls_client_config_init(const char *dns_name, const char *peer_cert_path, const char *local_cert_path, const char *private_key_path, const char *password)
Initialize a TLS client configuration.
Definition: rodbus.h:984
static rodbus_tls_server_config_t rodbus_tls_server_config_init(const char *peer_cert_path, const char *local_cert_path, const char *private_key_path, const char *password)
Initialize a TLS client configuration.
Definition: rodbus.h:1615
rodbus_param_error_t rodbus_client_channel_write_single_coil(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_bit_value_t value, rodbus_write_callback_t callback)
Write a single coil.
rodbus_param_error_t rodbus_server_create_rtu(rodbus_runtime_t *runtime, const char *path, rodbus_serial_port_settings_t serial_params, rodbus_retry_strategy_t retry, rodbus_device_map_t *endpoints, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Launch a RTU server.
bool rodbus_database_update_coil(rodbus_database_t *instance, uint16_t index, bool value)
Update the current value of a coil in the database.
bool rodbus_database_update_discrete_input(rodbus_database_t *instance, uint16_t index, bool value)
Update the current value of a discrete input in the database.
struct rodbus_client_channel_t rodbus_client_channel_t
Abstract representation of a client communication channel.
Definition: rodbus.h:942
rodbus_register_value_t * rodbus_register_value_iterator_next(rodbus_register_value_iterator_t *iter)
returns a pointer to the next value or NULL
bool rodbus_database_delete_holding_register(rodbus_database_t *instance, uint16_t index)
Remove a holding register address from the database.
rodbus_param_error_t rodbus_client_channel_create_tls(rodbus_runtime_t *runtime, const char *host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_tls_client_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t **out)
Create a new TLS channel instance.
static rodbus_serial_port_settings_t rodbus_serial_port_settings_init()
Initialize a serial port configuration.
Definition: rodbus.h:695
rodbus_param_error_t rodbus_client_channel_enable(rodbus_client_channel_t *instance)
Enable channel communications.
rodbus_param_error_t rodbus_server_update_database(rodbus_server_t *instance, uint8_t unit_id, rodbus_database_callback_t transaction)
Update the database associated with a particular unit id. If the unit id exists, lock the database an...
bool rodbus_database_delete_discrete_input(rodbus_database_t *instance, uint16_t index)
Remove a discrete input address from the database.
rodbus_param_error_t rodbus_client_channel_disable(rodbus_client_channel_t *instance)
Disable channel communications.
rodbus_param_error_t rodbus_client_channel_read_holding_registers(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_register_read_callback_t callback)
Start an asynchronous request to read holding registers.
void rodbus_client_channel_destroy(rodbus_client_channel_t *instance)
Shutdown a rodbus_client_channel_t and release all resources.
rodbus_param_error_t rodbus_server_create_tcp(rodbus_runtime_t *runtime, const char *address, uint16_t port, rodbus_address_filter_t *filter, uint16_t max_sessions, rodbus_device_map_t *endpoints, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Launch a TCP server.
static const char * rodbus_param_error_to_string(rodbus_param_error_t value)
Converts the enum to a string.
Definition: rodbus.h:92
rodbus_stop_bits_t
Number of stop bits.
Definition: rodbus.h:648
@ RODBUS_STOP_BITS_TWO
Two stop bits.
Definition: rodbus.h:652
@ RODBUS_STOP_BITS_ONE
One stop bit.
Definition: rodbus.h:650
static rodbus_write_result_t rodbus_write_result_success_init()
Initialize a rodbus_write_result_t to indicate a successful write operation.
Definition: rodbus.h:1472
static rodbus_register_value_t rodbus_register_value_init(uint16_t index, uint16_t value)
Fully construct rodbus_register_value_t specifying the value of each field.
Definition: rodbus.h:311
rodbus_parity_t
Parity checking modes.
Definition: rodbus.h:623
@ RODBUS_PARITY_ODD
Parity bit sets odd number of 1 bits.
Definition: rodbus.h:627
@ RODBUS_PARITY_NONE
No parity bit.
Definition: rodbus.h:625
@ RODBUS_PARITY_EVEN
Parity bit sets even number of 1 bits.
Definition: rodbus.h:629
rodbus_data_bits_t
Number of bits per character.
Definition: rodbus.h:570
@ RODBUS_DATA_BITS_FIVE
5 bits per character
Definition: rodbus.h:572
@ RODBUS_DATA_BITS_SEVEN
7 bits per character
Definition: rodbus.h:576
@ RODBUS_DATA_BITS_SIX
6 bits per character
Definition: rodbus.h:574
@ RODBUS_DATA_BITS_EIGHT
8 bits per character
Definition: rodbus.h:578
bool rodbus_database_delete_input_register(rodbus_database_t *instance, uint16_t index)
Remove a input register address from the database.
rodbus_bit_value_t * rodbus_bit_value_iterator_next(rodbus_bit_value_iterator_t *iter)
returns a pointer to the next value or NULL
void rodbus_server_destroy(rodbus_server_t *instance)
Shutdown and release all resources of a running server.
bool rodbus_database_add_discrete_input(rodbus_database_t *instance, uint16_t index, bool value)
Add a new discrete input to the database.
rodbus_param_error_t rodbus_client_channel_create_tcp(rodbus_runtime_t *runtime, const char *host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t **out)
Create a new TCP channel instance.
rodbus_param_error_t rodbus_client_channel_set_decode_level(rodbus_client_channel_t *instance, rodbus_decode_level_t level)
Set the decoding level for the channel.
static rodbus_decode_level_t rodbus_decode_level_nothing()
Initialize log levels to defaults which is to decode nothing.
Definition: rodbus.h:260
rodbus_param_error_t rodbus_address_filter_create(const char *address, rodbus_address_filter_t **out)
Create an address filter that matches one or more IP addresses. Ipv4 or IPv6 addresses are allowed.
rodbus_time_format_t
Describes if and how the time will be formatted in log messages.
Definition: rodbus.h:851
@ RODBUS_TIME_FORMAT_RFC_3339
Format the time using RFC 3339.
Definition: rodbus.h:855
@ RODBUS_TIME_FORMAT_NONE
Don't format the timestamp as part of the message.
Definition: rodbus.h:853
@ RODBUS_TIME_FORMAT_SYSTEM
Format the time in a human readable format e.g. 'Jun 25 14:27:12.955'.
Definition: rodbus.h:857
rodbus_param_error_t rodbus_address_filter_add(rodbus_address_filter_t *instance, const char *address)
Add an allowed IP address to the filter.
struct rodbus_device_map_t rodbus_device_map_t
Maps endpoint handlers to Modbus address.
Definition: rodbus.h:1562
static const char * rodbus_time_format_to_string(rodbus_time_format_t value)
Converts the enum to a string.
Definition: rodbus.h:863
static rodbus_runtime_config_t rodbus_runtime_config_init()
Initialize the configuration to default values.
Definition: rodbus.h:341
struct rodbus_bit_value_iterator_t rodbus_bit_value_iterator_t
Iterator of bit_value.
Definition: rodbus.h:505
struct rodbus_database_t rodbus_database_t
Class used to add, remove, update, and retrieve values.
Definition: rodbus.h:1321
static const char * rodbus_app_decode_level_to_string(rodbus_app_decode_level_t value)
Converts the enum to a string.
Definition: rodbus.h:158
rodbus_param_error_t rodbus_client_channel_create_rtu(rodbus_runtime_t *runtime, const char *path, rodbus_serial_port_settings_t serial_params, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_decode_level_t decode_level, rodbus_port_state_listener_t listener, rodbus_client_channel_t **out)
Create a new RTU channel instance.
rodbus_client_state_t
State of the client connection.
Definition: rodbus.h:1004
@ RODBUS_CLIENT_STATE_WAIT_AFTER_FAILED_CONNECT
Failed to establish a connection, waiting before retrying.
Definition: rodbus.h:1012
@ RODBUS_CLIENT_STATE_WAIT_AFTER_DISCONNECT
Client was disconnected, waiting before retrying.
Definition: rodbus.h:1014
@ RODBUS_CLIENT_STATE_CONNECTED
Client is connected to the remote device.
Definition: rodbus.h:1010
@ RODBUS_CLIENT_STATE_DISABLED
Client is disabled and idle until enabled.
Definition: rodbus.h:1006
@ RODBUS_CLIENT_STATE_SHUTDOWN
Client is shutting down.
Definition: rodbus.h:1016
@ RODBUS_CLIENT_STATE_CONNECTING
Client is trying to establish a connection to the remote device.
Definition: rodbus.h:1008
static const char * rodbus_port_state_to_string(rodbus_port_state_t value)
Converts the enum to a string.
Definition: rodbus.h:1069
bool rodbus_database_update_input_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Update the current value of a input register in the database.
rodbus_param_error_t rodbus_runtime_create(rodbus_runtime_config_t config, rodbus_runtime_t **out)
Creates a new runtime for running the protocol stack.
struct rodbus_register_list_t rodbus_register_list_t
Collection of register_list.
Definition: rodbus.h:1273
rodbus_param_error_t rodbus_server_create_tls_with_authz(rodbus_runtime_t *runtime, const char *address, uint16_t port, rodbus_address_filter_t *filter, uint16_t max_sessions, rodbus_device_map_t *endpoints, rodbus_tls_server_config_t tls_config, rodbus_authorization_handler_t authorization_handler, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Create a Modbus Security (TLS) server.
static const char * rodbus_nothing_to_string(rodbus_nothing_t value)
Converts the enum to a string.
Definition: rodbus.h:131
struct rodbus_bit_list_t rodbus_bit_list_t
Collection of bit_list.
Definition: rodbus.h:1246
static const char * rodbus_log_level_to_string(rodbus_log_level_t value)
Converts the enum to a string.
Definition: rodbus.h:812
static const char * rodbus_phys_decode_level_to_string(rodbus_phys_decode_level_t value)
Converts the enum to a string.
Definition: rodbus.h:213
static const char * rodbus_min_tls_version_to_string(rodbus_min_tls_version_t value)
Converts the enum to a string.
Definition: rodbus.h:720
static const char * rodbus_authorization_to_string(rodbus_authorization_t value)
Converts the enum to a string.
Definition: rodbus.h:1641
bool rodbus_device_map_add_endpoint(rodbus_device_map_t *instance, uint8_t unit_id, rodbus_write_handler_t handler, rodbus_database_callback_t configure)
Add an endpoint to the map.
rodbus_param_error_t rodbus_client_channel_read_discrete_inputs(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_bit_read_callback_t callback)
Start an asynchronous request to read discrete inputs.
void rodbus_device_map_destroy(rodbus_device_map_t *instance)
Destroy a previously created device map.
rodbus_param_error_t rodbus_database_get_discrete_input(rodbus_database_t *instance, uint16_t index, bool *out)
Get the current discrete input value of the database.
static rodbus_retry_strategy_t rodbus_retry_strategy_init()
Initialize a retry strategy to defaults.
Definition: rodbus.h:782
rodbus_address_filter_t * rodbus_address_filter_any()
Create an address filter that accepts any IP address.
rodbus_param_error_t rodbus_client_channel_read_input_registers(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_register_read_callback_t callback)
Start an asynchronous request to read input registers.
rodbus_modbus_exception_t
Error information returned during asynchronous API calls.
Definition: rodbus.h:524
@ RODBUS_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
Specialized use in conjunction with gateways, indicates that no response was obtained from the target...
Definition: rodbus.h:542
@ RODBUS_MODBUS_EXCEPTION_UNKNOWN
The status code is not defined in the Modbus specification, refer to the raw exception code to see wh...
Definition: rodbus.h:544
@ RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY
Specialized use in conjunction with programming commands. The server is engaged in processing a long-...
Definition: rodbus.h:536
@ RODBUS_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR
Specialized use in conjunction with function codes 20 and 21 and reference type 6,...
Definition: rodbus.h:538
@ RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE
A value contained in the request is not an allowable value for server.
Definition: rodbus.h:530
@ RODBUS_MODBUS_EXCEPTION_ACKNOWLEDGE
Specialized use in conjunction with programming commands. The server has accepted the request and is ...
Definition: rodbus.h:534
@ RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE
An unrecoverable error occurred while the server was attempting to perform the requested action.
Definition: rodbus.h:532
@ RODBUS_MODBUS_EXCEPTION_ILLEGAL_FUNCTION
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:526
@ RODBUS_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE
Specialized use in conjunction with gateways, indicates that the gateway was unable to allocate an in...
Definition: rodbus.h:540
@ RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:528
rodbus_authorization_t
Authorization result used by rodbus_authorization_handler_t.
Definition: rodbus.h:1631
@ RODBUS_AUTHORIZATION_DENY
Client is NOT authorized to perform the operation.
Definition: rodbus.h:1635
@ RODBUS_AUTHORIZATION_ALLOW
Client is authorized to perform the operation.
Definition: rodbus.h:1633
static const char * rodbus_client_state_to_string(rodbus_client_state_t value)
Converts the enum to a string.
Definition: rodbus.h:1022
rodbus_phys_decode_level_t
Controls how data transmitted at the physical layer (TCP, serial, etc) is logged.
Definition: rodbus.h:201
@ RODBUS_PHYS_DECODE_LEVEL_DATA
Log the length and the actual data that is sent and received.
Definition: rodbus.h:207
@ RODBUS_PHYS_DECODE_LEVEL_LENGTH
Log only the length of data that is sent and received.
Definition: rodbus.h:205
@ RODBUS_PHYS_DECODE_LEVEL_NOTHING
Log nothing.
Definition: rodbus.h:203
rodbus_device_map_t * rodbus_device_map_create()
Create a device map that will be used to bind devices to a server endpoint.
rodbus_param_error_t rodbus_database_get_holding_register(rodbus_database_t *instance, uint16_t index, uint16_t *out)
Get the current holding register value of the database.
bool rodbus_database_add_input_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Add a new input register to the database.
void rodbus_register_list_destroy(rodbus_register_list_t *instance)
Destroys an instance of the collection.
static rodbus_write_result_t rodbus_write_result_raw_exception_init(uint8_t raw_exception)
Initialize a rodbus_write_result_t to indicate a non-standard Modbus exception.
Definition: rodbus.h:1508
const char * rodbus_version()
Get the version of the library as a string.
rodbus_param_error_t rodbus_server_set_decode_level(rodbus_server_t *instance, rodbus_decode_level_t level)
Set the decoding level for the server.
rodbus_param_error_t
Error type that indicates a bad parameter or bad programmer logic.
Definition: rodbus.h:46
@ RODBUS_PARAM_ERROR_OK
Success, i.e. no error occurred.
Definition: rodbus.h:48
@ RODBUS_PARAM_ERROR_INVALID_UTF8
String argument was not valid UTF-8.
Definition: rodbus.h:86
@ RODBUS_PARAM_ERROR_RUNTIME_CANNOT_BLOCK_WITHIN_ASYNC
Runtime cannot execute blocking call within asynchronous context.
Definition: rodbus.h:60
@ RODBUS_PARAM_ERROR_INVALID_RANGE
Invalid Modbus address range.
Definition: rodbus.h:64
@ RODBUS_PARAM_ERROR_INVALID_LOCAL_CERTIFICATE
Invalid local certificate file.
Definition: rodbus.h:76
@ RODBUS_PARAM_ERROR_INVALID_REQUEST
Invalid Modbus request.
Definition: rodbus.h:66
@ RODBUS_PARAM_ERROR_INVALID_INDEX
Invalid index.
Definition: rodbus.h:68
@ RODBUS_PARAM_ERROR_INVALID_PRIVATE_KEY
Invalid private key file.
Definition: rodbus.h:78
@ RODBUS_PARAM_ERROR_SERVER_BIND_ERROR
Server failed to bind to the specified port.
Definition: rodbus.h:70
@ RODBUS_PARAM_ERROR_RUNTIME_CREATION_FAILURE
Failed to create Tokio runtime.
Definition: rodbus.h:56
@ RODBUS_PARAM_ERROR_INVALID_DNS_NAME
Invalid DNS name.
Definition: rodbus.h:80
@ RODBUS_PARAM_ERROR_INVALID_IP_ADDRESS
Invalid IP address.
Definition: rodbus.h:62
@ RODBUS_PARAM_ERROR_NULL_PARAMETER
Null parameter.
Definition: rodbus.h:52
@ RODBUS_PARAM_ERROR_SHUTDOWN
The task has been shutdown.
Definition: rodbus.h:84
@ RODBUS_PARAM_ERROR_BAD_TLS_CONFIG
Bad TLS configuration.
Definition: rodbus.h:82
@ RODBUS_PARAM_ERROR_INVALID_PEER_CERTIFICATE
Invalid peer certificate file.
Definition: rodbus.h:74
@ RODBUS_PARAM_ERROR_LOGGING_ALREADY_CONFIGURED
Logging can only be configured once.
Definition: rodbus.h:54
@ RODBUS_PARAM_ERROR_RUNTIME_DESTROYED
Runtime was already disposed of.
Definition: rodbus.h:58
@ RODBUS_PARAM_ERROR_NO_SUPPORT
The FFI library was compiled without support for this feature.
Definition: rodbus.h:50
@ RODBUS_PARAM_ERROR_INVALID_UNIT_ID
The specified unit id is not associated to this server.
Definition: rodbus.h:72
static const char * rodbus_stop_bits_to_string(rodbus_stop_bits_t value)
Converts the enum to a string.
Definition: rodbus.h:658
void rodbus_address_filter_destroy(rodbus_address_filter_t *instance)
Destroy an address filter.
static const char * rodbus_log_output_format_to_string(rodbus_log_output_format_t value)
Converts the enum to a string.
Definition: rodbus.h:839
rodbus_log_level_t
Log level.
Definition: rodbus.h:796
@ RODBUS_LOG_LEVEL_ERROR
Error log level.
Definition: rodbus.h:798
@ RODBUS_LOG_LEVEL_INFO
Information log level.
Definition: rodbus.h:802
@ RODBUS_LOG_LEVEL_TRACE
Trace log level.
Definition: rodbus.h:806
@ RODBUS_LOG_LEVEL_DEBUG
Debugging log level.
Definition: rodbus.h:804
@ RODBUS_LOG_LEVEL_WARN
Warning log level.
Definition: rodbus.h:800
rodbus_certificate_mode_t
Determines how the certificate(s) presented by the peer are validated.
Definition: rodbus.h:734
@ RODBUS_CERTIFICATE_MODE_SELF_SIGNED
Validates that the peer presents a single certificate which is a byte-for-byte match against the conf...
Definition: rodbus.h:744
@ RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED
Validates the peer certificate against one or more configured trust anchors.
Definition: rodbus.h:740
static rodbus_logging_config_t rodbus_logging_config_init()
Initialize the configuration to default values.
Definition: rodbus.h:899
rodbus_nothing_t
A single value enum which is used as a placeholder for futures that don't return a value.
Definition: rodbus.h:123
@ RODBUS_NOTHING_NOTHING
the only value this enum has
Definition: rodbus.h:125
rodbus_app_decode_level_t
Controls how transmitted and received message at the application layer are decoded at the INFO log le...
Definition: rodbus.h:144
@ RODBUS_APP_DECODE_LEVEL_DATA_VALUES
Decode the function code, the general description of the data and the actual data values.
Definition: rodbus.h:152
@ RODBUS_APP_DECODE_LEVEL_NOTHING
Decode nothing.
Definition: rodbus.h:146
@ RODBUS_APP_DECODE_LEVEL_FUNCTION_CODE
Decode the function code only.
Definition: rodbus.h:148
@ RODBUS_APP_DECODE_LEVEL_DATA_HEADERS
Decode the function code and the general description of the data.
Definition: rodbus.h:150
struct rodbus_register_value_iterator_t rodbus_register_value_iterator_t
Iterator of register_value.
Definition: rodbus.h:514
Range of 16-bit addresses sent in a request from the client to the server.
Definition: rodbus.h:457
uint16_t start
Starting address of the range.
Definition: rodbus.h:459
uint16_t count
Number of addresses in the range.
Definition: rodbus.h:461
User implemented interface defines which request and roles are allowed for different functions when i...
Definition: rodbus.h:1653
rodbus_authorization_t(* write_single_coil)(uint8_t, uint16_t, const char *, void *)
Authorize a Write Single Coil request.
Definition: rodbus.h:1693
rodbus_authorization_t(* write_multiple_registers)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Write Multiple Registers request.
Definition: rodbus.h:1717
rodbus_authorization_t(* read_input_registers)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Input Registers request.
Definition: rodbus.h:1685
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1720
rodbus_authorization_t(* read_coils)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Coils request.
Definition: rodbus.h:1661
rodbus_authorization_t(* read_holding_registers)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Holding Registers request.
Definition: rodbus.h:1677
void * ctx
Context data.
Definition: rodbus.h:1722
rodbus_authorization_t(* write_single_register)(uint8_t, uint16_t, const char *, void *)
Authorize a Write Single Register request.
Definition: rodbus.h:1701
rodbus_authorization_t(* write_multiple_coils)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Write Multiple Coils request.
Definition: rodbus.h:1709
rodbus_authorization_t(* read_discrete_inputs)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Discrete Inputs request.
Definition: rodbus.h:1669
Callbacks received when reading coils or discrete inputs.
Definition: rodbus.h:1139
void(* on_complete)(rodbus_bit_value_iterator_t *, void *)
Invoked when the asynchronous operation completes successfully.
Definition: rodbus.h:1144
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1152
void * ctx
Context data.
Definition: rodbus.h:1154
void(* on_failure)(rodbus_request_error_t, void *)
Invoked when the asynchronous operation fails.
Definition: rodbus.h:1149
Index/value tuple of a bit type.
Definition: rodbus.h:275
bool value
Value of the bit.
Definition: rodbus.h:279
uint16_t index
Index of bit.
Definition: rodbus.h:277
Callback for monitoring the state of a TCP/TLS connection state.
Definition: rodbus.h:1038
void(* on_change)(rodbus_client_state_t, void *)
Called when the client state changed.
Definition: rodbus.h:1043
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1046
void * ctx
Context data.
Definition: rodbus.h:1048
Callback used to access the internal database while it is locked.
Definition: rodbus.h:1434
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1442
void(* callback)(rodbus_database_t *, void *)
callback function
Definition: rodbus.h:1439
void * ctx
Context data.
Definition: rodbus.h:1444
Controls the decoding of transmitted and received data at the application, frame, and physical layer.
Definition: rodbus.h:228
rodbus_app_decode_level_t app
Controls decoding of the application layer (PDU)
Definition: rodbus.h:230
rodbus_frame_decode_level_t frame
Controls decoding of frames (MBAP / Serial PDU)
Definition: rodbus.h:232
rodbus_phys_decode_level_t physical
Controls the logging of physical layer read/write.
Definition: rodbus.h:234
Logging interface that receives the log messages and writes them somewhere.
Definition: rodbus.h:914
void(* on_message)(rodbus_log_level_t, const char *, void *)
Called when a log message was received and should be logged.
Definition: rodbus.h:920
void * ctx
Context data.
Definition: rodbus.h:925
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:923
Logging configuration options.
Definition: rodbus.h:876
bool print_module_info
optionally print the underlying Rust module information to the message string
Definition: rodbus.h:886
rodbus_time_format_t time_format
optional time format
Definition: rodbus.h:882
rodbus_log_output_format_t output_format
output formatting options
Definition: rodbus.h:880
rodbus_log_level_t level
logging level
Definition: rodbus.h:878
bool print_level
optionally print the log level as part to the message string
Definition: rodbus.h:884
Callback interface for receiving updates about the state of a serial port.
Definition: rodbus.h:1083
void(* on_change)(rodbus_port_state_t, void *)
Invoked when the serial port changes state.
Definition: rodbus.h:1088
void * ctx
Context data.
Definition: rodbus.h:1093
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1091
Callbacks received when reading reading holding or input registers.
Definition: rodbus.h:1159
void(* on_complete)(rodbus_register_value_iterator_t *, void *)
Invoked when the asynchronous operation completes successfully.
Definition: rodbus.h:1164
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1172
void * ctx
Context data.
Definition: rodbus.h:1174
void(* on_failure)(rodbus_request_error_t, void *)
Invoked when the asynchronous operation fails.
Definition: rodbus.h:1169
Index/value tuple of a register type.
Definition: rodbus.h:300
uint16_t index
Index of register.
Definition: rodbus.h:302
uint16_t value
Value of the register.
Definition: rodbus.h:304
Address and timeout parameters for requests.
Definition: rodbus.h:482
uint64_t timeout
Response timeout for the request.
Definition: rodbus.h:487
uint8_t unit_id
Modbus address for the request.
Definition: rodbus.h:484
Retry strategy configuration.
Definition: rodbus.h:766
uint64_t max_delay
Maximum delay between two retries.
Definition: rodbus.h:772
uint64_t min_delay
Minimum delay between two retries.
Definition: rodbus.h:769
Runtime configuration.
Definition: rodbus.h:328
uint16_t num_core_threads
Number of runtime threads to spawn. For a guess of the number of CPU cores, use 0.
Definition: rodbus.h:332
Serial port settings.
Definition: rodbus.h:672
rodbus_stop_bits_t stop_bits
Number of bits to use to signal the end of a character.
Definition: rodbus.h:682
rodbus_data_bits_t data_bits
Number of bits used to represent a character sent on the line.
Definition: rodbus.h:676
rodbus_flow_control_t flow_control
Type of signalling to use for controlling data transfer.
Definition: rodbus.h:678
uint32_t baud_rate
Baud rate (in symbols-per-second)
Definition: rodbus.h:674
rodbus_parity_t parity
Type of parity to use for error checking.
Definition: rodbus.h:680
TLS client configuration.
Definition: rodbus.h:948
bool allow_server_name_wildcard
If set to true, a '*' may be used for rodbus_tls_client_config_t::dns_name to bypass server name vali...
Definition: rodbus.h:968
rodbus_certificate_mode_t certificate_mode
Certificate validation mode.
Definition: rodbus.h:966
const char * peer_cert_path
Path to the PEM-encoded certificate of the peer.
Definition: rodbus.h:952
rodbus_min_tls_version_t min_tls_version
Minimum TLS version allowed.
Definition: rodbus.h:964
const char * dns_name
Name expected to be in the presented certificate (only in RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED)
Definition: rodbus.h:950
const char * private_key_path
Path to the the PEM-encoded private key.
Definition: rodbus.h:956
const char * local_cert_path
Path to the PEM-encoded local certificate.
Definition: rodbus.h:954
const char * password
Optional password if the private key file is encrypted.
Definition: rodbus.h:962
TLS server configuration.
Definition: rodbus.h:1585
const char * password
Optional password if the private key file is encrypted.
Definition: rodbus.h:1597
rodbus_certificate_mode_t certificate_mode
Certficate validation mode.
Definition: rodbus.h:1601
const char * private_key_path
Path to the the PEM-encoded private key.
Definition: rodbus.h:1591
const char * local_cert_path
Path to the PEM-encoded local certificate.
Definition: rodbus.h:1589
const char * peer_cert_path
Path to the PEM-encoded certificate of the peer.
Definition: rodbus.h:1587
rodbus_min_tls_version_t min_tls_version
Minimum TLS version allowed.
Definition: rodbus.h:1599
Callback methods received from asynchronous write operations.
Definition: rodbus.h:1179
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1192
void * ctx
Context data.
Definition: rodbus.h:1194
void(* on_failure)(rodbus_request_error_t, void *)
Invoked when the asynchronous operation fails.
Definition: rodbus.h:1189
void(* on_complete)(rodbus_nothing_t, void *)
Invoked when the asynchronous operation completes successfully.
Definition: rodbus.h:1184
Interface used to handle write requests received from the client.
Definition: rodbus.h:1521
rodbus_write_result_t(* write_single_coil)(uint16_t, bool, rodbus_database_t *, void *)
Write a single coil received from the client.
Definition: rodbus.h:1529
void * ctx
Context data.
Definition: rodbus.h:1558
rodbus_write_result_t(* write_multiple_registers)(uint16_t, rodbus_register_value_iterator_t *, rodbus_database_t *, void *)
Write multiple registers received from the client.
Definition: rodbus.h:1553
rodbus_write_result_t(* write_multiple_coils)(uint16_t, rodbus_bit_value_iterator_t *, rodbus_database_t *, void *)
Write multiple coils received from the client.
Definition: rodbus.h:1545
rodbus_write_result_t(* write_single_register)(uint16_t, uint16_t, rodbus_database_t *, void *)
write a single coil received from the client
Definition: rodbus.h:1537
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1556
Describes to the server if a write operation was successful or not.
Definition: rodbus.h:1455
uint8_t raw_exception
Raw exception value when rodbus_write_result_t::exception field is RODBUS_MODBUS_EXCEPTION_UNKNOWN.
Definition: rodbus.h:1461
rodbus_modbus_exception_t exception
Exception enumeration. If RODBUS_MODBUS_EXCEPTION_UNKNOWN, look at the raw value.
Definition: rodbus.h:1459
bool success
true if the operation was successful, false otherwise. Error details found in the exception field.
Definition: rodbus.h:1457