AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 81 forks source link

Fix byte count when writing multiple coils #105

Closed acolomb closed 4 years ago

acolomb commented 4 years ago

Fix off-by-one error in WriteMultipleCoils calculation. For full bytes, the Byte Count field was calculated too high: 8 // 8 + 1 = 2 while only one byte is needed to represent 8 coils.

Offset the values length before the truncating division to correctly round to whole bytes. This is easier than what the standard formulates: N = Quantity of Outputs / 8, if the remainder is different of 0 ==> N = N+1

Note that the actual data bytes were already handled with the correct length. So in case of 8 coils, uModbus would send a Byte Count of 2, but only one data byte before the checksum

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.5%) to 95.814% when pulling 4db2279ab12d491245bb063b00bb3d38348fac0c on acolomb:fix-length-writing-multiple-coils into 63c7679fa3feb4d85e8b4c3ef892c2f264dbf4b2 on AdvancedClimateSystems:master.