USB-DIO-32 Sample Program Release Notes

Table of Contents

Overview

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 $Revision: 1.13 $ $Date: 2009/10/16 18:17:11 $
  (AIOUSB library $Revision: 1.63 $ $Date: 2009/10/15 18:12:01 $)
  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 (12 characters)
    Number of digital I/O bytes: 2
    Number of counters: 1 
  Device at index 1:
    Product ID: 0x8001
    Product name: USB-DIO-32 (10 characters)
    Number of digital I/O bytes: 4
    Number of counters: 3
  Device at index 2:
    Product ID: 0x8001
    Product name: USB-DIO-32 (10 characters)
    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.