Agile Modbus  1.1.4
Lightweight modbus protocol stack.
agile_modbus.h File Reference

Agile Modbus software package common header file. More...

#include <stdint.h>
#include "agile_modbus_rtu.h"
#include "agile_modbus_tcp.h"
Include dependency graph for agile_modbus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  agile_modbus_sft
 contains the modbus header parameter structure More...
 
struct  agile_modbus_backend
 Agile Modbus backend interface structure. More...
 
struct  agile_modbus
 Agile Modbus structure. More...
 
struct  agile_modbus_slave_info
 Agile Modbus slave information structure. More...
 

Macros

#define AGILE_MODBUS_FC_READ_COILS   0x01
 
#define AGILE_MODBUS_FC_READ_DISCRETE_INPUTS   0x02
 
#define AGILE_MODBUS_FC_READ_HOLDING_REGISTERS   0x03
 
#define AGILE_MODBUS_FC_READ_INPUT_REGISTERS   0x04
 
#define AGILE_MODBUS_FC_WRITE_SINGLE_COIL   0x05
 
#define AGILE_MODBUS_FC_WRITE_SINGLE_REGISTER   0x06
 
#define AGILE_MODBUS_FC_READ_EXCEPTION_STATUS   0x07
 
#define AGILE_MODBUS_FC_WRITE_MULTIPLE_COILS   0x0F
 
#define AGILE_MODBUS_FC_WRITE_MULTIPLE_REGISTERS   0x10
 
#define AGILE_MODBUS_FC_REPORT_SLAVE_ID   0x11
 
#define AGILE_MODBUS_FC_MASK_WRITE_REGISTER   0x16
 
#define AGILE_MODBUS_FC_WRITE_AND_READ_REGISTERS   0x17
 
#define AGILE_MODBUS_VERSION_STRING   "AMB_1.1.4"
 Agile Modbus version number. More...
 
#define AGILE_MODBUS_BROADCAST_ADDRESS   0
 Modbus broadcast address. More...
 
#define AGILE_MODBUS_MAX_PDU_LENGTH   253
 
#define AGILE_MODBUS_MAX_ADU_LENGTH   260
 
Quantity limit of Coils
   Modbus_Application_Protocol_V1_1b.pdf (chapter 6 section 1 page 12)
   Quantity of Coils to read (2 bytes): 1 to 2000 (0x7D0)
   (chapter 6 section 11 page 29)
   Quantity of Coils to write (2 bytes): 1 to 1968 (0x7B0)
#define AGILE_MODBUS_MAX_READ_BITS   2000
 
#define AGILE_MODBUS_MAX_WRITE_BITS   1968
 
Quantity limit of Registers
   Modbus_Application_Protocol_V1_1b.pdf (chapter 6 section 3 page 15)
   Quantity of Registers to read (2 bytes): 1 to 125 (0x7D)
   (chapter 6 section 12 page 31)
   Quantity of Registers to write (2 bytes) 1 to 123 (0x7B)
   (chapter 6 section 17 page 38)
   Quantity of Registers to write in R/W registers (2 bytes) 1 to 121 (0x79)
#define AGILE_MODBUS_MAX_READ_REGISTERS   125
 
#define AGILE_MODBUS_MAX_WRITE_REGISTERS   123
 
#define AGILE_MODBUS_MAX_WR_WRITE_REGISTERS   121
 
#define AGILE_MODBUS_MAX_WR_READ_REGISTERS   125
 

Typedefs

typedef struct agile_modbus_sft agile_modbus_sft_t
 contains the modbus header parameter structure More...
 
typedef struct agile_modbus agile_modbus_t
 Agile Modbus structure. More...
 
typedef struct agile_modbus_backend agile_modbus_backend_t
 Agile Modbus backend interface structure. More...
 
typedef int(* agile_modbus_slave_callback_t) (agile_modbus_t *ctx, struct agile_modbus_slave_info *slave_info, const void *data)
 Slave callback function. More...
 

Enumerations

enum  {
  AGILE_MODBUS_EXCEPTION_ILLEGAL_FUNCTION = 0x01 , AGILE_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS , AGILE_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE , AGILE_MODBUS_EXCEPTION_SLAVE_OR_SERVER_FAILURE ,
  AGILE_MODBUS_EXCEPTION_ACKNOWLEDGE , AGILE_MODBUS_EXCEPTION_SLAVE_OR_SERVER_BUSY , AGILE_MODBUS_EXCEPTION_NEGATIVE_ACKNOWLEDGE , AGILE_MODBUS_EXCEPTION_MEMORY_PARITY ,
  AGILE_MODBUS_EXCEPTION_NOT_DEFINED , AGILE_MODBUS_EXCEPTION_GATEWAY_PATH , AGILE_MODBUS_EXCEPTION_GATEWAY_TARGET , AGILE_MODBUS_EXCEPTION_UNKNOW = 0xff
}
 Modbus exception code. More...
 
enum  agile_modbus_backend_type_t { AGILE_MODBUS_BACKEND_TYPE_RTU = 0 , AGILE_MODBUS_BACKEND_TYPE_TCP }
 @ brief Modbus backend type More...
 
enum  agile_modbus_msg_type_t { AGILE_MODBUS_MSG_INDICATION , AGILE_MODBUS_MSG_CONFIRMATION }
 Modbus received message type. More...
 

Functions

void agile_modbus_common_init (agile_modbus_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz)
 initialize modbus handle More...
 
int agile_modbus_set_slave (agile_modbus_t *ctx, int slave)
 set address More...
 
void agile_modbus_set_compute_meta_length_after_function_cb (agile_modbus_t *ctx, uint8_t(*cb)(agile_modbus_t *ctx, int function, agile_modbus_msg_type_t msg_type))
 sets the data element length callback function to be received after calculating the function code of the modbus object More...
 
void agile_modbus_set_compute_data_length_after_meta_cb (agile_modbus_t *ctx, int(*cb)(agile_modbus_t *ctx, uint8_t *msg, int msg_length, agile_modbus_msg_type_t msg_type))
 sets the data length callback function to be received after calculating the data element of the modbus object More...
 
int agile_modbus_receive_judge (agile_modbus_t *ctx, int msg_length, agile_modbus_msg_type_t msg_type)
 Verify the correctness of received data. More...
 
int agile_modbus_serialize_read_bits (agile_modbus_t *ctx, int addr, int nb)
 
int agile_modbus_deserialize_read_bits (agile_modbus_t *ctx, int msg_length, uint8_t *dest)
 
int agile_modbus_serialize_read_input_bits (agile_modbus_t *ctx, int addr, int nb)
 
int agile_modbus_deserialize_read_input_bits (agile_modbus_t *ctx, int msg_length, uint8_t *dest)
 
int agile_modbus_serialize_read_registers (agile_modbus_t *ctx, int addr, int nb)
 
int agile_modbus_deserialize_read_registers (agile_modbus_t *ctx, int msg_length, uint16_t *dest)
 
int agile_modbus_serialize_read_input_registers (agile_modbus_t *ctx, int addr, int nb)
 
int agile_modbus_deserialize_read_input_registers (agile_modbus_t *ctx, int msg_length, uint16_t *dest)
 
int agile_modbus_serialize_write_bit (agile_modbus_t *ctx, int addr, int status)
 
int agile_modbus_deserialize_write_bit (agile_modbus_t *ctx, int msg_length)
 
int agile_modbus_serialize_write_register (agile_modbus_t *ctx, int addr, const uint16_t value)
 
int agile_modbus_deserialize_write_register (agile_modbus_t *ctx, int msg_length)
 
int agile_modbus_serialize_write_bits (agile_modbus_t *ctx, int addr, int nb, const uint8_t *src)
 
int agile_modbus_deserialize_write_bits (agile_modbus_t *ctx, int msg_length)
 
int agile_modbus_serialize_write_registers (agile_modbus_t *ctx, int addr, int nb, const uint16_t *src)
 
int agile_modbus_deserialize_write_registers (agile_modbus_t *ctx, int msg_length)
 
int agile_modbus_serialize_mask_write_register (agile_modbus_t *ctx, int addr, uint16_t and_mask, uint16_t or_mask)
 
int agile_modbus_deserialize_mask_write_register (agile_modbus_t *ctx, int msg_length)
 
int agile_modbus_serialize_write_and_read_registers (agile_modbus_t *ctx, int write_addr, int write_nb, const uint16_t *src, int read_addr, int read_nb)
 
int agile_modbus_deserialize_write_and_read_registers (agile_modbus_t *ctx, int msg_length, uint16_t *dest)
 
int agile_modbus_serialize_report_slave_id (agile_modbus_t *ctx)
 
int agile_modbus_deserialize_report_slave_id (agile_modbus_t *ctx, int msg_length, int max_dest, uint8_t *dest)
 
int agile_modbus_compute_response_length_from_request (agile_modbus_t *ctx, uint8_t *req)
 Calculate the expected response data length. More...
 
int agile_modbus_serialize_raw_request (agile_modbus_t *ctx, const uint8_t *raw_req, int raw_req_length)
 Pack the original data into a request message. More...
 
int agile_modbus_deserialize_raw_response (agile_modbus_t *ctx, int msg_length)
 parses the original response data More...
 
int agile_modbus_slave_handle (agile_modbus_t *ctx, int msg_length, uint8_t slave_strict, agile_modbus_slave_callback_t slave_cb, const void *slave_data, int *frame_length)
 slave data processing More...
 
void agile_modbus_slave_io_set (uint8_t *buf, int index, int status)
 slave IO settings More...
 
uint8_t agile_modbus_slave_io_get (uint8_t *buf, int index)
 Read slave IO status. More...
 
void agile_modbus_slave_register_set (uint8_t *buf, int index, uint16_t data)
 slave register settings More...
 
uint16_t agile_modbus_slave_register_get (uint8_t *buf, int index)
 Read slave register data. More...
 

Detailed Description

Agile Modbus software package common header file.

Author
Ma Longwei (25440.nosp@m.4721.nosp@m.3@qq..nosp@m.com)
Date
2022-07-28
Attention

© Copyright (c) 2021 Ma Longwei. All rights reserved.

Definition in file agile_modbus.h.