原地址: http://libmodbus.org/docs/v3.0.6/
描述
libmodbus 是一个和遵从modbus协议的设备之间收发数据的库。库中包含了多样的遵从网络模式的后端通讯(串口和TCP)。
背景
Modbus 协议有多种实现变体,为了缓解实现变量的困难,在库中,每一个变量有一个后台。每一个后台都指定一个独特的功能来new一个modbus_t 。modbus_t 是一个不开放的结构体,包含了所有的建立与其他设备通信的信息。有如下三种:
RTU Context、
TCP (IPv4) Context
TCP PI (IPv4 and IPv6) Context
TCP (IPv4)这里不需要校验,创建TCP (IPv4)环境需要 modbus_new_tcp(3)。
modbus_get_response_timeout(3)
modbus_set_response_timeout(3)
libmodbus是线程安全的。能在各个应用的线程中随意使用
数据操作的宏命令
MODBUS_GET_HIGH_BYTE(data), extracts the high byte from a byte 提取高字节
MODBUS_GET_LOW_BYTE(data), extracts the low byte from a byte提取低字节MODBUS_GET_INT32_FROM_INT16(tab_int16, index), builds an int32 from the two first int16 starting at tab_int16[index] 在tabint16索引中构建一个int32
MODBUS_GET_INT16_FROM_INT8(tab_int8, index), builds an int16 from the two first int8 starting at tab_int8[index]
MODBUS_SET_INT16_TO_INT8(tab_int8, index, value), set an int16 value into the two first bytes starting at tab_int8[index] 将一个int16值设置为两个字节
数据操作的功能Data mapping:数据映射
Receive 接收
Reply 响应