Classes | Macros | Typedefs | Enumerations | Functions | Variables
modbus.h File Reference
#include <stdint.h>
#include <sys/time.h>
#include "libmodbus/modbus-version.h"
#include "modbus-tcp.h"
#include "modbus-rtu.h"
Include dependency graph for modbus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  modbus_mapping_t
 

Macros

#define EMBBADCRC   (EMBXGTAR + 1)
 
#define EMBBADDATA   (EMBXGTAR + 2)
 
#define EMBBADEXC   (EMBXGTAR + 3)
 
#define EMBMDATA   (EMBXGTAR + 5)
 
#define EMBUNKEXC   (EMBXGTAR + 4)
 
#define EMBXACK   (MODBUS_ENOBASE + MODBUS_EXCEPTION_ACKNOWLEDGE)
 
#define EMBXGPATH   (MODBUS_ENOBASE + MODBUS_EXCEPTION_GATEWAY_PATH)
 
#define EMBXGTAR   (MODBUS_ENOBASE + MODBUS_EXCEPTION_GATEWAY_TARGET)
 
#define EMBXILADD   (MODBUS_ENOBASE + MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS)
 
#define EMBXILFUN   (MODBUS_ENOBASE + MODBUS_EXCEPTION_ILLEGAL_FUNCTION)
 
#define EMBXILVAL   (MODBUS_ENOBASE + MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE)
 
#define EMBXMEMPAR   (MODBUS_ENOBASE + MODBUS_EXCEPTION_MEMORY_PARITY)
 
#define EMBXNACK   (MODBUS_ENOBASE + MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE)
 
#define EMBXSBUSY   (MODBUS_ENOBASE + MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY)
 
#define EMBXSFAIL   (MODBUS_ENOBASE + MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE)
 
#define FALSE   0
 
#define MODBUS_BEGIN_DECLS
 
#define MODBUS_BROADCAST_ADDRESS   0
 
#define MODBUS_END_DECLS
 
#define MODBUS_ENOBASE   112345678
 
#define MODBUS_GET_HIGH_BYTE(data)   (((data) >> 8) & 0xFF)
 
#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index)   ((tab_int8[(index)] << 8) + tab_int8[(index) + 1])
 
#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index)   ((tab_int16[(index)] << 16) + tab_int16[(index) + 1])
 
#define MODBUS_GET_LOW_BYTE(data)   ((data) & 0xFF)
 
#define MODBUS_MAX_READ_BITS   2000
 
#define MODBUS_MAX_READ_REGISTERS   125
 
#define MODBUS_MAX_RW_WRITE_REGISTERS   121
 
#define MODBUS_MAX_WRITE_BITS   1968
 
#define MODBUS_MAX_WRITE_REGISTERS   123
 
#define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value)
 
#define OFF   0
 
#define ON   1
 
#define TRUE   1
 

Typedefs

typedef struct _modbus modbus_t
 

Enumerations

enum  {
  MODBUS_EXCEPTION_ILLEGAL_FUNCTION = 0x01, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE,
  MODBUS_EXCEPTION_ACKNOWLEDGE, MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY, MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE, MODBUS_EXCEPTION_MEMORY_PARITY,
  MODBUS_EXCEPTION_NOT_DEFINED, MODBUS_EXCEPTION_GATEWAY_PATH, MODBUS_EXCEPTION_GATEWAY_TARGET, MODBUS_EXCEPTION_MAX
}
 
enum  modbus_error_recovery_mode { MODBUS_ERROR_RECOVERY_NONE = 0, MODBUS_ERROR_RECOVERY_LINK = (1<<1), MODBUS_ERROR_RECOVERY_PROTOCOL = (1<<2) }
 

Functions

void modbus_close (modbus_t *ctx)
 
int modbus_connect (modbus_t *ctx)
 
int modbus_flush (modbus_t *ctx)
 
void modbus_free (modbus_t *ctx)
 
uint8_t modbus_get_byte_from_bits (const uint8_t *src, int index, unsigned int nb_bits)
 
void modbus_get_byte_timeout (modbus_t *ctx, struct timeval *timeout)
 
float modbus_get_float (const uint16_t *src)
 
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_coil_status, int nb_input_status, int nb_holding_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_receive_from (modbus_t *ctx, int sockfd, uint8_t *req)
 
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_bits_from_byte (uint8_t *dest, int index, const uint8_t value)
 
void modbus_set_bits_from_bytes (uint8_t *dest, int index, unsigned int nb_bits, const uint8_t *tab_byte)
 
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_float (float f, uint16_t *dest)
 
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 coil_addr, int status)
 
int modbus_write_bits (modbus_t *ctx, int addr, int nb, const uint8_t *data)
 
int modbus_write_register (modbus_t *ctx, int reg_addr, int value)
 
int modbus_write_registers (modbus_t *ctx, int addr, int nb, const uint16_t *data)
 

Variables

const unsigned int libmodbus_version_major
 
const unsigned int libmodbus_version_micro
 
const unsigned int libmodbus_version_minor
 

Macro Definition Documentation

#define EMBBADCRC   (EMBXGTAR + 1)

Definition at line 115 of file modbus.h.

#define EMBBADDATA   (EMBXGTAR + 2)

Definition at line 116 of file modbus.h.

#define EMBBADEXC   (EMBXGTAR + 3)

Definition at line 117 of file modbus.h.

#define EMBMDATA   (EMBXGTAR + 5)

Definition at line 119 of file modbus.h.

#define EMBUNKEXC   (EMBXGTAR + 4)

Definition at line 118 of file modbus.h.

#define EMBXACK   (MODBUS_ENOBASE + MODBUS_EXCEPTION_ACKNOWLEDGE)

Definition at line 107 of file modbus.h.

#define EMBXGPATH   (MODBUS_ENOBASE + MODBUS_EXCEPTION_GATEWAY_PATH)

Definition at line 111 of file modbus.h.

Definition at line 112 of file modbus.h.

Definition at line 104 of file modbus.h.

Definition at line 103 of file modbus.h.

Definition at line 105 of file modbus.h.

#define EMBXMEMPAR   (MODBUS_ENOBASE + MODBUS_EXCEPTION_MEMORY_PARITY)

Definition at line 110 of file modbus.h.

Definition at line 109 of file modbus.h.

Definition at line 108 of file modbus.h.

Definition at line 106 of file modbus.h.

#define FALSE   0

Definition at line 48 of file modbus.h.

#define MODBUS_BEGIN_DECLS

Definition at line 41 of file modbus.h.

#define MODBUS_BROADCAST_ADDRESS   0

Definition at line 63 of file modbus.h.

#define MODBUS_END_DECLS

Definition at line 42 of file modbus.h.

#define MODBUS_ENOBASE   112345678

Definition at line 85 of file modbus.h.

#define MODBUS_GET_HIGH_BYTE (   data)    (((data) >> 8) & 0xFF)

UTILS FUNCTIONS

Definition at line 201 of file modbus.h.

#define MODBUS_GET_INT16_FROM_INT8 (   tab_int8,
  index 
)    ((tab_int8[(index)] << 8) + tab_int8[(index) + 1])

Definition at line 204 of file modbus.h.

#define MODBUS_GET_INT32_FROM_INT16 (   tab_int16,
  index 
)    ((tab_int16[(index)] << 16) + tab_int16[(index) + 1])

Definition at line 203 of file modbus.h.

#define MODBUS_GET_LOW_BYTE (   data)    ((data) & 0xFF)

Definition at line 202 of file modbus.h.

#define MODBUS_MAX_READ_BITS   2000

Definition at line 70 of file modbus.h.

#define MODBUS_MAX_READ_REGISTERS   125

Definition at line 80 of file modbus.h.

#define MODBUS_MAX_RW_WRITE_REGISTERS   121

Definition at line 82 of file modbus.h.

#define MODBUS_MAX_WRITE_BITS   1968

Definition at line 71 of file modbus.h.

#define MODBUS_MAX_WRITE_REGISTERS   123

Definition at line 81 of file modbus.h.

#define MODBUS_SET_INT16_TO_INT8 (   tab_int8,
  index,
  value 
)
Value:
do { \
tab_int8[(index)] = (value) >> 8; \
tab_int8[(index) + 1] = (value) & 0xFF; \
} while (0)

Definition at line 205 of file modbus.h.

#define OFF   0

Definition at line 56 of file modbus.h.

#define ON   1

Definition at line 60 of file modbus.h.

#define TRUE   1

Definition at line 52 of file modbus.h.

Typedef Documentation

typedef struct _modbus modbus_t

Definition at line 125 of file modbus.h.

Enumeration Type Documentation

anonymous enum
Enumerator
MODBUS_EXCEPTION_ILLEGAL_FUNCTION 
MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS 
MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE 
MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE 
MODBUS_EXCEPTION_ACKNOWLEDGE 
MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY 
MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE 
MODBUS_EXCEPTION_MEMORY_PARITY 
MODBUS_EXCEPTION_NOT_DEFINED 
MODBUS_EXCEPTION_GATEWAY_PATH 
MODBUS_EXCEPTION_GATEWAY_TARGET 
MODBUS_EXCEPTION_MAX 

Definition at line 88 of file modbus.h.

Enumerator
MODBUS_ERROR_RECOVERY_NONE 
MODBUS_ERROR_RECOVERY_LINK 
MODBUS_ERROR_RECOVERY_PROTOCOL 

Definition at line 138 of file modbus.h.

Function Documentation

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.

uint8_t modbus_get_byte_from_bits ( const uint8_t *  src,
int  index,
unsigned int  nb_bits 
)

Definition at line 57 of file modbus-data.c.

void modbus_get_byte_timeout ( modbus_t ctx,
struct timeval *  timeout 
)

Definition at line 1500 of file modbus.c.

float modbus_get_float ( const uint16_t *  src)

Definition at line 77 of file modbus-data.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_coil_status,
int  nb_input_status,
int  nb_holding_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_receive_from ( modbus_t ctx,
int  sockfd,
uint8_t *  req 
)
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_bits_from_byte ( uint8_t *  dest,
int  index,
const uint8_t  value 
)

Definition at line 30 of file modbus-data.c.

void modbus_set_bits_from_bytes ( uint8_t *  dest,
int  index,
unsigned int  nb_bits,
const uint8_t *  tab_byte 
)

Definition at line 41 of file modbus-data.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_float ( float  f,
uint16_t *  dest 
)

Definition at line 89 of file modbus-data.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  coil_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 *  data 
)

Definition at line 1231 of file modbus.c.

int modbus_write_register ( modbus_t ctx,
int  reg_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 *  data 
)

Definition at line 1290 of file modbus.c.

Variable Documentation

const unsigned int libmodbus_version_major

Definition at line 39 of file modbus.c.

const unsigned int libmodbus_version_micro

Definition at line 41 of file modbus.c.

const unsigned int libmodbus_version_minor

Definition at line 40 of file modbus.c.



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