REXGEN 1REXGEN 2REXGEN 2 IMU GNSSREXGEN AirSocketCANDeveloper
REXGEN SocketCAN driver: use a logger as a Linux CAN interface
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.
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
-
Install the build tools and can-utils.
sudo apt-get install git gcc make can-utils -
Install the kernel headers. The build uses the headers of the running kernel.
sudo apt-get install raspberrypi-kernel-headers -
Get the source.
git clone https://github.com/InfluxTechnology/rexgen-socketcan.git cd rexgen-socketcan -
Load the CAN core module.
sudo modprobe can-dev -
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 - Connect the logger and reboot. Plug the logger into a USB port, then restart the PC.
Install on Ubuntu
-
Install the build tools, kernel headers and can-utils.
The build needs the kernel headers.sudo apt-get install git gcc make can-utils linux-headers-$(uname -r) -
Get the source, load the CAN core module and build.
Warnings during the build are normal.git clone https://github.com/InfluxTechnology/rexgen-socketcan.git cd rexgen-socketcan sudo modprobe can-dev sudo ./do_make.sh - 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
-
Set the bit rate. For classic CAN at 500 kbit/s:
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 500000sudo ip link set can0 type can bitrate 500000 dbitrate 8000000 fd on -
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 -
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
- To watch live CAN in a graphical tool, see REXGEN: live CAN with SavvyCAN.
- To drive the logger from your own Windows application, see REXGEN Open API: control a logger over USB from your own application.
- To use the logger as a diagnostic pass-thru interface, see REXGEN: use the logger as a J2534 pass-thru interface.
Products in this guide
Still stuck?
Our engineers answer support questions on every Influx Technology product.