Skip to content

Commit 8cfdf75

Browse files
Merge pull request #176 from stan-dalencon/feature/eds_dummy_mapping
EDS : Add loading of DummyUsage definitions
2 parents 61bc0a0 + 3656059 commit 8cfdf75

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

canopen/objectdictionary/eds.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ def import_eds(source, node_id):
3636
od.node_id = int(eds.get("DeviceComissioning", "NodeID"))
3737

3838
for section in eds.sections():
39+
# Match dummy definitions
40+
match = re.match(r"^[Dd]ummy[Uu]sage$", section)
41+
if match is not None:
42+
for i in range(1, 8):
43+
key = "Dummy%04d" % i
44+
if eds.getint(section, key) == 1:
45+
var = objectdictionary.Variable(key, i, 0)
46+
var.data_type = i
47+
var.access_type = "const"
48+
od.add_object(var)
49+
3950
# Match indexes
4051
match = re.match(r"^[0-9A-Fa-f]{4}$", section)
4152
if match is not None:

test/sample.eds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ LSS_SerialNumber=0
3939
[DummyUsage]
4040
Dummy0001=0
4141
Dummy0002=0
42-
Dummy0003=0
42+
Dummy0003=1
4343
Dummy0004=0
4444
Dummy0005=0
4545
Dummy0006=0

test/test_eds.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@ def test_compact_subobj_parameter_name_with_percent(self):
7676
def test_sub_index_w_capital_s(self):
7777
name = self.od[0x3010][0].name
7878
self.assertEqual(name, 'Temperature')
79+
80+
def test_dummy_variable(self):
81+
var = self.od['Dummy0003']
82+
self.assertIsInstance(var, canopen.objectdictionary.Variable)
83+
self.assertEqual(var.index, 0x0003)
84+
self.assertEqual(var.subindex, 0)
85+
self.assertEqual(var.name, 'Dummy0003')
86+
self.assertEqual(var.data_type, canopen.objectdictionary.INTEGER16)
87+
self.assertEqual(var.access_type, 'const')
88+
self.assertEqual(len(var), 16)
89+
90+
def test_dummy_variable_undefined(self):
91+
with self.assertRaises(KeyError):
92+
var_undef = self.od['Dummy0001']

0 commit comments

Comments
 (0)