Skip to main content

Crate can_hal

Crate can_hal 

Source
Expand description

§can-hal

Hardware-agnostic traits for CAN bus communication.

This crate defines portable types and traits that CAN hardware backends (SocketCAN, PCAN, Kvaser, etc.) implement so that application code can be written once and run on any supported hardware.

§no_std support

This crate is no_std-compatible. The std feature (enabled by default) is not required for any of the trait definitions or frame types. Disable default features to use in embedded / no_std contexts:

[dependencies]
can-hal-rs = { version = "0.3", default-features = false }

§Quick start

use can_hal::{CanId, CanFrame};

let id = CanId::new_standard(0x123).unwrap();
let frame = CanFrame::new(id, &[0xDE, 0xAD]).unwrap();
assert_eq!(frame.id(), id);
assert_eq!(frame.data(), &[0xDE, 0xAD]);

Re-exports§

pub use bus::BusState;
pub use bus::BusStatus;
pub use bus::ErrorCounters;
pub use channel::Receive;
pub use channel::ReceiveFd;
pub use channel::Transmit;
pub use channel::TransmitFd;
pub use error::CanError;
pub use filter::Filter;
pub use filter::Filterable;
pub use frame::CanFdFrame;
pub use frame::CanFrame;
pub use frame::Frame;
pub use frame::Timestamped;
pub use id::CanId;
pub use timing::SamplePoint;

Modules§

bus
channel
error
filter
frame
id
timing
CAN bit-timing types.