From 2a82e7b388268af9d0753969dfc006dc22a6052c Mon Sep 17 00:00:00 2001 From: Philipp Jungkamp Date: Wed, 23 Aug 2023 14:43:42 +0200 Subject: [PATCH] node-modbus: Improve _read and _write loop Signed-off-by: Philipp Jungkamp --- lib/nodes/modbus.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/nodes/modbus.cpp b/lib/nodes/modbus.cpp index f169dbdfe..090d3a1b1 100644 --- a/lib/nodes/modbus.cpp +++ b/lib/nodes/modbus.cpp @@ -514,11 +514,12 @@ int ModbusNode::_read(struct Sample *smps[], unsigned cnt) for (unsigned int i = 0; i < cnt; ++i) { auto smp = smps[i]; + smp->length = num_in_signals; smp->flags |= (int) SampleFlags::HAS_DATA; + assert(smp->length <= smp->capacity); + for (auto &mapping : in_mappings) { - smp->length = num_in_signals; - assert(smp->length <= smp->capacity); if (auto ret = readBlock(mapping, smp->data, smp->length)) return ret; } @@ -587,8 +588,9 @@ int ModbusNode::_write(struct Sample *smps[], unsigned cnt) for (unsigned int i = 0; i < cnt; ++i) { auto smp = smps[i]; + assert(smp->length == num_out_signals); + for (auto &mapping : out_mappings) { - assert(smp->length == num_out_signals); if (auto ret = writeBlock(mapping, smp->data, smp->length)) return ret; }