AxsunOCTCapture  3.0.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 image capture functionality of AxsunOCTCapture in a C++ client application.

// 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
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.
// 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)) throw retval; }
~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";
// declare local variables
uint32_t imaging, last_packet, last_frame, last_image, dropped_packets, frames_since_sync, returned_image_number, required_buffer_size;
int32_t height, width;
AxDataType data_type;
uint8_t force_trig, trig_too_fast;
// create a capture session with 100 MB main image buffer
AxsunOCTCapture AOC(100);
// select capture interface for this session
#ifdef PCIEMODE
if (auto retval = axSelectInterface(AOC(), AxInterface::PCI_EXPRESS)) throw retval;
#else
if (auto retval = axSelectInterface(AOC(), AxInterface::GIGABIT_ETHERNET)) throw retval;
#endif
// print message describing current capture interface status
if (auto retval = axGetMessage(AOC(), message)) throw retval;
std::cout << message << "\n";
// setup OpenGL-based rendering
if (auto retval = axSetupDisplay(AOC(), 0, 0, 0, 1024, 512, NULL)) 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 = axImagingCntrlPCIe(AOC(), -1)) throw retval; // set DAQ Imaging On mode (live)
if (auto retval = axPipelineMode(AOC(), AxPipelineMode::EIGHT_BIT)) throw retval; // set pipeline mode to 8-bit processed data
#endif
int32_t counter = 0;
while (!_kbhit()) { // display loop until a key is pressed (this function in conio.h)
// get Main Image Buffer status
if (auto retval = axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync)) throw retval;
if (imaging) {
// get image info on most recent image enqueued
if (auto retval = axGetImageInfoAdv(AOC(), -1, &returned_image_number, &height, &width, &data_type, &required_buffer_size, &force_trig, &trig_too_fast)) {
// print error details
printf("axGetImageInfo() returned %d ", retval);
axGetErrorString(retval, message);
printf(message); printf("\n");
}
else {
// if no errors, display the image
retval = axDisplayImage(AOC(), returned_image_number, &returned_image_number, &height, &width);
// and print some statistics to the console (every 25th iteration)
if (!(counter % 25)) {
printf("Image number: %d, Width: %d, Dropped Packets: %d", returned_image_number, width, dropped_packets);
if (force_trig) printf(" *** TRIGGER TOO SLOW, FORCE TRIGGERED ***");
if (trig_too_fast) printf(" *** TRIGGER TOO FAST ***");
printf("\n");
}
}
}
else {
if (!(counter % 50)) { // print every 50th iteration
printf("Imaging is off. Turn on laser emission and set DAQ to Imaging On mode.\n");
}
}
// increment loop counter
counter++;
// loop timer for approximately 30 fps update rate (this function in windows.h)
std::this_thread::sleep_for(33ms);
}
#ifdef PCIEMODE
// FOR PCIe INTERFACE, set DAQ Imaging Off mode (idle)
if (auto retval = axImagingCntrlPCIe(AOC(), 0)) throw retval;
#endif
}
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";
}