Struct HidApi

Source
pub struct HidApi { /* private fields */ }
Expand description

Object for handling hidapi context and implementing RAII for it. Only one instance can exist at a time.

Implementations§

Source§

impl HidApi

Source

pub fn new() -> Result<HidApi, HidError>

Initializes the hidapi.

Will also initialize the currently available device list.

Source

pub fn refresh_devices(&mut self) -> Result<(), HidError>

Refresh devices list and information about them (to access them use device_list() method)

Source

pub fn devices(&self) -> &Vec<HidDeviceInfo>

👎Deprecated

Returns vec of objects containing information about connected devices

Deprecated. Use HidApi::device_list() instead.

Source

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

Returns iterator containing information about attached HID devices.

Source

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

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, ) -> Result<HidDevice, HidError>

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) -> Result<HidDevice, HidError>

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).

Auto Trait Implementations§

§

impl Freeze for HidApi

§

impl RefUnwindSafe for HidApi

§

impl Send for HidApi

§

impl Sync for HidApi

§

impl Unpin for HidApi

§

impl UnwindSafe for HidApi

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>,

Source§

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>,

Source§

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.