Skip to content

SocketCAN Development Guide

SocketCAN is the CAN bus protocol stack natively supported by Linux kernel. KH-UCANFD_Linux SDK is fully compatible with SocketCAN interface.

SocketCAN Initialization

Device Identification

Confirm whether CAN device is properly mounted and obtain device basic information (such as model, interface name).

Device Configuration

Set core parameters such as bit rate, sample point, and operating mode to ensure bus communication matching.

📚 Detailed Operation Guide: SocketCAN Basic Configuration

can-utils Tool Set

can-utils is the official SocketCAN command-line toolset that provides rapid CAN communication testing and debugging capabilities. Common tools are shown in the table below.

Tool CommandFunction DescriptionCommon Parameter Example
cansendSend single CAN framecansend can0 123#112233445566
candumpListen to and record CAN frames, can output to screen or filecandump -l -t a can0
cansnifferReal-time listening to CAN frames, display grouped by ID, supports filteringcansniffer -c can0
canbusloadStatistics of CAN bus load ratecanbusload can0@500000

📦 Tool Set Complete Documentation: can-utils Usage Guide

SocketCAN Programming

SocketCAN's core advantage is supporting standard Socket programming interface, allowing developers to quickly implement CAN frame transmission/reception, filtering, and exception handling based on this. Programming modules will cover following core content:

  • SocketCAN socket creation and initialization (AF_CAN protocol family configuration)
  • CAN frame structure parsing (standard frame/extended frame, data field, ID, etc.)
  • Core interface usage for bind(), sendto(), recvfrom()
  • CAN frame filtering rule configuration and interrupt handling
  • CAN FD high-bandwidth communication programming implementation

💻 Programming Practice Tutorial: SocketCAN Programming

Driving Intelligent Connections, Empowering the Future