1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <iostream>
18 #include <iterator>
19 #include <iomanip>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <USBDeviceManager.hpp>
24 #include <USB_DA12_8A_Family.hpp>
25
26
27 using namespace AIOUSB;
28 using namespace std;
29
30 int main( int argc, char *argv[] ) {
31 USBDeviceManager deviceManager;
32 try {
33 deviceManager.open();
34 cout <<
35 "USB-DA12-8A sample program version 1.1, 29 January 2010\n"
36 " AIOUSB C++ class library version " << deviceManager.VERSION_NUMBER << ", " << deviceManager.VERSION_DATE << "\n"
37 " AIOUSB library version " << deviceManager.getAIOUSBVersion() << ", " << deviceManager.getAIOUSBVersionDate() << "\n"
38 "\n"
39 " This program demonstrates controlling a USB-DA12-8A family device on\n"
40 " the USB bus. For simplicity, it uses the first such device found\n"
41 " on the bus and supports these product IDs: ";
42 const StringArray supportedProductNames = USB_DA12_8A_Family::getSupportedProductNames();
43 for( int index = 0; index < ( int ) supportedProductNames.size(); index++ ) {
44 if( index > 0 )
45 cout << ", ";
46 cout << supportedProductNames.at( index );
47 }
48 cout << endl;
49 deviceManager.printDevices();
50 USBDeviceArray devices = deviceManager.getDeviceByProductID( USB_DA12_8A_Family::getSupportedProductIDs() );
51 if( devices.size() > 0 ) {
52 USB_DA12_8A_Family &device = *( USB_DA12_8A_Family * ) devices.at( 0 );
53 device.setCommTimeout( 1000 );
54
55
56
57
58 cout << "Found device \'" << device.getName() << "\' with serial number " << hex << device.getSerialNumber() << endl;
59
60
61
62
63 const int numChannels = device.dac().getNumChannels();
64 const int TEST_CHANNEL = 0;
65 const unsigned short counts = DA12_AnalogOutputSubsystem::MAX_COUNTS / 2;
66 device.dac().writeCounts( TEST_CHANNEL, counts );
67 cout << dec << counts << " D/A counts successfully output to channel " << TEST_CHANNEL << endl;
68
69
70
71
72 UShortArray countPoints( numChannels * 2 );
73 for( int channel = 0; channel < numChannels; channel++ ) {
74 countPoints.at( channel * 2 ) = channel;
75 countPoints.at( channel * 2 + 1 ) = ( unsigned short ) ( ( channel + 1 ) * DA12_AnalogOutputSubsystem::MAX_COUNTS / numChannels );
76 }
77 device.dac().writeCounts( countPoints );
78 cout << "Multiple D/A counts successfully output to " << numChannels << " channels" << endl;
79
80
81
82
83
84
85
86 const int HARDWARE_RANGE = DA12_AnalogOutputSubsystem::RANGE_10V;
87 const double volts = 5;
88 device.dac().setRange( HARDWARE_RANGE );
89 device.dac().writeVolts( TEST_CHANNEL, volts );
90 cout << volts << " volts (" << device.dac().voltsToCounts( TEST_CHANNEL, volts ) << " D/A counts)"
91 << " successfully output to channel " << TEST_CHANNEL << endl;
92
93
94
95
96 OutputVoltagePointArray voltPoints( numChannels );
97 for( int channel = 0; channel < numChannels; channel++ ) {
98 voltPoints.at( channel ).channel = channel;
99 voltPoints.at( channel ).volts = ( channel + 1 ) * 10.0 / numChannels;
100 }
101 device.dac().writeVolts( voltPoints );
102 cout << "Multiple volts successfully output to " << numChannels << " channels" << endl;
103 } else
104 cout << "No USB-DA12-8A devices found on USB bus" << endl;
105 deviceManager.close();
106 } catch( exception &ex ) {
107 cerr << "Error \'" << ex.what() << "\' occurred while configuring device" << endl;
108 if( deviceManager.isOpen() )
109 deviceManager.close();
110 }
111 }
112
113