pub trait UsbContext {
// Required method
fn scan(
&self,
usb_vid: Option<u16>,
usb_pid: Option<u16>,
usb_protocol: Option<(u8, u8, u8)>,
usb_serial: Option<&str>,
) -> Result<Vec<Box<dyn UsbDevice>>>;
// Provided methods
fn device_by_id(
&self,
usb_vid: u16,
usb_pid: u16,
usb_serial: Option<&str>,
) -> Result<Box<dyn UsbDevice>> { ... }
fn device_by_id_with_timeout(
&self,
usb_vid: u16,
usb_pid: u16,
usb_serial: Option<&str>,
timeout: Duration,
) -> Result<Box<dyn UsbDevice>> { ... }
fn device_by_interface(
&self,
class: u8,
subclass: u8,
protocol: u8,
usb_serial: Option<&str>,
) -> Result<Box<dyn UsbDevice>> { ... }
fn device_by_interface_with_timeout(
&self,
class: u8,
subclass: u8,
protocol: u8,
usb_serial: Option<&str>,
timeout: Duration,
) -> Result<Box<dyn UsbDevice>> { ... }
}Expand description
A trait which represents a USB context.
Required Methods§
Sourcefn scan(
&self,
usb_vid: Option<u16>,
usb_pid: Option<u16>,
usb_protocol: Option<(u8, u8, u8)>,
usb_serial: Option<&str>,
) -> Result<Vec<Box<dyn UsbDevice>>>
fn scan( &self, usb_vid: Option<u16>, usb_pid: Option<u16>, usb_protocol: Option<(u8, u8, u8)>, usb_serial: Option<&str>, ) -> Result<Vec<Box<dyn UsbDevice>>>
Scan the USB bus for devices matching VID/PID, and optionally also matching a serial number. This method always returns immediately with the list of currently plugged devices matching the requested criteria.
Provided Methods§
Sourcefn device_by_id(
&self,
usb_vid: u16,
usb_pid: u16,
usb_serial: Option<&str>,
) -> Result<Box<dyn UsbDevice>>
fn device_by_id( &self, usb_vid: u16, usb_pid: u16, usb_serial: Option<&str>, ) -> Result<Box<dyn UsbDevice>>
Find a device by VID:PID, and optionally disambiguate by serial number.
If no device matches, this function returns immediately and does not wait.
Sourcefn device_by_id_with_timeout(
&self,
usb_vid: u16,
usb_pid: u16,
usb_serial: Option<&str>,
timeout: Duration,
) -> Result<Box<dyn UsbDevice>>
fn device_by_id_with_timeout( &self, usb_vid: u16, usb_pid: u16, usb_serial: Option<&str>, timeout: Duration, ) -> Result<Box<dyn UsbDevice>>
Find a device by VID:PID, and optionally disambiguate by serial number.
If no device matches, this function will keep trying until the provided timeout expires.
Sourcefn device_by_interface(
&self,
class: u8,
subclass: u8,
protocol: u8,
usb_serial: Option<&str>,
) -> Result<Box<dyn UsbDevice>>
fn device_by_interface( &self, class: u8, subclass: u8, protocol: u8, usb_serial: Option<&str>, ) -> Result<Box<dyn UsbDevice>>
Find a device with a specific interface, and optionally disambiguate by serial number.
If no device matches, this function returns immediately and does not wait.
Sourcefn device_by_interface_with_timeout(
&self,
class: u8,
subclass: u8,
protocol: u8,
usb_serial: Option<&str>,
timeout: Duration,
) -> Result<Box<dyn UsbDevice>>
fn device_by_interface_with_timeout( &self, class: u8, subclass: u8, protocol: u8, usb_serial: Option<&str>, timeout: Duration, ) -> Result<Box<dyn UsbDevice>>
Find a device with a specific interface, and optionally disambiguate by serial number.
If no device matches, this function will keep trying until the provided timeout expires.