Posted by: yegorich | January 23, 2014

Automatically Bring Up SLCAN Device Via Udev

SocketCAN supports SLCAN to work with serial to CAN converters speaking ASCII protocol. In order to use such device, you need a special daemon from can-utils, called slcand. So the normal procedure looks as follows (these tests were made with VScom USB-CAN adapter):

1. find, what tty name the adapter got using for example dmesg (in our case it is /dev/ttyUSB0)
2. start slcand as super user: slcand -o -s8 -t hw -S 3000000 ttyUSB0

If you execute “ip addr” now, you’ll see slcan0 in the list of available devices.

These steps could be automated, so that you won’t need to care about devices names, calling daemon etc.

Create following udev rule /etc/udev/rules.d/90-slcan.rules:

KERNEL=="ttyUSB?", ATTRS{interface}=="USB-CAN*", ACTION=="add", RUN+="/usr/local/bin/"

And then create following script /usr/local/bin/


echo $DEVNAME >> /tmp/udev-can.txt

if [ -z "$DEVNAME" ]; then
        exit 1

slcand -o -s8 -t hw -S 3000000 $DEVNAME

You’re done. Now as soon as you attach your CAN adapter, you’ll get slcan0 device working at 1Mbit/s (-s8).



  1. . Apart from the fact that I have a very regular job, writing could be the easy part; coming up with all the ideas will be the tough part.

  2. Thank you for this. Great ammount of good info.

  3. Few points are missing here:
    1. The modules “can”, “can_raw” and “slcan” need to be added to the kernel or you should add them to /etc/modules to load them automatically
    2. The suggested script will not work if you didn’t install the can-utils (perform “make install” in the can-utils directory)
    3. For me the script doesn’t work (i think it’s because it need root privileges as it uses hardware (ttyUSB0))

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: