Skip to content

Reading OD entries that are not 32 bits results in unpack error #5

@igutekunst

Description

@igutekunst

I've just started testing out this library for a consulting project. It looks really nice! I've found what I'm pretty sure is a bug.

Problem
I have a CANOpen device with an OD Entry of type I8. When I try to read it from python, I get an unpack error.

Analysis of Problem
It appears that SDO_STRUCT defined on line 14 of sdo.py is hard coded to expect 8 byte SDO responses. I don't have a PR yet, because I wanted to ask about it first.

Proposed Solution
A dictionary of structs for different sized OD entries might be good enough solution. We could then raise an ObjectDictionaryError: Mismatch between expected and actual data size, as currently done when the device sends a 8 byte response, but the python side expects a smaller response.

Traceback (most recent call last):
  File "C:\Users\ig\canopen-science.py", line 35, in <module>
    print "Mode: {0}".format(device_mode.raw)
  File "C:\Python27\lib\site-packages\canopen\common.py", line 64, in raw
    value = self.od.decode_raw(self.data)
  File "C:\Python27\lib\site-packages\canopen\common.py", line 24, in data
    return self.get_data()
  File "C:\Python27\lib\site-packages\canopen\sdo.py", line 242, in get_data
    return self.sdo_node.upload(self.od.index, self.od.subindex)
  File "C:\Python27\lib\site-packages\canopen\sdo.py", line 89, in upload
    response)
error: unpack requires a string argument of length 8

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions