Struct hidapi::HidDevice

source ·
pub struct HidDevice { /* private fields */ }

Implementations§

source§

impl HidDevice

source

pub fn check_error(&self) -> HidResult<HidError>

👎Deprecated since 2.2.3: use the return values from the other methods

Get the last error, which happened in the underlying hidapi C library.

The Ok() variant of the result will contain a HidError::HidApiError.

When Err() is returned, then acquiring the error string from the hidapi C library failed. The contained HidError is the cause, why no error could be fetched.

source

pub fn write(&self, data: &[u8]) -> HidResult<usize>

Write an Output report to a HID device.

The first byte of data must contain the Report ID. For devices which only support a single report, this must be set to 0x0. The remaining bytes contain the report data. Since the Report ID is mandatory, calls to write() will always contain one more byte than the report contains. For example, if a hid report is 16 bytes long, 17 bytes must be passed to write(), the Report ID (or 0x0, for devices with a single report), followed by the report data (16 bytes). In this example, the length passed in would be 17. write() will send the data on the first OUT endpoint, if one exists. If it does not, it will send the data through the Control Endpoint (Endpoint 0).

If successful, returns the actual number of bytes written.

source

pub fn read(&self, buf: &mut [u8]) -> HidResult<usize>

Read an Input report from a HID device.

Input reports are returned to the host through the ‘INTERRUPT IN’ endpoint. The first byte will contain the Report number if the device uses numbered reports.

If successful, returns the actual number of bytes read.

source

pub fn read_timeout(&self, buf: &mut [u8], timeout: i32) -> HidResult<usize>

Read an Input report from a HID device with timeout.

Input reports are returned to the host through the ‘INTERRUPT IN’ endpoint. The first byte will contain the Report number if the device uses numbered reports. Timeout measured in milliseconds, set -1 for blocking wait.

If successful, returns the actual number of bytes read.

source

pub fn send_feature_report(&self, data: &[u8]) -> HidResult<()>

Send a Feature report to the device.

Feature reports are sent over the Control endpoint as a Set_Report transfer. The first byte of data must contain the ‘Report ID’. For devices which only support a single report, this must be set to 0x0. The remaining bytes contain the report data. Since the ‘Report ID’ is mandatory, calls to send_feature_report() will always contain one more byte than the report contains. For example, if a hid report is 16 bytes long, 17 bytes must be passed to send_feature_report(): ‘the Report ID’ (or 0x0, for devices which do not use numbered reports), followed by the report data (16 bytes). In this example, the length passed in would be 17.

If successful, returns the actual number of bytes written.

source

pub fn get_feature_report(&self, buf: &mut [u8]) -> HidResult<usize>

Get a feature report from a HID device.

Set the first byte of buf to the ‘Report ID’ of the report to be read. Upon return, the first byte will still contain the Report ID, and the report data will start in buf[1].

If successful, returns the number of bytes read plus one for the report ID (which is still in the first byte).

source

pub fn set_blocking_mode(&self, blocking: bool) -> HidResult<()>

Set the device handle to be in blocking or in non-blocking mode. In non-blocking mode calls to read() will return immediately with an empty slice if there is no data to be read. In blocking mode, read() will wait (block) until there is data to read before returning. Modes can be changed at any time.

source

pub fn get_manufacturer_string(&self) -> HidResult<Option<String>>

Get The Manufacturer String from a HID device.

source

pub fn get_product_string(&self) -> HidResult<Option<String>>

Get The Manufacturer String from a HID device.

source

pub fn get_serial_number_string(&self) -> HidResult<Option<String>>

Get The Serial Number String from a HID device.

source

pub fn get_indexed_string(&self, index: i32) -> HidResult<Option<String>>

Get a string from a HID device, based on its string index.

source

pub fn get_report_descriptor(&self, buf: &mut [u8]) -> HidResult<usize>

Get a report descriptor from a HID device

User has to provide a preallocated buffer where the descriptor will be copied to. It is recommended to use a preallocated buffer of MAX_REPORT_DESCRIPTOR_SIZE size.

source

pub fn get_device_info(&self) -> HidResult<DeviceInfo>

Get DeviceInfo from a HID device.

Trait Implementations§

source§

impl Debug for HidDevice

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.