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

This is Windows OS example source code showing how to use the image capture functionality of AxsunOCTCapture in a ANSI C client application.

// AxsunOCTCapture_example.c
//
// NOTES:
//
// 1. AxsunOCTCapture functions are Standard C and do NOT throw C++ exceptions, but rather
// return an error status of type AxErr. Calls to AxsunOCTCapture functions in this
// example program are typically wrapped in an "if (status != OK) throw AxErr" fashion
// and contained in a try/catch block in order to make the behavior exception-based.
//
// 2. The intent of this example program is to exemplify the capabilities of the
// AxsunOCTCapture library. Program structure is simplified for readability and is not
// intended for "production" use as-is.
//
#include "AxsunOCTCapture.h" // for all AxsunOCTCapture functions, structs, enums, typedefs
#include <stdio.h> // for printf(); not related to AxsunOCTCapture functionality
#include <windows.h> // for loop timer Sleep function; not related to AxsunOCTCapture functionality
#include <conio.h> // for console keyboard interaction; not related to AxsunOCTCapture functionality
#define PCIEMODE // comment this line out for Ethernet interface, leave uncommented for PCIe interface
int main()
{
printf("Welcome to the AxsunOCTCapture Example Console Application (ANSI C version).\n");
// declare local variables
AOChandle session = NULL;
AxErr retval = NO_AxERROR;
char message[512];
// create a capture session with 100 MB main image buffer
if (retval = axStartSession(&session, 100)) goto axerror;
// select capture interface for this session
#ifdef PCIEMODE
if (retval = axSelectInterface(session, PCI_EXPRESS)) goto axerror;
#else
if (retval = axSelectInterface(session, GIGABIT_ETHERNET)) goto axerror;
#endif
// print message describing current capture interface status
if (retval = axGetMessage(session, message)) goto axerror;
printf(message); printf("\n");
// setup OpenGL-based rendering
if (retval = axSetupDisplay(session, 0, 0, 0, 1024, 512, 0)) goto axerror;
if (retval = axAdjustBrightnessContrast(session, 1, 0, 1)) goto axerror;
// 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 (retval = axPipelineMode(session, EIGHT_BIT, CHAN_1)) goto axerror; // set pipeline mode to 8-bit processed data on Channel 1
if (retval = axImagingCntrlPCIe(session, -1)) goto axerror; // 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 = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // initialize struct variable
int32_t counter = 0;
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);
// get Main Image Buffer status
if (retval = axGetStatus(session, &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync)) goto axerror;
if (imaging) {
// get image info on most recent image enqueued
if (retval = axGetImageInfo(session, MOST_RECENT_IMAGE, &info)) {
// print error details
printf("axGetImageInfo() returned %d ", retval);
axGetErrorString(retval, message);
printf(message); printf("\n");
}
else {
// if no errors, configure the request preferences and then request the image for display
prefs.which_window = 1;
retval = axRequestImage(session, info.image_number, prefs, 0, NULL, &info);
// and print some statistics to the console (every 25th iteration)
if (!(counter % 25)) {
printf("Image number: %d, Width: %d, Dropped Packets: %d", info.image_number, info.width, dropped_packets);
if (info.force_trig) printf(" *** TRIGGER TOO SLOW, FORCE TRIGGERED ***");
if (info.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)
Sleep(33);
}
#ifdef PCIEMODE
// FOR PCIe INTERFACE, set DAQ Imaging Off mode (idle)
if (retval = axImagingCntrlPCIe(session, 0)) goto axerror;
#endif
axerror:
if (retval) { // if we got here because of an error, print error code description
printf("Error %d: ", retval);
axGetErrorString(retval, message);
printf(message); printf("\n");
}
printf("Quitting...\n\n");
// stop the capture session
axStopSession(session);
}
@ 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 axGetImageInfo(AOChandle session, uint32_t requested_image, image_info_t *image_info)
Get information on an image in the Main Image Buffer.
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.
@ PCI_EXPRESS
Definition: AxsunOCTCapture.h:275
@ GIGABIT_ETHERNET
Definition: AxsunOCTCapture.h:273
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 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.
@ DISPLAY_ONLY
Definition: AxsunOCTCapture.h:227
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 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
uint8_t trig_too_fast
Definition: AxsunOCTCapture.h:476
int32_t width
Definition: AxsunOCTCapture.h:458
uint32_t image_number
Definition: AxsunOCTCapture.h:454
uint8_t force_trig
Definition: AxsunOCTCapture.h:474
Structure for image request preferences.
Definition: AxsunOCTCapture.h:386
int32_t which_window
Definition: AxsunOCTCapture.h:391
AxRequestMode request_mode
Definition: AxsunOCTCapture.h:389