pyhys / minimalmodbus

Easy-to-use Modbus RTU and Modbus ASCII implementation for Python.
Apache License 2.0
306 stars 146 forks source link

Wrong LRC calculation in ASCII MODE #125

Open uaranguren opened 8 months ago

uaranguren commented 8 months ago

When trying to use ASCII mode, the LRC is not correctly calculated.

The function _calculate_lrc receives data in ASCII (not converted to hex). Then, it performs the correct operations but the input is incorrect. To solve this problem, _calculate_lrc shoult convert its input to hex using _hexencode. It could be also possible that the previous function (_embed_payload) performed this conversion before.