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

gs_usb does not support set_bitrate() for some Candlelight devices #1747

Open
tuwuhs opened this issue Feb 26, 2024 · 1 comment
Open

gs_usb does not support set_bitrate() for some Candlelight devices #1747

tuwuhs opened this issue Feb 26, 2024 · 1 comment
Labels

Comments

@tuwuhs
Copy link

tuwuhs commented Feb 26, 2024

Describe the bug

Cannot set bitrate for some Candlelight devices. I'm using MKS CANable V2.0 Pro board with Candlelight firmware.

To Reproduce

Demonstrated here on an interactive session:

>>> import usb
>>> import can
>>> dev = usb.core.find(idVendor=0x1d50, idProduct=0x606f)
>>> bus = can.Bus(interface='gs_usb', channel=dev.product, bus=dev.bus, address=dev.address, bitrate=1000000)
>>> bus.gs_usb.set_bitrate(1000000)
False

Expected behavior

bus.gs_usb.set_bitrate(1000000) returns True.

Additional context

OS and version: Windows 10
Python version: 3.9.15
python-can version: main (@d40915ca)
python-can interface/s (if applicable):

The board works perfectly fine in Linux / SocketCAN, bitrate can be set through ip link command as is usual with native SocketCAN devices.

Traceback and logs
@tuwuhs tuwuhs added the bug label Feb 26, 2024
@tuwuhs
Copy link
Author

tuwuhs commented Feb 26, 2024

Checking deeper, looks like the culprit is this: https://github.com/jxltom/gs_usb/blob/master/gs_usb/gs_usb.py#L79

The gs_usb module only implements bit timing conversion for 48 MHz and 80 MHz clocks, while my board apparently runs at 170 MHz.

>>> import usb
>>> import can
>>> dev = usb.core.find(idVendor=0x1d50, idProduct=0x606f)
>>> bus = can.Bus(interface='gs_usb', channel=dev.product, bus=dev.bus, address=dev.address, bitrate=1000000)
>>> bus.gs_usb.device_capability.fclk_can
170000000

I think instead of relying on this conversion, we can use the python-can's BitTiming. I'll write some quick fix and send a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant