A comprehensive collection of test utilities for UART/serial and CAN bus communication on Linux systems.
This project was developed with assistance from Artificial Intelligence tools.
While the code has been reviewed and tested, users are advised to:
- ✅ Review and understand the code before deployment in production environments
- ✅ Thoroughly test the tools in your specific environment
- ✅ Use caution when testing on critical systems or hardware
- ✅ Report any issues or bugs encountered
The tools are provided as-is for testing and development purposes. Users assume full responsibility for their use.
This project provides three test tools for debugging and testing serial communication interfaces:
- comm_test (Recommended) - Integrated tool supporting both UART and CAN interfaces
- uart_test - Standalone UART/serial interface tester
- can_test - Standalone CAN bus interface tester
- ✅ Support for UART and CAN interfaces
- ✅ Configurable timeout and transmission intervals (millisecond precision)
- ✅ Auto-configuration for CAN interfaces (no manual setup required)
- ✅ Real-time data transmission/reception display
- ✅ Graceful exit with Ctrl+C signal handling
- ✅ Cross-platform support (x86 and ARM architectures)
- GCC compiler (for x86)
- ARM cross-compiler (for ARM builds):
arm-linux-gnueabihf-gcc
- Linux kernel with CAN support (for CAN tools)
- Root/sudo privileges (for CAN interface configuration)
# Build all tools
make
# Clean build artifacts
make clean
# Install to /usr/local/bin
make install# Build ARM versions
./build_arm.sh
# Or use Makefile directly
make -f Makefile.arm
make -f Makefile.arm clean
# Strip debug symbols and reduce size
make -f Makefile.arm strip
# Create deployment package
make -f Makefile.arm packageThe comm_test tool combines UART and CAN testing capabilities in one unified interface.
./comm_test -t <type> -d <device> -m <mode> [options]-t <type>: Interface type -uartorcan[required]-d <device>: Device name - e.g.,/dev/ttyAS3orcan0[required]-m <mode>: Operation mode -0for receive,1for send [required]-i <timeout>: Read timeout in milliseconds (default: 1000ms)-l <interval>: Send interval in milliseconds (default: 100ms)-h: Show help information
-b <baudrate>: Baud rate (default: 115200)- Supported rates: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600
-c <canid>: CAN ID in hex or decimal (default: 0x123)
UART Receive Mode:
# Basic receive mode
./comm_test -t uart -d /dev/ttyAS3 -m 0
# Custom baud rate and timeout
./comm_test -t uart -d /dev/ttyS0 -m 0 -b 9600 -i 5000
# USB serial adapter
./comm_test -t uart -d /dev/ttyUSB0 -m 0 -b 115200 -i 2000UART Send Mode:
# Basic send mode
./comm_test -t uart -d /dev/ttyAS3 -m 1
# Fast send (50ms interval)
./comm_test -t uart -d /dev/ttyAS3 -m 1 -b 115200 -l 50
# Slow send (2 second interval)
./comm_test -t uart -d /dev/ttyAS3 -m 1 -b 115200 -l 2000CAN Receive Mode:
# Listen for all CAN frames
./comm_test -t can -d can0 -m 0
# Long listening session (10 second timeout)
./comm_test -t can -d can0 -m 0 -i 10000
# Real-time monitoring (no timeout)
./comm_test -t can -d can0 -m 0 -i 0CAN Send Mode:
# Send standard CAN frame (ID=0x123)
./comm_test -t can -d can0 -m 1
# Custom CAN ID (hex)
./comm_test -t can -d can0 -m 1 -c 0x456 -l 100
# Custom CAN ID (decimal)
./comm_test -t can -d can0 -m 1 -c 300 -l 200
# High-speed send (10ms interval)
./comm_test -t can -d can0 -m 1 -c 0x100 -l 10Simple UART tester with fixed parameters.
# Receive mode
./uart_test -d /dev/ttyAS3 -b 115200 -m 0
# Send mode (fixed 2 second interval)
./uart_test -d /dev/ttyAS3 -b 115200 -m 1Simple CAN tester with fixed parameters.
# Receive mode
./can_test -d can0 -m 0
# Send mode
./can_test -d can0 -m 1 -i 0x123 -l 100comm_test automatically configures CAN interfaces on startup:
- Brings down the interface
- Configures bitrate to 500Kbps
- Brings up the interface
Note: Automatic configuration requires root privileges.
If you prefer to configure manually:
# Load CAN kernel modules
sudo modprobe can
sudo modprobe can_raw
# Configure CAN interface (e.g., can0 at 500Kbps)
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
# Verify interface status
ip -details link show can0./build_arm.shscp build_arm/comm_test root@<device-ip>:/usr/local/bin/chmod +x /usr/local/bin/comm_test
comm_test -t uart -d /dev/ttyAS3 -m 1 -b 115200- Receive:
<device> 接收[bytes]: <data> - Send:
<device> 发送[counter]: <data>
- Receive:
<device> 接收[bytes]: ID=0xXXX DLC=N 数据: XX XX XX XX XX XX XX XX - Send:
<device> 发送: ID=0xXXX DLC=N 数据: XX XX XX XX XX XX XX XX
All tools support graceful exit via:
- Ctrl+C (SIGINT)
killcommand (SIGTERM)
Resources are properly cleaned up on exit.
.
├── comm_test.c # Integrated UART/CAN test tool
├── uart_test.c # Standalone UART test tool
├── can_test.c # Standalone CAN test tool
├── Makefile # Native build configuration
├── Makefile.arm # ARM cross-compilation configuration
├── build_arm.sh # ARM build script
└── build_x86.sh # x86 build script
| Tool | Features | Recommended For |
|---|---|---|
| comm_test | ✅ Most comprehensive ✅ Single tool for both interfaces ✅ Fully configurable ✅ Bilingual interface |
Daily use - all scenarios |
| uart_test | Simple, fixed parameters | Basic UART testing only |
| can_test | Simple, fixed parameters | Basic CAN testing only |
Recommendation: Use comm_test for most scenarios. It provides the most complete functionality and best user experience.
This project is provided as-is for testing and development purposes.
Contributions are welcome! Please feel free to submit issues or pull requests.