rodbus (C API) 1.3.1
|
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | rodbus_decode_level_t |
Controls the decoding of transmitted and received data at the application, frame, and physical layer. More... | |
struct | rodbus_bit_value_t |
Index/value tuple of a bit type. More... | |
struct | rodbus_register_value_t |
Index/value tuple of a register type. More... | |
struct | rodbus_runtime_config_t |
Runtime configuration. More... | |
struct | rodbus_address_range_t |
Range of 16-bit addresses sent in a request from the client to the server. More... | |
struct | rodbus_request_param_t |
Address and timeout parameters for requests. More... | |
struct | rodbus_serial_port_settings_t |
Serial port settings. More... | |
struct | rodbus_retry_strategy_t |
Retry strategy configuration. More... | |
struct | rodbus_logging_config_t |
Logging configuration options. More... | |
struct | rodbus_logger_t |
Logging interface that receives the log messages and writes them somewhere. More... | |
struct | rodbus_tls_client_config_t |
TLS client configuration. More... | |
struct | rodbus_client_state_listener_t |
Callback for monitoring the state of a TCP/TLS connection state. More... | |
struct | rodbus_port_state_listener_t |
Callback interface for receiving updates about the state of a serial port. More... | |
struct | rodbus_bit_read_callback_t |
Callbacks received when reading coils or discrete inputs. More... | |
struct | rodbus_register_read_callback_t |
Callbacks received when reading reading holding or input registers. More... | |
struct | rodbus_write_callback_t |
Callback methods received from asynchronous write operations. More... | |
struct | rodbus_database_callback_t |
Callback used to access the internal database while it is locked. More... | |
struct | rodbus_write_result_t |
Describes to the server if a write operation was successful or not. More... | |
struct | rodbus_write_handler_t |
Interface used to handle write requests received from the client. More... | |
struct | rodbus_tls_server_config_t |
TLS server configuration. More... | |
struct | rodbus_authorization_handler_t |
User implemented interface defines which request and roles are allowed for different functions when implementing Modbus security. More... | |
Macros | |
#define | RODBUS_VERSION_MAJOR 1 |
#define | RODBUS_VERSION_MINOR 3 |
#define | RODBUS_VERSION_PATCH 1 |
#define | RODBUS_VERSION_STRING "1.3.1" |
Typedefs | |
typedef struct rodbus_runtime_t | rodbus_runtime_t |
Handle to the underlying runtime. More... | |
typedef struct rodbus_bit_value_iterator_t | rodbus_bit_value_iterator_t |
Iterator of bit_value. More... | |
typedef struct rodbus_register_value_iterator_t | rodbus_register_value_iterator_t |
Iterator of register_value. More... | |
typedef struct rodbus_client_channel_t | rodbus_client_channel_t |
Abstract representation of a client communication channel. More... | |
typedef struct rodbus_bit_list_t | rodbus_bit_list_t |
Collection of bit_list. More... | |
typedef struct rodbus_register_list_t | rodbus_register_list_t |
Collection of register_list. More... | |
typedef struct rodbus_database_t | rodbus_database_t |
Class used to add, remove, update, and retrieve values. More... | |
typedef struct rodbus_device_map_t | rodbus_device_map_t |
Maps endpoint handlers to Modbus address. More... | |
typedef struct rodbus_address_filter_t | rodbus_address_filter_t |
Filter used to restrict which IP addresses may communicate with a server. More... | |
typedef struct rodbus_server_t | rodbus_server_t |
Handle to the running server. The server runs on a background task until this class is destroyed. More... | |
Functions | |
static const char * | rodbus_param_error_to_string (rodbus_param_error_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_nothing_to_string (rodbus_nothing_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_app_decode_level_to_string (rodbus_app_decode_level_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_frame_decode_level_to_string (rodbus_frame_decode_level_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_phys_decode_level_to_string (rodbus_phys_decode_level_t value) |
Converts the enum to a string. More... | |
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. More... | |
static rodbus_decode_level_t | rodbus_decode_level_nothing () |
Initialize log levels to defaults which is to decode nothing. More... | |
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. More... | |
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. More... | |
static rodbus_runtime_config_t | rodbus_runtime_config_init () |
Initialize the configuration to default values. More... | |
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. More... | |
void | rodbus_runtime_destroy (rodbus_runtime_t *instance) |
Destroy a runtime. More... | |
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 spawned tasks to yield. More... | |
static const char * | rodbus_request_error_to_string (rodbus_request_error_t value) |
Converts the enum to a string. More... | |
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. More... | |
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. More... | |
rodbus_bit_value_t * | rodbus_bit_value_iterator_next (rodbus_bit_value_iterator_t *iter) |
returns a pointer to the next value or NULL More... | |
rodbus_register_value_t * | rodbus_register_value_iterator_next (rodbus_register_value_iterator_t *iter) |
returns a pointer to the next value or NULL More... | |
static const char * | rodbus_modbus_exception_to_string (rodbus_modbus_exception_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_data_bits_to_string (rodbus_data_bits_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_flow_control_to_string (rodbus_flow_control_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_parity_to_string (rodbus_parity_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_stop_bits_to_string (rodbus_stop_bits_t value) |
Converts the enum to a string. More... | |
static rodbus_serial_port_settings_t | rodbus_serial_port_settings_init () |
Initialize a serial port configuration. More... | |
static const char * | rodbus_min_tls_version_to_string (rodbus_min_tls_version_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_certificate_mode_to_string (rodbus_certificate_mode_t value) |
Converts the enum to a string. More... | |
static rodbus_retry_strategy_t | rodbus_retry_strategy_init () |
Initialize a retry strategy to defaults. More... | |
static const char * | rodbus_log_level_to_string (rodbus_log_level_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_log_output_format_to_string (rodbus_log_output_format_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_time_format_to_string (rodbus_time_format_t value) |
Converts the enum to a string. More... | |
static rodbus_logging_config_t | rodbus_logging_config_init () |
Initialize the configuration to default values. More... | |
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. More... | |
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. More... | |
static const char * | rodbus_client_state_to_string (rodbus_client_state_t value) |
Converts the enum to a string. More... | |
static const char * | rodbus_port_state_to_string (rodbus_port_state_t value) |
Converts the enum to a string. More... | |
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. More... | |
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. More... | |
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. More... | |
void | rodbus_client_channel_destroy (rodbus_client_channel_t *instance) |
Shutdown a rodbus_client_channel_t and release all resources. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
rodbus_bit_list_t * | rodbus_bit_list_create (uint32_t reserve_size) |
Creates an instance of the collection. More... | |
void | rodbus_bit_list_destroy (rodbus_bit_list_t *instance) |
Destroys an instance of the collection. More... | |
void | rodbus_bit_list_add (rodbus_bit_list_t *instance, bool value) |
Add a value to the collection. More... | |
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. More... | |
rodbus_register_list_t * | rodbus_register_list_create (uint32_t reserve_size) |
Creates an instance of the collection. More... | |
void | rodbus_register_list_destroy (rodbus_register_list_t *instance) |
Destroys an instance of the collection. More... | |
void | rodbus_register_list_add (rodbus_register_list_t *instance, uint16_t value) |
Add a value to the collection. More... | |
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. More... | |
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. More... | |
rodbus_param_error_t | rodbus_client_channel_enable (rodbus_client_channel_t *instance) |
Enable channel communications. More... | |
rodbus_param_error_t | rodbus_client_channel_disable (rodbus_client_channel_t *instance) |
Disable channel communications. More... | |
bool | rodbus_database_add_coil (rodbus_database_t *instance, uint16_t index, bool value) |
Add a new coil to the database. More... | |
bool | rodbus_database_add_discrete_input (rodbus_database_t *instance, uint16_t index, bool value) |
Add a new discrete input to the database. More... | |
bool | rodbus_database_add_holding_register (rodbus_database_t *instance, uint16_t index, uint16_t value) |
Add a new holding register to the database. More... | |
bool | rodbus_database_add_input_register (rodbus_database_t *instance, uint16_t index, uint16_t value) |
Add a new input register to the database. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
bool | rodbus_database_update_coil (rodbus_database_t *instance, uint16_t index, bool value) |
Update the current value of a coil in the database. More... | |
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. More... | |
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. More... | |
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. More... | |
bool | rodbus_database_delete_coil (rodbus_database_t *instance, uint16_t index) |
Remove a coil address from the database. More... | |
bool | rodbus_database_delete_discrete_input (rodbus_database_t *instance, uint16_t index) |
Remove a discrete input address from the database. More... | |
bool | rodbus_database_delete_holding_register (rodbus_database_t *instance, uint16_t index) |
Remove a holding register address from the database. More... | |
bool | rodbus_database_delete_input_register (rodbus_database_t *instance, uint16_t index) |
Remove a input register address from the database. More... | |
static rodbus_write_result_t | rodbus_write_result_success_init () |
Initialize a rodbus_write_result_t to indicate a successful write operation. More... | |
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. More... | |
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. More... | |
rodbus_device_map_t * | rodbus_device_map_create () |
Create a device map that will be used to bind devices to a server endpoint. More... | |
void | rodbus_device_map_destroy (rodbus_device_map_t *instance) |
Destroy a previously created device map. More... | |
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. More... | |
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. More... | |
static const char * | rodbus_authorization_to_string (rodbus_authorization_t value) |
Converts the enum to a string. More... | |
rodbus_address_filter_t * | rodbus_address_filter_any () |
Create an address filter that accepts any IP address. More... | |
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. More... | |
rodbus_param_error_t | rodbus_address_filter_add (rodbus_address_filter_t *instance, const char *address) |
Add an allowed IP address to the filter. More... | |
void | rodbus_address_filter_destroy (rodbus_address_filter_t *instance) |
Destroy an address filter. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | rodbus_server_destroy (rodbus_server_t *instance) |
Shutdown and release all resources of a running server. More... | |
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 and call user code to perform the transaction. More... | |
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. More... | |
const char * | rodbus_version () |
Get the version of the library as a string. More... | |
C API for the rodbus library
typedef struct rodbus_address_filter_t rodbus_address_filter_t |
Filter used to restrict which IP addresses may communicate with a server.
typedef struct rodbus_bit_list_t rodbus_bit_list_t |
Collection of bit_list.
typedef struct rodbus_bit_value_iterator_t rodbus_bit_value_iterator_t |
Iterator of bit_value.
typedef struct rodbus_client_channel_t rodbus_client_channel_t |
Abstract representation of a client communication channel.
The underlying channel may be TCP, TLS, or serial.
typedef struct rodbus_database_t rodbus_database_t |
Class used to add, remove, update, and retrieve values.
typedef struct rodbus_device_map_t rodbus_device_map_t |
Maps endpoint handlers to Modbus address.
typedef struct rodbus_register_list_t rodbus_register_list_t |
Collection of register_list.
typedef struct rodbus_register_value_iterator_t rodbus_register_value_iterator_t |
Iterator of register_value.
typedef struct rodbus_runtime_t rodbus_runtime_t |
Handle to the underlying runtime.
typedef struct rodbus_server_t rodbus_server_t |
Handle to the running server. The server runs on a background task until this class is destroyed.
Controls how transmitted and received message at the application layer are decoded at the INFO log level.
Application-layer messages are referred to as Protocol Data Units (PDUs) in the specification.
Authorization result used by rodbus_authorization_handler_t.
Enumerator | |
---|---|
RODBUS_AUTHORIZATION_ALLOW | Client is authorized to perform the operation. |
RODBUS_AUTHORIZATION_DENY | Client is NOT authorized to perform the operation. |
Determines how the certificate(s) presented by the peer are validated.
This validation always occurs after the handshake signature has been verified.
State of the client connection.
Used by the rodbus_client_state_listener_t.
enum rodbus_data_bits_t |
Controls how the transmitted and received frames are decoded at the INFO log level.
Transport-specific framing wraps the application-layer traffic. You'll see these frames called ADUs in the Modbus specification.
On TCP, this is the MBAP decoding. On serial, this controls the serial line PDU.
Enumerator | |
---|---|
RODBUS_FRAME_DECODE_LEVEL_NOTHING | Log nothing. |
RODBUS_FRAME_DECODE_LEVEL_HEADER | Decode the header. |
RODBUS_FRAME_DECODE_LEVEL_PAYLOAD | Decode the header and the raw payload as hexadecimal. |
enum rodbus_log_level_t |
Log level.
Used in rodbus_logger_t::on_message callback to identify the log level of a message.
Error information returned during asynchronous API calls.
enum rodbus_nothing_t |
enum rodbus_param_error_t |
Error type that indicates a bad parameter or bad programmer logic.
enum rodbus_parity_t |
Controls how data transmitted at the physical layer (TCP, serial, etc) is logged.
enum rodbus_port_state_t |
State of the serial port.
Used by the rodbus_port_state_listener_t.
Error information returned from asynchronous functions calls.
Unlike rodbus_param_error_t, the values here generally represent spontaneous failures that are outside developer control, e.g. network failures, etc
enum rodbus_stop_bits_t |
enum rodbus_time_format_t |
Describes if and how the time will be formatted in log messages.
rodbus_param_error_t rodbus_address_filter_add | ( | rodbus_address_filter_t * | instance, |
const char * | address | ||
) |
Add an allowed IP address to the filter.
This function may only be called if the AddressFilter was initially constructed with a single static address
instance | Instance of rodbus_address_filter_t |
address | IP address to add |
rodbus_address_filter_t * rodbus_address_filter_any | ( | ) |
Create an address filter that accepts any IP address.
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.
Examples: 192.168.1.26, 192.168.0.*, *.*.*.*
Wildcards are only supported for IPv4 addresses
address | IP address to accept |
out | Instance of rodbus_address_filter_t |
void rodbus_address_filter_destroy | ( | rodbus_address_filter_t * | instance | ) |
Destroy an address filter.
instance | Instance of rodbus_address_filter_t to destroy |
|
static |
Fully construct rodbus_address_range_t specifying the value of each field.
start | Starting address of the range |
count | Number of addresses in the range |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
void rodbus_bit_list_add | ( | rodbus_bit_list_t * | instance, |
bool | value | ||
) |
Add a value to the collection.
instance | instance to which to add the value |
value | value to add to the instance |
rodbus_bit_list_t * rodbus_bit_list_create | ( | uint32_t | reserve_size | ) |
Creates an instance of the collection.
reserve_size | preallocate a particular size |
void rodbus_bit_list_destroy | ( | rodbus_bit_list_t * | instance | ) |
Destroys an instance of the collection.
instance | instance to destroy |
|
static |
Fully construct rodbus_bit_value_t specifying the value of each field.
index | Index of bit |
value | Value of the bit |
rodbus_bit_value_t * rodbus_bit_value_iterator_next | ( | rodbus_bit_value_iterator_t * | iter | ) |
returns a pointer to the next value or NULL
iter | opaque iterator on which to retrieve the next value |
|
static |
Converts the enum to a string.
value | Enum to convert |
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.
runtime | runtime on which to create the channel |
path | Path to the serial device. Generally /dev/tty0 on Linux and COM1 on Windows. |
serial_params | Serial port settings |
max_queued_requests | Maximum number of requests to queue before failing the next request |
retry_strategy | Strategy which controls how long to wait between attempts to open the serial port after failures |
decode_level | Decode levels for this client |
listener | Listener used to receive updates on the status of the serial port |
out | Pointer to the created channel |
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.
runtime | Runtime on which to create the channel |
host | IP (v4/v6) or host name remote endpoint |
port | remote port |
max_queued_requests | Maximum number of requests to queue before failing the next request |
retry_strategy | Reconnection timing strategy |
decode_level | Decode levels for this client |
listener | TCP connection listener used to receive updates on the status of the channel |
out | Pointer to the created channel |
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.
runtime | Runtime on which to create the channel |
host | IP (v4/v6) or host name remote endpoint |
port | remote port |
max_queued_requests | Maximum number of requests to queue before failing the next request |
retry_strategy | Reconnection timing strategy |
tls_config | TLS client configuration |
decode_level | Decode levels for this client |
listener | TCP connection listener used to receive updates on the status of the channel |
out | Pointer to the created channel or NULL if an error occurred |
void rodbus_client_channel_destroy | ( | rodbus_client_channel_t * | instance | ) |
Shutdown a rodbus_client_channel_t and release all resources.
instance | Instance of rodbus_client_channel_t to destroy |
rodbus_param_error_t rodbus_client_channel_disable | ( | rodbus_client_channel_t * | instance | ) |
Disable channel communications.
instance | Instance of rodbus_client_channel_t |
rodbus_param_error_t rodbus_client_channel_enable | ( | rodbus_client_channel_t * | instance | ) |
Enable channel communications.
instance | Instance of rodbus_client_channel_t |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
range | Range of addresses to read |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
range | Range of addresses to read |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
range | Range of addresses to read |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
range | Range of addresses to read |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
level | Decoding level |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
start | Starting address |
items | List of items to write |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
start | Starting address |
items | List of items to write |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
value | Address and value to write |
callback | callback invoked when the operation completes |
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.
instance | Instance of rodbus_client_channel_t |
param | Parameters for the request |
value | Address and value to write |
callback | callback invoked when the operation completes |
|
static |
Converts the enum to a string.
value | Enum to convert |
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.
There is only a single globally allocated logger. Calling this method a second time will return an error.
If this method is never called, no logging will be performed.
config | Configuration options for logging |
logger | Logger that will receive each logged message |
|
static |
Converts the enum to a string.
value | Enum to convert |
bool rodbus_database_add_coil | ( | rodbus_database_t * | instance, |
uint16_t | index, | ||
bool | value | ||
) |
Add a new coil to the database.
instance | Instance of rodbus_database_t |
index | Address of the coil |
value | Initial value of the coil |
bool rodbus_database_add_discrete_input | ( | rodbus_database_t * | instance, |
uint16_t | index, | ||
bool | value | ||
) |
Add a new discrete input to the database.
instance | Instance of rodbus_database_t |
index | Address of the discrete input |
value | Initial value of the discrete input |
bool rodbus_database_add_holding_register | ( | rodbus_database_t * | instance, |
uint16_t | index, | ||
uint16_t | value | ||
) |
Add a new holding register to the database.
instance | Instance of rodbus_database_t |
index | Address of the holding register |
value | Initial value of the holding register |
bool rodbus_database_add_input_register | ( | rodbus_database_t * | instance, |
uint16_t | index, | ||
uint16_t | value | ||
) |
Add a new input register to the database.
instance | Instance of rodbus_database_t |
index | Address of the input register |
value | Initial value of the input register |
bool rodbus_database_delete_coil | ( | rodbus_database_t * | instance, |
uint16_t | index | ||
) |
Remove a coil address from the database.
instance | Instance of rodbus_database_t |
index | Address of the coil |
bool rodbus_database_delete_discrete_input | ( | rodbus_database_t * | instance, |
uint16_t | index | ||
) |
Remove a discrete input address from the database.
instance | Instance of rodbus_database_t |
index | Address of the discrete input |
bool rodbus_database_delete_holding_register | ( | rodbus_database_t * | instance, |
uint16_t | index | ||
) |
Remove a holding register address from the database.
instance | Instance of rodbus_database_t |
index | Address of the holding register |
bool rodbus_database_delete_input_register | ( | rodbus_database_t * | instance, |
uint16_t | index | ||
) |
Remove a input register address from the database.
instance | Instance of rodbus_database_t |
index | Address of the input register |
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.
instance | Instance of rodbus_database_t |
index | Address of the coil |
out | Current value of the point |
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.
instance | Instance of rodbus_database_t |
index | Address of the discrete input |
out | Current value of the point |
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.
instance | Instance of rodbus_database_t |
index | Address of the holding register |
out | Current value of the point |
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.
instance | Instance of rodbus_database_t |
index | Address of the input register |
out | Current value of the point |
bool rodbus_database_update_coil | ( | rodbus_database_t * | instance, |
uint16_t | index, | ||
bool | value | ||
) |
Update the current value of a coil in the database.
instance | Instance of rodbus_database_t |
index | Address of the coil |
value | New value of the coil |
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.
instance | Instance of rodbus_database_t |
index | Address of the discrete input |
value | New value of the discrete input |
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.
instance | Instance of rodbus_database_t |
index | Address of the holding register |
value | New value of the holding register |
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.
instance | Instance of rodbus_database_t |
index | Address of the input register |
value | New value of the input register |
|
static |
Fully construct rodbus_decode_level_t specifying the value of each field.
app | Controls decoding of the application layer (PDU) |
frame | Controls decoding of frames (MBAP / Serial PDU) |
physical | Controls the logging of physical layer read/write |
|
static |
Initialize log levels to defaults which is to decode nothing.
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.
instance | Instance of rodbus_device_map_t |
unit_id | Unit id of the endpoint |
handler | Callback interface for handling write operations for this device |
configure | One-time callback interface configuring the initial state of the database |
rodbus_device_map_t * rodbus_device_map_create | ( | ) |
Create a device map that will be used to bind devices to a server endpoint.
void rodbus_device_map_destroy | ( | rodbus_device_map_t * | instance | ) |
Destroy a previously created device map.
instance | Instance of rodbus_device_map_t to destroy |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Initialize the configuration to default values.
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
void rodbus_register_list_add | ( | rodbus_register_list_t * | instance, |
uint16_t | value | ||
) |
Add a value to the collection.
instance | instance to which to add the value |
value | value to add to the instance |
rodbus_register_list_t * rodbus_register_list_create | ( | uint32_t | reserve_size | ) |
Creates an instance of the collection.
reserve_size | preallocate a particular size |
void rodbus_register_list_destroy | ( | rodbus_register_list_t * | instance | ) |
Destroys an instance of the collection.
instance | instance to destroy |
|
static |
Fully construct rodbus_register_value_t specifying the value of each field.
index | Index of register |
value | Value of the register |
rodbus_register_value_t * rodbus_register_value_iterator_next | ( | rodbus_register_value_iterator_t * | iter | ) |
returns a pointer to the next value or NULL
iter | opaque iterator on which to retrieve the next value |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Fully construct rodbus_request_param_t specifying the value of each field.
unit_id | Modbus address for the request |
timeout | Response timeout for the request |
|
static |
Initialize a retry strategy to defaults.
|
static |
Initialize the configuration to default values.
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.
config | Runtime configuration |
out | Instance of rodbus_runtime_t |
void rodbus_runtime_destroy | ( | rodbus_runtime_t * | instance | ) |
Destroy a runtime.
This method will gracefully wait for all asynchronous operation to end before returning
instance | Instance of rodbus_runtime_t to destroy |
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 spawned tasks to yield.
Setting this value will put a maximum time bound on the eventual shutdown. Threads that have not exited within this timeout will be terminated.
instance | Instance of rodbus_runtime_t |
timeout | Maximum number of seconds to wait for the runtime to shut down (seconds) |
|
static |
Initialize a serial port configuration.
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.
runtime | runtime on which to spawn the server |
path | Path to the serial device. Generally /dev/tty0 on Linux and COM1 on Windows. |
serial_params | Serial port settings |
retry | Parameters that control How long to wait before re-opening the serial port |
endpoints | map of endpoints which is emptied upon passing to this function |
decode_level | Decode levels for this server |
out | RTU server instance |
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.
Recommended port for Modbus is 502.
When the maximum number of concurrent sessions is reached, the oldest session is closed.
runtime | runtime on which to spawn the server |
address | Local IP (v4/v6) address. Accepts '0.0.0.0' (all adapters), '127.0.0.1' (localhost), or the address of a particular network adapter |
port | Port on which to listen |
filter | Filter used to limit which IP address(es) can connect |
max_sessions | Maximum number of concurrent sessions |
endpoints | Map of endpoints which is emptied upon passing to this function |
decode_level | Decode levels for this server |
out | TCP server instance |
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.
This functionality is not standardized by Modbus.org, but nevertheless is commonly implemented
When the maximum number of concurrent sessions is reached, the oldest session is closed.
runtime | runtime on which to spawn the server |
address | Local IP (v4/v6) address. Accepts '0.0.0.0' (all adapters), '127.0.0.1' (localhost), or the address of a particular network adapter |
port | Port on which to listen |
filter | Filter used to limit which IP address(es) can connect |
max_sessions | Maximum number of concurrent sessions |
endpoints | map of endpoints which is emptied upon passing to this function |
tls_config | TLS server configuration |
decode_level | Decode levels for this server |
out | Modbus Security (TLS) server instance |
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.
This server requires that the client certificate contains the role extension and authorizes each request against the supplied handler.
Recommended port for Modbus Security is 802.
When the maximum number of concurrent sessions is reached, the oldest session is closed.
runtime | runtime on which to spawn the server |
address | Local IP (v4/v6) address. Accepts '0.0.0.0' (all adapters), '127.0.0.1' (localhost), or the address of a particular network adapter |
port | Port on which to listen |
filter | Filter used to limit which IP address(es) can connect |
max_sessions | Maximum number of concurrent sessions |
endpoints | map of endpoints which is emptied upon passing to this function |
tls_config | TLS server configuration |
authorization_handler | Authorization handler |
decode_level | Decode levels for this server |
out | Modbus Security (TLS) server instance |
void rodbus_server_destroy | ( | rodbus_server_t * | instance | ) |
Shutdown and release all resources of a running server.
instance | Instance of rodbus_server_t to destroy |
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.
instance | Instance of rodbus_server_t |
level | Decoding level |
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 and call user code to perform the transaction.
instance | Instance of rodbus_server_t |
unit_id | Unit id of the database to update |
transaction | Callback invoked when a lock has been acquired |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Converts the enum to a string.
value | Enum to convert |
|
static |
Initialize a TLS client configuration.
dns_name | Name expected to be in the presented certificate (only in RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED) |
peer_cert_path | Path to the PEM-encoded certificate of the peer |
local_cert_path | Path to the PEM-encoded local certificate |
private_key_path | Path to the the PEM-encoded private key |
password | Optional password if the private key file is encrypted |
|
static |
Initialize a TLS client configuration.
peer_cert_path | Path to the PEM-encoded certificate of the peer |
local_cert_path | Path to the PEM-encoded local certificate |
private_key_path | Path to the the PEM-encoded private key |
password | Optional password if the private key file is encrypted |
const char * rodbus_version | ( | ) |
Get the version of the library as a string.
|
static |
Initialize a rodbus_write_result_t to indicate a standard Modbus exception.
exception | Exception enumeration. If RODBUS_MODBUS_EXCEPTION_UNKNOWN, look at the raw value |
|
static |
Initialize a rodbus_write_result_t to indicate a non-standard Modbus exception.
raw_exception | Raw exception value when rodbus_write_result_t::exception field is RODBUS_MODBUS_EXCEPTION_UNKNOWN |
|
static |
Initialize a rodbus_write_result_t to indicate a successful write operation.