AIOUSB C++ Class Library Reference

Introduction

The AIOUSB C++ Class Library is an object-oriented C++ layer that runs on top of the AIOUSB library. All access to the USB devices is through fully object-oriented C++ classes. The user never needs to call the underlying AIOUSB library, although that is possible if necessary.

This C++ library supports all the features of all the USB products except the D/A streaming features of the USB-DA12-8A product, although support for those features will be provided eventually. While the underlying AIOUSB library has been thoroughly tested, this C++ library has not yet been thoroughly tested and should be considered beta software.

Packaging

As with the AIOUSB library, the AIOUSB C++ class library is packaged into several library (.a) files. libclassaiousb.a is a release version of the library and libclassaiousbdbg.a is a debug version, compiled with the "-ggdb" compiler option and with assertion checks enabled. When linking programs that use the AIOUSB C++ class library, you must not only specify the AIOUSB C++ class library on the linker command line, but the AIOUSB C library as well since the AIOUSB C++ class library uses AIOUSB.

Sample Program

Below is an example of a minimalist C++ program that demonstrates how to properly initialize the library, query the device manager for devices, query an individual device for its product ID and name and then terminate use of the library. If the AIOUSB C library and the AIOUSB C++ class library are properly installed, you should be able to copy this sample program from this document, paste it into a file named test.cpp and compile it using the command shown below. This program uses the first ACCES device it finds on the bus. A "real" application would probably be looking for devices of a particular type, which can be located using one of the AIOUSB::USBDeviceManager::getDeviceByProductID( int productID ) const methods.

/*
 * compile: g++ -ggdb -Wall -pthread -fPIC test.cpp ../libclassaiousbdbg.a ../../lib/libaiousbcppdbg.a -lusb-1.0 -o test
 * /
#include <iostream>
#include <iomanip>
#include <USBDeviceManager.hpp>
using namespace AIOUSB;
using namespace std;
int main( int argc, char *argv[] ) {
  int result = 0;
  USBDeviceManager deviceManager;
  try {
    deviceManager.open();
    USBDeviceArray devices = deviceManager.getDeviceByProductID( USBDeviceManager::MIN_PRODUCT_ID, USBDeviceManager::MAX_PRODUCT_ID );
    if( devices.size() > 0 ) {
      USBDevice &device = *devices.at( 0 );
      cout << "Found a device with product ID " << hex << device.getProductID() << " and name \'" << device.getName() << "\'" << endl;
    } else
      cout << "No devices found" << endl;
    deviceManager.close();
  } catch( exception &ex ) {
    cerr << "Error \'" << ex.what() << "\' occurred while manipulating device" << endl;
    result = 1;
    if( deviceManager.isOpen() )
      deviceManager.close();
  }  // catch( ...
  return result;
}  // main()

The above example is obviously simplistic as well as generic. In a "real" application, one would search for devices of a specific type (i.e. product ID) and then cast instances of the generic class AIOUSB::USBDevice to a specific device class, such as AIOUSB::USB_AI16_Family.


Document:
Revision
1.2
Date
2009/12/24 19:43:43

doxygen