From 1d5d6de72c55091f9428d5cace4ac929da204b0e Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Wed, 13 Mar 2024 16:15:09 +0800 Subject: [PATCH] plugin(modbus): fix modbus rtu slave check --- plugins/modbus/modbus_req.c | 2 +- plugins/modbus/modbus_stack.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/modbus/modbus_req.c b/plugins/modbus/modbus_req.c index d2f3aae71..a675211bc 100644 --- a/plugins/modbus/modbus_req.c +++ b/plugins/modbus/modbus_req.c @@ -699,7 +699,7 @@ static int process_protocol_buf(neu_plugin_t *plugin, uint8_t slave_id, plog_recv_protocol(plugin, recv_buf, ret); } neu_protocol_unpack_buf_init(&pbuf, recv_buf, ret); - int ret_s = modbus_stack_recv(plugin->stack, 0, &pbuf); + int ret_s = modbus_stack_recv(plugin->stack, slave_id, &pbuf); if (ret_s == MODBUS_DEVICE_ERR) { ret = ret_s; } else { diff --git a/plugins/modbus/modbus_stack.c b/plugins/modbus/modbus_stack.c index 94f4589fe..504691224 100644 --- a/plugins/modbus/modbus_stack.c +++ b/plugins/modbus/modbus_stack.c @@ -84,10 +84,8 @@ int modbus_stack_recv(modbus_stack_t *stack, uint8_t slave_id, return -1; } - if (stack->protocol == MODBUS_PROTOCOL_TCP) { - if (code.slave_id != slave_id) { - return -1; - } + if (code.slave_id != slave_id) { + return -1; } switch (code.function) {