HomeSupportAPIsXiAPI → XIMEA API Sample With Start Stop Acquisition

XIMEA API Sample With Start Stop Acquisition

This is sample of xiAPI with:
  • getting number of connected camera (xiGetNumberDevices)
  • start and stop acquisition

// Sample for XIMEA Software Package V2.57

#include "stdafx.h" 
#include "..\include\xiApi.h" 

#define HandleResult(res,place) if (res!=XI_OK) {printf("Error after %s (%d)",place,res);goto finish;}

int main ()
{
    // Sample for XIMEA API V2.10
    DWORD dwNumberOfDevices = 0;
    HANDLE  hMV = INVALID_HANDLE_VALUE;
    DWORD size = 0;
    XI_RETURN stat=XI_OK;

    // Retrieving number of connected cameras
    stat = xiGetNumberDevices(&dwNumberOfDevices);
    HandleResult(stat,"xiGetNumberDevices");

    // Retrieving a handle to the camera device 
    stat = xiOpenDevice(0, &hMV);
    HandleResult(stat,"xiOpenDevice");

    // Setting "exposure" parameter    (integer)
    printf("Set PRM_EXPOSURE (integer)\n");
    int exposure_us = 10000;
    stat = xiSetParam(hMV, XI_PRM_EXPOSURE, &exposure_us, sizeof(DWORD), xiTypeInteger);
    HandleResult(stat,"xiSetParam exposure");

    // Start acquisition
    stat = xiStartAcquisition(hMV);
    HandleResult(stat,"xiStartAcquisition");

    // Retrieving image
    XI_IMG image;
    image.size = sizeof(XI_IMG);
    image.bp = NULL;
    image.bp_size = 0;
    stat = xiGetImage(hMV, 1000, &image);
    HandleResult(stat,"xiGetImage");

    printf("Got one image (%dx%d) from camera\n", image.width, image.height);

    // Stop acquisition
    stat = xiStopAcquisition(hMV);
    HandleResult(stat,"xiGetImage");
    printf("Success\n");
finish:
    // Close device
    if (hMV != INVALID_HANDLE_VALUE)
    {
        xiCloseDevice(hMV);
    }
}