This directory contains several sample programs for the USB-AI16-16A which demonstrate use of different features and libraries.
Sample.cpp is a simple program to demonstrate using the AIOUSB module to control 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 – 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.24, 26 November 2009 AIOUSB library version 1.81, 23 November 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: 0x8040 Product name: USB-AI16-16A Number of digital I/O bytes: 2 Number of counters: 1 Serial number of device at index 0: 40e38f15d5c94894 A/D settings successfully configured Automatic calibration completed successfully Ground counts = 1 (should be approx. 0) Reference counts = 65101 (should be approx. 65102) Volts read: Channel 0 = 0.006714 Channel 1 = 0.102083 Channel 2 = 0.123751 Channel 3 = 0.017243 Channel 4 = 0.023957 Channel 5 = 0.086824 Channel 6 = 0.031434 Channel 7 = 0.003967 Channel 8 = 0.103609 Channel 9 = 0.121462 Channel 10 = 0.129091 Channel 11 = 0.040894 Channel 12 = 0.121920 Channel 13 = 0.108492 Channel 14 = 0.050050 Channel 15 = 0.059968 Volts read from A/D channel 5 = 0.006867 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 76800 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 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 Extcal.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 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).
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.10, 29 November 2009 AIOUSB Java library version: 1.2, 26 November 2009 AIOUSB library version: 1.81, 23 November 2009 JRE version: 1.6.0_17 OS version: Linux amd64 2.6.31.5-0.1-default 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: 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 channels: 16 Number of tristates: 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 Counts read from channel 0 to channel 15 using 50 oversamples Channel 0 = 32868 (0.00306706340123597 volts) Channel 1 = 35310 (0.07759212634470125 volts) Channel 2 = 36905 (0.12626840619516289 volts) Channel 3 = 35514 (0.08381780727855337 volts) Channel 4 = 37262 (0.1371633478294041 volts) Channel 5 = 36932 (0.1270923933775845 volts) Channel 6 = 37398 (0.1413138017853055 volts) Channel 7 = 35518 (0.08393987945372694 volts) Channel 8 = 35924 (0.09633020523384461 volts) Channel 9 = 35383 (0.07981994354161892 volts) Channel 10 = 35342 (0.07856870374608982 volts) Channel 11 = 33534 (0.02339208056763553 volts) Channel 12 = 35816 (0.09303425650415797 volts) Channel 13 = 34895 (0.06492713817044327 volts) Channel 14 = 33816 (0.031998168917372505 volts) Channel 15 = 34282 (0.04621957732509352 volts) Bulk read 20000 samples, 980000 remaining Bulk read 40000 samples, 960000 remaining Bulk read 60000 samples, 940000 remaining Bulk read 80000 samples, 920000 remaining Bulk read 100000 samples, 900000 remaining Bulk read 120000 samples, 880000 remaining Bulk read 140000 samples, 860000 remaining Bulk read 160000 samples, 840000 remaining Bulk read 180000 samples, 820000 remaining Bulk read 200000 samples, 800000 remaining Bulk read 220000 samples, 780000 remaining Bulk read 240000 samples, 760000 remaining Bulk read 260000 samples, 740000 remaining Bulk read 280000 samples, 720000 remaining Bulk read 300000 samples, 700000 remaining Bulk read 320000 samples, 680000 remaining Bulk read 340000 samples, 660000 remaining Bulk read 360000 samples, 640000 remaining Bulk read 380000 samples, 620000 remaining Bulk read 400000 samples, 600000 remaining Bulk read 420000 samples, 580000 remaining Bulk read 440000 samples, 560000 remaining Bulk read 460000 samples, 540000 remaining Bulk read 480000 samples, 520000 remaining Bulk read 500000 samples, 500000 remaining Bulk read 520000 samples, 480000 remaining Bulk read 540000 samples, 460000 remaining Bulk read 560000 samples, 440000 remaining Bulk read 580000 samples, 420000 remaining Bulk read 600000 samples, 400000 remaining Bulk read 620000 samples, 380000 remaining Bulk read 640000 samples, 360000 remaining Bulk read 660000 samples, 340000 remaining Bulk read 680000 samples, 320000 remaining Bulk read 700000 samples, 300000 remaining Bulk read 720000 samples, 280000 remaining Bulk read 740000 samples, 260000 remaining Bulk read 760000 samples, 240000 remaining Bulk read 780000 samples, 220000 remaining Bulk read 800000 samples, 200000 remaining Bulk read 820000 samples, 180000 remaining Bulk read 840000 samples, 160000 remaining Bulk read 860000 samples, 140000 remaining Bulk read 880000 samples, 120000 remaining Bulk read 900000 samples, 100000 remaining Bulk read 920000 samples, 80000 remaining Bulk read 940000 samples, 60000 remaining Bulk read 960000 samples, 40000 remaining Bulk read 980000 samples, 20000 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 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.
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.11, 29 November 2009 AIOUSB C++ class library version 1.3, 26 November 2009 AIOUSB library version 1.81, 23 November 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. 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 channels: 16 Number of tristates: 0 Number of counter blocks: 1 Number of counters: 3 Measuring calibration point 1: Feed a voltage into channel 10 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 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 Extcal.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 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).
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.5, 29 November 2009 AIOUSB Java library version: 1.2, 26 November 2009 AIOUSB library version: 1.81, 23 November 2009 JRE version: 1.6.0_17 OS version: Linux amd64 2.6.31.5-0.1-default 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: 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 channels: 16 Number of tristates: 0 Number of counter blocks: 1 Number of counters: 3 Measuring calibration point 1: Feed a voltage into channel 0 and enter voltage here (enter nothing to finish and calibrate A/D): ...