Agile Modbus 1.1.1
Lightweight modbus protocol stack.
agile_modbus.h 文件参考

Agile Modbus 软件包通用头文件 更多...

#include <stdint.h>
#include "agile_modbus_rtu.h"
#include "agile_modbus_tcp.h"
agile_modbus.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

结构体

struct  agile_modbus_sft
 包含 modbus 头部参数结构体 更多...
 
struct  agile_modbus_backend
 Agile Modbus 后端接口结构体 更多...
 
struct  agile_modbus
 Agile Modbus 结构体 更多...
 
struct  agile_modbus_slave_info
 Agile Modbus 从机信息结构体 更多...
 

宏定义

#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.0"
 Agile Modbus 版本号 更多...
 
#define AGILE_MODBUS_BROADCAST_ADDRESS   0
 Modbus 广播地址 更多...
 
#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
 

类型定义

typedef struct agile_modbus_sft agile_modbus_sft_t
 包含 modbus 头部参数结构体 更多...
 
typedef struct agile_modbus agile_modbus_t
 Agile Modbus 结构体 更多...
 
typedef struct agile_modbus_backend agile_modbus_backend_t
 Agile Modbus 后端接口结构体 更多...
 
typedef int(* agile_modbus_slave_callback_t) (agile_modbus_t *ctx, struct agile_modbus_slave_info *slave_info)
 从机回调函数 更多...
 

枚举

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 异常码 更多...
 
enum  agile_modbus_backend_type_t { AGILE_MODBUS_BACKEND_TYPE_RTU = 0 , AGILE_MODBUS_BACKEND_TYPE_TCP }
 Modbus 后端类型 更多...
 
enum  agile_modbus_msg_type_t { AGILE_MODBUS_MSG_INDICATION , AGILE_MODBUS_MSG_CONFIRMATION }
 Modbus 收到消息类型 更多...
 

函数

void agile_modbus_common_init (agile_modbus_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz)
 初始化 modbus 句柄 更多...
 
int agile_modbus_set_slave (agile_modbus_t *ctx, int slave)
 设置地址 更多...
 
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))
 设置 modbus 对象的计算功能码后要接收的数据元长度回调函数 更多...
 
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))
 设置 modbus 对象的计算数据元之后要接收的数据长度回调函数 更多...
 
int agile_modbus_receive_judge (agile_modbus_t *ctx, int msg_length, agile_modbus_msg_type_t msg_type)
 校验接收数据正确性 更多...
 
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_serialize_raw_request (agile_modbus_t *ctx, const uint8_t *raw_req, int raw_req_length)
 将原始数据打包成请求报文 更多...
 
int agile_modbus_deserialize_raw_response (agile_modbus_t *ctx, int msg_length)
 解析响应原始数据 更多...
 
int agile_modbus_slave_handle (agile_modbus_t *ctx, int msg_length, uint8_t slave_strict, agile_modbus_slave_callback_t slave_cb, int *frame_length)
 从机数据处理 更多...
 
void agile_modbus_slave_io_set (uint8_t *buf, int index, int status)
 从机 IO 设置 更多...
 
uint8_t agile_modbus_slave_io_get (uint8_t *buf, int index)
 读取从机 IO 状态 更多...
 
void agile_modbus_slave_register_set (uint8_t *buf, int index, uint16_t data)
 从机寄存器设置 更多...
 
uint16_t agile_modbus_slave_register_get (uint8_t *buf, int index)
 读取从机寄存器数据 更多...
 

详细描述

Agile Modbus 软件包通用头文件

作者
马龙伟 (25440.nosp@m.4721.nosp@m.3@qq..nosp@m.com)
日期
2021-12-01
注意

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

在文件 agile_modbus.h 中定义.