public interface HidApiLibrary
extends com.sun.jna.Library
JNA library interface to act as the proxy for the underlying native library
This approach removes the need for any JNI or native code
Modifier and Type | Field and Description |
---|---|
static HidApiLibrary |
INSTANCE |
Modifier and Type | Method and Description |
---|---|
void |
hid_close(com.sun.jna.Pointer device)
Close a HID device
|
HidDeviceInfoStructure |
hid_enumerate(short vendor_id,
short product_id)
Enumerate the HID Devices.
|
com.sun.jna.Pointer |
hid_error(com.sun.jna.Pointer device)
Get a string describing the last error which occurred.
|
void |
hid_exit()
Finalize the HIDAPI library.
|
void |
hid_free_enumeration(com.sun.jna.Pointer devs)
Free an enumeration linked list
|
int |
hid_get_feature_report(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference data,
int length)
Get a feature report from a HID device.
|
int |
hid_get_indexed_string(com.sun.jna.Pointer device,
int idx,
com.sun.jna.Structure.ByReference string,
int len)
Get a string from a HID device, based on its string index.
|
int |
hid_get_manufacturer_string(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference str,
int len)
Get the manufacturer string from a HID device
|
int |
hid_get_product_string(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference str,
int len)
Get the product number string from a HID device
|
int |
hid_get_serial_number_string(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference str,
int len)
Get the serial number string from a HID device
|
void |
hid_init()
Initialize the HIDAPI library.
|
com.sun.jna.Pointer |
hid_open_path(String path)
Open a HID device by its path name.
|
com.sun.jna.Pointer |
hid_open(short vendor_id,
short product_id,
com.sun.jna.WString serial_number)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
|
int |
hid_read_timeout(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference bytes,
int length,
int timeout)
Read an Input report from a HID device with timeout.
|
int |
hid_read(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference bytes,
int length)
Read an Input report from a HID device.
|
int |
hid_send_feature_report(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference data,
int length)
Send a Feature report to the device.
|
int |
hid_set_nonblocking(com.sun.jna.Pointer device,
int nonblock)
Set the device handle to be non-blocking.
|
int |
hid_write(com.sun.jna.Pointer device,
com.sun.jna.Structure.ByReference data,
int len)
Write an Output report to a HID device.
|
static final HidApiLibrary INSTANCE
void hid_init()
Initialize the HIDAPI library.
This function initializes the HIDAPI library. Calling it is not strictly necessary, as it will be called automatically by hid_enumerate() and any of the hid_open_*() functions if it is needed. This function should be called at the beginning of execution however, if there is a chance of HIDAPI handles being opened by different threads simultaneously.
void hid_exit()
Finalize the HIDAPI library.
This function frees all of the static data associated with HIDAPI. It should be called at the end of execution to avoid memory leaks.
com.sun.jna.Pointer hid_open(short vendor_id, short product_id, com.sun.jna.WString serial_number)
vendor_id
- The vendor IDproduct_id
- The product IDserial_number
- The serial number (or null for wildcard)void hid_close(com.sun.jna.Pointer device)
device
- A device handlecom.sun.jna.Pointer hid_error(com.sun.jna.Pointer device)
device
- A device handleint hid_read(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference bytes, int length)
device
- A device handle returned from hid_open().bytes
- A buffer to put the read data into.length
- The number of bytes to read. For devices with multiple reports, make sure to read an extra byte for the report number.int hid_read_timeout(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference bytes, int length, int timeout)
device
- A device handlebytes
- A buffer to put the read data into.length
- The number of bytes to read. For devices with multiple reports, make sure to read an extra byte for the report number.timeout
- The timeout in milliseconds or -1 for blocking wait.int hid_write(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference data, int len)
device
- A device handledata
- the data to send, including the report number as the first bytelen
- The length in bytes of the data to sendint hid_get_feature_report(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference data, int length)
device
- A device handledata
- A buffer to put the read data into, including the Report ID. Set the first byte of data[] to the Report ID of the report to be read, or set it to zero if your device does not use numbered reports.length
- The number of bytes to read, including an extra byte for the report ID. The buffer can be longer than the actual report.int hid_send_feature_report(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference data, int length)
device
- The device handledata
- The data to send, including the report number as the first bytelength
- The length inbytes of the data to send, including the report numberint hid_get_indexed_string(com.sun.jna.Pointer device, int idx, com.sun.jna.Structure.ByReference string, int len)
device
- the device handleidx
- The index of the string to getstring
- A wide string buffer to put the data intolen
- The length of the buffer in multiples of wchar_tint hid_get_manufacturer_string(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference str, int len)
device
- the device handlestr
- A wide string buffer to put the data intolen
- The length of the buffer in multiple of wchar_tint hid_get_product_string(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference str, int len)
device
- the device handlestr
- A wide string buffer to put the data intolen
- The length of the buffer in multiple of wchar_tint hid_get_serial_number_string(com.sun.jna.Pointer device, com.sun.jna.Structure.ByReference str, int len)
device
- the device handlestr
- A wide string buffer to put the data intolen
- The length of the buffer in multiple of wchar_tint hid_set_nonblocking(com.sun.jna.Pointer device, int nonblock)
device
- The device handlenonblock
- 0 disables non-blocking, 1 enables non-blockingHidDeviceInfoStructure hid_enumerate(short vendor_id, short product_id)
vendor_id
- The vendor IDproduct_id
- The product IDvoid hid_free_enumeration(com.sun.jna.Pointer devs)
devs
- The device information pointercom.sun.jna.Pointer hid_open_path(String path)
path
- The path nameCopyright © 2014–2015 Bitcoin Solutions Ltd. All rights reserved.