6 releases

3.0.0-rc2 Aug 13, 2024
3.0.0-rc0 Aug 12, 2024
2.0.0-rc3 Jun 11, 2024
1.0.0-rc4 May 31, 2024
0.2.2 Mar 30, 2024

#337 in Hardware support

Download history 105/week @ 2024-07-03 8/week @ 2024-07-24 335/week @ 2024-08-07 106/week @ 2024-08-14 17/week @ 2024-09-11 6/week @ 2024-09-18 49/week @ 2024-09-25 35/week @ 2024-10-02

85 downloads per month

GPL-3.0 license

8MB
7.5K SLoC

Rust 6.5K SLoC // 0.0% comments C 563 SLoC // 0.0% comments INI 382 SLoC C++ 377 SLoC // 0.0% comments

Contains (Windows DLL, 650KB) ZlgCloud.dll, (Windows DLL, 525KB) ZlgCloud.dll, (ELF lib, 425KB) library/linux/x86_64/libusb-1.0.so, (ELF lib, 380KB) library/linux/x86_64/libusbcanfd800u.so, (Windows DLL, 285KB) CANFDNET.dll, (Windows DLL, 300KB) CANWIFI_TCP.dll and 35 more.

How to use:

use can_type_rs::frame::Frame;
use can_type_rs::identifier::Id;
use zlgcan_common::can::{CanChlCfgExt, CanChlCfgFactory, ZCanChlMode, ZCanChlType, CanMessage};
use zlgcan_common::device::ZCanDeviceType;
use zlgcan_common::error::ZCanError;
use zlgcan_driver::driver::{ZCanDriver, ZDevice};

#[test]
fn main() -> anyhow::Result<()> {
    let dev_type = ZCanDeviceType::ZCAN_USBCANFD_200U;
    let dev_idx = 0;

    // Create driver instance
    let mut driver = ZCanDriver::new(dev_type as u32, dev_idx, None)?;

    // Open device
    driver.open()?;

    // Get device info and assert some information
    let dev_info = driver.device_info()?;
    assert_eq!(dev_info.can_channels(), 2);
    assert_eq!(dev_info.canfd(), true);

    // Create channel configuration factory
    let factory = CanChlCfgFactory::new()?;
    let ch1_cfg = factory.new_can_chl_cfg(dev_type as u32, ZCanChlType::CANFD_ISO as u8, ZCanChlMode::Normal as u8, 500_000,
                                          CanChlCfgExt::new(None, Some(1_000_000), None, None, None, None))?;
    let ch2_cfg = factory.new_can_chl_cfg(dev_type as u32, ZCanChlType::CANFD_ISO as u8, ZCanChlMode::Normal as u8, 500_000,
                                          CanChlCfgExt::new(None, Some(1_000_000), None, None, None, None))?;
    let cfg = vec![ch1_cfg, ch2_cfg];

    // intialize channels
    driver.init_can_chl(cfg)?;

    // Create CANFD frame
    let mut msg = CanMessage::new(
        Id::from_bits(0x7df, false), [0x01, 0x02, 0x03, 0x04, 0x05].as_slice()
    )
        .ok_or(ZCanError::Other("invalid data length".to_string()))?;
    msg.set_can_fd(true);
    let frames = vec![msg];

    // Transmit frame
    let ret = driver.transmit_canfd(0, frames)?;
    assert_eq!(ret, 1);

    driver.close();

    Ok(())
}

How to test

  • Enter driver/tests folder. Select test file by your device type.
  • If the channels of device is less than 2:
    • Connect another CAN device with you device's channel for a monitor.
    • Then run the selected testcase.
    • When see receive frame from the monitor, then send frame by the monitor device.
    • It means pass when the testcase exited without any panic.
  • If the channels of device is rather than 2:
    • Connected the channels 0 and 1.
    • Then run the selected testcase.
    • It means pass when the testcase exited without any panic.
  • All testcase will output the send and received debug info.

The tested device list(include windows and linux):

  • USBCAN1 (include office device and deriving device)
  • USBCAN2 (only deriving device)
  • USBCANFD-200U
  • USBCANFD-400U (without supporting channel 3 and 4)

LICENSE

  • GNU LESSER GENERAL PUBLIC LICENSE V3

Dependencies

~4–11MB
~118K SLoC