Kvaser / pycanlib

The pycanlib package is a Python wrapper for Kvaser CANlib SDK.
https://pycanlib.readthedocs.io
MIT License
16 stars 4 forks source link

@phys.setter setting frame data as 0 if negative non-binary number passed in #1

Closed unijay2671 closed 1 year ago

unijay2671 commented 2 years ago

We have an issue where the @phys.setter function (line 18 in canlib/kvadblib/bound_signal.py) sets the frame data as 0 when we pass in a negative non-binary number as the value.

A temporary fix for us was adding 2^(bitsize) of the signal we wanted to send, but we were hoping for a more permanent fix baked into the library.

TroyVia commented 2 years ago

Please provide the dbc description of the signal you were trying to use with phys.setter function (signal type, byte order, mode, bit position, length, factor, offset, minimum, and maximum).

unijay2671 commented 2 years ago

This happens when we try to store as an int in python and then pack it into 10-bits before sending on the bus.

<signal_name> : 24|10@0- (0.125,0) [-64|63.875] "m" DAQ

Length is 10 bits, factor is 0.125, minimum is -64, max is 63.875, offset is 0, bit position is 24, mode is big endian, signed.

kvanfr commented 2 years ago

We were unable to reproduce this.

Here is the test used:

phys.dbc

BO_ 1 msg: 8 Vector__XXX
 SG_ testsig : 24|10@0- (0.125,0) [-64|63.875] "" Vector__XXX

test + results

__________________ test_reproduce_phys_setter_issue ___________________ 

    def test_reproduce_phys_setter_issue():
        db = kvadblib.Dbc(filename=os.path.join(DATADIR, "phys.dbc"))   
        framebox = kvadblib.FrameBox(db, messages=("msg",))

        bsig = framebox.signal('testsig')
        bsig.phys = -1

        frames = list(framebox.frames())
        data = list(frames[0].data)

>       assert not any(data) # expect all zeros if reproducible
E       assert not True
E        +  where True = any([0, 0, 0, 1, 252, 0, ...])

test_phys_setter.py:16: AssertionError
======================= short test summary info =======================