Bringing CAN interface up
SocketCAN provides several CAN interface types:
- virtual interfaces like vcan0
- native (real hardware) interfaces like can0
- SLCAN based interfaces like slcan0
Virtual CAN interfaces will be brought up via ipoute2 ip utility:
$ modprobe vcan $ sudo ip link add dev vcan0 type vcan $ sudo ip link set up vcan0
modprobe is needed in the case the driver is sill not loaded.
In most cases you won't need to load the kernel driver for your real hardware. So let us concentrate on ip invocation:
$ sudo ip link set can0 type can bitrate 125000 $ sudo ip link set up can0
Aside from bringing interface up it is important to specify bitrate (assumes that CONFIG_CAN_CALC_BITTIMING is enabled in kernel)
SLCAN based Interfaces
SLCAN based device provide a serial interface. At first you'll need a special daemon (slcand from can-utils), that will link this serial interface with a virtual CAN device. By default these devices get slcan name base. This is an example for a USB-to-CAN adapter working at 3Mbit/s:
$ sudo slcand -o -s8 -t hw -S 3000000 /dev/ttyUSB0 $ sudo ip link set up slcan0
So far there is no way to set bitrate for SLCAN based devices via ip tool, so you'll have to do this by slcand invocation: -sX parameter. -s8 in the above example will set adapter's bitrate to 1Mbit/s.