REXGEN 1REXGEN 2REXGEN 2 IMU GNSSREXGEN AirSocketCANDeveloper

REXGEN SocketCAN driver: use a logger as a Linux CAN interface

Updated

Install the REXGEN SocketCAN driver on Linux, bring the logger up as can0 and send and receive frames with the standard SocketCAN tools.

What the driver does

The driver is a Linux kernel module, rexgen_usb. It makes a REXGEN logger connected over USB appear as SocketCAN network interfaces, one for each CAN channel (can0, can1). Any SocketCAN program can then use it: can-utils, python-can or your own code. The source is on GitHub at InfluxTechnology/rexgen-socketcan under the GPL-2.0 licence.

How a SocketCAN program reaches the CAN bus REXGEN · SOCKETCAN DRIVER How a SocketCAN program reaches the CAN bus Linux computer Your SocketCAN program can-utils (candump, cansend) or python-can SocketCAN interfaces can0, can1: one per CAN channel REXGEN SocketCAN driver rexgen_usb kernel module USB REXGEN logger USB PC connection CAN bus in the vehicle Set with ip link set can0 type can bitrate 500000 classic CAN bit rate dbitrate 8000000 fd on CAN FD data phase loopback on listen-only on fd-non-iso on non-ISO CAN FD Needs a USB PC connection: REXGEN Pro connects over Wi-Fi and cannot use the driver. REXGEN 1 is CAN 2.0 only, so the CAN FD options do not apply to it. can1 appears on a two-channel logger.

The driver needs a logger that connects to the PC over USB. These are REXGEN 1, REXGEN 2, REXGEN 2 IMU GNSS and REXGEN Air over its Micro USB port. REXGEN Pro connects over Wi-Fi and cannot use it. REXGEN 1 is CAN 2.0 only, so the CAN FD commands in this guide do not apply to it.

For how SocketCAN works, see the kernel SocketCAN documentation.

Install on Raspberry Pi OS

  1. Install the build tools and can-utils.
    sudo apt-get install git gcc make can-utils
  2. Install the kernel headers. The build uses the headers of the running kernel.
    sudo apt-get install raspberrypi-kernel-headers
  3. Get the source.
    git clone https://github.com/InfluxTechnology/rexgen-socketcan.git
    cd rexgen-socketcan
  4. Load the CAN core module.
    sudo modprobe can-dev
  5. Build and install the driver. The script removes any earlier build, builds the module, installs it and clears the kernel message log. Warnings during the build are normal.
    sudo ./do_make.sh
  6. Connect the logger and reboot. Plug the logger into a USB port, then restart the PC.

Install on Ubuntu

  1. Install the build tools, kernel headers and can-utils.
    sudo apt-get install git gcc make can-utils linux-headers-$(uname -r)
    The build needs the kernel headers.
  2. Get the source, load the CAN core module and build.
    git clone https://github.com/InfluxTechnology/rexgen-socketcan.git
    cd rexgen-socketcan
    sudo modprobe can-dev
    sudo ./do_make.sh
    Warnings during the build are normal.
  3. Connect the logger and reboot. Plug the logger into a USB port, then restart the PC.

Check that the driver is loaded

Module names use underscores, so search for can_dev, not can-dev.

lsmod | grep can_dev
lsmod | grep rexgen_usb
ip link show

With the logger connected, ip link show lists can0 (and can1 on a two-channel logger). If they are missing, run dmesg straight after you plug the logger in. It shows what the kernel reports.

Configure and bring up the interface

  1. Set the bit rate. For classic CAN at 500 kbit/s:
    sudo ip link set can0 type can bitrate 500000
    For CAN FD at 500 kbit/s with an 8 Mbit/s data phase (not on REXGEN 1):
    sudo ip link set can0 type can bitrate 500000 dbitrate 8000000 fd on
  2. Add a mode if you need one. The driver supports loopback, listen-only and non-ISO CAN FD:
    sudo ip link set can0 type can bitrate 500000 dbitrate 8000000 fd on loopback on
    sudo ip link set can0 type can bitrate 500000 dbitrate 8000000 fd on listen-only on
    sudo ip link set can0 type can bitrate 500000 dbitrate 8000000 fd on fd-non-iso on
  3. Start the interface.
    sudo ip link set can0 up

Send and receive frames

A frame gets through only on a connected, terminated bus with at least one other node to acknowledge it. Send with cansend:

cansend can0 123#112233             # classic frame, 11-bit identifier
cansend can0 00000123#112233        # classic frame, 29-bit identifier
cansend can0 123##0112233           # CAN FD frame
cansend can0 123##1112233           # CAN FD frame with bit rate switch
cansend can0 00000123##1112233      # CAN FD, bit rate switch, 29-bit identifier

Receive with candump. Add -x for extra detail, such as the direction and CAN FD flags:

candump can0
candump can0 -x

If nothing arrives, check that the bit rate matches the bus, then check the wiring and termination. See CAN bus wiring: termination, cable length and grounding.

Related tools

Products in this guide

REXGEN 1

Vehicle black box

View REXGEN 1 Ask an engineer

REXGEN 2

Evidence data logger

View REXGEN 2 Ask an engineer

REXGEN 2 IMU GNSS

Motion & location data logging

View REXGEN 2 IMU GNSS Ask an engineer

REXGEN Air

CAN to cloud

View REXGEN Air Ask an engineer

Still stuck?

Our engineers answer support questions on every Influx Technology product.