Struct fdcanusb::FdCanUSB

source ·
pub struct FdCanUSB<T>
where T: Write + Read,
{ /* private fields */ }
Expand description

FdCanUSB communications struct

Can be used with any transport type that implements std::io::Write and std::io::Read The baud rate is unused, as the FdCanUSB communicates via USB CDC

§Example

use fdcanusb::{FdCanUSB, serial2};
let transport = serial2::SerialPort::open("/dev/fdcanusb", serial2::KeepSettings)?;
let mut fdcanusb = FdCanUSB::new(transport);

§serial2 Integration

To use the FdCanUSB with a serial2::SerialPort, you can use the FdCanUSB::open method.

§Example

use fdcanusb::FdCanUSB;

let mut fdcanusb = FdCanUSB::open("/dev/fdcanusb", serial2::KeepSettings).expect("Failed to open serial port");

Implementations§

source§

impl FdCanUSB<SerialPort>

source

pub fn open<P: AsRef<Path>>( path: P, serial_settings: impl IntoSettings, ) -> Result<Self>

For convenience, we provide a FdCanUSB implementation for serial2::SerialPort. Enable with the serial2 feature.

source

pub fn flush(&mut self) -> Result<()>

source§

impl<T> FdCanUSB<T>
where T: Write + Read,

source

pub fn new(transport: T) -> Self

Create a new FdCanUSB instance

source

pub fn transfer_single( &mut self, frame: CanFdFrame, response: bool, ) -> Result<Option<CanFdFrame>>

Transfer a single frame. If response is true, the function will wait for a response frame. Otherwise, it will return None.

source

pub fn write_frame(&mut self, frame: FdCanUSBFrame) -> Result<()>

Write a frame to the FdCanUSB

Frames are logged at the trace level by default.

source

pub fn read_ok(&mut self) -> Result<()>

The FdCanUSB responds with OK after a correct frame is parsed. read_ok waits for this response, and returns an error if it is not received.

source

pub fn read_response(&mut self) -> Result<CanFdFrame>

Read a response frame from the FdCanUSB. Responses are logged at the trace level by default.

Trait Implementations§

source§

impl<T> Debug for FdCanUSB<T>
where T: Write + Read + Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FdCanUSB<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for FdCanUSB<T>
where T: RefUnwindSafe,

§

impl<T> Send for FdCanUSB<T>
where T: Send,

§

impl<T> Sync for FdCanUSB<T>
where T: Sync,

§

impl<T> Unpin for FdCanUSB<T>
where T: Unpin,

§

impl<T> UnwindSafe for FdCanUSB<T>
where T: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.