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

pythoncan: timeout is incorrectly multiplied by 1000 #77

Open
oystub opened this issue Dec 18, 2024 · 0 comments
Open

pythoncan: timeout is incorrectly multiplied by 1000 #77

oystub opened this issue Dec 18, 2024 · 0 comments

Comments

@oystub
Copy link

oystub commented Dec 18, 2024

Description

When calling receive on a PythonCAN driver, the timeout parameter is accidentally multiplied by 1000.

timeout = -1 if timeout is None else (timeout * 1000)

This leads to the true timeout duration being 1000x too long. For example leading to dronecan_gui_tool taking over a minute to load when using python-can on a bus without traffic.

Based om the python-can driver, it should simply be passed along without changes.
https://github.com/hardbyte/python-can/blob/654a02ae24bfc50bf1bb1fad7aab4aa88763d302/can/bus.py#L110-L121

...and it seems to have been like that for at least 7 years 🤔
https://github.com/hardbyte/python-can/blob/6913c4951faba39eb9d9fea2a9f151d60a39d9e0/can/bus.py#L45-L53

Proposed solution

Remove the problematic line
See #78

To reproduce on Debian/Ubuntu:

  1. Create a virtual socketcan device
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
  1. Run the following program
import time
import dronecan.driver as driver
from dronecan.node import Node

driver_pythoncan = driver.PythonCAN(bustype="socketcan", channel='vcan0', bitrate=1000000)
driver_socketcan = driver.SocketCAN(interface='vcan0', bitrate=1000000)

node = Node(driver_pythoncan)
start = time.time()
node.spin(0.01)
print(f"python-can: {time.time() - start}s")

node = Node(driver_socketcan)
start = time.time()
node.spin(0.01)
print(f"socketcan: {time.time() - start}s")

Which outputs something like

python-can: 10.00549864768982s
socketcan: 0.010323524475097656s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant