Skip to content

pythoncan: timeout is incorrectly multiplied by 1000 #77

@oystub

Description

@oystub

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions