Legacy: CANard with Python

Applications: Using CANable from Python with CANard

NOTE: CANard is no longer recommended. Please use python-can for future python development with CANable applications

CANard is a python library that allows you to easily communicate on the CAN bus from Python. The library supports connecting to CANable/CANtact devices directly with PySerial, so it works well on both Windows and Linux systems without a kernel CAN module.

I have a fork of CANard available that fixes a couple of issues and is compatible with both Python 2 and Python 3.

CANard also supports native socketcan devices such as a CANtact/CANable initialized with slcand.

Getting started is quite simple:

"""Connect to CANable; print and echo any received frames"""
from canard import can
from canard.hw import cantact

dev = cantact.CantactDev("/dev/ttyACM0") # Connect to CANable that enumerated as ttyACM0
dev.set_bitrate(1000000) # Set the bitrate to a 1Mbaud
dev.start() # Go on the bus
count = 0

while True:
    count += 1
    frame = dev.recv() # Receive a CAN frame
    dev.send(frame) # Echo the CAN frame back out on the bus
    print(str(count) + ": " + str(frame)) # Print out the received frame