gs_usb - GS-USB Protocol Implementation for Rust
A Rust implementation of the GS-USB protocol for communicating with CAN bus adapters like candleLight, CANable, and other GS-USB compatible devices.
Features
- Classic CAN Support: Up to 1 Mbps bitrate
- CAN FD Support: Up to 10 Mbps data rate with flexible data length
- Hardware Timestamps: Microsecond-precision timestamps from the device
- Multiple Operating Modes: Normal, listen-only, loopback, and one-shot modes
- Device State Monitoring: Error counters and bus state information
- Cross-Platform: Works on Linux, macOS, and Windows
Supported Devices
- GS-USB devices (VID: 0x1D50, PID: 0x606F)
- candleLight (VID: 0x1209, PID: 0x2323)
- CES CANext FD (VID: 0x1CD2, PID: 0x606F)
- ABE CANdebugger FD (VID: 0x16D0, PID: 0x10B8)
Installation
Add this to your Cargo.toml:
[]
= "0.1"
System Dependencies
This crate requires libusb to be installed:
Linux (Debian/Ubuntu):
Linux (Fedora):
macOS:
Windows: Download and install libusb from https://libusb.info/
Quick Start
use ;
use Duration;
Examples
Run the examples with:
# Basic usage example
# Device initialization sequence
# CAN FD channel start sequence
# Test all supported bitrates
# Test GET_STATE feature
Supported Bitrates
Classic CAN (87.5% sample point)
| Bitrate | 80 MHz | 40 MHz |
|---|---|---|
| 10 kbps | ✓ | ✓ |
| 20 kbps | ✓ | ✓ |
| 50 kbps | ✓ | ✓ |
| 100 kbps | ✓ | ✓ |
| 125 kbps | ✓ | ✓ |
| 250 kbps | ✓ | ✓ |
| 500 kbps | ✓ | ✓ |
| 800 kbps | ✓ | ✓ |
| 1 Mbps | ✓ | ✓ |
CAN FD Data Phase (75% sample point)
| Data Bitrate | 80 MHz | 40 MHz |
|---|---|---|
| 2 Mbps | ✓ | ✓ |
| 4 Mbps | ✓ | ✓ |
| 5 Mbps | ✓ | ✓ |
| 8 Mbps | ✓ | ✓ |
| 10 Mbps | - | ✓ |
API Overview
Device Discovery
// Scan for all GS-USB devices
let devices = scan?;
// Find a specific device by bus and address
let device = find?;
Configuration
// Set bitrate (classic CAN)
dev.set_bitrate?;
// Set CAN FD data bitrate
dev.set_data_bitrate?;
// Set raw timing parameters
dev.set_timing?;
Operating Modes
use *;
// Normal mode with hardware timestamps
dev.start?;
// Listen-only mode (no ACKs)
dev.start?;
// Loopback mode for testing
dev.start?;
// CAN FD mode
dev.start?;
Frame Types
use ;
// Standard frame (11-bit ID)
let frame = with_data;
// Extended frame (29-bit ID)
let frame = with_data;
// Remote transmission request
let frame = with_data;
// CAN FD frame with BRS (bit rate switch)
let frame = with_fd_data;
Device Information
// Get device info (channels, firmware version)
let info = dev.device_info?;
println!;
println!;
// Get device capabilities
let cap = dev.device_capability?;
println!;
println!;
// Check CAN FD support
if dev.supports_fd?
// Get bus state and error counters
if dev.supports_get_state?
Linux Permissions
To access USB devices without root on Linux, create a udev rule:
License
MIT License
Acknowledgments
This is a Rust port of the Python gs_usb library.