pub struct Interface { /* private fields */ }
Expand description
Interface for interacting with CANtact devices
Implementations§
Source§impl Interface
impl Interface
Sourcepub fn new() -> Result<Interface, Error>
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.
Sourcepub fn start(
&mut self,
rx_callback: impl FnMut(Frame) + Sync + Send + 'static,
) -> Result<(), Error>
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.
Sourcepub fn set_bitrate(&mut self, channel: usize, bitrate: u32) -> Result<(), Error>
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.
Sourcepub fn set_data_bitrate(
&mut self,
channel: usize,
bitrate: u32,
) -> Result<(), Error>
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.
Sourcepub fn set_bit_timing(
&mut self,
channel: usize,
brp: u32,
phase_seg1: u32,
phase_seg2: u32,
sjw: u32,
) -> Result<(), Error>
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.
Sourcepub fn set_monitor(
&mut self,
channel: usize,
enabled: bool,
) -> Result<(), Error>
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.
Sourcepub fn set_enabled(
&mut self,
channel: usize,
enabled: bool,
) -> Result<(), Error>
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.
Sourcepub fn set_loopback(
&mut self,
channel: usize,
enabled: bool,
) -> Result<(), Error>
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!
Sourcepub fn set_fd(&mut self, channel: usize, enabled: bool) -> Result<(), Error>
pub fn set_fd(&mut self, channel: usize, enabled: bool) -> Result<(), Error>
Enable or disable CAN FD support for a channel
Sourcepub fn supports_fd(&self) -> bool
pub fn supports_fd(&self) -> bool
Returns true if device suports CAN-FD operation, false otherwise.