This is example source code showing how to use the AxsunOCTCapture scanner command API in a C++ client application (Windows OS).
#include <iostream>
#include <string>
#include <chrono>
using namespace std::chrono_literals;
using std::cout;
using std::cin;
using std::string;
string GetErrorStringCpp(
AxErr e) {
char errormsg[512];
return errormsg;
}
class ScannerSession {
public:
ScannerSession() {}
~ScannerSession() {
}
};
void DeviceConnectedCallback(void * user_data) {
try {
if (devices < 0)
throw static_cast<AxErr>(devices);
cout << "Total devices connected: " << devices << '\n';
for (int index = 0; index < devices; index++) {
if (serialno > 0 && modelno > 0)
cout << "USB-" << std::dec << modelno << " (" << std::hex << serialno << ") is device index " << std::dec << index << '\n';
else throw static_cast<AxErr>(devices);
}
cout << '\n';
}
cout << "***** ERROR: " << GetErrorStringCpp(e) << "\n\n";
}
}
int main()
{
try {
cout << "Welcome to the AxsunOCTCapture DAQmx Scanner Control example application.\n";
AxErr retval{ AxErr::NO_AxERROR };
ScannerSession mySession;
bool running = true;
char which_command;
while (running) {
cout << "Type a character and press enter to execute a command.\n>> ";
cin >> which_command;
try {
switch (which_command) {
case '?':
cout << "\n***** COMMAND LIST *****\n";
cout << "(see matrix in AxsunOCTCapture.h for supported devices and functions)\n\n";
cout << "L\tList connected device serial numbers using axScanCmd(GET_DEVICE_SERIALNO, ..);\n";
cout << "D\tMake device at index 1 active using axScanCmd(SELECT_DEVICE, 1, ..);\n";
cout << "P\tSet scan parameters using axScanCmd(set_rect_pattern, ..);\n";
cout << "1\tStart continuous 1D linear scanning using axScanCmd(CONTINUOUS_LINE_SCAN, ..);\n";
cout << "2\tStart continuous 2D raster scanning using axScanCmd(CONTINUOUS_RASTER_SCAN, ..);\n";
cout << "S\tStop scanning using axScanCmd(STOP_AT_POSITION, ..);\n";
cout << "I\tSet internal sample clock using axScanCmd(SET_SAMPLE_CLOCK, 1, ..);\n";
cout << "E\tSet external sample clock using axScanCmd(SET_SAMPLE_CLOCK, 0, ..);\n";
cout << "B\tPrepare for burst raster scan using axScanCmd(SETUP_BURST_RASTER, ..);\n";
cout << "R\tStart burst raster scan using axScanCmd(START_BURST_RASTER, ..);\n";
cout << "M\tSet maximum analog output voltage to 1.0V using axScanCmd(SET_MAX_VOLTAGE, 1.0, ..);\n";
cout << "W\tSet square wave synthesizer to 7200 Hz using axScanCmd(SET_SQUAREWAVE_OUTPUT, 7200, ..);\n";
cout << "X\tTurn square wave synthesizer off using axScanCmd(SET_SQUAREWAVE_OUTPUT, 0.0, ..);\n";
cout << "N\tTurn general purpose digital output ON using axScanCmd(SET_DIGITAL_OUTPUT, 1.0, ..);\n";
cout << "F\tTurn general purpose digital output OFF using axScanCmd(SET_DIGITAL_OUTPUT, 0.0, ..);\n";
cout << "A\tSet auxiliary analog output to 2.5 Vdc using axScanCmd(SET_AUX_DC_ANALOG_OUTPUT, 2.5, ..);\n";
cout << "O\tTurn auxiliary analog DC output OFF using axScanCmd(SET_AUX_DC_ANALOG_OUTPUT, 0.0, ..);\n";
cout << "U\tSet max limit on auxiliary analog DC output to 1.0V using axScanCmd(SET_AUX_DC_ANALOG_MAX, 1.0, ..);\n";
cout << "?\tList command options.\n";
cout << "Q\tQuit this program.\n\n";
break;
case '1':
cout << "Linear scan started.\n";
break;
case '2':
cout << "Raster scan started.\n";
break;
case 's':
case 'S':
{
scan_pattern.Y_shift = -1.0;
cout << "Scan stopped at (" << scan_pattern.X_shift << "," << scan_pattern.Y_shift << ").\n";
break;
}
case 'p':
case 'P':
{
scan_pattern.Y_increments = 2000;
scan_pattern.X_range = 3.0;
scan_pattern.Y_range = 3.0;
cout << "Scan parameters set.\n";
break;
}
case 'l':
case 'L':
{
DeviceConnectedCallback(NULL);
break;
}
case 'd':
case 'D':
break;
case 'e':
case 'E':
cout << "Selected external sample clock. \n";
break;
case 'i':
case 'I':
cout << "Selected internal 100 kHz sample clock. \n";
break;
case 'm':
case 'M':
cout << "Maxiumum analog output voltage has been set. \n";
break;
case 'b':
case 'B':
cout << "Burst raster setup and waiting for START_BURST_RASTER command. \n";
break;
case 'w':
case 'W':
cout << "Square wave synthesizer configured for 7200 Hz. \n";
break;
case 'x':
case 'X':
cout << "Square wave synthesizer off. \n";
break;
case 'n':
case 'N':
cout << "General purpose digital output ON. \n";
break;
case 'f':
case 'F':
cout << "General purpose digital output OFF. \n";
break;
case 'r':
case 'R':
{
cout << "Burst raster started... \n";
cout << "Burst raster completed.\n";
break;
}
case 'a':
case 'A':
{
cout << "Auxiliary analog output set to 2.5 Vdc.\n";
break;
}
case 'o':
case 'O':
{
cout << "Auxiliary analog output disabled.\n";
break;
}
case 'u':
case 'U':
{
cout << "Auxiliary analog output limit set to 1.0V.\n";
break;
}
case 'q':
case 'Q':
cout << "Quitting.\n";
running = false;
break;
default:
cout << "Command not recognized. Enter '?' to list options.\n";
}
}
cout << "***** ERROR: " << GetErrorStringCpp(e) << "\n\n";
}
}
}
cout << "***** ERROR: " << GetErrorStringCpp(e) << " Program terminating.\n";
}
catch (...) {
cout << "***** UNKNOWN ERROR. Program terminating.\n";
}
}