CAN driver for Geschwister Schneider USB/CAN devices
Project description
python-can-candle
CAN driver for Geschwister Schneider USB/CAN devices.
Feature
Support multichannel and can fd.
Installation
pip install python-can-candle
Example
Using with python-can (recommended)
This library implements the plugin interface in python-can, aiming to replace the gs_usb interface within it.
import can
from candle import CandleBus
bus: CandleBus # This line is added to provide type hints.
with can.Bus(interface='candle', channel=0) as bus:
# Create listener and notifier.
print_listener = can.Printer()
notifier = can.Notifier(bus, [print_listener])
# Send normal can message without data.
bus.send(can.Message(arbitration_id=1, is_extended_id=False))
# Send normal can message with extended id
bus.send(can.Message(arbitration_id=2, is_extended_id=True))
# Send normal can message with data.
bus.send(can.Message(arbitration_id=3, is_extended_id=False, data=[i for i in range(8)]))
# Send can fd message.
if bus.is_fd_supported:
bus.send(can.Message(arbitration_id=3, is_extended_id=False, is_fd=True, bitrate_switch=True, error_state_indicator=True, data=[i for i in range(64)]))
# Stop notifier.
notifier.stop()
candle-api
Using the API directly can be very cumbersome. However, we still provide a simple example for developers to refer to.
from candle.candle_api import CandleDevice, GSHostFrame, GSHostFrameHeader, GSCANFlag
# Scan available devices.
available_devices = list(CandleDevice.scan())
# Select a device.
for i, device in enumerate(available_devices):
print(f'{i}: {device}')
device = available_devices[int(input('Select a device by index: '))]
# Select a interface.
interface = device[0]
# Select a channel.
channel = interface[int(input(f'Select a channel by index (total {len(interface)}): '))]
# Send a frame.
channel.write(
GSHostFrame(
header=GSHostFrameHeader(
echo_id=0,
can_id=1,
can_dlc=8,
channel=channel.index,
flags=GSCANFlag(0)
),
data=bytes([i for i in range(8)])
)
)
# Receive a frame.
frame = channel.read()
print(frame.data)
Reference
https://github.com/torvalds/linux/blob/master/drivers/net/can/usb/gs_usb.c
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 python_can_candle-0.0.1.tar.gz.
File metadata
- Download URL: python_can_candle-0.0.1.tar.gz
- Upload date:
- Size: 45.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3953df661c10aa6d8dc3032ea474d796082697a31e730393733d24701444f817
|
|
| MD5 |
653ce6d47a1726e489c6ec9f1e7ad1d3
|
|
| BLAKE2b-256 |
8bc8e8f8e1ebddc84d45ece6998d74545b7f0972455a8bcfc10eac83720daca0
|
File details
Details for the file python_can_candle-0.0.1-py3-none-any.whl.
File metadata
- Download URL: python_can_candle-0.0.1-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
742966f4ab8ad047af3972c0be2641dd8578b817348f5046b782fe4244857024
|
|
| MD5 |
0623ac2d50b90ac2d732121ce7639cd7
|
|
| BLAKE2b-256 |
790efe63b13118f15e93ffa7e474e2a645e80d4030c1b5818b7ac6acc5196dd5
|