1 Star 0 Fork 0

NightBreeze/modbus-esp8266

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Bridge functions

Basic

Basic 'Bridge'. Indeed this sample pulling data from Modbus Server and stores it to local registers. Local registers can be accessed via Modbus Client instance that running aside.

ModbusRTU to ModbusTCP bridge

Fullfunctional ModbusRTU to ModbusTCP bridge.

Multiple Server ID

Respond for multiple ModbusRTU IDs from single device

ModbusTCP to Modbus RTU Simulator

Fullfunctional ModbusTCP to ModbusRTU bridge with on-device ModbusRTU simulator

uint16_t rawRequest(id_ip, uint8_t* data, uint16_t len, cbTransaction cb = nullptr, uint8_t unit = MODBUSIP_UNIT);
uint16_t rawResponce(id_ip, uint8_t* data, uint16_t len, uint8_t unit = MODBUSIP_UNIT);
uint16_t errorResponce(id_ip, Modbus::FunctionCode fn, Modbus::ResultCode excode, uint8_t unit = MODBUSIP_UNIT);
  • id_ip SlaveId (uint8_t) or server IP address (IPAddress)
  • data Pointer to data buffer to send
  • len Byte count to send
  • unit UnitId (ModbusTCP/TLS only)
  • fn function code in responce
  • excode Exception code in responce
uint16_t setTransactionId(uint16_t id);
  • id Value to replace transaction id sequence (ModbusTCP/TLS only)
union frame_arg_t {
struct frame_arg_t {
    bool to_server; // true if frame is responce for local Modbus server/slave
    union {
        // For ModbusRTU
		uint8_t slaveId;
        // For ModbusTCP/TLS
		struct { 
			uint8_t unitId; // UnitId as passed in MBAP header
			uint32_t ipaddr; // IP address from which frame is received
			uint16_t transactionId; // TransactionId as passed in MBAP header
		};
    };
};
typedef std::function<ResultCode(uint8_t*, uint8_t, void*)> cbRaw; // Callback function Type for STL
typedef ResultCode (*cbRaw)(uint8_t* frame, uint8 len, void* data); // Callback function Type
bool onRaw(cbRaw cb = nullptr);
  • frame Modbus payload frame with stripped MBAP/slaveid and crc
  • len frame size in bytes
  • data Pointer to frame_arg_t filled with frame header information

Returns:

  • If a special error code Modbus::EX_PASSTHROUGH returned frame will be processed normally
  • If a special error code Modbus::EX_FORCE_PROCESS returned frame will be processed even if addressed to another Modbus unit
  • Any other return code disables normal frame processing. Only transactional callback will be executed (if any and transaction data is correct) The callback is executed only on Modbus frame with valid header and CRC.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/d__xin/modbus-esp8266.git
git@gitee.com:d__xin/modbus-esp8266.git
d__xin
modbus-esp8266
modbus-esp8266
master

搜索帮助