Skip to main content

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 --active whenever 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_FD in the frame header (matching the Linux kernel driver) instead of packet size, which breaks when GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE is active
  • Hardware timestamp support (GS_CAN_MODE_HW_TIMESTAMP)
  • set_data_bitrate() and full CAN FD mode setup
  • pycandump CLI monitor
  • Identify LED and bus termination control

License

MIT — see LICENSE.
Original work © 2020 jxltom. Modifications © 2024 Diego Asanza.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

candle_usb-0.4.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

candle_usb-0.4.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

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

Hashes for candle_usb-0.4.1.tar.gz
Algorithm Hash digest
SHA256 92b8987135132040fafbb072208abdb3094a127bb28c23281c6d6e8675d95e6e
MD5 cb7e97ec4e1dad62da03318ef9c30b6f
BLAKE2b-256 1e91ccccf8acc066889fedff200e1b8cc011c71e86dae10466686678316f2a07

See more details on using hashes here.

Provenance

The following attestation bundles were made for candle_usb-0.4.1.tar.gz:

Publisher: publish.yml on asanza/candle-usb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for candle_usb-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e145457dd02225255a5e8138a87dea4c762598389d14254483152d008ae2eee
MD5 319f153dd3d4f5c973a7a4b692aa1dea
BLAKE2b-256 caf60ab3328857439c664d951775d708e59165ce4730636f5c0117f3a5c6c317

See more details on using hashes here.

Provenance

The following attestation bundles were made for candle_usb-0.4.1-py3-none-any.whl:

Publisher: publish.yml on asanza/candle-usb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page