-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Description
When calling receive
on a PythonCAN
driver, the timeout
parameter is accidentally multiplied by 1000.
pydronecan/dronecan/driver/python_can.py
Line 139 in 19ac176
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:
- Create a virtual socketcan device
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
- 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