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
11 changes: 11 additions & 0 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def import_eds(source, node_id):
od.node_id = int(eds.get("DeviceComissioning", "NodeID"))

for section in eds.sections():
# Match dummy definitions
match = re.match(r"^[Dd]ummy[Uu]sage$", section)
if match is not None:
for i in range(1, 8):
key = "Dummy%04d" % i
if eds.getint(section, key) == 1:
var = objectdictionary.Variable(key, i, 0)
var.data_type = i
var.access_type = "const"
od.add_object(var)

# Match indexes
match = re.match(r"^[0-9A-Fa-f]{4}$", section)
if match is not None:
Expand Down
2 changes: 1 addition & 1 deletion test/sample.eds
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LSS_SerialNumber=0
[DummyUsage]
Dummy0001=0
Dummy0002=0
Dummy0003=0
Dummy0003=1
Dummy0004=0
Dummy0005=0
Dummy0006=0
Expand Down
14 changes: 14 additions & 0 deletions test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,17 @@ def test_compact_subobj_parameter_name_with_percent(self):
def test_sub_index_w_capital_s(self):
name = self.od[0x3010][0].name
self.assertEqual(name, 'Temperature')

def test_dummy_variable(self):
var = self.od['Dummy0003']
self.assertIsInstance(var, canopen.objectdictionary.Variable)
self.assertEqual(var.index, 0x0003)
self.assertEqual(var.subindex, 0)
self.assertEqual(var.name, 'Dummy0003')
self.assertEqual(var.data_type, canopen.objectdictionary.INTEGER16)
self.assertEqual(var.access_type, 'const')
self.assertEqual(len(var), 16)

def test_dummy_variable_undefined(self):
with self.assertRaises(KeyError):
var_undef = self.od['Dummy0001']