From 9eba2a7230434df29bacca7f1e2cced03d8e2f3d Mon Sep 17 00:00:00 2001 From: fengzero Date: Tue, 30 Aug 2022 08:04:21 +0000 Subject: [PATCH] fix(modbus): read/write tag value endian --- plugins/modbus/modbus_req.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/modbus/modbus_req.c b/plugins/modbus/modbus_req.c index 2141a4a7..7832ed64 100644 --- a/plugins/modbus/modbus_req.c +++ b/plugins/modbus/modbus_req.c @@ -154,11 +154,13 @@ int modbus_value_handle(void *ctx, uint8_t slave_id, uint16_t n_byte, switch ((*p_tag)->type) { case NEU_TYPE_UINT16: case NEU_TYPE_INT16: + dvalue.value.u16 = ntohs(dvalue.value.u16); + break; case NEU_TYPE_FLOAT: case NEU_TYPE_INT32: - case NEU_TYPE_UINT32: { + case NEU_TYPE_UINT32: + dvalue.value.u32 = ntohl(dvalue.value.u32); break; - } case NEU_TYPE_BIT: { switch ((*p_tag)->area) { case MODBUS_AREA_HOLD_REGISTER: @@ -220,22 +222,21 @@ int modbus_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag, switch (tag->type) { case NEU_TYPE_UINT16: case NEU_TYPE_INT16: { - n_byte = sizeof(uint16_t); + value.u16 = htons(value.u16); + n_byte = sizeof(uint16_t); break; } case NEU_TYPE_UINT32: - case NEU_TYPE_INT32: { - n_byte = sizeof(uint32_t); + case NEU_TYPE_INT32: + case NEU_TYPE_FLOAT: { + value.u32 = htonl(value.u32); + n_byte = sizeof(uint32_t); break; } case NEU_TYPE_BIT: { n_byte = sizeof(uint8_t); break; } - case NEU_TYPE_FLOAT: { - n_byte = sizeof(float); - break; - } case NEU_TYPE_STRING: { switch (point.option.string.type) { case NEU_DATATAG_STRING_TYPE_H: