Setting and testing a CAN bus connection in Linux

This content has 6 years. Please, read this page keeping its age in your mind.

Assuming that you have successfully customised the kernel and your raspberry pi configures the CANbus USB adapter correctly, it’s time to test the connection!

Configure the CANbus interface (the number at the end is the baud rate)

sudo ip link set can0 type can bitrate 125000

bring the connection up:

sudo ip link set up can0

Print interface info:

ifconfig 
ifconfig can0

Set up a listener and send it in the background (if you use server version and you have only terminal access)

candump can0 &

and then send something to the bus by executing:

cansend can0 123#1122334455667788

To run these tests, you should have installed the can-utils package.

External resources:

How To Use SocketCAN With The Command-Line In Linux