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
sourceimpl HidApi
impl HidApi
sourcepub fn new() -> HidResult<Self>
pub fn new() -> HidResult<Self>
Initializes the hidapi.
Will also initialize the currently available device list.
sourcepub fn refresh_devices(&mut self) -> HidResult<()>
pub fn refresh_devices(&mut self) -> HidResult<()>
Refresh devices list and information about them (to access them use
device_list()
method)
sourcepub fn devices(&self) -> &Vec<HidDeviceInfo>
👎 Deprecated
pub fn devices(&self) -> &Vec<HidDeviceInfo>
Returns vec of objects containing information about connected devices
Deprecated. Use HidApi::device_list()
instead.
sourcepub fn device_list(&self) -> impl Iterator<Item = &DeviceInfo>
pub fn device_list(&self) -> impl Iterator<Item = &DeviceInfo>
Returns iterator containing information about attached HID devices.
sourcepub fn open(&self, vid: u16, pid: u16) -> HidResult<HidDevice>
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.
sourcepub fn open_serial(&self, vid: u16, pid: u16, sn: &str) -> HidResult<HidDevice>
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.
sourcepub fn open_path(&self, device_path: &CStr) -> HidResult<HidDevice>
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).
sourcepub fn check_error(&self) -> HidResult<HidError>
pub fn check_error(&self) -> HidResult<HidError>
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
impl RefUnwindSafe for HidApi
impl Send for HidApi
impl Sync for HidApi
impl Unpin for HidApi
impl UnwindSafe for HidApi
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more