Java usb independent input platform

I'm struggling to find a Java API that allows you to capture the input of any device connected via USB. I found jUsb, but it seems outdated and old.

I would like to:

  • platform independent API (running on Unix, Windows, Mac)
  • An API that can capture inputs from any device (in fact, I want to connect the joystick to my USB port)
+4
source share
3 answers

We had the same problem for our USB sensors: there is no 100% Java solution there. You will always need code for a specific OS that is written in another language (and which has access to its own API).

The most portable solution we found was to implement a kind of gateway that would encapsulate USB data through a local TCP socket. We have 3 gateway implementations (OSX, UNIX, and Windows) that will call our own API to interact with a USB device. Java code will send / receive USB traffic through a TCP gateway. We performed some tests , and we measure that the total difference between pure C ++ code and the Java implementation is less than 10 ms (for a large 45 ms transaction), while latency is negligible (no impact) when you have an open channel.

We are writing a message explaining our decision here .

+3
source

You need to install device drivers that may first discover your device.

In the Device Manager → Ports (COM and LPT) you can see the port to which your device is connected. e.g. COM1 / COM2 / COM3

You can use the code to add listener events to read data from these ports. Many libraries are available for working with COM ports. This link may be useful to you.

I use comm.jar to read inputs from a handheld scanner.

0
source

In the past, I used libusb. Not easy, but if you are corning enough, you can get drivers for several operating systems and Java bindings.

0
source

Source: https://habr.com/ru/post/1443416/


All Articles