This directory contains several sample programs for the USB-AI16-16A which demonstrate use of different features and libraries.
Sample2.c and sample.cpp are simple programs to demonstrate using the AIOUSB module to control an ACCES I/O model USB-AI16-16A analog input board. These programs are nearly identical, one written for the standard gcc compiler and the other written for the g++ compiler. They are not intended to be comprehensive demonstrations and are limited to demonstrating the following features of the AIOUSB API:
Initializing and shutting down the API – AIOUSB_Init(), AIOUSB_Exit()
Identifying devices on the USB bus – QueryDeviceInfo()
Obtaining the serial number of a device on the bus – GetDeviceSerialNumber()
Configuring the board – ADC_SetConfig()
Calibrating the converter – ADC_SetCal()
Reading the analog inputs – ADC_GetScan(), ADC_GetScanV(), ADC_GetChannelV()
Bulk reading of analog inputs – ADC_BulkAcquire(), ADC_BulkPoll(), AIOUSB_SetStreamingBlockSize()
For easy identification, the source code lines prefixed with the comment /*API*/ denote calls to the AIOUSB API.
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
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 a USB-AI16-16A 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-AI16-16A 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-AI16-16A sample program version 1.26, 22 December 2009
AIOUSB library version 1.84, 22 December 2009
This program demonstrates controlling a USB-AI16-16A 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: 0x8045
Product name: USB-AI16-64MA
Number of digital I/O bytes: 2
Number of counters: 1
Serial number of device at index 0: 40e39bb62c62cd35
A/D settings successfully configured
Automatic calibration completed successfully
Ground counts = 0 (should be approx. 0)
Reference counts = 65130 (should be approx. 65130)
Volts read:
Channel 0 = 0.006256
Channel 1 = 0.006104
Channel 2 = 0.006104
Channel 3 = 0.006256
Channel 4 = 0.107729
Channel 5 = 0.084840
Channel 6 = 0.066529
Channel 7 = 0.052796
Channel 8 = 0.009308
Channel 9 = 0.008850
Channel 10 = 0.008698
Channel 11 = 0.008392
Channel 12 = 0.000000
Channel 13 = 0.000000
Channel 14 = 0.000000
Channel 15 = 0.001373
Volts read from A/D channel 5 = 0.006409
Started bulk acquire of 35200000 bytes
34397184 bytes remaining
33393664 bytes remaining
32390144 bytes remaining
31386624 bytes remaining
30383104 bytes remaining
29379584 bytes remaining
28376064 bytes remaining
27573248 bytes remaining
26569728 bytes remaining
25566208 bytes remaining
24562688 bytes remaining
23559168 bytes remaining
22555648 bytes remaining
21552128 bytes remaining
20548608 bytes remaining
19745792 bytes remaining
18742272 bytes remaining
17738752 bytes remaining
16735232 bytes remaining
15731712 bytes remaining
14728192 bytes remaining
13724672 bytes remaining
12721152 bytes remaining
11918336 bytes remaining
10914816 bytes remaining
9911296 bytes remaining
8907776 bytes remaining
7904256 bytes remaining
6900736 bytes remaining
5897216 bytes remaining
4893696 bytes remaining
4090880 bytes remaining
3087360 bytes remaining
2083840 bytes remaining
1080320 bytes remaining
0 bytes remaining
Successfully bulk acquired 35200000 bytes
The sample program prints out a list of all the ACCES devices found on the USB bus and then proceeds to exercise the first USB-AI16-16A board found.
Sample.java is a Java implementation of the above sample program. It demonstrates use of the Java class library, which is nearly identical to the C++ class library. Refer to AIOUSB Java Class Library Reference for detailed documentation on the Java class library.
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 will write the bulk A/D data it receives from the device to a file named bulkdata in the current directory. With the default settings, this file will be 2,000,000 bytes in size. If you prefer not to have the program create such a file, simply edit Sample.java and set the variable named SAVE_DATA_TO_FILE to false.
In addition, the probram checks the data received for zero, which, using the default settings would indicate some sort of problem with the hardware or software. However, if zero is a legitimate count value for the device to measure (i.e. you are feeding a voltage into the board that is at or below the board's minimum measurement range), then you may wish to turn off that data check as well. You can do so by setting the variable named CHECK_FOR_ZERO_DATA to false.
To execute the program, attach a USB-AI16-16A 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-AI16-16A 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-AI16-16A sample program version: 1.22, 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-AI16-16A family device on
the USB bus. For simplicity, it uses the first such device found
on the bus and supports these product IDs:[USB-AI16-16A, USB-AI16-16E,
USB-AI12-16A, USB-AI12-16, USB-AI12-16E, USB-AI16-64MA, USB-AI16-64ME,
USB-AI12-64MA, USB-AI12-64M, USB-AI12-64ME, USB-AI16-32A, USB-AI16-32E,
USB-AI12-32A, USB-AI12-32, USB-AI12-32E, USB-AI16-64A, USB-AI16-64E,
USB-AI12-64A, USB-AI12-64, USB-AI12-64E, USB-AI16-96A, USB-AI16-96E,
USB-AI12-96A, USB-AI12-96, USB-AI12-96E, USB-AI16-128A, USB-AI16-128E,
USB-AI12-128A, USB-AI12-128, USB-AI12-128E]
ACCES devices found:
Device at index 0
Product ID: 0x8045
Product name: USB-AI16-64MA
Serial number: 0x40e39bb62c62cd35
Number of A/D channels: 16
Number of MUXed A/D channels: 64
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
EEPROM contents:
[32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]
A/D successfully configured
Calibrating A/D, may take a few seconds ... successful
Read from channel 0 to channel 63 using 50 oversamples:
Channel 0 = 32812 (0.0067903 volts)
Channel 1 = 32812 (0.0067903 volts)
Channel 2 = 32812 (0.0067903 volts)
Channel 3 = 32813 (0.0069429 volts)
Channel 4 = 32864 (0.0147250 volts)
...
Channel 59 = 32884 (0.0177768 volts)
Channel 60 = 33169 (0.0612650 volts)
Channel 61 = 33065 (0.0453956 volts)
Channel 62 = 32992 (0.0342565 volts)
Channel 63 = 32941 (0.0264744 volts)
Analog input data set captured from USB-AI16-64MA (S/N 0x40e39bb62c62cd35):
Time stamp: Fri Dec 25 09:44:51 PST 2009
Calibration mode: 0
Trigger mode: 4
Over-sample: 50
Discard first sample: true
64 data points:
Channel 000, 32816 A/D counts, 0.0074006V, +/-5V, single-ended
Channel 001, 32817 A/D counts, 0.0075532V, +/-5V, single-ended
Channel 002, 32818 A/D counts, 0.0077058V, +/-5V, single-ended
Channel 003, 32819 A/D counts, 0.0078584V, +/-5V, single-ended
Channel 004, 33478 A/D counts, 0.1084154V, +/-5V, single-ended
...
Channel 059, 32889 A/D counts, 0.0185397V, +/-5V, single-ended
Channel 060, 33194 A/D counts, 0.0650797V, +/-5V, single-ended
Channel 061, 33081 A/D counts, 0.0478370V, +/-5V, single-ended
Channel 062, 33003 A/D counts, 0.0359350V, +/-5V, single-ended
Channel 063, 32949 A/D counts, 0.0276951V, +/-5V, single-ended
Bulk read 4000 samples, 996000 remaining
Bulk read 8000 samples, 992000 remaining
Bulk read 12000 samples, 988000 remaining
Bulk read 16000 samples, 984000 remaining
Bulk read 20000 samples, 980000 remaining
...
Bulk read 984000 samples, 16000 remaining
Bulk read 988000 samples, 12000 remaining
Bulk read 992000 samples, 8000 remaining
Bulk read 996000 samples, 4000 remaining
Bulk read 1000000 samples, 0 remaining
Extcal.cpp is another simple program to demonstrate using the AIOUSB module and AIOUSB C++ class library to perform an external calibration of an ACCES I/O model USB-AI16-16A analog input board. 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()
Configuring the board – USBDevice::setCommTimeout(), AnalogInputSubsystem::setCalMode(), AnalogInputSubsystem::setDiscardFirstSample(), AnalogInputSubsystem::setTriggerMode(), AnalogInputSubsystem::setGainCodeAndDiffMode(), AnalogInputSubsystem::setOversample()
Installing a default calibration table – AnalogInputSubsystem::calibrate(bool,...)
Reading the analog inputs in counts – AnalogInputSubsystem::read()
Generating an external calibration table – AnalogInputSubsystem::calibrate(double[],...)
As with the sample program described above, the source code lines prefixed with the comment /*API*/ denote calls to the AIOUSB and C++ class library API.
The C++ class library should be considered beta software and is 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 for detailed documentation on the C++ class library.
The prerequisites for building extcal are the same as those for building the sample program described above, with the added requirement that the C++ class library also be installed. The program can be built using the make file provided or the explicit command:
g++ extcal.cpp -lclassaiousb -laiousbcpp -lusb-1.0 -o extcal
To execute the program, attach a USB-AI16-16A 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 ./extcal at the command line. There are no command line arguments to worry about. The program will search for the first USB-AI16-16A 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-AI16-16 sample program version 1.18, 25 December 2009
AIOUSB C++ class library version 1.7, 23 December 2009
AIOUSB library version 1.84, 22 December 2009
This program demonstrates external calibration of a USB-AI16-16 device
on the USB bus. For simplicity, it uses the first such device found on
the bus and supports these product IDs: USB-AI16-16A, USB-AI16-16E,
USB-AI12-16A, USB-AI12-16, USB-AI12-16E, USB-AI16-64MA, USB-AI16-64ME,
USB-AI12-64MA, USB-AI12-64M, USB-AI12-64ME, USB-AI16-32A, USB-AI16-32E,
USB-AI12-32A, USB-AI12-32, USB-AI12-32E, USB-AI16-64A, USB-AI16-64E,
USB-AI12-64A, USB-AI12-64, USB-AI12-64E, USB-AI16-96A, USB-AI16-96E,
USB-AI12-96A, USB-AI12-96, USB-AI12-96E, USB-AI16-128A, USB-AI16-128E,
USB-AI12-128A, USB-AI12-128, USB-AI12-128E.
This external calibration procedure allows you to inject a sequence of
precise voltages into the USB-AI16-16 that will be used to calibrate its
A/D. This procedure calibrates the A/D using channel 0 on the 0-10V range.
A minimum of 2 calibration points are required. The procedure is as follows:
1) Adjust a precision voltage source to a desired target voltage. These
target voltages do not have to be evenly spaced or provided in any
particular order.
2) When you have adjusted the precision voltage source to your desired
target, type in the exact voltage being fed into the USB-AI16-16 and
press <Enter>. This program will read the A/D and display the reading,
asking you to accept it or not. If it looks acceptable, press 'y'.
Otherwise, press any other key and the program will retake the reading.
3) When you are finished calibrating, press <Enter> without entering a
voltage, and the A/D will be calibrated using the data entered, and
the calibration table will be saved to a file in a format that can be
subsequently loaded into the A/D.
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
Calibrating A/D, may take a few seconds ... successful
Measuring calibration point 1:
Feed a voltage into channel 0 and enter voltage here
(enter nothing to finish and calibrate A/D): 0
Read 115 A/D counts (0.0175479 volts), accept (y/n)? y
Measuring calibration point 2:
Feed a voltage into channel 0 and enter voltage here
(enter nothing to finish and calibrate A/D): 9.9
Read 64851 A/D counts (9.8956283 volts), accept (y/n)? y
Measuring calibration point 3:
Feed a voltage into channel 0 and enter voltage here
(enter nothing to finish and calibrate A/D):
External calibration of A/D successful, table saved in ADC-Ext-Cal-Table-40e38f15d5c94894
Extcal.java is a Java implementation of the above calibration utility. It demonstrates use of the Java class library, which is nearly identical to the C++ class library. Refer to AIOUSB Java Class Library Reference for detailed documentation on the Java class library.
The prerequisites for building Extcal.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 Extcal.java
To execute the program, attach a USB-AI16-16A 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:. Extcal
Notice that multiple class paths are specified in the above command: the path to aiousb.jar and ".", which represents the class path of Extcal.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 Extcal.jar
There are no command line arguments to worry about. The program will search for the first USB-AI16-16A 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-AI16-16A sample program version: 1.11, 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 external calibration of a USB-AI16-16 device
on the USB bus. For simplicity, it uses the first such device found on
the bus.
This external calibration procedure allows you to inject a sequence of
precise voltages into the USB-AI16-16 that will be used to calibrate its
A/D. This procedure calibrates the A/D using channel 0 on the 0-10V range.
A minimum of 2 calibration points are required. The procedure is as follows:
1) Adjust a precision voltage source to a desired target voltage. These
target voltages do not have to be evenly spaced or provided in any
particular order.
2) When you have adjusted the precision voltage source to your desired
target, type in the exact voltage being fed into the USB-AI16-16 and
press <Enter>. This program will read the A/D and display the reading,
asking you to accept it or not. If it looks acceptable, press 'y'.
Otherwise, press any other key and the program will retake the reading.
3) When you are finished calibrating, press <Enter> without entering a
voltage, and the A/D will be calibrated using the data entered, and
the calibration table will be saved to a file in a format that can be
subsequently loaded into the A/D.
ACCES devices found:
Device at index 0
Product ID: 0x8045
Product name: USB-AI16-64MA
Serial number: 0x40e39bb62c62cd35
Number of A/D channels: 16
Number of MUXed A/D channels: 64
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
Calibrating A/D, may take a few seconds ... successful
Measuring calibration point 1:
Feed a voltage into channel 0 and enter voltage here
(enter nothing to finish and calibrate A/D):
...