This is example source code showing how to use the AxsunOCTControl_LW API in a C++ client application, including context construction/destruction (axOpen.. & axClose..), callback function registration, opening of communication interfaces, and sending a variety of commands to Laser and DAQ devices with user interaction. Several additional helper functions are also provided for conversion from char* or enums into std::string for console output.
#include <iostream>
#include <string>
#include <memory>
#include <vector>
using std::cout;
using std::cin;
using std::string;
switch (device) {
default: return "Unknown";
}
}
switch (connection) {
default: return "Unknown";
}
}
string GetErrorStringCpp(
AxErr e) {
char errormsg[256];
return errormsg;
}
void PrintConnectedDevices() {
cout << "\nTotal devices connected: " << count << "\n";
if (count > 0) {
for (auto i = 0; i < count; i++) {
if (retval != AxErr::NO_AxERROR) throw retval;
if (retval != AxErr::NO_AxERROR) throw retval;
uint32_t major, minor, patch;
if (retval != AxErr::NO_AxERROR) throw retval;
char serial_no[40];
cout << AxDevTypeString(device_type) << " (" << AxConnectTypeString(connection_type) << ")\tFW: v" << major << "." << minor << "." << patch << "\tSN: " << serial_no << "\t";
uint32_t build;
if (retval != AxErr::NO_AxERROR) throw retval;
cout << "\tFPGA: v" << major << "." << minor << "." << patch << "." << build;
}
cout << "\n";
}
cout << "\n";
}
}
void ConnectedCallbackFunc(void* userData) {
try {
PrintConnectedDevices();
}
catch (
AxErr e) { cout <<
"***** ERROR: " << GetErrorStringCpp(e) <<
" in callback function.\n"; }
}
class AOCTLW {
public:
AOCTLW(uint32_t open_all_interfaces) {
if (retval != AxErr::NO_AxERROR) throw retval;
}
~AOCTLW() {
}
};
int main()
{
try {
AOCTLW myInstance(0);
uint32_t major, minor, patch, build;
if (retval != AxErr::NO_AxERROR) throw retval;
cout << "Using AxsunOCTControl_LW library version: " << major << "." << minor << "." << patch << "." << build << "\n\n";
if (retval != AxErr::NO_AxERROR) throw retval;
if (retval != AxErr::NO_AxERROR) throw retval;
if (retval != AxErr::NO_AxERROR) throw retval;
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 'd':
case 'D':
cout << "axSetLaserEmission(...) for LASER OFF\n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case 'e':
case 'E':
cout << "axSetLaserEmission(...) for LASER ON\n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case 'f':
case 'F':
{
cout << "axGetFPGARegisterRange(0..63)\n";
auto regvals = std::make_unique<uint16_t[]>(64);
if (retval != AxErr::NO_AxERROR) throw retval;
for (auto i = 0; i < 64; i++) {
cout << "Reg " << i << " =\t" << std::hex << regvals[i] << std::dec << "\n";
}
}
break;
case 'h':
case 'H':
cout << "axHomeVDL(...)\n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case 'i':
case 'I':
PrintConnectedDevices();
break;
case 'l':
case 'L':
cout << "axImagingCntrlEthernet(...) for LIVE IMAGING\n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case 'o':
case 'O':
cout << "axImagingCntrlEthernet(...) for IDLE\n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case 'b':
case 'B':
cout << "axImagingCntrlEthernet(...) for BURST RECORD\n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case 't':
case 'T':
cout << "axTECState(...) ";
if (retval != AxErr::NO_AxERROR) throw retval;
cout << "State of Primary TEC: " << state << "\n";
break;
case 'a':
case 'A':
cout << "axSetFPGADataArray(...) \n";
{
std::vector<uint16_t> pattern(1024, 500);
if (retval != AxErr::NO_AxERROR) throw retval;
}
break;
case 'c':
case 'C':
cout << "axSetFPGADataArray(...) \n";
{
std::vector<uint16_t> pattern(1024, 0);
if (retval != AxErr::NO_AxERROR) throw retval;
}
break;
case 'm':
case 'M':
cout << "axSetPipelineMode(...) \n";
if (retval != AxErr::NO_AxERROR) throw retval;
break;
case '?':
cout << "\n***** COMMAND LIST *****\n";
cout << "D\tLASER: axSetLaserEmission(false); // Laser OFF\n";
cout << "E\tLASER: axSetLaserEmission(true); // Laser ON\n";
cout << "H\tLASER: axHomeVDL();\n";
cout << "T\tLASER: axGetTECState();\n";
cout << "F\tDAQ: axGetFPGARegisterRange(...);\n";
cout << "L\tDAQ: axImagingCntrlEthernet(-1); // Imaging ON - Live\n";
cout << "O\tDAQ: axImagingCntrlEthernet(0); // Imaging OFF - Idle\n";
cout << "B\tDAQ: axImagingCntrlEthernet(100); // Burst Record 100 Images\n";
cout << "A\tDAQ: axSetFPGADataArray(...); // Load Test Pattern\n";
cout << "C\tDAQ: axSetFPGADataArray(...); // Clear Test Pattern\n";
cout << "M\tDAQ: axSetPipelineMode(...); // LOG, INTERLEAVED\n";
cout << "\nI\tGet info on connected devices.\n";
cout << "?\tList command options.\n";
cout << "Q\tQuit this program.\n\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: " << static_cast<int32_t>(e) << " " << GetErrorStringCpp(e) << " Program terminating.\n";
}
catch (...) {
cout << "***** UNKNOWN ERROR. Program terminating.\n";
}
}