USB-DIO-32 Sample Program Release Notes

Table of Contents

Overview

This directory contains several sample programs for the USB-DIO-32 which demonstrate use of different features and libraries.

C/C++ Language Sample

Sample.cpp is a simple program to demonstrate using the AIOUSB module to control an ACCES I/O model USB-DIO-32 digital I/O board. The program is not intended to be a comprehensive demonstration and is limited to demonstrating the following features of the AIOUSB API:

For easy identification, the source code lines prefixed with the comment /*API*/ denote calls to the AIOUSB API.

Building

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 -laiousb -lusb-1.0 -o sample

Executing

Before executing the sample program, make sure the Linux system is configured to automatically detect ACCES I/O devices plugged into the USB bus and upload the appropriate firmware to those devices. The files that support this automatic configuration have recently been updated and new documentation prepared. Please refer to Configuring ACCES I/O USB Devices To Work Under Linux for details.

To execute the program, attach two USB-DIO-32 digital I/O boards to the USB bus and verify that their LEDs turn on, indicating that firmware has been successfully uploaded to the boards. Then simply type ./sample at the command line. There are no command line arguments to worry about. The program will search for the first two USB-DIO-32 digital I/O boards on the USB bus. (If you have only one board and want to use this sample program, simply change the DEVICES_REQUIRED constant at the top of the sample program to 1 and recompile the sample program by typing make at the command prompt.) If the sample program fails to find two boards, it will print an error message and quit. If it finds two such boards, the following output will appear:

USB-DIO-32 sample program version 1.17, 26 November 2009
  AIOUSB library version 1.84, 22 December 2009
  This program demonstrates communicating with 2 USB-DIO-32 devices on
  the same USB bus. For simplicity, it uses the first 2 such devices
  found on the bus.
ACCES devices found:
  Device at index 0:
    Product ID: 0x8040
    Product name: USB-AI16-16A
    Number of digital I/O bytes: 2
    Number of counters: 1 
  Device at index 1:
    Product ID: 0x8001
    Product name: USB-DIO-32
    Number of digital I/O bytes: 4
    Number of counters: 3
  Device at index 2:
    Product ID: 0x8001
    Product name: USB-DIO-32
    Number of digital I/O bytes: 4
    Number of counters: 3
Serial number of device at index 1: 40e391cdff3dd1bb
Serial number of device at index 2: 40e391cdf95aa30c
Device at index 1 successfully configured
Device at index 2 successfully configured
Read the following values from device at index 1: 0x11 0x22 0x33 0x44 (correct)
Read the following values from device at index 2: 0x66 0x65 0x64 0x63 (correct)
Writing patterns to devices: 0 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0
 0xb0 0xc0 0xd0 0xe0 0xf0
All patterns written were read back correctly

The sample program prints out a list of all the ACCES devices found on the USB bus and then proceeds to exercise the two USB-DIO-32 boards found. Notice in the above example, the sample program also found a model USB-AI16-16A on the bus. The entire demonstration takes about 16 seconds.

Java Sample

Sample.java is a Java implementation of the above sample program. It demonstrates use of the Java class library. Refer to AIOUSB Java Class Library Reference for detailed documentation on the Java class library.

Building

The prerequisites for building Sample.class are that the Java Development Kit (JDK) 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.

Executing

To execute the program, attach a USB-DIO-32 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, assuming you used the make file to build the program, you can run it with the command:

java -jar Sample.jar

There are no command line arguments to worry about. The program will search for the first USB-DIO-32 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-DIO-32 sample program version: 1.3, 25 December 2009
  AIOUSB Java library version: 1.6, 17 December 2009
  AIOUSB library version: 1.84, 22 December 2009
  JRE version: 1.6.0_17
  OS version: Linux amd64 2.6.31.5-0.1-custom
  This program demonstrates controlling a USB-DIO-32 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 tristate channels: 0
    Number of counter blocks: 1
    Number of counters: 3
  Device at index 1
    Product ID: 0x8001
    Product name: USB-DIO-32
    Serial number: 0x40e39acf9e8dd7cc
    Number of digital I/O ports: 4
    Number of digital I/O channels: 32
    Number of tristate groups: 0
    Number of tristate channels: 0
    Number of counter blocks: 3
    Number of counters: 9
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
Turning all outputs on: 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
Turning all outputs off: 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
Turning all outputs on ... successful
Turning all outputs off ... successful