Sample.cpp and receiver.cpp are a pair of simple programs to demonstrate using the AIOUSB module to control an ACCES I/O model USB-DIO-16A 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:
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 – DIO_ConfigureEx()
Writing to, and reading from a digital I/O stream – DIO_StreamSetClocks(), DIO_StreamOpen(), DIO_StreamFrame(), DIO_StreamClose()
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 commands:
g++ sample.cpp -laiousb -lusb-1.0 -o sample
g++ receiver.cpp -laiousb -lusb-1.0 -o receiver
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-16A 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-16A digital I/O boards on the USB bus. 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-16A sample program $Revision: 1.3 $ $Date: 2009/10/15 23:47:17 $ (AIOUSB library $Revision: 1.63 $ $Date: 2009/10/15 18:12:01 $) This program demonstrates high speed streaming between 2 USB-DIO-16A 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: 0x800f Product name: USB-DIO-16A (11 characters) Number of digital I/O bytes: 4 Number of counters: 0 Device at index 1: Product ID: 0x800f Product name: USB-DIO-16A (11 characters) Number of digital I/O bytes: 4 Number of counters: 0 Sending device at index 0, serial number 40e368b0a9dad209 Receiving device at index 1, serial number 40e37d2f439bdd09 Stream clock for device at index 0 set to 1000432.0 Hz 1024000 point frame successfully written to device at index 0 1024000 point frame successfully read from device at index 1
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-16A boards found. Basically, sample executes receiver as a child process to receive the stream data from one of the two devices. Sample then transmits the stream data to the other device. The entire demonstration takes a couple of seconds.
Important: this sample program requires that the two USB-DIO-16A devices be electrically connected together so that one device can transmit to the other. This connection is accomplished by means of a standard 68-pin SCSI cable attached to the J1 connector of each device. Contact ACCES for more information or to purchase such a cable (part number C68PS18L).