KSL Embedded Blog
 

Java Communication Class for USB HID

We have the USB Motion PIR Sensor named Globx. More information about the possibilities of this motion detector you can find on the Globx wiki pages. We are faced with the task of developing a communication class that can work with a USB HID device in Java.
From the results of Internet search, we learned that Java does not officially support USB, but there are several projects that support communication with USB devices in Java.

jUSB

The jUSB project is a Java access to USB, currently using kernel 2.4 Linux-USB support. There is a “core” API for accessing USB devices, and simple tools including a USB viewer in Swing. Applications are being developed separately, including digital camera support. Project created by Mojo Jojo and David Brownell in June 2000. The main purpose was to create a set of free software Java APIs to access USB devices on Linux platforms. The API is distributed under the Lesser GPL (LGPL), which means that you can use it in proprietary as well as free software projects. The API supports control transfers, bulk transfers, and interrupt transfers. API works on GNU/Linux distributions. There is a project available from Mike Stahl, that support communication with USB devices in Windows jUSB for Windows. The jUSB API for Windows offers the oportunity to use the Java Programming language to access any kind of USB devices attached to the USB.

javax.usb

It is a Java API that allows direct USB-level access to the system's USB devices. It's composed of a collection of interfaces and base classes, and a class that loads an implementation. It is standardized and was created through the Java Community Process (JCP) Java Specification Request number 80 (JSR80). JSR-80 project was created by Dan Streetman. The project is licensed under the Common Public License and is developed using the Java Community Process. The javax project includes packages: javax-usb (the javax.usb API), javax-usb-ri (the common part of the OS-independent reference implementation), and javax-usb-ri-linux (the reference implementation for the Linux platform), javax-usb-libusb (the libusb implementation written for Windows platform). Read more about javax.usb project on SourceForge.net.

Java USB API based on JNA

We are experts in the development and support for USB devices, but do not use java everyday. Therefore it was decided to use a standard mechanism for running code, under operation of the Java virtual machine. The Java Native Access (JNA) enables the integration of code written in the Java programming language with code written in other languages such as C and C++. Java Native Access provides Java programs easy access to native shared libraries without using the Java Native Interface. JNA provides native access in a natural way with a minimum of effort. No boilerplate or generated glue code is required. Java interface used for describe functions and structures in the target native library. This makes it quite easy to take advantage of native platform features without incurring the high overhead of configuring and building JNI code for multiple platforms.

Read the next article that explains communication with USB HID device more detailed: Working with USB HID Device in Java

Discussion

Enter your comment