This is example source code showing how to use the AxsunOCTCapture scanner command API in a C++ client application (Windows only).
#include <iostream>
#include <string>
#include <chrono>
#include <vector>
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(int argc, char* argv[])
{
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 << "T\tLoad an external scan pattern using axScanCmd(LOAD_EXT_PATTERN, 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 = 4;
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 't':
case 'T':
{
constexpr auto x_increments{ 4000u };
constexpr auto y_increments{ 20u };
my_pattern.ext_Y_increments = y_increments;
auto pattern1D = std::vector<double>(2 * x_increments, 0.0);
auto pattern2D = std::vector<double>(2 * x_increments * y_increments, 0.0);
my_pattern.linear_pattern = pattern1D.data();
my_pattern.raster_pattern = pattern2D.data();
cout << "External scan pattern loaded.\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";
}
}
AxErr
Error codes returned from AxsunOCTCapture or AxsunOCTControl_LW functions. Use axGetErrorString() in ...
Definition: AxsunCommonEnums.h:40
This header file contains all exported function prototypes, structures, and enums necessary for integ...
@ START_BURST_RASTER
Definition: AxsunOCTCapture.h:319
@ DESTROY_SCAN
Definition: AxsunOCTCapture.h:305
@ WAIT_BURST
Definition: AxsunOCTCapture.h:321
@ SET_DIGITAL_OUTPUT
Definition: AxsunOCTCapture.h:333
@ SET_AUX_DC_ANALOG_MAX
Definition: AxsunOCTCapture.h:341
@ GET_DEVICE_SERIALNO
Definition: AxsunOCTCapture.h:325
@ COUNT_DEVICES
Definition: AxsunOCTCapture.h:329
@ SET_SAMPLE_CLOCK
Definition: AxsunOCTCapture.h:323
@ CONTINUOUS_LINE_SCAN
Definition: AxsunOCTCapture.h:311
@ CONTINUOUS_RASTER_SCAN
Definition: AxsunOCTCapture.h:313
@ SELECT_DEVICE
Definition: AxsunOCTCapture.h:327
@ GET_DEVICE_MODEL_NUMBER
Definition: AxsunOCTCapture.h:345
@ SETUP_BURST_RASTER
Definition: AxsunOCTCapture.h:317
@ SET_SQUAREWAVE_OUTPUT
Definition: AxsunOCTCapture.h:335
@ SET_RECT_PATTERN
Definition: AxsunOCTCapture.h:307
@ STOP_AT_POSITION
Definition: AxsunOCTCapture.h:315
@ SET_MAX_VOLTAGE
Definition: AxsunOCTCapture.h:331
@ SET_AUX_DC_ANALOG_OUTPUT
Definition: AxsunOCTCapture.h:339
@ LOAD_EXT_PATTERN
Definition: AxsunOCTCapture.h:309
AxErr __cdecl axScanCmd(AxScannerCommand scan_command, double misc_scalar, const scan_params_t *scan_parameters, ext_pattern_t *external_scan_pattern, void *RFU)
Control analog output waveform generation for 2 channel (X-Y) scanners. (Windows OS only)
void __cdecl axGetErrorString(AxErr errorcode, char *message_out)
Get a description of a specific AxErr error code.
AxErr __cdecl axRegisterScannerConnectCallback(AxConnectScannerCallbackFunction_t callback_function, void *userData)
Registers a callback function to be executed following a scanner (DAQmx) device connection or disconn...
Structure for passing a user-generated scan pattern to axScanCmd(LOAD_EXT_PATTERN,...
Definition: AxsunOCTCapture.h:373
uint32_t ext_X_increments
Definition: AxsunOCTCapture.h:375
Structure for passing raster scan pattern parameters to axScanCmd(SET_RECT_PATTERN,...
Definition: AxsunOCTCapture.h:351
double X_shift
Definition: AxsunOCTCapture.h:361
uint32_t X_increments
Definition: AxsunOCTCapture.h:353