This is example source code showing how to use the callback-based image capture functionality of AxsunOCTCapture in a C++ client application (Windows OS).
#include <iostream>
#include <chrono>
#include <thread>
#include <conio.h>
#include <windows.h>
#include <vector>
using namespace std::chrono_literals;
#define PCIEMODE // comment this line out for Ethernet interface, leave uncommented for PCIe interface
class AxsunOCTCapture {
private:
public:
AxsunOCTCapture(int32_t capacity) {
if (
auto retval =
axStartSession(&session_, capacity); retval != AxErr::NO_AxERROR)
throw retval; }
AOChandle operator()() {
if (session_)
return session_;
else throw AxErr::CAPTURE_SESSION_NOT_SETUP; }
};
uint32_t imaging, last_packet, last_frame, last_image, dropped_packets, frames_since_sync;
axGetStatus(data.
session, &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync);
auto& image_vector = *(static_cast<std::vector<uint8_t>*>(user_ptr));
if (retval == AxErr::NO_AxERROR) {
std::cout << info.image_number << "\tWidth: " << info.width;
if (info.force_trig)
std::cout << "\tForce triggered mode.";
else
std::cout <<
"\tBacklog: " << data.
waiting_callbacks <<
"\tDrop: " << dropped_packets;
std::cout << '\n';
}
else {
char error_message[512];
std::cout << "axRequestImage reported: " << static_cast<int>(retval) << ' ' << error_message << '\n';
}
}
else
std::cout <<
"Memory allocation too small for retrieval of image " << data.
image_number <<
'\n';
}
void ImagingModeChanged(uint32_t state, void* user_ptr) {
std::cout << "DAQ/buffer state -> STOPPED\n";
break;
std::cout << "DAQ/buffer state -> IMAGING\n";
break;
std::cout << "DAQ/buffer state -> RECORD COMPLETE\n";
break;
std::cout << "DAQ/buffer state -> RECORDING\n";
break;
std::cout << "DAQ/buffer state -> LOADING COMPLETE\n";
break;
std::cout << "DAQ/buffer state -> LOADING FROM DISK\n";
break;
}
}
int main() {
char message[512];
try {
std::cout << "Welcome to the AxsunOCTCapture Example Console Application (C++ version).\n";
auto bytes_allocated = uint32_t{ sizeof(int16_t) * 1024 * 40000 };
auto image_vector = std::vector<uint8_t>(bytes_allocated);
std::cout << "Bytes allocated: " << bytes_allocated << '\n';
{
AxsunOCTCapture AOC(500);
if (
auto retval =
axSetTrigTimeout(AOC(), 30); retval != AxErr::NO_AxERROR)
throw retval;
if (
auto retval =
axRegisterNewImageCallback(AOC(), NewImageArrived,
static_cast<void*
>(&image_vector)); retval != AxErr::NO_AxERROR)
throw retval;
if (
auto retval =
axRegisterDAQCallback(AOC(), ImagingModeChanged, NULL); retval != AxErr::NO_AxERROR)
throw retval;
#ifdef PCIEMODE
#else
#endif
if (
auto retval =
axGetMessage(AOC(), message); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << message << '\n';
if (
auto retval =
axSetupDisplay(AOC(), 0, 0, 0, 512, 256, 0); retval != AxErr::NO_AxERROR)
throw retval;
#ifdef PCIEMODE
if (
auto retval =
axImagingCntrlPCIe(AOC(), -1); retval != AxErr::NO_AxERROR)
throw retval;
#endif
uint32_t imaging, last_packet, last_frame, last_image, dropped_packets, frames_since_sync;
int32_t counter = 0;
while (!_kbhit()) {
MSG msg;
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
if (
auto retval =
axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync); retval != AxErr::NO_AxERROR)
throw retval;
if (!imaging && !(++counter % 50))
std::cout << "Imaging mode is off. Turn it on or press a key to exit.\n";
std::this_thread::sleep_for(50ms);
}
#ifdef PCIEMODE
if (
auto retval =
axImagingCntrlPCIe(AOC(), 0); retval != AxErr::NO_AxERROR)
throw retval;
#endif
}
}
std::cout << "ERROR: " << message << '\n';
}
catch (...) {
std::cout << "***** UNKNOWN ERROR. Program terminating.\n";
}
std::cout << "Quitting...\n\n";
}