Struct SocketCan

Source
pub struct SocketCan { /* private fields */ }

Implementations§

Source§

impl SocketCan

Source

pub fn new() -> Self

Source

pub fn init_channel( &mut self, channel: &str, canfd: bool, ) -> Result<(), CanError>

Source

pub fn read(&self, channel: &str) -> Result<CanMessage, CanError>

Source

pub fn read_timeout( &self, channel: &str, timeout: Duration, ) -> Result<CanMessage, CanError>

Blocking read a single can frame with timeout.

Source

pub fn write(&self, msg: CanMessage) -> Result<(), CanError>

Source

pub fn write_timeout( &self, msg: CanMessage, timeout: Duration, ) -> Result<(), CanError>

Blocking write a single can frame, retrying until it gets sent successfully.

Source

pub fn set_nonblocking( &self, channel: &str, nonblocking: bool, ) -> Result<(), CanError>

Change socket to non-blocking mode or back to blocking mode.

Source

pub fn set_read_timeout( &self, channel: &str, duration: Duration, ) -> Result<(), CanError>

Sets the read timeout on the socket

For convenience, the result value can be checked using ShouldRetry::should_retry when a timeout is set.

Source

pub fn set_write_timeout( &self, channel: &str, duration: Duration, ) -> Result<(), CanError>

Sets the write timeout on the socket

Source§

impl SocketCan

Source

pub fn set_filters( &self, channel: &str, filters: &[CanFilter], ) -> Result<(), CanError>

Sets CAN ID filters on the socket.

CAN packages received by SocketCAN are matched against these filters, only matching packets are returned by the interface.

See CanFilter for details on how filtering works. By default, all single filter matching all incoming frames is installed.

Source

pub fn set_filter_drop_all(&self, channel: &str) -> Result<(), CanError>

Disable reception of CAN frames.

Sets a completely empty filter; disabling all CAN frame reception.

Source

pub fn set_filter_accept_all(&self, channel: &str) -> Result<(), CanError>

Accept all frames, disabling any kind of filtering.

Replace the current filter with one containing a single rule that accepts all CAN frames.

Source

pub fn set_error_filter(&self, channel: &str, mask: u32) -> Result<(), CanError>

Sets the error mask on the socket.

By default (ERR_MASK_NONE) no error conditions are reported as special error frames by the socket. Enabling error conditions by setting ERR_MASK_ALL or another non-empty error mask causes the socket to receive notification about the specified conditions.

Source

pub fn set_error_filter_drop_all(&self, channel: &str) -> Result<(), CanError>

Sets the error mask on the socket to reject all errors.

Source

pub fn set_error_filter_accept_all(&self, channel: &str) -> Result<(), CanError>

Sets the error mask on the socket to accept all errors.

Source

pub fn set_loopback(&self, channel: &str, enabled: bool) -> Result<(), CanError>

Enable or disable loopback.

By default, loopback is enabled, causing other applications that open the same CAN bus to see frames emitted by different applications on the same system.

Source

pub fn set_recv_own_msgs( &self, channel: &str, enabled: bool, ) -> Result<(), CanError>

Enable or disable receiving of own frames.

When loopback is enabled, this settings controls if CAN frames sent are received back immediately by sender. Default is off.

Source

pub fn set_join_filters( &self, channel: &str, enabled: bool, ) -> Result<(), CanError>

Enable or disable join filters.

By default a frame is accepted if it matches any of the filters set with set_filters. If join filters is enabled, a frame has to match all filters to be accepted.

Trait Implementations§

Source§

impl Device for SocketCan

Source§

type Channel = String

Source§

type Frame = CanMessage

Source§

fn opened_channels(&self) -> Vec<Self::Channel>

get all channels that has opened
Source§

fn transmit( &self, msg: Self::Frame, timeout: Option<u32>, ) -> CanResult<(), CanError>

Transmit a CAN or CAN-FD Frame.
Source§

fn receive( &self, channel: Self::Channel, timeout: Option<u32>, ) -> CanResult<Vec<Self::Frame>, CanError>

Receive CAN and CAN-FD Frames.
Source§

fn shutdown(&mut self)

Close CAN device.
Source§

fn is_closed(&self) -> bool

Source§

impl Clone for SocketCan

Source§

fn clone(&self) -> SocketCan

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SocketCan

Source§

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

Formats the value using the given formatter. Read more
Source§

impl TryFrom<DeviceBuilder<String>> for SocketCan

Source§

type Error = Error

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

fn try_from(builder: DeviceBuilder<String>) -> Result<Self, Self::Error>

Performs the conversion.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.