This directory contains several sample programs for the USB-IIRO-16 which demonstrate use of different features and libraries.
Sample.cpp is a simple program to demonstrate controlling an ACCES I/O model USB-IIRO-16 digital I/O board using the AIOUSB module and the AIOUSB C++ class library. The program is not intended to be a comprehensive demonstration and is limited to demonstrating the following features of the AIOUSB API:
Initializing and shutting down the API – USBDeviceManager::open(), USBDeviceManager::close()
Finding devices on the USB bus – USBDeviceManager::getDeviceByProductID()
Reading and writing the custom area of the EEPROM – USBDevice::customEEPROMRead(), USBDevice::customEEPROMWrite()
Configuring the board – USBDevice::setCommTimeout(), DigitalIOSubsystem::configure()
Writing to individual outputs – DigitalIOSubsystem::write()
Writing to multiple outputs – DigitalIOSubsystem::write()
For easy identification, the source code lines prefixed with the comment /*API*/ denote calls to the AIOUSB and C++ class library API.
The C++ class library is preliminary and still being developed. Notice, too, that when using the C++ class library it is not necessary (in fact, it's not permitted) to call AIOUSB_Init() or AIOUSB_Exit(). These are implicitly called by USBDeviceManager::open() and USBDeviceManager::close(). Refer to AIOUSB C++ Class Library Reference Documentation for more information.
Before building the program, make sure the libusb module is installed. Also refer to the comments at the top of sample.cpp for additional details.
Also, make sure that the ACCES I/O AIOUSB module is installed (see Installing And Using AIOUSB Library).
The simplest way to build the sample program is to type make at the command line. The sample program is the default target in Makefile. Optionally, one can manually compile the program with the command:
g++ sample.cpp -lclassaiousb -laiousbcpp -lusb-1.0 -o sample
This sample program can demonstrate writing to the EEPROM. That demonstration is disabled by default, but if you wish to enable it, simply edit Sample.java and set the variable named DEMO_EEPROM_WRITE to true.
To execute the program, attach a USB-IIRO-16 analog input board to the USB bus and verify that its LED turns on, indicating that firmware has been successfully uploaded to the board. Then simply type ./sample at the command line. There are no command line arguments to worry about. The program will search for the first USB-IIRO-16 analog input board on the USB bus. If it fails to find such a board, it will print an error message and quit. If it finds such a board, the following output will appear:
USB-IIRO-16 sample program version: 1.2, 30 November 2009 AIOUSB C++ library version: 1.4, 30 November 2009 AIOUSB library version: 1.81, 23 November 2009 This program demonstrates controlling a USB-IIRO-16 device on the USB bus. For simplicity, it uses the first such device found on the bus. ACCES devices found: Device at index 0: Product ID: 0x8040 Product name: USB-AI16-16A Serial number: 0x40e38f15d5c94894 Number of A/D channels: 16 Number of MUXed A/D channels: 16 Number of digital I/O ports: 2 Number of digital I/O channels: 16 Number of tristate groups: 0 Number of tristates: 0 Number of counter blocks: 1 Number of counters: 3 Device at index 1: Product ID: 0x8010 Product name: USB-IIRO-16 Serial number: 0x40e399d4e1215a84 Number of digital I/O ports: 4 Number of digital I/O channels: 32 Number of tristate groups: 0 Number of tristates: 0 Writing to EEPROM ... successful EEPROM contents: [ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff] Configuring digital I/O ... successful In the following demonstrations, you should hear the relays click for the first 16 channels. The latter 16 channels are not connected to relays and will turn on and off silently. Also. the LED on the device should blink during these demos. CLosing relays: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Opening relays: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Closing all relays ... successful Opening all relays ... successful
Sample.java is a Java implementation of the above sample program. It demonstrates use of the Java class library, which is equivalent to the C++ class library. Refer to AIOUSB Java Class Library Reference for detailed information on the Java class library, which is also applicable to the C++ class library.
The prerequisites for building Sample.class are that the Java Runtime Environment (JRE) must be installed. In addition, the AIOUSB Java library (aiousb.jar) must be installed somewhere on your system. To compile the program, either use the supplied Makefile or use the command:
javac -cp ../../java/aiousb.jar Sample.java
This sample program can demonstrate writing to the EEPROM. That demonstration is disabled by default, but if you wish to enable it, simply edit Sample.java and set the variable named DEMO_EEPROM_WRITE to true.
To execute the program, attach a USB-IIRO-16 analog input board to the USB bus and verify that its LED turns on, indicating that firmware has been successfully uploaded to the board. Then type the command:
java -cp ../../java/aiousb.jar:. Sample
Notice that multiple class paths are specified in the above command: the path to aiousb.jar and ".", which represents the class path of Sample.class (assuming that it is the current directory).
Alternatively, you can use the command:
java -jar Sample.jar
There are no command line arguments to worry about. The program will search for the first USB-IIRO-16 analog input board on the USB bus. If it fails to find such a board, it will print an error message and quit. If it finds such a board, the following output will appear:
USB-IIRO-16 sample program version: 1.2, 30 November 2009 AIOUSB Java library version: 1.3, 30 November 2009 AIOUSB library version: 1.81, 23 November 2009 JRE version: 1.6.0_17 OS version: Linux i386 2.6.27.7-9-custom This program demonstrates controlling a USB-IIRO-16 device on the USB bus. For simplicity, it uses the first such device found on the bus. ACCES devices found: Device at index 0 Product ID: 0x8040 Product name: USB-AI16-16A Serial number: 0x40e38f15d5c94894 Number of A/D channels: 16 Number of MUXed A/D channels: 16 Number of digital I/O ports: 2 Number of digital I/O channels: 16 Number of tristate groups: 0 Number of tristates: 0 Number of counter blocks: 1 Number of counters: 3 Device at index 1 Product ID: 0x8010 Product name: USB-IIRO-16 Serial number: 0x40e399d4e1215a84 Number of digital I/O ports: 4 Number of digital I/O channels: 32 Number of tristate groups: 0 Number of tristates: 0 EEPROM contents: [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] Configuring digital I/O ... successful In the following demonstrations, you should hear the relays click for the first 16 channels. The latter 16 channels are not connected to relays and will turn on and off silently. Also. the LED on the device should blink during these demos. CLosing relays: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Opening relays: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Closing all relays ... successful Opening all relays ... successful