-
Notifications
You must be signed in to change notification settings - Fork 207
Open
Description
Consider this snippet:
import canopen
network = canopen.Network()
network.connect(channel='vcan0', bustype="socketcan")
network.sync.start(1.0)
network.sync.start(0.5)
# Using `candump -L vcan0` I have the two tasks running in parallel
network.sync.stop() # Only the latter task is stopped
network.sync.stop() # CanOperationError, the latter task is already stopped
In sync.py
, we notice that attribute self._task
is erased with the new task, which became inaccessible. I don't know if this hack will work, but we could only allow one sync event at the time:
diff --git a/canopen/sync.py b/canopen/sync.py
index d373451..6965b94 100644
--- a/canopen/sync.py
+++ b/canopen/sync.py
@@ -33,9 +33,14 @@ class SyncProducer:
if not self.period:
raise ValueError("A valid transmission period has not been given")
+ if self._task is not None:
+ self._task.stop()
+ self._task = None
+
self._task = self.network.send_periodic(self.cob_id, [], self.period)
def stop(self):
"""Stop periodic transmission of SYNC message."""
if self._task is not None:
self._task.stop()
+ self._task = None
Does it make sens?
Metadata
Metadata
Assignees
Labels
No labels