AxsunOCTCapture  3.6.0.0
Captures and buffers streamed imaged data from the Axsun Ethernet/PCIe DAQ and displays or retrieves images to a client application on request.
AxsunOCTCapture_Cpp_example.cpp

This is example source code showing how to use the polling-based image capture functionality of AxsunOCTCapture in a C++ client application (Windows OS).

// AxsunOCTCapture_Cpp_example.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "AxsunOCTCapture.h" // for all AxsunOCTCapture functions, structs, enums, typedefs
#include <iostream> // for std::cout, std::cin; not related to AxsunOCTCapture functionality
#include <chrono> // for loop timer sleep function; not related to AxsunOCTCapture functionality
#include <thread> // for loop timer sleep function; not related to AxsunOCTCapture functionality
#include <conio.h> // for console keyboard interaction; not related to AxsunOCTCapture functionality
#include <windows.h> // for Win32 event handling
using namespace std::chrono_literals;
// #define PCIEMODE // comment this line out for Ethernet interface, leave uncommented for PCIe interface
// Define AxsunOCTCapture class to wrap axStartSession(), axStopSession(), and the session handle in RAII fashion.
// (This will convieniently call axStopSession() automatically in the destructor so that resources are cleaned up.)
class AxsunOCTCapture {
private:
AOChandle session_{ nullptr };
public:
AxsunOCTCapture(int32_t capacity) { if (auto retval = axStartSession(&session_, capacity); retval != AxErr::NO_AxERROR) throw retval; } // C++17
~AxsunOCTCapture() { axStopSession(session_); }
AOChandle operator()() { if (session_) return session_; else throw AxErr::CAPTURE_SESSION_NOT_SETUP; }
};
int main() {
char message[512]; // variable for getting string output from axGetMessage() and axGetErrorString()
try {
std::cout << "Welcome to the AxsunOCTCapture Example Console Application (C++ version).\n";
// create a capture session with 500 MB main image buffer
AxsunOCTCapture AOC(500);
// select capture interface for this session
#ifdef PCIEMODE
if (auto retval = axSelectInterface(AOC(), AxInterface::PCI_EXPRESS); retval != AxErr::NO_AxERROR) throw retval;
#else
if (auto retval = axSelectInterface(AOC(), AxInterface::GIGABIT_ETHERNET); retval != AxErr::NO_AxERROR) throw retval;
#endif
// print message describing current capture interface status
if (auto retval = axGetMessage(AOC(), message); retval != AxErr::NO_AxERROR) throw retval;
std::cout << message << '\n';
// setup OpenGL-based rendering with auto-scaled contrast & brightness
if (auto retval = axSetupDisplay(AOC(), 0, 0, 0, 1024, 512, 0); retval != AxErr::NO_AxERROR) throw retval;
if (auto retval = axAdjustBrightnessContrast(AOC(), 1, 0, 1); retval != AxErr::NO_AxERROR) throw retval;
// NOTE: before proceeding with this program:
// TURN ON LASER EMISSION using AxsunOCTControl or AxsunOCTControl_LW API, or OCT Host or Hardware Control Tool GUI
// FOR GIGABIT_ETHERNET INTERFACE, need to set DAQ Imaging On mode using AxsunOCTControl or AxsunOCTControl_LW API, or OCT Host or Hardware Control Tool GUI
#ifdef PCIEMODE
// FOR PCIe INTERFACE,
if (auto retval = axPipelineMode(AOC(), AxPipelineMode::EIGHT_BIT, AxChannelMode::CHAN_1); retval != AxErr::NO_AxERROR) throw retval; // set pipeline mode to 8-bit processed data on Channel 1
if (auto retval = axImagingCntrlPCIe(AOC(), -1); retval != AxErr::NO_AxERROR) throw retval; // set DAQ Imaging On mode (live)
#endif
// declare local variables
uint32_t imaging, last_packet, last_frame, last_image, dropped_packets, frames_since_sync; // for axGetStatus()
request_prefs_t prefs{ };
image_info_t info{ };
int32_t counter = 0;
#ifdef _WIN32
while (!_kbhit()) { // display loop until a key is pressed (this function in conio.h)
// handle Win32 events in OpenGL rendering window
MSG msg;
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
#else
while (1) { // display loop until CTRL+C is pressed
#endif // WIN32
// get Main Image Buffer status
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) {
// get image info on most recent image enqueued in the buffer
if (auto retval = axGetImageInfo(AOC(), MOST_RECENT_IMAGE, &info); retval != AxErr::NO_AxERROR) {
// print error details
axGetErrorString(retval, message);
std::cout << "axGetImageInfo() returned " << static_cast<int32_t>(retval) << " " << message << '\n';
}
else {
// if no errors, configure the request preferences and then request the image for display
prefs.request_mode = AxRequestMode::DISPLAY_ONLY;
prefs.which_window = 1;
retval = axRequestImage(AOC(), info.image_number, prefs, 0, nullptr, &info); // no user buffer necessary for DISPLAY_ONLY
// and print some statistics to the console (every 25th iteration)
if (!(counter % 25)) {
std::cout << "Image number: " << info.image_number << ", Width: " << info.width <<", Dropped Packets: " << dropped_packets;
if (info.force_trig) std::cout << " *** TRIGGER TOO SLOW, FORCE TRIGGERED ***";
if (info.trig_too_fast) std::cout << " *** TRIGGER TOO FAST ***";
std::cout << '\n';
}
}
}
else {
if (!(counter % 50)) { // print every 50th iteration
std::cout << "Imaging is off. Turn on laser emission and set DAQ to Imaging On mode.\n";
}
}
// increment loop counter
counter++;
// loop timer for approximately 50 fps update rate
std::this_thread::sleep_for(20ms);
}
#ifdef PCIEMODE
// FOR PCIe INTERFACE, set DAQ Imaging Off mode (idle)
if (auto retval = axImagingCntrlPCIe(AOC(), 0); retval != AxErr::NO_AxERROR) throw retval;
#endif
std::this_thread::sleep_for(1s);
}
catch (const AxErr& e) {
axGetErrorString(e, message);
std::cout << "ERROR: " << message << '\n';
}
catch (...) {
std::cout << "***** UNKNOWN ERROR. Program terminating.\n";
}
std::cout << "Quitting...\n\n";
}
axGetImageInfo
AxErr axGetImageInfo(AOChandle session, uint32_t requested_image, image_info_t *image_info)
Get information on an image in the Main Image Buffer.
axSetupDisplay
AxErr 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 parent_window_handle)
Setup an OpenGL display window for direct rendering of image data. (WINDOWS ONLY)
AOChandle
struct CaptureSession * AOChandle
Axsun OCT Capture handle - a pointer to the opaque structure used to manage created capture sessions.
Definition: AxsunOCTCapture.h:132
CHAN_1
@ CHAN_1
Definition: AxsunCommonEnums.h:212
EIGHT_BIT
@ EIGHT_BIT
Definition: AxsunCommonEnums.h:201
axPipelineMode
AxErr axPipelineMode(AOChandle session, AxPipelineMode mode, AxChannelMode channels)
Configures FPGA registers to output the desired data type & location from the processing pipeline via...
axStopSession
AxErr axStopSession(AOChandle session)
Stop a capture session and deallocate all resources, including Main Image Buffer and interfaces.
axAdjustBrightnessContrast
AxErr axAdjustBrightnessContrast(AOChandle session, int32_t which_window, float brightness, float contrast)
Change the brightness and contrast of images displayed in an OpenGL window. (WINDOWS ONLY)
axGetErrorString
void axGetErrorString(AxErr errorcode, char *message_out)
Get a description of a specific AxErr error code.
axGetMessage
AxErr axGetMessage(AOChandle session, char *message_out)
Get a description of the capture session's interface status.
axGetStatus
AxErr 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.
image_info_t
Structure for conveying metadata information about an image.
Definition: AxsunOCTCapture.h:392
axRequestImage
AxErr 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.
AxErr
AxErr
Error codes returned from AxsunOCTCapture or AxsunOCTControl_LW functions. Use axGetErrorString() in ...
Definition: AxsunCommonEnums.h:34
axSelectInterface
AxErr axSelectInterface(AOChandle session, AxInterface which_interface)
Select the data interface (Ethernet, PCIe, or none) for the capture session.
DISPLAY_ONLY
@ DISPLAY_ONLY
Definition: AxsunOCTCapture.h:189
AxsunOCTCapture.h
This header file contains all exported function prototypes, structures, and enums necessary for integ...
axStartSession
AxErr axStartSession(AOChandle *session, float capacity_MB)
Start an Axsun DAQ imaging session by allocating memory for the Main Image Buffer.
PCI_EXPRESS
@ PCI_EXPRESS
Definition: AxsunOCTCapture.h:229
axImagingCntrlPCIe
AxErr axImagingCntrlPCIe(AOChandle session, int16_t number_of_images)
Control the image streaming behavior of the Axsun PCIe DAQ between Live Imaging, Burst Recording,...
request_prefs_t
Structure for image request preferences.
Definition: AxsunOCTCapture.h:326
GIGABIT_ETHERNET
@ GIGABIT_ETHERNET
Definition: AxsunOCTCapture.h:227