pub struct CanSocket { /* private fields */ }
Expand description

A socket for a CAN device.

Will be closed upon deallocation. To close manually, use std::drop::Drop. Internally this is just a wrapped file-descriptor.

Implementations

Open a named CAN device.

Usually the more common case, opens a socket can device by name, such as “vcan0” or “socan0”.

Open CAN device by interface number.

Opens a CAN device by kernel interface number.

Change socket to non-blocking mode

Sets the read timeout on the socket

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

Sets the write timeout on the socket

Blocking read a single can frame.

Blocking read a single can frame with timestamp

Note that reading a frame and retrieving the timestamp requires two consecutive syscalls. To avoid race conditions, exclusive access to the socket is enforce through requiring a mut &self.

Write a single can frame.

Note that this function can fail with an EAGAIN error or similar. Use write_frame_insist if you need to be sure that the message got sent or failed.

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

Sets 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.

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.

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.

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.

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

Extracts the raw file descriptor. Read more

Associated frame type.

Associated error type.

Blocks until a frame was received or an error occured.

Puts a frame in the transmit buffer. Blocks until space is available in the transmit buffer. Read more

Associated frame type.

Associated error type.

Returns a received frame if available.

Puts a frame in the transmit buffer to be sent on the bus. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Constructs a new instance of Self from the given raw file descriptor. Read more

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.