This is example source code showing how to retrieve images from the Main Image Buffer using the event-driven New Image Callback functionality of AxsunOCTCapture in a C++ client application. It also shows how to select a capture interface (Ethernet or PCIe), change imaging modes (PCIe only), and use the OpenGL-based image display (Windows only).
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#ifdef _WIN32
#include <conio.h>
#include <windows.h>
#endif
using namespace std::chrono_literals;
class AxsunOCTCapture {
private:
public:
AxsunOCTCapture(
float 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; }
};
static uint32_t counter{ 0 };
auto& image_vector = *(static_cast<std::vector<uint8_t>*>(user_ptr));
#ifdef _WIN32
prefs.which_window = 1;
#else
#endif
if (!(counter % 50) && retval == AxErr::NO_AxERROR) {
std::cout << "Image # " << info.image_number << "\tWidth: " << info.width;
std::cout << "\tPixels: ";
std::for_each(image_vector.begin(), image_vector.begin() + 10,
[&](const auto& pix) {std::cout << +pix << " "; });
if (info.force_trig)
std::cout << "\tImage_sync too slow or missing!";
else if (info.trig_too_fast)
std::cout << "\tImage_sync too fast!";
std::cout << std::endl;
}
else if (retval != AxErr::NO_AxERROR) {
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';
++counter;
}
void ModeChanged(int32_t state, void* user_ptr) {
std::cout << "callback: ";
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(int argc, char* argv[]) {
char message[512];
try {
std::cout << "Welcome to the AxsunOCTCapture Example Console Application (C++ version).\nPlease select a capture interface by entering 'P' for PCIe or 'E' for Ethernet. Enter 'Q' to quit.\n";
char user_input;
std::cin >> user_input;
switch (user_input) {
case 'e':
case 'E':
std::cout << "Selected Ethernet interface. Initializing capture session...\n";
break;
case 'p':
case 'P':
std::cout << "Selected PCIe interface. Initializing capture session...\n";
break;
default:
std::cout << "No interface selected. Quitting.";
std::this_thread::sleep_for(2s);
return 0;
}
auto bytes_allocated = uint32_t{ sizeof(int32_t) * 2048 * 10000 };
auto image_vector = std::vector<uint8_t>(bytes_allocated);
AxsunOCTCapture AOC(500.0f);
#ifdef _WIN32
if (
auto retval =
axSetupDisplay(AOC(), 0, 100, 100, 768, 512, 0); retval != AxErr::NO_AxERROR)
throw retval;
if (
auto retval =
axHideWindow(AOC(), 1, 4); retval != AxErr::NO_AxERROR)
throw retval;
#endif
if (
auto retval =
axSetTrigTimeout(AOC(), 12); 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(), ModeChanged, NULL); retval != AxErr::NO_AxERROR)
throw retval;
if (
auto retval =
axSelectInterface(AOC(), desired_interface); retval != AxErr::NO_AxERROR)
throw retval;
if (
auto retval =
axGetMessage(AOC(), message); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << message << '\n';
std::cout << "Turn Laser Emission -> ON and turn DAQ Imaging Mode -> ON using the Control/Control_LW API, or using the Hardware Control Tool or OCT Host GUI.\n";
}
else {
std::cout << "Turn Laser Emission -> ON using the Control/Control_LW API, or using the Hardware Control Tool or OCT Host GUI.\n";
if (
auto retval =
axImagingCntrlPCIe(AOC(), -1); retval != AxErr::NO_AxERROR)
throw retval;
}
auto check_status = [&](std::stop_token st) {
while (!st.stop_requested()) {
static uint32_t imaging, last_packet, last_frame, last_image, dropped_packets, frames_since_sync;
if (
auto retval =
axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync); retval == AxErr::NO_AxERROR) {
if (!imaging) {
std::cout << "Imaging mode is off.\n";
}
else {
}
}
else {
std::cout << "*** Error " << static_cast<int32_t>(retval) << " in axGetStatus().\n";
}
std::this_thread::sleep_for(2s);
}
};
std::jthread status_thread(check_status);
#ifdef _WIN32
MSG msg;
while (!_kbhit()) {
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
DispatchMessage(&msg);
}
std::this_thread::sleep_for(100ms);
}
#else
std::cin >> user_input;
#endif
std::cout << "Quitting...\n\n";
if (
auto retval =
axImagingCntrlPCIe(AOC(), 0); retval != AxErr::NO_AxERROR)
throw retval;
}
}
std::cout << "ERROR: " << message << '\n';
}
catch (...) {
std::cout << "***** UNKNOWN ERROR. Program terminating.\n";
}
std::cout << "Done.\n\n";
}
@ CHAN_1
Definition: AxsunCommonEnums.h:229
@ EIGHT_BIT
Definition: AxsunCommonEnums.h:218
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...
AxErr __cdecl axPipelineMode(AOChandle session, AxPipelineMode mode, AxChannelMode channels)
Configures FPGA registers to output the desired data type & location from the processing pipeline via...
struct CaptureSession * AOChandle
Axsun OCT Capture handle - a pointer to the opaque structure used to manage created capture sessions.
Definition: AxsunOCTCapture.h:170
AxErr __cdecl axImagingCntrlPCIe(AOChandle session, int16_t number_of_images)
Control the image streaming behavior of the Axsun PCIe DAQ between Live Imaging, Burst Recording,...
AxErr __cdecl axStopSession(AOChandle session)
Stop a capture session and deallocate all resources, including Main Image Buffer and interfaces.
AxInterface
Available capture interfaces to be selected by axSelectInterface().
Definition: AxsunOCTCapture.h:271
@ PCI_EXPRESS
Definition: AxsunOCTCapture.h:275
@ GIGABIT_ETHERNET
Definition: AxsunOCTCapture.h:273
@ NO_INTERFACE
Definition: AxsunOCTCapture.h:277
AxErr __cdecl axRegisterNewImageCallback(AOChandle session, AxNewImageCallbackFunction_t callback_function, void *user_data)
Registers a callback function to be executed each time a new image is enqueued in the Main Image Buff...
AxErr __cdecl axSelectInterface(AOChandle session, AxInterface which_interface)
Select the data interface (Ethernet, PCIe, or none) for the capture session.
AxErr __cdecl axSetupDisplay(AOChandle session, uint8_t window_style, int32_t w_left, int32_t w_top, int32_t w_width, int32_t w_height, uintptr_t linked_window_handle)
Setup an OpenGL display window for direct rendering of image data. (Windows OS only)
AxErr __cdecl axSetTrigTimeout(AOChandle session, uint32_t framesUntilForceTrig)
Control the behavior of Force Trigger mode.
AxErr __cdecl axStartSession(AOChandle *session, float capacity_MB)
Start an Axsun DAQ imaging session by allocating memory for the Main Image Buffer.
AxErr __cdecl axRequestImage(AOChandle session, uint32_t requested_image, request_prefs_t prefs, uint32_t output_buf_len, uint8_t *image_data_out, image_info_t *image_info)
Retrieve and/or display an image from the Main Image Buffer.
@ RETRIEVE_AND_DISPLAY
Definition: AxsunOCTCapture.h:229
@ RETRIEVE_TO_CALLER
Definition: AxsunOCTCapture.h:225
AxErr __cdecl axHideWindow(AOChandle session, int32_t which_window, uint32_t state)
Hide or unhide the OpenGL image display window. (Windows OS only)
AxErr __cdecl axGetStatus(AOChandle session, uint32_t *imaging, uint32_t *last_packet_in, uint32_t *last_frame_in, uint32_t *last_image_in, uint32_t *dropped_packets, uint32_t *frames_since_sync)
Get imaging mode status and Main Image Buffer statistics.
AxErr __cdecl axAdjustBrightnessContrast(AOChandle session, int32_t which_window, float brightness, float contrast)
Change the brightness and contrast of images displayed in an OpenGL window. (Windows OS only)
void __cdecl axGetErrorString(AxErr errorcode, char *message_out)
Get a description of a specific AxErr error code.
AxErr __cdecl axRegisterDAQCallback(AOChandle session, AxCallbackFunction_t callback_function, void *user_data)
Registers a callback function to be executed upon a change in the DAQ imaging state (e....
AxDAQEvent
Types of transitions in DAQ's operational mode, conveyed via user callback function....
Definition: AxsunOCTCapture.h:239
@ RECORD_START
Definition: AxsunOCTCapture.h:247
@ LOAD_DONE
Definition: AxsunOCTCapture.h:253
@ IMAGING_STOP
Definition: AxsunOCTCapture.h:241
@ IMAGING_START
Definition: AxsunOCTCapture.h:243
@ RECORD_DONE
Definition: AxsunOCTCapture.h:245
@ LOAD_START
Definition: AxsunOCTCapture.h:255
AxErr __cdecl axGetMessage(AOChandle session, char *message_out)
Get a description of the capture session's interface status.
Structure for conveying metadata information about an image.
Definition: AxsunOCTCapture.h:452
Structure for data made available to user in a new image callback event via registered AxNewImageCall...
Definition: AxsunOCTCapture.h:486
AOChandle session
Definition: AxsunOCTCapture.h:488
uint32_t image_number
Definition: AxsunOCTCapture.h:490
uint32_t required_buffer_size
Definition: AxsunOCTCapture.h:492
Structure for image request preferences.
Definition: AxsunOCTCapture.h:386
AxRequestMode request_mode
Definition: AxsunOCTCapture.h:389