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 Command | Function Description | Common Parameter Example |
|---|---|---|
| cansend | Send single CAN frame | cansend can0 123#112233445566 |
| candump | Listen to and record CAN frames, can output to screen or file | candump -l -t a can0 |
| cansniffer | Real-time listening to CAN frames, display grouped by ID, supports filtering | cansniffer -c can0 |
| canbusload | Statistics of CAN bus load rate | canbusload 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