Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBC --> XLS then XLS --> DBC does not preserve values #614

Closed
AlexDLSy opened this issue Nov 19, 2021 · 4 comments
Closed

DBC --> XLS then XLS --> DBC does not preserve values #614

AlexDLSy opened this issue Nov 19, 2021 · 4 comments
Assignees
Labels

Comments

@AlexDLSy
Copy link
Contributor

AlexDLSy commented Nov 19, 2021

I used canconvert on my dbc file to create an xls file, then used canconvert on the created xls file to output another dbc file.

I expected both dbc files to contain the same values, but the resulting dbc not only has had many attributes deleted, some values have been changed. The list of differences using cancompare is huge.

Is that intended ? Where can I find the coverage of conversion between xls and dbc ? (Ie what is exported in xls from dbc and what is not, and in the reverse direction as well)
Currently, the conversion from xlsx is not possible due to #541 so I cannot test the same conversion pattern with that format, but it might have the same issue.

@ebroecker
Copy link
Owner

Hi @AlexDLSy ,

yes, xls(x) is a lossy format.
It was not designed for the workflow you use it.

You can make things better by exporting some extra attributes to xls(x) with "–additionalSignalAttributes and –additionalFrameAttributes"

Some signal-attributes which will help:

  • min
  • max
  • is_signed
  • factor
  • offset

@wienans
Copy link

wienans commented Mar 15, 2022

Hi @ebroecker
i used the additionalSignalAttributes flag
canconvert --additionalSignalAttributes min,max,is_signed,factor,offset can_dbc.dbc test1.xls
and later tried to converted it back with
canconvert --additionalSignalAttributes min,max,is_signed,factor,offset test1.xls can_dbc_test.dbc
or
canconvert test1.xls can_dbc_test.dbc
which does not make a difference

But i incountered an error:

canconvert test1.xls can_dbc_test.dbc
ldf is not supported
INFO - convert - Importing test1.xls ... 
INFO - convert - done

INFO - convert - Exporting can_dbc_test.dbc ... 
INFO - convert - 
INFO - convert - 7 Frames found
Traceback (most recent call last):
  File "/home/sven/.local/bin/canconvert", line 33, in <module>
    sys.exit(load_entry_point('canmatrix==0.9.4.post2+gf56652f', 'console_scripts', 'canconvert')())
  File "/home/sven/.local/lib/python3.6/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/sven/.local/lib/python3.6/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/sven/.local/lib/python3.6/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sven/.local/lib/python3.6/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/sven/.local/lib/python3.6/site-packages/canmatrix/cli/convert.py", line 153, in cli_convert
    canmatrix.convert.convert(infile, outfile, **options)
  File "/home/sven/.local/lib/python3.6/site-packages/canmatrix/convert.py", line 331, in convert
    canmatrix.formats.dumpp(out_dbs, out_file_name, **options)
  File "/home/sven/.local/lib/python3.6/site-packages/canmatrix/formats/__init__.py", line 129, in dumpp
    dump(db, file_object, export_type, **options)
  File "/home/sven/.local/lib/python3.6/site-packages/canmatrix/formats/__init__.py", line 104, in dump
    module_instance.dump(can_matrix_or_cluster, file_object, **options)  # type: ignore
  File "/home/sven/.local/lib/python3.6/site-packages/canmatrix/formats/dbc.py", line 236, in dump
    if signal.phys2raw(None) != 0:
  File "/home/sven/.local/lib/python3.6/site-packages/canmatrix/canmatrix.py", line 432, in phys2raw
    raw_value = (value - self.offset) / self.factor
TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'float'

It looks like it only appears if i the factor and offset are exported to the dbc file

@ebroecker ebroecker self-assigned this Mar 15, 2022
@ebroecker ebroecker added the bug label Mar 15, 2022
@Karstensson
Copy link

I have a fix for this, but don't seem to have access to upload a branch for this, therefore I cannot create a PR.
But line 432 in canmatrix.py needs to be replaced by

raw_value = (value - self.offset) / self.factor

to
raw_value = (value - decimal.Decimal(self.offset)) / self.factor

@ebroecker
Copy link
Owner

@Karstensson
thanks, I'll doublecheck and include your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants