Macros | Enumerations | Functions | Variables
modbus.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <libmodbus/config.h>
#include "libmodbus/modbus.h"
#include "libmodbus/modbus-private.h"
Include dependency graph for modbus.c:

Go to the source code of this file.

Macros

#define MAX_MESSAGE_LENGTH   260
 
#define MSG_LENGTH_UNDEFINED   -1
 

Enumerations

enum  _step_t { _STEP_FUNCTION, _STEP_META, _STEP_DATA }
 
enum  msg_type_t { MSG_INDICATION, MSG_CONFIRMATION }
 

Functions

void _error_print (modbus_t *ctx, const char *context)
 
void _modbus_init_common (modbus_t *ctx)
 
int _sleep_and_flush (modbus_t *ctx)
 
static int check_confirmation (modbus_t *ctx, uint8_t *req, uint8_t *rsp, int rsp_length)
 
static int compute_data_length_after_meta (modbus_t *ctx, uint8_t *msg, msg_type_t msg_type)
 
static uint8_t compute_meta_length_after_function (int function, msg_type_t msg_type)
 
static unsigned int compute_response_length_from_request (modbus_t *ctx, uint8_t *req)
 
void modbus_close (modbus_t *ctx)
 
int modbus_connect (modbus_t *ctx)
 
int modbus_flush (modbus_t *ctx)
 
void modbus_free (modbus_t *ctx)
 
void modbus_get_byte_timeout (modbus_t *ctx, struct timeval *timeout)
 
int modbus_get_header_length (modbus_t *ctx)
 
void modbus_get_response_timeout (modbus_t *ctx, struct timeval *timeout)
 
int modbus_get_socket (modbus_t *ctx)
 
void modbus_mapping_free (modbus_mapping_t *mb_mapping)
 
modbus_mapping_tmodbus_mapping_new (int nb_bits, int nb_input_bits, int nb_registers, int nb_input_registers)
 
int modbus_read_bits (modbus_t *ctx, int addr, int nb, uint8_t *dest)
 
int modbus_read_input_bits (modbus_t *ctx, int addr, int nb, uint8_t *dest)
 
int modbus_read_input_registers (modbus_t *ctx, int addr, int nb, uint16_t *dest)
 
int modbus_read_registers (modbus_t *ctx, int addr, int nb, uint16_t *dest)
 
int modbus_receive (modbus_t *ctx, uint8_t *req)
 
int modbus_receive_confirmation (modbus_t *ctx, uint8_t *rsp)
 
int modbus_reply (modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_mapping)
 
int modbus_reply_exception (modbus_t *ctx, const uint8_t *req, unsigned int exception_code)
 
int modbus_report_slave_id (modbus_t *ctx, uint8_t *dest)
 
int modbus_send_raw_request (modbus_t *ctx, uint8_t *raw_req, int raw_req_length)
 
void modbus_set_byte_timeout (modbus_t *ctx, const struct timeval *timeout)
 
void modbus_set_debug (modbus_t *ctx, int boolean)
 
int modbus_set_error_recovery (modbus_t *ctx, modbus_error_recovery_mode error_recovery)
 
void modbus_set_response_timeout (modbus_t *ctx, const struct timeval *timeout)
 
int modbus_set_slave (modbus_t *ctx, int slave)
 
void modbus_set_socket (modbus_t *ctx, int socket)
 
const char * modbus_strerror (int errnum)
 
int modbus_write_and_read_registers (modbus_t *ctx, int write_addr, int write_nb, const uint16_t *src, int read_addr, int read_nb, uint16_t *dest)
 
int modbus_write_bit (modbus_t *ctx, int addr, int status)
 
int modbus_write_bits (modbus_t *ctx, int addr, int nb, const uint8_t *src)
 
int modbus_write_register (modbus_t *ctx, int addr, int value)
 
int modbus_write_registers (modbus_t *ctx, int addr, int nb, const uint16_t *src)
 
static int read_io_status (modbus_t *ctx, int function, int addr, int nb, uint8_t *dest)
 
static int read_registers (modbus_t *ctx, int function, int addr, int nb, uint16_t *dest)
 
static int receive_msg (modbus_t *ctx, uint8_t *msg, msg_type_t msg_type)
 
static int response_exception (modbus_t *ctx, sft_t *sft, int exception_code, uint8_t *rsp)
 
static int response_io_status (int address, int nb, uint8_t *tab_io_status, uint8_t *rsp, int offset)
 
static int send_msg (modbus_t *ctx, uint8_t *msg, int msg_length)
 
size_t strlcpy (char *dest, const char *src, size_t dest_size)
 
static int write_single (modbus_t *ctx, int function, int addr, int value)
 

Variables

const unsigned int libmodbus_version_major = LIBMODBUS_VERSION_MAJOR
 
const unsigned int libmodbus_version_micro = LIBMODBUS_VERSION_MICRO
 
const unsigned int libmodbus_version_minor = LIBMODBUS_VERSION_MINOR
 

Macro Definition Documentation

#define MAX_MESSAGE_LENGTH   260

Definition at line 44 of file modbus.c.

#define MSG_LENGTH_UNDEFINED   -1

Definition at line 36 of file modbus.c.

Enumeration Type Documentation

enum _step_t
Enumerator
_STEP_FUNCTION 
_STEP_META 
_STEP_DATA 

Definition at line 47 of file modbus.c.

enum msg_type_t
Enumerator
MSG_INDICATION 
MSG_CONFIRMATION 

Definition at line 238 of file modbus.c.

Function Documentation

void _error_print ( modbus_t ctx,
const char *  context 
)

Definition at line 88 of file modbus.c.

void _modbus_init_common ( modbus_t ctx)

Definition at line 1448 of file modbus.c.

int _sleep_and_flush ( modbus_t ctx)

Definition at line 100 of file modbus.c.

static int check_confirmation ( modbus_t ctx,
uint8_t *  req,
uint8_t *  rsp,
int  rsp_length 
)
static

Definition at line 478 of file modbus.c.

static int compute_data_length_after_meta ( modbus_t ctx,
uint8_t *  msg,
msg_type_t  msg_type 
)
static

Definition at line 281 of file modbus.c.

static uint8_t compute_meta_length_after_function ( int  function,
msg_type_t  msg_type 
)
static

Definition at line 246 of file modbus.c.

static unsigned int compute_response_length_from_request ( modbus_t ctx,
uint8_t *  req 
)
static

Definition at line 128 of file modbus.c.

void modbus_close ( modbus_t ctx)

Definition at line 1520 of file modbus.c.

int modbus_connect ( modbus_t ctx)

Definition at line 1515 of file modbus.c.

int modbus_flush ( modbus_t ctx)

Definition at line 118 of file modbus.c.

void modbus_free ( modbus_t ctx)

Definition at line 1528 of file modbus.c.

void modbus_get_byte_timeout ( modbus_t ctx,
struct timeval *  timeout 
)

Definition at line 1500 of file modbus.c.

int modbus_get_header_length ( modbus_t ctx)

Definition at line 1510 of file modbus.c.

void modbus_get_response_timeout ( modbus_t ctx,
struct timeval *  timeout 
)

Definition at line 1489 of file modbus.c.

int modbus_get_socket ( modbus_t ctx)

Definition at line 1483 of file modbus.c.

void modbus_mapping_free ( modbus_mapping_t mb_mapping)

Definition at line 1625 of file modbus.c.

modbus_mapping_t* modbus_mapping_new ( int  nb_bits,
int  nb_input_bits,
int  nb_registers,
int  nb_input_registers 
)

Definition at line 1547 of file modbus.c.

int modbus_read_bits ( modbus_t ctx,
int  addr,
int  nb,
uint8_t *  dest 
)

Definition at line 1059 of file modbus.c.

int modbus_read_input_bits ( modbus_t ctx,
int  addr,
int  nb,
uint8_t *  dest 
)

Definition at line 1083 of file modbus.c.

int modbus_read_input_registers ( modbus_t ctx,
int  addr,
int  nb,
uint16_t *  dest 
)

Definition at line 1173 of file modbus.c.

int modbus_read_registers ( modbus_t ctx,
int  addr,
int  nb,
uint16_t *  dest 
)

Definition at line 1153 of file modbus.c.

int modbus_receive ( modbus_t ctx,
uint8_t *  req 
)

Definition at line 460 of file modbus.c.

int modbus_receive_confirmation ( modbus_t ctx,
uint8_t *  rsp 
)

Definition at line 473 of file modbus.c.

int modbus_reply ( modbus_t ctx,
const uint8_t *  req,
int  req_length,
modbus_mapping_t mb_mapping 
)

Definition at line 641 of file modbus.c.

int modbus_reply_exception ( modbus_t ctx,
const uint8_t *  req,
unsigned int  exception_code 
)

Definition at line 982 of file modbus.c.

int modbus_report_slave_id ( modbus_t ctx,
uint8_t *  dest 
)

Definition at line 1410 of file modbus.c.

int modbus_send_raw_request ( modbus_t ctx,
uint8_t *  raw_req,
int  raw_req_length 
)

Definition at line 204 of file modbus.c.

void modbus_set_byte_timeout ( modbus_t ctx,
const struct timeval *  timeout 
)

Definition at line 1505 of file modbus.c.

void modbus_set_debug ( modbus_t ctx,
int  boolean 
)

Definition at line 1537 of file modbus.c.

int modbus_set_error_recovery ( modbus_t ctx,
modbus_error_recovery_mode  error_recovery 
)

Definition at line 1470 of file modbus.c.

void modbus_set_response_timeout ( modbus_t ctx,
const struct timeval *  timeout 
)

Definition at line 1494 of file modbus.c.

int modbus_set_slave ( modbus_t ctx,
int  slave 
)

Definition at line 1465 of file modbus.c.

void modbus_set_socket ( modbus_t ctx,
int  socket 
)

Definition at line 1478 of file modbus.c.

const char* modbus_strerror ( int  errnum)

Definition at line 53 of file modbus.c.

int modbus_write_and_read_registers ( modbus_t ctx,
int  write_addr,
int  write_nb,
const uint16_t *  src,
int  read_addr,
int  read_nb,
uint16_t *  dest 
)

Definition at line 1336 of file modbus.c.

int modbus_write_bit ( modbus_t ctx,
int  addr,
int  status 
)

Definition at line 1218 of file modbus.c.

int modbus_write_bits ( modbus_t ctx,
int  addr,
int  nb,
const uint8_t *  src 
)

Definition at line 1231 of file modbus.c.

int modbus_write_register ( modbus_t ctx,
int  addr,
int  value 
)

Definition at line 1225 of file modbus.c.

int modbus_write_registers ( modbus_t ctx,
int  addr,
int  nb,
const uint16_t *  src 
)

Definition at line 1290 of file modbus.c.

static int read_io_status ( modbus_t ctx,
int  function,
int  addr,
int  nb,
uint8_t *  dest 
)
static

Definition at line 1014 of file modbus.c.

static int read_registers ( modbus_t ctx,
int  function,
int  addr,
int  nb,
uint16_t *  dest 
)
static

Definition at line 1106 of file modbus.c.

static int receive_msg ( modbus_t ctx,
uint8_t *  msg,
msg_type_t  msg_type 
)
static

Definition at line 329 of file modbus.c.

static int response_exception ( modbus_t ctx,
sft_t sft,
int  exception_code,
uint8_t *  rsp 
)
static

Definition at line 621 of file modbus.c.

static int response_io_status ( int  address,
int  nb,
uint8_t *  tab_io_status,
uint8_t *  rsp,
int  offset 
)
static

Definition at line 595 of file modbus.c.

static int send_msg ( modbus_t ctx,
uint8_t *  msg,
int  msg_length 
)
static

Definition at line 162 of file modbus.c.

size_t strlcpy ( char *  dest,
const char *  src,
size_t  dest_size 
)

Definition at line 1651 of file modbus.c.

static int write_single ( modbus_t ctx,
int  function,
int  addr,
int  value 
)
static

Definition at line 1194 of file modbus.c.

Variable Documentation

const unsigned int libmodbus_version_major = LIBMODBUS_VERSION_MAJOR

Definition at line 39 of file modbus.c.

const unsigned int libmodbus_version_micro = LIBMODBUS_VERSION_MICRO

Definition at line 41 of file modbus.c.

const unsigned int libmodbus_version_minor = LIBMODBUS_VERSION_MINOR

Definition at line 40 of file modbus.c.



libmodbus
Author(s):
autogenerated on Sat Nov 21 2020 03:17:32