caran/can4python

64 bits signals are corrupted

cbibi opened this issue · 0 comments

cbibi commented

64 bits signals like do not work as the signal sent will be truncated. For example, 0x0102030405060708
becomes 0x0102030405060700.
Message 0xFFFFFFFFFFFFFFFF even creates an assertion error: "Trying to set too large signal value to frame"

Issue is located in canframe.py
scaled_value = float((physical_value - signaldefinition.valueoffset) / signaldefinition.scalingfactor)
Converting a 64 bit int (physical value) to float creates a rounding issue that is clearly seen when offset=0 and scalingfactor=1

Proposal is to use Decimal lib to fix it (see patch attached)

Provided also a small Python test file + kcd to highlight the issue

Other information
Tested on ubuntu 17.04 with can4python 0.2.1 and Python 3.5.3 with both vcan and real can (Microchip USB device)
Ran make test without any error

64bits_floatbug.zip