Skip to content

BIRLab/python-can-candle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-can-candle

PyPI - Version Python Version from PEP 621 TOML GitHub Actions Workflow Status

Full featured CAN driver for Geschwister Schneider USB/CAN devices.

Support Multichannel and CAN FD.

Installation

pip install python-can-candle

Example

Using with python-can

This library implements the plugin interface in python-can, aiming to replace the gs_usb interface within it.

import can
from candle import CandleBus

# Create a CandleBus instance in the python-can API.
with can.Bus(interface='candle', channel=0, ignore_config=True) as bus:
    # Bus is an instance of CandleBus.
    assert isinstance(bus, CandleBus)

Set ignore_config=True is recommended to prevent potential type casts.

Configurations

You can configure the device by appending the following parameters when creating the can.Bus.

  • bitrate: int, defaults to 1000000
  • sample_point: float, defaults to 87.5
  • data_bitrate: int, defaults to 5000000
  • data_sample_point: float, defaults to 87.5
  • fd: bool, defaults to False
  • loop_back: bool, defaults to False
  • listen_only: bool, defaults to False
  • triple_sample: bool, defaults to False
  • one_shot: bool, defaults to False
  • bit_error_reporting: bool, defaults to False
  • termination: bool or None, defaults to None

For example, create a canfd device with 1M bitrate and 5M data bitrate.

with can.Bus(interface='candle', channel=0, fd=True, bitrate=1000000, data_bitrate=5000000, ignore_config=True) as bus:
    ...

Connect multiple devices

When connecting multiple devices at the same time, you can set channel to serial_number:channel to create the specified can.Bus.

with can.Bus(interface='candle', channel='208233AD5003:0', ignore_config=True) as bus:
    ...

You can also select devices by appending some additional parameters.

  • vid: int, vendor ID
  • pid: int, product ID
  • manufacture: str, manufacture string
  • product: str, product string
  • serial_number: str, serial number

Device Discovery

Detect all available channels.

channels = can.detect_available_configs('candle')
print(channels)

Performance

The communication layer is implemented based on pybind11 with libusb. You can run the following script to evaluate the performance.

python -m candle.stress

Reference

About

CAN driver for Geschwister Schneider USB/CAN devices

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages