pub struct SocketCan { /* private fields */ }Expand description
A CANopen transport over a Linux SocketCAN interface.
Implementations§
Source§impl SocketCan
impl SocketCan
Sourcepub fn open(interface: &str) -> Result<Self>
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.
Sourcepub fn set_read_timeout(&self, timeout: Duration) -> Result<()>
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.
Sourcepub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
Put the socket into (non-)blocking mode.
Sourcepub fn send(&self, cob_id: u16, data: &[u8]) -> Result<()>
pub fn send(&self, cob_id: u16, data: &[u8]) -> Result<()>
Transmit data on COB-ID cob_id as a standard data frame.
Sourcepub fn recv(&self) -> Result<Received>
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.
Sourcepub fn send_nmt(&self, command: NmtCommand, target: NodeId) -> Result<()>
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).
Sourcepub fn sdo_read(
&self,
node: NodeId,
addr: Address,
data_type: DataType,
) -> Result<Value, SdoError>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SocketCan
impl RefUnwindSafe for SocketCan
impl Send for SocketCan
impl Sync for SocketCan
impl Unpin for SocketCan
impl UnsafeUnpin for SocketCan
impl UnwindSafe for SocketCan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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