You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my first post I'm sorry if it somehow doesn't match the required format.
I've been using canopen python package for a little while now and it is great.
I came accross a curious thing while using the SyncProducer's start method.
I've noticed there is no simple way to check whether the sync has already been started or not. So I figured it's maybe because calling the start method multiple times doesn't have any effect. I was wrong. When the start method is called multiple times, multiple periodic tasks are created and the SYNC is therefore sent multiples times. While this might be intended behavior (?) it also makes the stop method inefficient. Calling it does not stop all started task.
What I did as a workaround is checking if the task has already been started by accessing protected member of the SyncProducer _task._task.stopped. It's not very elegant and I was wondering if we could do something about it or if I'm mistaken about something here.
import canopen
import time
nw = canopen.Network()
nw.connect(interface='pcan', bitrate=250000, channel='PCAN_USBBUS1')
nw.sync.start(1)
nw.sync.start(1)
nw.sync.start(1)
time.sleep(3)
nw.sync.stop()
time.sleep(3) # you should see here that the sync is still being sent
if nw.sync._task is None or nw.sync._task._task.stopped: # workaround, if _task is None it's never been started before
nw.sync.start(1)
nw.disconnect()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Dear contributors/creator,
This is my first post I'm sorry if it somehow doesn't match the required format.
I've been using canopen python package for a little while now and it is great.
I came accross a curious thing while using the SyncProducer's start method.
I've noticed there is no simple way to check whether the sync has already been started or not. So I figured it's maybe because calling the start method multiple times doesn't have any effect. I was wrong. When the start method is called multiple times, multiple periodic tasks are created and the SYNC is therefore sent multiples times. While this might be intended behavior (?) it also makes the stop method inefficient. Calling it does not stop all started task.
What I did as a workaround is checking if the task has already been started by accessing protected member of the SyncProducer _task._task.stopped. It's not very elegant and I was wondering if we could do something about it or if I'm mistaken about something here.
Beta Was this translation helpful? Give feedback.
All reactions