Set up your CAN device ====================== List your CAN devices --------------------- .. note:: You can also list your CAN interfaces with the script :ref:`show-can-devices.sh ` or Your can have physical or virtual CAN interfaces or both. Virtual CAN interfaces don't require a device driver. They can be created on any Linux system and just emulate CAN interfaces. This is a great way to test CAN software without a CAN interface card. Enter the following command:: ip link show type vcan; ip link show type can If virtual CAN interfaces are set up, the output looks like this:: 4: vcan0: mtu 72 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/can 5: vcan1: mtu 72 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/can 6: vcan2: mtu 72 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/can 7: vcan3: mtu 72 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/can If physical CAN interfaces are set up, the output looks like this:: 3: can0: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can 4: can1: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can 5: can2: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can 6: can3: mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/can Set up your CAN interfaces -------------------------- Set up your device driver +++++++++++++++++++++++++ You need to have a CAN device driver installed for your CAN interface. Some CAN interface cards however, work with the standard drivers of the Linux Kernel. The standard kernel also contains drivers for a virtual CAN interface, here a CAN interface is only emulated. Initalization of physical CAN interfaces ++++++++++++++++++++++++++++++++++++++++ .. note:: You can load the driver and initialize your physical CAN interfaces with the script :ref:`init-can.sh `. First you may have to load a driver for your CAN bus interface. Here is a short list of drivers socan was tested with, depending on your CAN interface hardware your driver name may be different: - `PCAN-PCI Express FD `_: peak_pciefd - `PCAN-USB `_: peak_usb - `USB2CAN-Cable `_: not needed, driver is loaded automatically - `Virtual CAN Bus interface `_: vcan If you download and build the `PEAK-System `_ CAN Bus driver from source, it's name is "pcan". First see if your CAN driver is loaded (replace 'DRIVER' with the name of the driver you need):: lsmod | grep DRIVER If the command shows no output, load the driver with:: sudo modprobe DRIVER and repeat the 'lsmod' command. Now list all CAN devices:: ip link show type can For each CAN device do:: sudo ip link set down DEVICE Set the bit rate (For 1MBit use '1000000' for BITRATE) and set the transmission queue to 1000:: sudo ip link set DEVICE type can bitrate BITRATE sudo ip link set DEVICE txqueuelen 1000 Now bring the device up:: sudo ip link set up DEVICE Initalization of virtual CAN interfaces +++++++++++++++++++++++++++++++++++++++ .. note:: You can also initialize your virtual CAN interfaces with the script :ref:`init-can.sh `. First see if your CAN driver is loaded:: lsmod | grep vcan If the command shows no output, load the driver with:: sudo modprobe vcan and repeat the 'lsmod' command. Now list all CAN devices:: ip link show type vcan If there are none shown or you want to add an additional virtual CAN interface 'vcan' where N is a non negative integer (e.g. 'vcan2') enter:: sudo ip link add dev vcan type vcan now bring the device up:: sudo ip link set up vcan Linking of virtual CAN interfaces +++++++++++++++++++++++++++++++++ .. note:: You can also link your virtual CAN interfaces with the script :ref:`link-vcan-devices.sh `. First show, of a CAN link is already defined:: cangw -L If the output looks like this:: cangw -A -s vcan1 -d vcan0 -e # 0 handled 0 dropped 0 deleted cangw -A -s vcan0 -d vcan1 -e # 0 handled 0 dropped 0 deleted the link (here between vcan0 and vcan1) is already defined. If the link is not defined, you can add a link between two interfaces DEVICE1 and DEVICE2 (e.g. 'vcan0' and 'vcan1') like this:: sudo cangw -A -s DEVICE1 -d DEVICE2 -e sudo cangw -A -s DEVICE2 -d DEVICE1 -e You may remove the same link later on with:: sudo cangw -D -s DEVICE1 -d DEVICE2 -e sudo cangw -D -s DEVICE2 -d DEVICE1 -e Scripts and programs provided by socan -------------------------------------- These are described here: :doc:`programs`.