Closed brianruss closed 9 years ago
Thank you! I'm not sure how this snuck by. The way it's currently calculating the byte count is just embarrassingly wrong.
I'll merge your changes in as well as open an issue for and implement reporting encoding and decoding errors to any outstanding CompletableFutures.
You see any issue with this formula instead?
int byteCount = (request.getQuantity() + 7) / 8;
I think this is what my brain must have been reaching for when I wrote the broken version.
The alternative formula is good.
When using a WriteMultipleCoilsRequest, if the quantity parameter is not a multiple of 8, the request fails to send, and a response timeout ensues. The issue appears to be with the formula used to calculate the number of bytes that are needed to hold the quantity of bits to be written. Currently the formula (in ModbusRequestEncoder.encodeWriteMultipleCoils() ) is:
This should be:
The ModbusRequestSerializationTest could be enhanced to check for these as below:
The problem is detected as a IndexOutOfBoundsException, which does not get reported to the Modbus sendRequest() future.