Skip to main content

SocketCan

Struct SocketCan 

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

A CANopen transport over a Linux SocketCAN interface.

Implementations§

Source§

impl SocketCan

Source

pub fn open(interface: &str) -> Result<Self>

Open the named CAN interface (e.g. "can0" or "vcan0").

Fails with a message naming the interface — and hinting that it may not be up — if it does not exist.

Source

pub fn set_read_timeout(&self, timeout: Duration) -> Result<()>

Set a read timeout, so SocketCan::recv (and the SDO helpers) fail with a timeout error rather than blocking forever.

Source

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

Put the socket into (non-)blocking mode.

Source

pub fn send(&self, cob_id: u16, data: &[u8]) -> Result<()>

Transmit data on COB-ID cob_id as a standard data frame.

Source

pub fn recv(&self) -> Result<Received>

Receive the next CANopen data frame, skipping remote and error frames and any frame with a 29-bit extended identifier.

Source

pub fn send_nmt(&self, command: NmtCommand, target: NodeId) -> Result<()>

Send an NMT node-control command to target on COB-ID 0x000.

Use NodeId::BROADCAST to address every node at once — e.g. send_nmt(NmtCommand::StartRemoteNode, NodeId::BROADCAST).

Source

pub fn sdo_read( &self, node: NodeId, addr: Address, data_type: DataType, ) -> Result<Value, SdoError>

Read object addr from node, interpreting the result as data_type.

Runs the full SDO upload transaction (expedited or segmented) and returns the value, or an SdoError on abort or I/O failure. Set a read timeout first so an unresponsive node cannot block forever.

Source

pub fn sdo_write( &self, node: NodeId, addr: Address, value: Value, ) -> Result<(), SdoError>

Write value to object addr on node.

Runs the full SDO download transaction (expedited or segmented), choosing the transfer type from the value’s size.

Trait Implementations§

Source§

impl Debug for SocketCan

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.