Skip to content
Open
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
7 changes: 5 additions & 2 deletions canopen/nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ def send_command(self, code: int) -> None:
# The heartbeat service should start on the transition
# between INITIALIZING and PRE-OPERATIONAL state
if old_state == 0 and self._state == 127:
heartbeat_time_ms = self._local_node.sdo[0x1017].raw
self.start_heartbeat(heartbeat_time_ms)
try:
heartbeat_time_ms = self._local_node.sdo[0x1017].raw
self.start_heartbeat(heartbeat_time_ms)
except KeyError:
pass
else:
self.update_heartbeat()

Expand Down
8 changes: 8 additions & 0 deletions test/test_nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ def test_heartbeat(self):

self.local_node.nmt.stop_heartbeat()

def test_heartbeat_no_producer_time(self):
# Create a node without the producer heartbeat time parameter
node = canopen.LocalNode(1, canopen.ObjectDictionary())
with self.assertRaises(KeyError):
node.sdo[0x1017].raw = 100
# Should not fail because of missing 0x1017 object entry
node.nmt.state = "PRE-OPERATIONAL"


if __name__ == "__main__":
unittest.main()
Loading