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 '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(...) ";
{
std::vector<uint16_t> pattern(1024, 500);
}
cout << "Retval: " << static_cast<int32_t>(retval) << "\n";
break;
case 'c':
case 'C':
cout << "axSetFPGADataArray(...) ";
{
std::vector<uint16_t> pattern(1024, 0);
}
cout << "Retval: " << static_cast<int32_t>(retval) << "\n";
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 << "A\tDAQ: axSetFPGADataArray(...); // Load Test Pattern\n";
cout << "C\tDAQ: axSetFPGADataArray(...); // Clear Test Pattern\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";
}
}
AxErr
Error codes returned from AxsunOCTCapture or AxsunOCTControl_LW functions. Use axGetErrorString() in ...
Definition: AxsunCommonEnums.h:34
This header file defines the usage of the AxsunOCTControl_LW "lightweight" library in a C or C++ appl...
AxErr axGetFPGARegisterRange(const uint32_t start_regnum, const uint32_t end_regnum, uint16_t *regvals, const uint32_t bytes_allocated, uint32_t which_DAQ)
Gets (i.e. reads) current values in a range of FPGA registers.
AxTECState
Laser TEC states.
Definition: AxsunOCTControl_LW_C.h:50
AxErr axSetLaserEmission(uint32_t emission_state, uint32_t which_laser)
Enables or disables swept laser emission.
AxConnectionType
Definition: AxsunOCTControl_LW_C.h:34
@ RS232_PASSTHROUGH
Definition: AxsunOCTControl_LW_C.h:37
@ RS232
Definition: AxsunOCTControl_LW_C.h:38
@ USB
Definition: AxsunOCTControl_LW_C.h:36
@ ETHERNET
Definition: AxsunOCTControl_LW_C.h:39
AxErr axFPGAVersion(uint32_t *major, uint32_t *minor, uint32_t *patch, uint32_t *build, uint32_t which_device)
Gets the device FPGA version.
AxErr axConnectionType(AxConnectionType *connection_type, uint32_t which_device)
Gets the device connection interface (e.g. USB, Ethernet, RS-232).
AxDevType
Definition: AxsunOCTControl_LW_C.h:42
@ LASER
Definition: AxsunOCTControl_LW_C.h:44
@ CLDAQ
Definition: AxsunOCTControl_LW_C.h:45
@ EDAQ
Definition: AxsunOCTControl_LW_C.h:46
AxErr axNetworkInterfaceOpen(uint32_t interface_status)
Opens, resets, or closes the Ethernet network interface.
AxErr axUSBInterfaceOpen(uint32_t interface_status)
Opens, resets, or closes the USB interface.
AxErr axSerialNumber(char *serial_number, uint32_t which_device)
Gets the device serial number string.
AxErr axDeviceType(AxDevType *device_type, uint32_t which_device)
Gets the device type (e.g. Laser, EDAQ).
AxErr axSetFPGADataArray(const uint32_t regnum, const uint16_t *data_array, const uint32_t number_of_words, uint32_t which_DAQ)
Sets (i.e. writes) a FPGA register with an array of multiple values.
AxErr axHomeVDL(uint32_t which_laser)
Starts the VDL home operation.
void axGetErrorExplained(AxErr errornum, char *error_string)
Gets a string which explains an error code in a more verbose fashion.
AxErr axOpenAxsunOCTControl(uint32_t open_all_interfaces)
Opens the AxsunOCTControl context for subsequent device communication.
AxErr axFirmwareVersion(uint32_t *major, uint32_t *minor, uint32_t *patch, uint32_t which_device)
Gets the device firmware version.
uint32_t axCountConnectedDevices()
Counts the number of devices successfully connected and enumerated by AxsunOCTControl.
AxErr axCloseAxsunOCTControl()
Closes an AxsunOCTControl context previously opened with axOpenAxsunOCTControl().
AxErr axImagingCntrlEthernet(int16_t number_of_images, uint32_t which_DAQ)
Control the DAQ operational mode (Live Imaging, Burst Recording, or Imaging Off) when using the Ether...
AxErr axGetTECState(AxTECState *TEC_state, uint32_t which_TEC, uint32_t which_laser)
Gets the current state of a Laser Thermo-Electric Cooler (TEC).
AxErr axLibraryVersion(uint32_t *major, uint32_t *minor, uint32_t *patch, uint32_t *build)
Gets the library version.
AxErr axRegisterConnectCallback(AxConnectCallbackFunctionC_t callback_function, void *userData)
Registers a callback function to be executed following a device connection or disconnection event.