Skip to content

Serial line CAN interface implementation in Rust with support for CAN FD

License

Notifications You must be signed in to change notification settings

adom-inc/slcan_fd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slcan_fd

A portable serial line CAN (slcan) interface for Rust with support for the newer CAN FD protocol.

Since sending and receiving CAN FD frames over an SLCAN interface is not standardized, this crate looks to be compatible with the commands supported by the CANable 2.0 Firmware.

By default this crate is async and uses the tokio-serial crate, but it can also be used in a sync context (See Cargo Features).

Usage

use slcan_fd::{tokio::CanSocket, NominalBitRate, OperatingMode};
use tokio_serial::SerialPortBuilderExt;

let mut port = tokio_serial::new("/dev/ttyUSB0", 115_200).open_native_async()?;

#[cfg(unix)]
port.set_exclusive(false)
    .expect("Unable to set serial port exclusive to false");

let mut can = CanSocket::new(port);

can.close().await?;
can.set_operating_mode(OperatingMode::Silent).await?;
can.open(NominalBitRate::Rate500Kbit).await?;

loop {
    match can.read().await {
        Ok(frame) => println!("{:?}", frame),
        Err(e) => eprintln!("{:?}", e),
    }
}

Cargo Features

The tokio feature is enabled by default.

  • tokio - Implements the async API with the tokio-serial crate.
  • sync - Implements the synchronous API with the serialport crate.

Credits

This crate is very loosely based on a previous crate for slcan without FD support which can be found here.

About

Serial line CAN interface implementation in Rust with support for CAN FD

Topics

Resources

License

Stars

Watchers

Forks

Languages