Python CAN / CAN FD driver for candleLight USB adapters and Geschwister Schneider gs_usb devices (Windows, Linux, macOS).
Project description
candle-usb
Python CAN / CAN FD driver for candleLight USB adapters and Geschwister Schneider gs_usb devices — Windows, Linux, macOS.
Install
pip install candle-usb
Requires libusb. On Linux install libusb-1.0-0 and add a udev rule; on Windows use Zadig to bind WinUSB to the device.
pycandump
A candump-style live monitor is included and available on the PATH after install:
pycandump # classic CAN, 500 kbps, listen-only
pycandump --bitrate 250000
pycandump --data-bitrate 1000000 # enables CAN FD mode
pycandump --active # required when adapter is sole receiver
pycandump --filter 0x100:0x7FF
pycandump --fd-only
pycandump --log trace.log
pycandump --device 6:14 # pick a specific USB device
Note on
--active: in listen-only mode the adapter sends no ACK bits. If it is the only receiver on the bus the sender will retransmit the same frame indefinitely. Pass--activewhenever you are the sole node.
API usage
Classic CAN
from candle_usb.gs_usb import GsUsb
from candle_usb.gs_usb_frame import GsUsbFrame
from candle_usb.constants import CAN_EFF_FLAG
devs = GsUsb.scan()
dev = devs[0]
dev.set_bitrate(500000)
dev.start()
frame = GsUsbFrame(can_id=0x7FF, data=b"\x01\x02\x03")
dev.send(frame)
rx = GsUsbFrame()
if dev.read(rx, timeout_ms=100):
print(rx)
dev.stop()
CAN FD
from candle_usb.gs_usb import GsUsb
from candle_usb.gs_usb_frame import GsUsbFrame
from candle_usb.constants import (
GS_CAN_MODE_FD, GS_CAN_MODE_HW_TIMESTAMP,
GS_CAN_FEATURE_FD, GS_CAN_FEATURE_HW_TIMESTAMP,
)
dev = GsUsb.scan()[0]
dev.set_bitrate(250000)
dev.set_data_bitrate(1000000)
dev.start(GS_CAN_MODE_FD | GS_CAN_MODE_HW_TIMESTAMP)
frame = GsUsbFrame()
if dev.read(frame, timeout_ms=200):
print(frame) # shows FD / BRS / ESI flags automatically
dev.stop()
Publishing a new release
Push a version tag and GitHub Actions builds and publishes to PyPI automatically:
git tag v0.4.0
git push origin v0.4.0
The workflow uses PyPI Trusted Publishing (OIDC — no API token needed). On first use, configure the publisher on PyPI under the project settings:
- Publisher: GitHub Actions
- Owner:
diegoasanza - Repository:
candle-usb - Workflow:
publish.yml - Environment:
pypi
Fork notice
This is a fork of gs_usb by jxltom, extended with:
- Correct CAN FD frame parsing — dispatch on
GS_CAN_FLAG_FDin the frame header (matching the Linux kernel driver) instead of packet size, which breaks whenGS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZEis active - Hardware timestamp support (
GS_CAN_MODE_HW_TIMESTAMP) set_data_bitrate()and full CAN FD mode setuppycandumpCLI monitor- Identify LED and bus termination control
License
MIT — see LICENSE.
Original work © 2020 jxltom. Modifications © 2024 Diego Asanza.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file candle_usb-0.4.1.tar.gz.
File metadata
- Download URL: candle_usb-0.4.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92b8987135132040fafbb072208abdb3094a127bb28c23281c6d6e8675d95e6e
|
|
| MD5 |
cb7e97ec4e1dad62da03318ef9c30b6f
|
|
| BLAKE2b-256 |
1e91ccccf8acc066889fedff200e1b8cc011c71e86dae10466686678316f2a07
|
Provenance
The following attestation bundles were made for candle_usb-0.4.1.tar.gz:
Publisher:
publish.yml on asanza/candle-usb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
candle_usb-0.4.1.tar.gz -
Subject digest:
92b8987135132040fafbb072208abdb3094a127bb28c23281c6d6e8675d95e6e - Sigstore transparency entry: 1893421123
- Sigstore integration time:
-
Permalink:
asanza/candle-usb@702e347384bd65ce1d22f219f860560b85eae8a5 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/asanza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@702e347384bd65ce1d22f219f860560b85eae8a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file candle_usb-0.4.1-py3-none-any.whl.
File metadata
- Download URL: candle_usb-0.4.1-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e145457dd02225255a5e8138a87dea4c762598389d14254483152d008ae2eee
|
|
| MD5 |
319f153dd3d4f5c973a7a4b692aa1dea
|
|
| BLAKE2b-256 |
caf60ab3328857439c664d951775d708e59165ce4730636f5c0117f3a5c6c317
|
Provenance
The following attestation bundles were made for candle_usb-0.4.1-py3-none-any.whl:
Publisher:
publish.yml on asanza/candle-usb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
candle_usb-0.4.1-py3-none-any.whl -
Subject digest:
3e145457dd02225255a5e8138a87dea4c762598389d14254483152d008ae2eee - Sigstore transparency entry: 1893421266
- Sigstore integration time:
-
Permalink:
asanza/candle-usb@702e347384bd65ce1d22f219f860560b85eae8a5 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/asanza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@702e347384bd65ce1d22f219f860560b85eae8a5 -
Trigger Event:
push
-
Statement type: