pub struct AsyncDeviceStream { /* private fields */ }Expand description
An async connected device stream for bidirectional communication.
Implementations§
Source§impl AsyncDeviceStream
impl AsyncDeviceStream
pub async fn connect( addr: SocketAddr, bus_id: u32, dev_id: &str, password: Option<&str>, ) -> Result<Self, ViiperError>
Sourcepub async fn send<T: DeviceInput>(&self, input: &T) -> Result<(), ViiperError>
pub async fn send<T: DeviceInput>(&self, input: &T) -> Result<(), ViiperError>
Send a device input to the device.
Sourcepub async fn send_timeout<T: DeviceInput>(
&self,
input: &T,
timeout: Duration,
) -> Result<(), ViiperError>
pub async fn send_timeout<T: DeviceInput>( &self, input: &T, timeout: Duration, ) -> Result<(), ViiperError>
Send a device input to the device with a timeout.
§Arguments
input- The device input to sendtimeout- Timeout duration for the operation
Sourcepub fn on_output<F, Fut>(&mut self, callback: F) -> Result<(), ViiperError>
pub fn on_output<F, Fut>(&mut self, callback: F) -> Result<(), ViiperError>
Register a callback to receive device output asynchronously. The callback receives a shared reference to the read half and must read the exact number of bytes expected. The callback will be invoked repeatedly on a tokio task until it returns an error. Only one callback can be registered at a time.
pub fn on_disconnect<F>(&mut self, callback: F) -> Result<(), ViiperError>
Sourcepub async fn send_raw(&self, data: &[u8]) -> Result<(), ViiperError>
pub async fn send_raw(&self, data: &[u8]) -> Result<(), ViiperError>
Send raw bytes to the device.
Sourcepub async fn read_raw(&self, buf: &mut [u8]) -> Result<usize, ViiperError>
pub async fn read_raw(&self, buf: &mut [u8]) -> Result<usize, ViiperError>
Read raw bytes from the device.
Sourcepub async fn read_exact(&self, buf: &mut [u8]) -> Result<(), ViiperError>
pub async fn read_exact(&self, buf: &mut [u8]) -> Result<(), ViiperError>
Read exact number of bytes from the device.
Trait Implementations§
Source§impl Drop for AsyncDeviceStream
Available on crate feature async only.
impl Drop for AsyncDeviceStream
Available on crate feature
async only.Auto Trait Implementations§
impl !Freeze for AsyncDeviceStream
impl !RefUnwindSafe for AsyncDeviceStream
impl Send for AsyncDeviceStream
impl Sync for AsyncDeviceStream
impl Unpin for AsyncDeviceStream
impl UnsafeUnpin for AsyncDeviceStream
impl !UnwindSafe for AsyncDeviceStream
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
Mutably borrows from an owned value. Read more