Skip to content

Commit a142fb5

Browse files
Add 'relative' property for COB-ID vars relative to the node-ID (#281)
1 parent 89bc634 commit a142fb5

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

canopen/objectdictionary/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def __init__(self, name: str, index: int, subindex: int = 0):
304304
self.max: Optional[int] = None
305305
#: Default value at start-up
306306
self.default: Optional[int] = None
307+
#: Is the default value relative to the node-ID (only applies to COB-IDs)
308+
self.relative = False
307309
#: The value of this variable stored in the object dictionary
308310
self.value: Optional[int] = None
309311
#: Data type according to the standard as an :class:`int`

canopen/objectdictionary/eds.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ def build_variable(eds, section, node_id, index, subindex=0):
262262
if eds.has_option(section, "DefaultValue"):
263263
try:
264264
var.default_raw = eds.get(section, "DefaultValue")
265+
if '$NODEID' in var.default_raw:
266+
var.relative = True
265267
var.default = _convert_variable(node_id, var.data_type, eds.get(section, "DefaultValue"))
266268
except ValueError:
267269
pass

test/test_eds.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def test_variable(self):
2626
self.assertEqual(var.data_type, canopen.objectdictionary.UNSIGNED16)
2727
self.assertEqual(var.access_type, 'rw')
2828
self.assertEqual(var.default, 0)
29+
self.assertFalse(var.relative)
30+
31+
def test_relative_variable(self):
32+
var = self.od['Receive PDO 0 Communication Parameter']['COB-ID use by RPDO 1']
33+
self.assertTrue(var.relative)
34+
self.assertEqual(var.default, 512 + self.od.node_id)
2935

3036
def test_record(self):
3137
record = self.od['Identity object']

0 commit comments

Comments
 (0)