SocketCAN is a set of open source CAN device drivers and networking stack that extend the Berkeley socket API in Linux. Installing SocketCAN is rather easy. It introduces a new protocol family called PF_CAN. SocketCAN coexists with other protocol families like PF_INET for the Internet Protocol. The communication with the CAN bus is therefore done analogously to the use of the Internet Protocol, via sockets.

Installing SocketCAN

Installing SocketCAN is rather easy. In fact, it just needs to install Debian/Ubuntu packages. To proceed, uses the following command:

sudo apt-get install can-utils

You can find the detailed installation and configuration commands in the following web site. However, I copied some parts below to avoid the reader jumping from a site to another ans ease its life.

Enabling SockerCAN

By default, the SocketCAN device drivers are not automatically loaded by Linux at boot time on all systems: you may need to enable the relevant linux kernel modules. You can manually load these modules with the following command:

sudo modprobe can  sudo modprobe vcan  sudo modprobe slcan

Loading kernel modules at boot time

Instead of manually loading the modules after the system has booted, you can configure the system to do it automatically for you. For that, just edit the file /etc/modules and configure it as below:

# /etc/modules: kernel modules to load at boot time.  #  # This file contains the names of kernel modules that should be loaded  # at boot time, one per line. Lines beginning with "#" are ignored.  can  can_raw  can_dev  intrepid

Using SocketCAN with CanUSB

To use CanUSB with SocketCAN, you have to establish a “link” between the drivers and the hardware. This is done with the following command:

sudo slcand -o -c -s8 /dev/ttyACM0 can0

The -s parameter allow to configure different interface speed as indicated below.

ASCII Command CAN Bitrate
s0 10 Kbit/s
s1 20 Kbit/s
s2 50 Kbit/s
s3 100 Kbit/s
s4 125 Kbit/s
s5 250 Kbit/s
s6 500 Kbit/s
s7 800 Kbit/s
s8 1000 Kbit/s

If everything worked fine, you should now see the can0 network device. To very it, just type the following command:


Now that socketcan works, it is possible to prepare ROS to use CAN.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.