pub trait UsbDevice {
Show 27 methods
// Required methods
fn get_vendor_id(&self) -> u16;
fn get_product_id(&self) -> u16;
fn get_serial_number(&self) -> Option<&str>;
fn get_parent(&self) -> Result<Box<dyn UsbDevice>>;
fn set_active_configuration(&self, config: u8) -> Result<()>;
fn claim_interface(&self, iface: u8) -> Result<()>;
fn release_interface(&self, iface: u8) -> Result<()>;
fn set_alternate_setting(&self, iface: u8, setting: u8) -> Result<()>;
fn kernel_driver_active(&self, iface: u8) -> Result<bool>;
fn detach_kernel_driver(&self, iface: u8) -> Result<()>;
fn attach_kernel_driver(&self, iface: u8) -> Result<()>;
fn device_descriptor(&self) -> Device<'_>;
fn active_configuration(&self) -> Result<Configuration<'_>>;
fn bus_number(&self) -> u8;
fn address(&self) -> u8;
fn port_numbers(&self) -> Result<Vec<u8>>;
fn read_string_descriptor_ascii(&self, idx: u8) -> Result<String>;
fn reset(&self) -> Result<()>;
fn get_timeout(&self) -> Duration;
fn write_control_timeout(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &[u8],
timeout: Duration,
) -> Result<usize>;
fn read_control_timeout(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &mut [u8],
timeout: Duration,
) -> Result<usize>;
fn read_bulk_timeout(
&self,
endpoint: u8,
data: &mut [u8],
timeout: Duration,
) -> Result<usize>;
fn write_bulk_timeout(
&self,
endpoint: u8,
data: &[u8],
timeout: Duration,
) -> Result<usize>;
// Provided methods
fn write_control(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &[u8],
) -> Result<usize> { ... }
fn read_control(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &mut [u8],
) -> Result<usize> { ... }
fn read_bulk(&self, endpoint: u8, data: &mut [u8]) -> Result<usize> { ... }
fn write_bulk(&self, endpoint: u8, data: &[u8]) -> Result<usize> { ... }
}Expand description
A trait which represents a USB device.
Required Methods§
Sourcefn get_vendor_id(&self) -> u16
fn get_vendor_id(&self) -> u16
Return the VID of the device.
Sourcefn get_product_id(&self) -> u16
fn get_product_id(&self) -> u16
Return the PID of the device.
Sourcefn get_serial_number(&self) -> Option<&str>
fn get_serial_number(&self) -> Option<&str>
Gets the serial number of the device.
Sourcefn get_parent(&self) -> Result<Box<dyn UsbDevice>>
fn get_parent(&self) -> Result<Box<dyn UsbDevice>>
Try to get the parent of this device (or None if root).
Sourcefn set_active_configuration(&self, config: u8) -> Result<()>
fn set_active_configuration(&self, config: u8) -> Result<()>
Set the active configuration.
Sourcefn claim_interface(&self, iface: u8) -> Result<()>
fn claim_interface(&self, iface: u8) -> Result<()>
Claim an interface for use with the kernel.
Sourcefn release_interface(&self, iface: u8) -> Result<()>
fn release_interface(&self, iface: u8) -> Result<()>
Release a previously claimed interface to the kernel.
Sourcefn set_alternate_setting(&self, iface: u8, setting: u8) -> Result<()>
fn set_alternate_setting(&self, iface: u8, setting: u8) -> Result<()>
Set an interface alternate setting.
Sourcefn kernel_driver_active(&self, iface: u8) -> Result<bool>
fn kernel_driver_active(&self, iface: u8) -> Result<bool>
Check whether a kernel driver currentl controls the device.
Sourcefn detach_kernel_driver(&self, iface: u8) -> Result<()>
fn detach_kernel_driver(&self, iface: u8) -> Result<()>
Detach the kernel driver from the device.
Sourcefn attach_kernel_driver(&self, iface: u8) -> Result<()>
fn attach_kernel_driver(&self, iface: u8) -> Result<()>
Attach the kernel driver to the device.
Sourcefn device_descriptor(&self) -> Device<'_>
fn device_descriptor(&self) -> Device<'_>
Return the device’s descriptor.
Sourcefn active_configuration(&self) -> Result<Configuration<'_>>
fn active_configuration(&self) -> Result<Configuration<'_>>
Return the currently active configuration’s descriptor.
Sourcefn bus_number(&self) -> u8
fn bus_number(&self) -> u8
Return the device’s bus number.
Sourcefn port_numbers(&self) -> Result<Vec<u8>>
fn port_numbers(&self) -> Result<Vec<u8>>
Return the sequence of port numbers from the root down to the device.
Sourcefn read_string_descriptor_ascii(&self, idx: u8) -> Result<String>
fn read_string_descriptor_ascii(&self, idx: u8) -> Result<String>
Return a string descriptor in ASCII.
Sourcefn reset(&self) -> Result<()>
fn reset(&self) -> Result<()>
Reset the device.
Note that this UsbDevice handle will most likely become invalid after resetting the device and a new one has to be obtained.
Sourcefn get_timeout(&self) -> Duration
fn get_timeout(&self) -> Duration
Get the default timeout for operations.
Sourcefn write_control_timeout(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &[u8],
timeout: Duration,
) -> Result<usize>
fn write_control_timeout( &self, request_type: u8, request: u8, value: u16, index: u16, buf: &[u8], timeout: Duration, ) -> Result<usize>
Issue a USB control request with optional host-to-device data.
Sourcefn read_control_timeout(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &mut [u8],
timeout: Duration,
) -> Result<usize>
fn read_control_timeout( &self, request_type: u8, request: u8, value: u16, index: u16, buf: &mut [u8], timeout: Duration, ) -> Result<usize>
Issue a USB control request with optional device-to-host data.
Provided Methods§
Sourcefn write_control(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &[u8],
) -> Result<usize>
fn write_control( &self, request_type: u8, request: u8, value: u16, index: u16, buf: &[u8], ) -> Result<usize>
Issue a USB control request with optional host-to-device data.
This function uses the default timeout set up by the context.
Sourcefn read_control(
&self,
request_type: u8,
request: u8,
value: u16,
index: u16,
buf: &mut [u8],
) -> Result<usize>
fn read_control( &self, request_type: u8, request: u8, value: u16, index: u16, buf: &mut [u8], ) -> Result<usize>
Issue a USB control request with optional device-to-host data.
This function uses the default timeout set up by the context.