SocketCAN (Linux)
SocketCAN lets a Linux PC, Jetson, or Raspberry Pi control CAN and CAN FD devices directly. After the board is connected through USB, Linux exposes the four CAN/CAN FD channels as four canX network interfaces. You can use can-utils, python-can, or other SocketCAN software.
SocketCAN does not use SANPO ST, ET, SF, or EF headers. RS485 is not accessed through SocketCAN.
Connect and Identify the Board
Connect the board to the Linux host through USB.
Connect and power the motor on a board CAN interface.
Install tools and load the driver:
sudo apt update
sudo apt install can-utils
sudo modprobe gs_usb
List CAN interfaces:
ip link show type can
A complete board normally exposes four canX interfaces. Linux assigns numbers by enumeration order, so can0 to can3 do not identify physical board connectors by themselves.
For first use, connect one motor and send a query on each interface to identify the mapping. You can also inspect the USB path:
readlink -f /sys/class/net/can0/device
udevadm info -q property -p "$(readlink -f /sys/class/net/can0/device)"
For long-term use, create udev rules based on the USB physical port or device serial number to assign stable interface names.
Classic CAN
Configure can0 for 1 Mbps:
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 1000000
sudo ip link set can0 up
Monitor the bus:
candump can0
Send a standard frame:
cansend can0 123#11223344
Send an extended frame:
cansend can0 0000FD01#0102030405060708
cansend normally prints nothing on success. A reply depends on the motor protocol, ID, and current state.
CAN FD
Configure can0 for 1 Mbps arbitration, 5 Mbps data, and CAN FD:
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 1000000 dbitrate 5000000 fd on
sudo ip link set can0 up
Send a CAN FD standard frame with BRS:
cansend can0 123##11122334455667788
Send a CAN FD extended frame with BRS:
cansend can0 0000FD01##11122334455667788
After ##, the first hexadecimal digit contains CAN FD flags. 1 enables BRS; the remaining digits are data.
Check Interface State
ip -s -details link show can0
With CAN FD enabled, the output should show fd on, bitrate, and dbitrate. If error counters continue increasing, stop transmission and check bitrate, termination, wiring, and device power.
SocketCAN settings are not saved to the board. Reapply ip link settings after a power cycle, USB reconnect, or re-enumeration.
CyberGear Example
Example: SocketCAN CyberGear
Control motor ID 1 on can0:
sudo python3 socketcan_cybergear_demo_v6.py \
--setup-links \
--motor-map "can0:1"
Multiple interfaces:
--motor-map "can0:1,2,3;can1:4,5,6"
Update interface names and motor IDs to match the actual enumeration and wiring.
Troubleshooting
Symptom |
Action |
|---|---|
No |
Confirm both MCU devices have V6 firmware, run |
|
Run |
|
Set the interface down before configuring it again |
|
Check wiring, bitrate, and termination; after fixing the bus, set the interface down and up again |
Frames transmit but the motor does not reply |
Check |