public class HidDevice extends Object
High level wrapper to provide the following to API consumers:
Constructor and Description |
---|
HidDevice(HidDeviceInfoStructure infoStructure) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this device freeing the HidApi resources
|
boolean |
equals(Object o) |
int |
getFeatureReport(byte[] data,
byte reportId)
Get a feature report from a HID device
|
String |
getId()
The "path" is well-supported across Windows, Mac and Linux so makes a
better choice for a unique ID
See #8 for details
|
String |
getIndexedString(int index)
Get a string from a HID device, based on its string index
|
int |
getInterfaceNumber() |
String |
getLastErrorMessage() |
String |
getManufacturer() |
String |
getPath() |
String |
getProduct() |
short |
getProductId() |
int |
getReleaseNumber() |
String |
getSerialNumber() |
int |
getUsage() |
int |
getUsagePage() |
short |
getVendorId() |
int |
hashCode() |
boolean |
isOpen() |
boolean |
isVidPidSerial(int vendorId,
int productId,
String serialNumber) |
boolean |
open() |
int |
read(byte[] data)
Read an Input report from a HID device
|
int |
read(byte[] bytes,
int timeoutMillis)
Read an Input report from a HID device with timeout
|
int |
sendFeatureReport(byte[] data,
byte reportId)
Send a Feature report to the device
|
void |
setNonBlocking(boolean nonBlocking)
Set the device handle to be non-blocking
|
String |
toString() |
int |
write(byte[] message,
int packetLength,
byte reportId) |
public HidDevice(HidDeviceInfoStructure infoStructure)
infoStructure
- The HID device info structure providing detailspublic String getId()
public String getPath()
public short getVendorId()
public short getProductId()
public String getSerialNumber()
public int getReleaseNumber()
public String getManufacturer()
public String getProduct()
public int getUsagePage()
public int getUsage()
public int getInterfaceNumber()
public int write(byte[] message, int packetLength, byte reportId)
public String getLastErrorMessage()
public boolean open()
public void close()
Close this device freeing the HidApi resources
public void setNonBlocking(boolean nonBlocking)
Set the device handle to be non-blocking
In non-blocking mode calls to hid_read() will return immediately with a value of 0 if there is no data to be read. In blocking mode, hid_read() will wait (block) until there is data to read before returning
Non-blocking can be turned on and off at any time
nonBlocking
- True if non-blocking mode is requiredpublic int read(byte[] data)
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
data
- The buffer to read intopublic int read(byte[] bytes, int timeoutMillis)
Read an Input report from a HID device with timeout
bytes
- The buffer to read intotimeoutMillis
- The number of milliseconds to wait before giving uppublic int getFeatureReport(byte[] data, byte reportId)
Get a feature report from a HID device
Under the covers the HID library will set the first byte of data[] 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 data[1]
This method handles all the wide string and array manipulation for you
data
- The buffer to contain the reportreportId
- The report ID (or (byte) 0x00)public int sendFeatureReport(byte[] data, byte reportId)
Send a Feature report to the device
Under the covers, 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 hid_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 hid_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
This method handles all the array manipulation for you
data
- The feature report data (will be widened and have the report
ID pre-pended)reportId
- The report ID (or (byte) 0x00)public String getIndexedString(int index)
Get a string from a HID device, based on its string index
index
- The indexpublic boolean isOpen()
public boolean isVidPidSerial(int vendorId, int productId, String serialNumber)
Copyright © 2014–2015 Bitcoin Solutions Ltd. All rights reserved.