Struct hidapi::HidApi

source ·
pub struct HidApi { /* private fields */ }
Expand description

hidapi context.

The hidapi C library is lazily initialized when creating the first instance, and never deinitialized. Therefore, it is allowed to create multiple HidApi instances.

Each instance has its own device list cache.

Implementations§

source§

impl HidApi

source

pub fn new() -> HidResult<Self>

Create a new hidapi context.

Will also initialize the currently available device list.

§Panics

Panics if hidapi is already initialized in “without enumerate” mode (i.e. if new_without_enumerate() has been called before).

source

pub fn new_without_enumerate() -> HidResult<Self>

Create a new hidapi context, in “do not enumerate” mode.

This is needed on Android, where access to USB device enumeration is limited.

§Panics

Panics if hidapi is already initialized in “do enumerate” mode (i.e. if new() has been called before).

source

pub fn refresh_devices(&mut self) -> HidResult<()>

Refresh devices list and information about them (to access them use device_list() method) Identical to reset_devices() followed by add_devices(0, 0).

source

pub fn reset_devices(&mut self) -> HidResult<()>

Reset devices list. Intended to be used with the add_devices method.

source

pub fn add_devices(&mut self, vid: u16, pid: u16) -> HidResult<()>

Indexes devices that match the given VID and PID filters. 0 indicates no filter.

source

pub fn device_list(&self) -> impl Iterator<Item = &DeviceInfo>

Returns iterator containing information about attached HID devices that have been indexed, either by refresh_devices or add_devices.

source

pub fn open(&self, vid: u16, pid: u16) -> HidResult<HidDevice>

Open a HID device using a Vendor ID (VID) and Product ID (PID).

When multiple devices with the same vid and pid are available, then the first one found in the internal device list will be used. There are however no guarantees, which device this will be.

source

pub fn open_serial(&self, vid: u16, pid: u16, sn: &str) -> HidResult<HidDevice>

Open a HID device using a Vendor ID (VID), Product ID (PID) and a serial number.

source

pub fn open_path(&self, device_path: &CStr) -> HidResult<HidDevice>

The path name be determined by inspecting the device list available with HidApi::devices()

Alternatively a platform-specific path name can be used (eg: /dev/hidraw0 on Linux).

source

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

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

Get the last non-device specific error, which happened in the underlying hidapi C library. To get the last device specific error, use HidDevice::check_error.

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.

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.