This is example source code showing how to use the AxsunOCTCapture scanner command API in a C++ client application.
#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) {
if (devices < 0) throw static_cast<AxErr>(devices);
cout << "Total devices connected: " << devices << "\n";
for (int index = 0; index < devices; index++) {
if (serialno > 0)
cout << std::hex << serialno << " is device index " << std::dec << index << "\n";
else throw static_cast<AxErr>(devices);
}
cout << "\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 << "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 << "?\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 'r':
case 'R':
{
cout << "Burst raster started... \n";
cout << "Burst raster completed.\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";
}
}