The AIOUSB Java Class Library is an object-oriented Java layer that runs on top of the AIOUSB library, utilizing the Java Native Interface (JNI) to enable other Java libraries and applications to control ACCES I/O USB products. All access to the USB devices is through fully object-oriented Java classes. The user never needs to call the underlying AIOUSB library. (In fact, it's not even possible to do so in Java, although it is possible in C++.)
This Java library currently supports all the features of all the USB products except the D/A streaming features of the USB-DA12-8A product. While the underlying AIOUSB library has been thoroughly tested, this Java library has not yet been thoroughly tested and should be considered beta software.
For convenience, the entire AIOUSB Java class library is packaged into a JAR file. You may extract the classes from the JAR file, add your own classes to it or refer to the JAR file as a class path. For example, if you have a Java program named Test.java which uses the AIOUSB Java class library, you can compile it with the command:
javac -cp /path/aiousb.jar Test.java
After you have compiled it, producing Test.class, you can run the program with the command:
java -cp /path/aiousb.jar:. Test
Notice that multiple class paths are specified in the above command: the path to aiousb.jar and ".", which represents the class path of Test.class (assuming that it is the current directory).
Between AIOUSB and this Java class library is a module named libjavaaiousb.so which contains the JNI interface. This interface module is a shared library that is loaded by the Java VM at run-time. Therefore, it must be located in a place where the operating system loader can find it. You can also modify the LD_LIBRARY_PATH environment variable to point to where libjavaaiousb.so resides.
Below is an example of a minimalist Java program that demonstrates how to properly initialize the library, query the bus for devices, query an individual device for its product ID and name and then terminate use of the library. If libjavaaiousb.so is properly installed, you should be able to copy this sample program from this document, paste it into a file named Test.java and compile it using the command shown below. This program uses the first ACCES device it finds on the bus. A "real" application would probably be looking for devices of a particular type, which can be located using one of the USBDeviceManager.getDeviceByProductID() methods.
/* * compile: javac -cp /path/aiousb.jar Test.java * run: java -cp /path/aiousb.jar:. Test */ import com.acces.aiousb.*; class Test { public static void main( String args[] ) { USBDeviceManager deviceManager = new USBDeviceManager(); try { deviceManager.open(); USBDevice[] devices = deviceManager.getDeviceByProductID( USBDeviceManager.MIN_PRODUCT_ID , USBDeviceManager.MAX_PRODUCT_ID ); if( devices.length > 0 ) System.out.println( "Found a device with product ID " + Integer.toHexString( devices[ 0 ].getProductID() ) + " and name \'" + devices[ 0 ].getName() + "\'" ); else System.out.println( "No devices found" ); deviceManager.close(); } catch( Exception ex ) { System.err.println( "Error \'" + ex.toString() + "\' occurred while manipulating device" ); if( deviceManager.isOpen() ) deviceManager.close(); } // catch( ... } // main() } // class Test
The above example is obviously simplistic as well as generic. In a "real" application, one would search for devices of a specific type (i.e. product ID) and then cast instances of the generic class USBDevice to a specific device class, such as USB_AI16_Family.