8 releases
new 0.2.3 | Apr 11, 2025 |
---|---|
0.2.2 | Apr 10, 2025 |
0.2.0 | Mar 31, 2025 |
0.1.0-beta0 |
|
0.1.0-alpha2 |
|
#181 in Hardware support
1,230 downloads per month
275KB
5.5K
SLoC
Overview
zlgcan is a cross-platform driver for ZLG(周立功) device. Include windows and linux.
It is a part of rust-can driver.
It also can use UDS-protocol directly.
Please refer to examples
for usage examples
Device list
- USBCAN-I/II
- USBCANFD-200U
- USNCANFD-400U(only channel 1 and channel 2 can be used)
- USBCANFD-800U
Prerequisites
- Rust 1.70 or higher
- Cargo (included with Rust)
Demo
use rs_can::{CanError, DeviceBuilder, ChannelConfig};
use zlgcan_rs::{can::{ZCanChlMode, ZCanChlType}, device::ZCanDeviceType, driver::{ZDevice, ZCanDriver}, CHANNEL_MODE, CHANNEL_TYPE, DEVICE_INDEX, DEVICE_TYPE, LIBPATH};
fn main() -> Result<(), CanError> {
let mut builder = DeviceBuilder::new();
let mut ch1_cfg = ChannelConfig::new(500_000);
ch1_cfg.add_other(CHANNEL_MODE, Box::new(ZCanChlMode::Normal))
.add_other(CHANNEL_TYPE, Box::new(ZCanChlType::CAN));
let mut ch2_cfg = ChannelConfig::new(500_000);
ch2_cfg.add_other(CHANNEL_MODE, Box::new(ZCanChlMode::Normal))
.add_other(CHANNEL_TYPE, Box::new(ZCanChlType::CAN));
builder
.add_other(LIBPATH, Box::new("library".to_string()))
.add_other(DEVICE_TYPE, Box::new(ZCanDeviceType::ZCAN_USBCANFD_200U))
.add_other(DEVICE_INDEX, Box::new(0))
.add_config(0.to_string(), ch1_cfg)
.add_config(1.to_string(), ch2_cfg);
let device = builder.build::<ZCanDriver>()?;
// todo something
Ok(())
}
Adding to Your Project
To use zlgcan in your Rust project, add it as a dependency in your Cargo.toml
:
[dependencies]
zlgcan = { version="lastest-version" }
Create library and configuration
-
Create folder and ensure the file of folder like:
library ├── bitrate.cfg.yaml ├── linux │ └── x86_64 └── windows ├── x86 └── x86_64
and copy all files into correct directory.
The basic library. The bitrate.cfg.yaml
-
Configurate your device builder:
fn main() { let mut builder = DeviceBuilder::new(); builder .add_other(LIBPATH, Box::new("library".to_string())) }
Known defects
- The timestamp of frame is incorrect.
Contributing
We're always looking for users who have thoughts on how to make zlgcan
better, or users with
interesting use cases.
Of course, we're also happy to accept code contributions for outstanding feature requests!
Dependencies
~2–3MB
~62K SLoC