Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the passed node ID to the resulting OD in import_od() #484

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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: 4 additions & 2 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ def import_eds(source, node_id):

if eds.has_section("DeviceComissioning"):
od.bitrate = int(eds.get("DeviceComissioning", "Baudrate")) * 1000
od.node_id = int(eds.get("DeviceComissioning", "NodeID"), 0)
node_id = node_id or od.node_id

if node_id is None:
node_id = int(eds.get("DeviceComissioning", "NodeID"), base=0)
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
od.node_id = node_id

for section in eds.sections():
# Match dummy definitions
Expand Down
2 changes: 1 addition & 1 deletion test/sample.eds
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ NrOfTXPDO=4
LSS_Supported=0

[DeviceComissioning]
NodeID=2
NodeID=0x10
NodeName=Some name
Baudrate=500
NetNumber=0
Expand Down
9 changes: 9 additions & 0 deletions test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ def test_load_file_object(self):
od = canopen.import_od(fp)
self.assertTrue(len(od) > 0)

def test_load_implicit_nodeid(self):
# sample.eds has a DeviceComissioning section with NodeID set to 0x10.
od = canopen.import_od(EDS_PATH)
self.assertEqual(od.node_id, 16)

def test_load_explicit_nodeid(self):
od = canopen.import_od(EDS_PATH, node_id=3)
self.assertEqual(od.node_id, 3)

def test_variable(self):
var = self.od['Producer heartbeat time']
self.assertIsInstance(var, canopen.objectdictionary.ODVariable)
Expand Down
Loading