nanoMODBUS
|
#include <nanomodbus.h>
Data Fields | |
nmbs_transport | transport |
int32_t(* | read )(uint8_t *buf, uint16_t count, int32_t byte_timeout_ms, void *arg) |
int32_t(* | write )(const uint8_t *buf, uint16_t count, int32_t byte_timeout_ms, void *arg) |
uint16_t(* | crc_calc )(const uint8_t *data, uint32_t length, void *arg) |
void * | arg |
uint32_t | initialized |
nanoMODBUS platform configuration struct. Passed to nmbs_server_create() and nmbs_client_create().
read() and write() are the platform-specific methods that read/write data to/from a serial port or a TCP connection.
Both methods should block until either:
count
bytes of data are read/writtenbyte_timeout_ms >= 0
, expiresA value < 0
for byte_timeout_ms
means no timeout.
Their return value should be the number of bytes actually read/written, or < 0
in case of error. A return value between 0
and count - 1
will be treated as if a timeout occurred on the transport side. All other values will be treated as transport errors.
Additionally, an optional crc_calc() function can be defined to override the default nanoMODBUS CRC calculation function.
These methods accept a pointer to arbitrary user-data, which is the arg member of this struct. After the creation of an instance it can be changed with nmbs_set_platform_arg().
void* nmbs_platform_conf::arg |
User data, will be passed to functions above
uint16_t(* nmbs_platform_conf::crc_calc) (const uint8_t *data, uint32_t length, void *arg) |
CRC calculation function pointer. Optional
uint32_t nmbs_platform_conf::initialized |
Reserved, workaround for older user code not calling nmbs_platform_conf_create()
int32_t(* nmbs_platform_conf::read) (uint8_t *buf, uint16_t count, int32_t byte_timeout_ms, void *arg) |
Bytes read transport function pointer
nmbs_transport nmbs_platform_conf::transport |
Transport type
int32_t(* nmbs_platform_conf::write) (const uint8_t *buf, uint16_t count, int32_t byte_timeout_ms, void *arg) |
Bytes write transport function pointer