Struct Interface

Source
pub struct Interface { /* private fields */ }
Expand description

Interface for interacting with CANtact devices

Implementations§

Source§

impl Interface

Source

pub fn new() -> Result<Interface, Error>

Creates a new interface. This always selects the first device found by libusb. If no device is found, Error::DeviceNotFound is returned.

Source

pub fn start( &mut self, rx_callback: impl FnMut(Frame) + Sync + Send + 'static, ) -> Result<(), Error>

Start CAN communication on all configured channels.

After starting the device, Interface.send can be used to send frames. For every received frame, the rx_callback closure will be called.

Source

pub fn stop(&mut self) -> Result<(), Error>

Stop CAN communication on all channels.

Source

pub fn set_bitrate(&mut self, channel: usize, bitrate: u32) -> Result<(), Error>

Set bitrate for specified channel to requested bitrate value in bits per second.

Source

pub fn set_data_bitrate( &mut self, channel: usize, bitrate: u32, ) -> Result<(), Error>

Set CAN FD data bitrate for specified channel to requested bitrate value in bits per second.

Source

pub fn set_bit_timing( &mut self, channel: usize, brp: u32, phase_seg1: u32, phase_seg2: u32, sjw: u32, ) -> Result<(), Error>

Set a custom bit timing for the specified channel.

Source

pub fn set_monitor( &mut self, channel: usize, enabled: bool, ) -> Result<(), Error>

Enable or disable a channel’s listen only mode. When this mode is enabled, the device will not transmit any frames, errors, or acknowledgements.

Source

pub fn set_enabled( &mut self, channel: usize, enabled: bool, ) -> Result<(), Error>

Enable or disable a channel’s listen only mode. When this mode is enabled, the device will not transmit any frames, errors, or acknowledgements.

Source

pub fn set_loopback( &mut self, channel: usize, enabled: bool, ) -> Result<(), Error>

Enable or disable a channel’s loopback mode. When this mode is enabled, frames sent by the device will be received by the device as if they had been sent by another node on the bus.

This mode is primarily intended for device testing!

Source

pub fn set_fd(&mut self, channel: usize, enabled: bool) -> Result<(), Error>

Enable or disable CAN FD support for a channel

Source

pub fn supports_fd(&self) -> bool

Returns true if device suports CAN-FD operation, false otherwise.

Source

pub fn send(&mut self, f: Frame) -> Result<(), Error>

Send a CAN frame using the device

Source

pub fn channels(&self) -> usize

Returns the number of channels this Interface has

Trait Implementations§

Source§

impl Debug for Interface

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.