diff --git a/canopen/emcy.py b/canopen/emcy.py index 9d88753e..ac6b06c2 100644 --- a/canopen/emcy.py +++ b/canopen/emcy.py @@ -22,18 +22,19 @@ def __init__(self): def on_emcy(self, can_id, data, timestamp): code, register, data = self.EMCY_STRUCT.unpack(data) - if code & 0xFF == 0: + entry = EmcyError(code, register, data, timestamp) + + with self.emcy_received: + self.log.append(entry) + self.active.append(entry) + self.emcy_received.notify_all() + + if code & 0xFFFF == 0: # Error reset self.active = [] for callback in self.callbacks: callback(None) else: - entry = EmcyError(code, register, data, timestamp) - #print("EMCY received for node %d: %s" % (can_id & 0x7F, entry)) - with self.emcy_received: - self.log.append(entry) - self.active.append(entry) - self.emcy_received.notify_all() for callback in self.callbacks: callback(entry) diff --git a/test/test_emcy.py b/test/test_emcy.py index 81c5f351..9c167434 100644 --- a/test/test_emcy.py +++ b/test/test_emcy.py @@ -29,7 +29,7 @@ def test_emcy_list(self): self.assertEqual(emcy_node.active[1], error) emcy_node.on_emcy(0x81, b'\x00\x00\x00\x00\x00\x00\x00\x00', 1473418397.0) - self.assertEqual(len(emcy_node.log), 2) + self.assertEqual(len(emcy_node.log), 3) self.assertEqual(len(emcy_node.active), 0) def test_str(self):