eModbus / eModbus

Modbus library for RTU, ASCII and TCP protocols. Primarily developed on and for ESP32 MCUs.

Home Page:https://emodbus.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in TCPCoilExample?

Miq1 opened this issue · comments

Discussed in #255

Originally posted by JustMe-NL January 8, 2023
In TCPCoilExample at function FC_0F there is a sanity check on the number of available databytes based on the number of written coils:

line 109: if (numBytes == (numCoils >> 3) + 1) { ... }

But if the Client writes 8 coils this function fails because it expects 2 bytes while 8 coils fit in 1 byte.
Am I right in assuming this should be:

if (numBytes == ((numCoils - 1) >> 3) + 1) { ... }

and

if (newValue.size() >= (size_t)(((length - 1) >> 3) + 1)) { ... }

for line 223 in CoilData.cpp?