Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ def add_bit_definition(self, name: str, bits: List[int]) -> None:
"""
self.bit_definitions[name] = bits

@property
def fixed_size(self) -> bool:
"""Indicate whether the amount of needed data is known in advance."""
# Only for types which we parse using a structure.
return self.data_type in self.STRUCT_TYPES

def decode_raw(self, data: bytes) -> Union[int, float, str, bytes, bytearray]:
if self.data_type == VISIBLE_STRING:
# Strip any trailing NUL characters from C-based systems
Expand Down
4 changes: 1 addition & 3 deletions canopen/sdo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ def upload(self, index: int, subindex: int) -> bytes:
var = self.od.get_variable(index, subindex)
if var is not None:
# Found a matching variable in OD
# If this is a data type (string, domain etc) the size is
# unknown anyway so keep the data as is
if var.data_type not in objectdictionary.DATA_TYPES:
if var.fixed_size:
# Get the size in bytes for this variable
var_size = len(var) // 8
if response_size is None or var_size < response_size:
Expand Down
2 changes: 0 additions & 2 deletions test/test_sdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ def test_unknown_od_112(self):

def test_unknown_datatype32(self):
"""Test an unknown datatype, but known OD, of 32 bits (4 bytes)."""
return # FIXME: Disabled temporarily until datatype conditionals are fixed, see #436
# Add fake entry 0x2100 to OD, using fake datatype 0xFF
if 0x2100 not in self.node.object_dictionary:
fake_var = ODVariable("Fake", 0x2100)
Expand All @@ -829,7 +828,6 @@ def test_unknown_datatype32(self):

def test_unknown_datatype112(self):
"""Test an unknown datatype, but known OD, of 112 bits (14 bytes)."""
return # FIXME: Disabled temporarily until datatype conditionals are fixed, see #436
# Add fake entry 0x2100 to OD, using fake datatype 0xFF
if 0x2100 not in self.node.object_dictionary:
fake_var = ODVariable("Fake", 0x2100)
Expand Down
Loading