4 releases

new 0.2.0-alpha4 Mar 28, 2025
0.2.0-alpha2 Mar 26, 2025
0.1.0-beta0 Nov 15, 2024
0.1.0-alpha5 Oct 25, 2024
0.1.0-alpha2 Sep 10, 2024

#190 in Hardware support

Download history 11/week @ 2024-12-06 76/week @ 2025-03-14 224/week @ 2025-03-21

300 downloads per month

MIT OR GPL-3.0

275KB
5.5K SLoC

A Cross-platform ZLG(周立功) CAN driver.

Latest version Documentation LGPL MIT

Overview

zlgcan is a cross-platform driver for ZLG(周立功) device. Including 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, interfaces::ZLGCAN, ChannelConfig};
use zlgcan_rs::{can::{ZCanChlMode, ZCanChlType}, device::ZCanDeviceType, driver::{ZDevice, ZCanDriver}, CHANNEL_MODE, CHANNEL_TYPE, DEVICE_INDEX, DEVICE_TYPE};

fn main() -> Result<(), CanError> {
    let mut builder = DeviceBuilder::new(ZLGCAN);

    let mut ch1_cfg = ChannelConfig::new(500_000);
    ch1_cfg.add_other(CHANNEL_MODE, Box::new(ZCanChlMode::Normal as u8))
        .add_other(CHANNEL_TYPE, Box::new(ZCanChlType::CAN as u8));

    let mut ch2_cfg = ChannelConfig::new(500_000);
    ch2_cfg.add_other(CHANNEL_MODE, Box::new(ZCanChlMode::Normal as u8))
        .add_other(CHANNEL_TYPE, Box::new(ZCanChlType::CAN as u8));

    builder.add_other(DEVICE_TYPE, Box::new(ZCanDeviceType::ZCAN_USBCANFD_200U as u32))
        .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:

    ├── bitrate.cfg.yaml
    ├── linux
       └── x86_64
    └── windows
        ├── x86
        └── x86_64
    

    and copy all files into correct directory.

    The basic library. The bitrate.cfg.yaml

  • Create zcan.env at your project path for special ZCAN_LIBRARY path, For example:

    ZCAN_LIBRARY=/path/to/your/created
    

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.1–3MB
~64K SLoC