Skip to content
Gary Rowe edited this page Sep 20, 2020 · 3 revisions

The examples are able to be run from within an IDE and directly from the command line using Maven. This gives maximum flexibility when first discovering the project API and seeing it work within your own environment.

I'll assume you can execute standalone Java classes with their main() methods from your IDE and only provide the command line entries to avoid duplication.

UsbHidEnumerationExample - Demonstrating device enumeration

The easiest way into the examples is through device enumeration.

mvn clean test exec:java -Dexec.classpathScope="test" -Dexec.mainClass="org.hid4java.examples.UsbHidEnumerationExample"

Use CTRL+C to quit the example or wait 30s.

UsbHidDeviceExample - Interaction with a Trezor device

One of the earliest uses for hid4java was to interact with Satoshi Labs Trezor devices and these have become fairly popular over time. If you happen to have one just plug it in and try out the following:

mvn clean test exec:java -Dexec.classpathScope="test" -Dexec.mainClass="org.hid4java.examples.UsbHidDeviceExample"

If you have a Trezor device attached you'll see a Features response message appear as a big block of hex otherwise it will be just a simple enumeration of attached USB devices. There is no data collection from the device, just the initial handshake via Initialise -> Features to get the basic device capabilities.

You can plug various devices in and out to see messages.

Use CTRL+C to quit the example or wait 30s.

Clone this wiki locally