Rodbus-FFI
0.1.1
Idiomatic C API to the Rodbus crate via Rust FFI
|
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "prelude.h"
Go to the source code of this file.
Classes | |
struct | Session |
Struct that bundles together the types needed to make requests on a channel. More... | |
struct | Callbacks |
struct | Sizes |
struct | RuntimeConfig |
Optional non-default configuration of the Tokio runtime. More... | |
struct | Bit |
struct | Register |
struct | Result |
Type that describes the success or failure of an operation. More... | |
Macros | |
#define | MAX_READ_COILS_COUNT 2000 |
#define | MAX_READ_REGISTERS_COUNT 125 |
#define | MAX_WRITE_COILS_COUNT 1968 |
#define | MAX_WRITE_REGISTERS_COUNT 123 |
Typedefs | |
typedef uint8_t | Exception |
typedef uint8_t | Level |
typedef uint8_t | Status |
typedef struct BitIterator | BitIterator |
typedef struct Handler | Handler |
typedef struct RegisterIterator | RegisterIterator |
typedef struct ServerHandle | ServerHandle |
typedef struct Updater | Updater |
typedef struct Session | Session |
Struct that bundles together the types needed to make requests on a channel. More... | |
typedef bool(* | WriteSingleCallback_bool) (bool, uint16_t, void *) |
typedef bool(* | WriteSingleCallback_u16) (uint16_t, uint16_t, void *) |
typedef bool(* | WriteMultipleCallback_bool) (const bool *, uint16_t, uint16_t, void *) |
typedef bool(* | WriteMultipleCallback_u16) (const uint16_t *, uint16_t, uint16_t, void *) |
typedef struct Callbacks | Callbacks |
typedef struct Sizes | Sizes |
typedef struct RuntimeConfig | RuntimeConfig |
Optional non-default configuration of the Tokio runtime. More... | |
typedef struct Bit | Bit |
typedef struct Register | Register |
typedef struct Result | Result |
Type that describes the success or failure of an operation. More... | |
Functions | |
Updater * | acquire_updater (Handler *handler) |
Session | build_session (Runtime *runtime, Channel *channel, uint8_t unit_id, uint32_t timeout_ms) |
Convenience function to build a session struct. More... | |
Callbacks | create_callbacks (WriteSingleCallback_bool write_single_coil_cb, WriteSingleCallback_u16 write_single_register_cb, WriteMultipleCallback_bool write_multiple_coils, WriteMultipleCallback_u16 write_multiple_registers) |
Handler * | create_handler (Runtime *runtime, Sizes sizes, Callbacks callbacks, void *user_data) |
ServerHandle * | create_server (Runtime *runtime, const char *address, uint8_t unit_id, Handler *handler) |
Sizes | create_sizes (uint16_t num_coils, uint16_t num_discrete_inputs, uint16_t num_holding_registers, uint16_t num_input_registers) |
Channel * | create_tcp_client (Runtime *runtime, const char *address, uint16_t max_queued_requests) |
Create an instance of a TCP client channel. More... | |
Runtime * | create_threaded_runtime (const RuntimeConfig *config) |
create an instance of the multi-threaded work-stealing Tokio runtime More... | |
void | destroy_channel (Channel *channel) |
Destroy a previously created channel instance. More... | |
void | destroy_handler (Handler *handler) |
void | destroy_runtime (Runtime *runtime) |
Destroy a previously created runtime instance. More... | |
void | destroy_server (ServerHandle *handle) |
bool | get_next_bit (BitIterator *iterator, Bit *value) |
retrieve the next bit and/or index from iterator More... | |
bool | get_next_register (RegisterIterator *iterator, Register *value) |
retrieve the next register value and/or index from iterator More... | |
Result | read_coils (Session *session, uint16_t start, uint16_t count, bool *output) |
perform a blocking operation to read coils More... | |
void | read_coils_cb (Session *session, uint16_t start, uint16_t count, void(*callback)(Result, BitIterator *, void *), void *user_data) |
perform a non-blocking operation to read coils More... | |
Result | read_discrete_inputs (Session *session, uint16_t start, uint16_t count, bool *output) |
perform a blocking operation to read discrete inputs More... | |
void | read_discrete_inputs_cb (Session *session, uint16_t start, uint16_t count, void(*callback)(Result, BitIterator *, void *), void *user_data) |
perform a non-blocking operation to read discrete inputs More... | |
Result | read_holding_registers (Session *session, uint16_t start, uint16_t count, uint16_t *output) |
perform a blocking operation to read holding registers More... | |
void | read_holding_registers_cb (Session *session, uint16_t start, uint16_t count, void(*callback)(Result, RegisterIterator *, void *), void *user_data) |
perform a non-blocking operation to read holding registers More... | |
Result | read_input_registers (Session *session, uint16_t start, uint16_t count, uint16_t *output) |
perform a blocking operation to read input registers More... | |
void | read_input_registers_cb (Session *session, uint16_t start, uint16_t count, void(*callback)(Result, RegisterIterator *, void *), void *user_data) |
perform a non-blocking operation to read input registers More... | |
void | release_updater (Updater *updater) |
bool | set_log_callback (void(*callback)(Level level, const char *message)) |
set the callback to invoke when an enabled level is logged More... | |
void | set_max_level (Level level) |
set the maximum log level More... | |
bool | update_coil (Updater *updater, bool value, uint16_t index) |
void | update_handler (Handler *handler, void *user_data, void(*callback)(Updater *, void *)) |
Result | write_multiple_coils (Session *session, uint16_t start, const bool *values, uint16_t count) |
perform a blocking operation to write multiple coils More... | |
void | write_multiple_coils_cb (Session *session, uint16_t start, const bool *values, uint16_t count, void(*callback)(Result, void *), void *user_data) |
perform a non-blocking operation to write multiple coils More... | |
Result | write_multiple_registers (Session *session, uint16_t start, const uint16_t *values, uint16_t count) |
perform a blocking operation to write multiple registers More... | |
void | write_multiple_registers_cb (Session *session, uint16_t start, const uint16_t *values, uint16_t count, void(*callback)(Result, void *), void *user_data) |
perform a non-blocking operation to write multiple registers More... | |
Result | write_single_coil (Session *session, uint16_t index, bool value) |
perform a blocking operation to write a single coil More... | |
void | write_single_coil_cb (Session *session, uint16_t index, bool value, void(*callback)(Result, void *), void *user_data) |
perform a non-blocking operation to write a single coil More... | |
Result | write_single_register (Session *session, uint16_t index, uint16_t value) |
perform a blocking operation to write a single register More... | |
void | write_single_register_cb (Session *session, uint16_t index, uint16_t value, void(*callback)(Result, void *), void *user_data) |
perform a non-blocking operation to write a single register More... | |
#define MAX_READ_COILS_COUNT 2000 |
Maximum count allowed in a read coils/discrete inputs request
#define MAX_READ_REGISTERS_COUNT 125 |
Maximum count allowed in a read holding/input registers request
#define MAX_WRITE_COILS_COUNT 1968 |
Maximum count allowed in a write multiple coils
request
#define MAX_WRITE_REGISTERS_COUNT 123 |
Maximum count allowed in a write multiple registers
request
typedef struct BitIterator BitIterator |
typedef uint8_t Exception |
typedef uint8_t Level |
typedef struct RegisterIterator RegisterIterator |
typedef struct RuntimeConfig RuntimeConfig |
Optional non-default configuration of the Tokio runtime.
typedef struct ServerHandle ServerHandle |
Struct that bundles together the types needed to make requests on a channel.
typedef uint8_t Status |
typedef bool(* WriteMultipleCallback_bool) (const bool *, uint16_t, uint16_t, void *) |
typedef bool(* WriteMultipleCallback_u16) (const uint16_t *, uint16_t, uint16_t, void *) |
typedef bool(* WriteSingleCallback_bool) (bool, uint16_t, void *) |
typedef bool(* WriteSingleCallback_u16) (uint16_t, uint16_t, void *) |
enum Exception |
Exception values from the Modbus specification
enum Level |
enum Status |
Status returned during synchronous and asynchronous API calls
Session build_session | ( | Runtime * | runtime, |
Channel * | channel, | ||
uint8_t | unit_id, | ||
uint32_t | timeout_ms | ||
) |
Convenience function to build a session struct.
This function does not allocate and is merely a helper function create the Session struct.
runtime | pointer to the Runtime that will be used to make requests on the channel |
channel | pointer to the Channel on which requests associated with the built Session will be made |
unit_id | Modbus unit identifier of the server |
timeout_ms | timeout in milliseconds for any requests made via this session object |
Callbacks create_callbacks | ( | WriteSingleCallback_bool | write_single_coil_cb, |
WriteSingleCallback_u16 | write_single_register_cb, | ||
WriteMultipleCallback_bool | write_multiple_coils, | ||
WriteMultipleCallback_u16 | write_multiple_registers | ||
) |
ServerHandle* create_server | ( | Runtime * | runtime, |
const char * | address, | ||
uint8_t | unit_id, | ||
Handler * | handler | ||
) |
Sizes create_sizes | ( | uint16_t | num_coils, |
uint16_t | num_discrete_inputs, | ||
uint16_t | num_holding_registers, | ||
uint16_t | num_input_registers | ||
) |
Channel* create_tcp_client | ( | Runtime * | runtime, |
const char * | address, | ||
uint16_t | max_queued_requests | ||
) |
Create an instance of a TCP client channel.
This function allocates an opaque struct which must be later destroyed using destroy_channel()
runtime | pointer to the Runtime that will be used to run the channel task |
address | string representation on an IPv4 or IPv6 address and port, e.g. "127.0.0.1:502" |
max_queued_requests | Maximum number of queued requests that will be accepted before back-pressure (blocking) is applied |
Runtime* create_threaded_runtime | ( | const RuntimeConfig * | config | ) |
create an instance of the multi-threaded work-stealing Tokio runtime
This instance is typically created at the beginning of your program and destroyed using destroy_runtime() before your program exits.
config | Optional configuration of the runtime. If "config" is NULL, default settings are applied |
void destroy_channel | ( | Channel * | channel | ) |
Destroy a previously created channel instance.
This operation stops channel task execution. Any pending asynchronous callbacks may not complete, and no further Modbus requests on this channel should be made after this call.
channel | Channel to stop and destroy |
void destroy_handler | ( | Handler * | handler | ) |
void destroy_runtime | ( | Runtime * | runtime | ) |
Destroy a previously created runtime instance.
This operation is typically performed just before program exit. It blocks until the runtime stops and all operations are canceled. Any pending asynchronous callbacks may not complete, and no further Modbus requests can be made after this call using this runtime and any channels or sessions created from it
runtime | Runtime to stop and destroy |
void destroy_server | ( | ServerHandle * | handle | ) |
bool get_next_bit | ( | BitIterator * | iterator, |
Bit * | value | ||
) |
retrieve the next bit and/or index from iterator
pointer | to the iterator |
pointer | to the value to write (output param) |
pointer | to the value to write (output param) |
bool get_next_register | ( | RegisterIterator * | iterator, |
Register * | value | ||
) |
retrieve the next register value and/or index from iterator
pointer | to the iterator |
pointer | to the value to write (output param) |
pointer | to the value to write (output param) |
perform a blocking operation to read coils
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
output | buffer that is written on success. |
void read_coils_cb | ( | Session * | session, |
uint16_t | start, | ||
uint16_t | count, | ||
void(*)(Result, BitIterator *, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to read coils
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data providing context to the callback |
perform a blocking operation to read discrete inputs
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
output | buffer that is written on success. |
void read_discrete_inputs_cb | ( | Session * | session, |
uint16_t | start, | ||
uint16_t | count, | ||
void(*)(Result, BitIterator *, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to read discrete inputs
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data providing context to the callback |
Result read_holding_registers | ( | Session * | session, |
uint16_t | start, | ||
uint16_t | count, | ||
uint16_t * | output | ||
) |
perform a blocking operation to read holding registers
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
output | buffer that is written on success. |
void read_holding_registers_cb | ( | Session * | session, |
uint16_t | start, | ||
uint16_t | count, | ||
void(*)(Result, RegisterIterator *, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to read holding registers
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data providing context to the callback |
Result read_input_registers | ( | Session * | session, |
uint16_t | start, | ||
uint16_t | count, | ||
uint16_t * | output | ||
) |
perform a blocking operation to read input registers
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
output | buffer that is written on success. |
void read_input_registers_cb | ( | Session * | session, |
uint16_t | start, | ||
uint16_t | count, | ||
void(*)(Result, RegisterIterator *, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to read input registers
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address for the operation |
count | count of items for the operation |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data providing context to the callback |
void release_updater | ( | Updater * | updater | ) |
bool set_log_callback | ( | void(*)(Level level, const char *message) | callback | ) |
set the callback to invoke when an enabled level is logged
callback | Callback function to invoke |
void set_max_level | ( | Level | level | ) |
set the maximum log level
level | maximum level at which messages will be logged |
bool update_coil | ( | Updater * | updater, |
bool | value, | ||
uint16_t | index | ||
) |
Result write_multiple_coils | ( | Session * | session, |
uint16_t | start, | ||
const bool * | values, | ||
uint16_t | count | ||
) |
perform a blocking operation to write multiple coils
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address of the values |
values | array of values to write |
count | of values to write |
void write_multiple_coils_cb | ( | Session * | session, |
uint16_t | start, | ||
const bool * | values, | ||
uint16_t | count, | ||
void(*)(Result, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to write multiple coils
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address of the values |
values | array of values to write |
count | count of values to write |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data data providing context to the callback |
Result write_multiple_registers | ( | Session * | session, |
uint16_t | start, | ||
const uint16_t * | values, | ||
uint16_t | count | ||
) |
perform a blocking operation to write multiple registers
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address of the values |
values | array of values to write |
count | of values to write |
void write_multiple_registers_cb | ( | Session * | session, |
uint16_t | start, | ||
const uint16_t * | values, | ||
uint16_t | count, | ||
void(*)(Result, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to write multiple registers
session | pointer to the Session struct that provides the runtime, channel, etc |
start | starting address of the values |
values | array of values to write |
count | count of values to write |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data data providing context to the callback |
void write_single_coil_cb | ( | Session * | session, |
uint16_t | index, | ||
bool | value, | ||
void(*)(Result, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to write a single coil
session | pointer to the Session struct that provides the runtime, channel, etc |
index | address of the value |
value | value to write |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data data providing context to the callback |
void write_single_register_cb | ( | Session * | session, |
uint16_t | index, | ||
uint16_t | value, | ||
void(*)(Result, void *) | callback, | ||
void * | user_data | ||
) |
perform a non-blocking operation to write a single register
session | pointer to the Session struct that provides the runtime, channel, etc |
index | address of the value |
value | value to write |
callback | callback function to invoke when the operation completes |
user_data | pointer to optional user data data providing context to the callback |