Struct rusb::DeviceHandle[][src]

pub struct DeviceHandle<T: UsbContext> { /* fields omitted */ }
Expand description

A handle to an open USB device.

Implementations

Get the raw libusb_device_handle pointer, for advanced use in unsafe code.

This structure tracks claimed interfaces, and will get out if sync if interfaces are manipulated externally. Use only libusb endpoint IO functions.

Consumes the DeviceHandle, returning the raw libusb_device_handle pointer, for advanced use in unsafe code.

Safety

Panics if you have any claimed interfaces on this handle.

Get the context associated with this device

Get the device associated to this handle

Safety

Converts an existing libusb_device_handle pointer into a DeviceHandle<T>. handle must be a pointer to a valid libusb_device_handle. Rusb assumes ownership of the handle, and will close it on drop.

Returns the active configuration number.

Sets the device’s active configuration.

Puts the device in an unconfigured state.

Resets the device.

Clear the halt/stall condition for an endpoint.

Indicates whether the device has an attached kernel driver.

This method is not supported on all platforms.

Detaches an attached kernel driver from the device.

This method is not supported on all platforms.

Attaches a kernel driver to the device.

This method is not supported on all platforms.

Enable/disable automatic kernel driver detachment.

When this is enabled rusb will automatically detach the kernel driver on an interface when claiming the interface, and attach it when releasing the interface.

On platforms which do not have support, this function will return Error::NotSupported, and rusb will continue as if this function was never called.

Claims one of the device’s interfaces.

An interface must be claimed before operating on it. All claimed interfaces are released when the device handle goes out of scope.

Releases a claimed interface.

Sets an interface’s active setting.

Reads from an interrupt endpoint.

This function attempts to read from the interrupt endpoint with the address given by the endpoint parameter and fills buf with any data received from the endpoint. The function blocks up to the amount of time specified by timeout. Minimal timeout is 1 microseconds.

If the return value is Ok(n), then buf is populated with n bytes of data received from the endpoint.

Errors

If this function encounters any form of error while fulfilling the transfer request, an error variant will be returned. If an error variant is returned, no bytes were read.

The errors returned by this function include:

  • InvalidParam if the endpoint is not an input endpoint.
  • Timeout if the transfer timed out.
  • Pipe if the endpoint halted.
  • Overflow if the device offered more data.
  • NoDevice if the device has been disconnected.
  • Io if the transfer encountered an I/O error.

Writes to an interrupt endpoint.

This function attempts to write the contents of buf to the interrupt endpoint with the address given by the endpoint parameter. The function blocks up to the amount of time specified by timeout. Minimal timeout is 1 microseconds.

If the return value is Ok(n), then n bytes of buf were written to the endpoint.

Errors

If this function encounters any form of error while fulfilling the transfer request, an error variant will be returned. If an error variant is returned, no bytes were written.

The errors returned by this function include:

  • InvalidParam if the endpoint is not an output endpoint.
  • Timeout if the transfer timed out.
  • Pipe if the endpoint halted.
  • NoDevice if the device has been disconnected.
  • Io if the transfer encountered an I/O error.

Reads from a bulk endpoint.

This function attempts to read from the bulk endpoint with the address given by the endpoint parameter and fills buf with any data received from the endpoint. The function blocks up to the amount of time specified by timeout. Minimal timeout is 1 microseconds.

If the return value is Ok(n), then buf is populated with n bytes of data received from the endpoint.

Errors

If this function encounters any form of error while fulfilling the transfer request, an error variant will be returned. If an error variant is returned, no bytes were read.

The errors returned by this function include:

  • InvalidParam if the endpoint is not an input endpoint.
  • Timeout if the transfer timed out.
  • Pipe if the endpoint halted.
  • Overflow if the device offered more data.
  • NoDevice if the device has been disconnected.
  • Io if the transfer encountered an I/O error.

Writes to a bulk endpoint.

This function attempts to write the contents of buf to the bulk endpoint with the address given by the endpoint parameter. The function blocks up to the amount of time specified by timeout. Minimal timeout is 1 microseconds.

If the return value is Ok(n), then n bytes of buf were written to the endpoint.

Errors

If this function encounters any form of error while fulfilling the transfer request, an error variant will be returned. If an error variant is returned, no bytes were written.

The errors returned by this function include:

  • InvalidParam if the endpoint is not an output endpoint.
  • Timeout if the transfer timed out.
  • Pipe if the endpoint halted.
  • NoDevice if the device has been disconnected.
  • Io if the transfer encountered an I/O error.

Reads data using a control transfer.

This function attempts to read data from the device using a control transfer and fills buf with any data received during the transfer. The function blocks up to the amount of time specified by timeout. Minimal timeout is 1 microseconds.

The parameters request_type, request, value, and index specify the fields of the control transfer setup packet (bmRequestType, bRequest, wValue, and wIndex respectively). The values for each of these parameters shall be given in host-endian byte order. The value for the request_type parameter can be built with the helper function, request_type(). The meaning of the other parameters depends on the type of control request.

If the return value is Ok(n), then buf is populated with n bytes of data.

Errors

If this function encounters any form of error while fulfilling the transfer request, an error variant will be returned. If an error variant is returned, no bytes were read.

The errors returned by this function include:

  • InvalidParam if request_type does not specify a read transfer.
  • Timeout if the transfer timed out.
  • Pipe if the control request was not supported by the device.
  • NoDevice if the device has been disconnected.
  • Io if the transfer encountered an I/O error.

Writes data using a control transfer.

This function attempts to write the contents of buf to the device using a control transfer. The function blocks up to the amount of time specified by timeout. Minimal timeout is 1 microseconds.

The parameters request_type, request, value, and index specify the fields of the control transfer setup packet (bmRequestType, bRequest, wValue, and wIndex respectively). The values for each of these parameters shall be given in host-endian byte order. The value for the request_type parameter can be built with the helper function, request_type(). The meaning of the other parameters depends on the type of control request.

If the return value is Ok(n), then n bytes of buf were transfered.

Errors

If this function encounters any form of error while fulfilling the transfer request, an error variant will be returned. If an error variant is returned, no bytes were read.

The errors returned by this function include:

  • InvalidParam if request_type does not specify a write transfer.
  • Timeout if the transfer timed out.
  • Pipe if the control request was not supported by the device.
  • NoDevice if the device has been disconnected.
  • Io if the transfer encountered an I/O error.

Reads the languages supported by the device’s string descriptors.

This function returns a list of languages that can be used to read the device’s string descriptors.

Reads a ascii string descriptor from the device.

Reads a string descriptor from the device.

language should be one of the languages returned from read_languages.

Reads the device’s manufacturer string descriptor (ascii).

Reads the device’s manufacturer string descriptor.

Reads the device’s product string descriptor (ascii).

Reads the device’s product string descriptor.

Reads the device’s serial number string descriptor (ascii).

Reads the device’s serial number string descriptor.

Reads the string descriptor for a configuration’s description.

Reads the string descriptor for a interface’s description.

Trait Implementations

Formats the value using the given formatter. Read more

Closes the device.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.