Spinnaker C
4.3.0.189
 
Acquisition_C.c

Acquisition_C.c shows how to acquire images. It relies on information provided in the Enumeration_C example. Following this, check out the NodeMapInfo_C example if you haven't already. It explores retrieving information from various node types.

This example touches on the preparation and cleanup of a camera just before and just after the acquisition of images. Image retrieval and conversion, grabbing image data, and saving images are all covered.

Once comfortable with Acquisition_C and NodeMapInfo_C, we suggest checking out AcquisitionMultipleCamera_C, NodeMapCallback_C, or SaveToVideo_C. AcquisitionMultipleCamera_C demonstrates simultaneously acquiring images from a number of cameras, NodeMapCallback_C acts as a good introduction to programming with callbacks and events, and SaveToVideo_C exhibits video creation.

Please leave us feedback at: https://www.surveymonkey.com/r/TDYMVAPI More source code examples at: https://github.com/Teledyne-MV/Spinnaker-Examples Need help? Check out our forum at: https://teledynevisionsolutions.zendesk.com/hc/en-us/community/topics

//=============================================================================
// Copyright (c) 2025 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR).
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================
#include "SpinnakerC.h"
#include "stdio.h"
#include "string.h"
// This macro helps with C-strings.
#define MAX_BUFF_LEN 256
// Use the following enum to select the stream mode
typedef enum
{
STREAM_MODE_TELEDYNE_GIGE_VISION, // Teledyne Gige Vision stream mode is the default stream mode for spinview which is supported on Windows
STREAM_MODE_PGRLWF, // Light Weight Filter driver is our legacy driver which is supported on Windows
STREAM_MODE_SOCKET, // Socket is supported for MacOS and Linux, and uses native OS network sockets instead of a
// filter driver
#if defined(WIN32) || defined(WIN64)
#else
#endif
// Helper for getting error messages
{
// Note: lastErrorMessage is shared across multiple threads; a different thread could overwrite the last error
// message before this function is called to grab the latest message
}
// This function helps to check if a node is readable
bool8_t IsReadable(spinNodeHandle hNode, char nodeName[])
{
spinError err = SPINNAKER_ERR_SUCCESS;
bool8_t pbReadable = False;
err = spinNodeIsReadable(hNode, &pbReadable);
{
printf(
"Unable to retrieve node readability (%s node) Error: %s [%d]\n\n", nodeName, GetLastErrorMessage(), err);
}
return pbReadable;
}
// This function helps to check if a node is writable
bool8_t IsWritable(spinNodeHandle hNode, char nodeName[])
{
spinError err = SPINNAKER_ERR_SUCCESS;
bool8_t pbWritable = False;
err = spinNodeIsWritable(hNode, &pbWritable);
{
printf(
"Unable to retrieve node writability (%s node) Error: %s [%d]\n\n", nodeName, GetLastErrorMessage(), err);
}
return pbWritable;
}
// This function handles the error prints when a node or entry is unavailable or
// not readable/writable on the connected camera
void PrintRetrieveNodeFailure(char node[], char name[])
{
printf("Unable to get %s (%s %s retrieval failed).\n\n", node, name, node);
}
// Disables or enables heartbeat on GEV cameras so debugging does not incur timeout errors
spinError ConfigureGVCPHeartbeat(spinCamera hCam, bool8_t enableHeartbeat)
{
spinNodeHandle hHeartbeatDisable = NULL;
spinError err = SPINNAKER_ERR_SUCCESS;
spinNodeHandle hDeviceType;
char deviceType[MAX_BUFF_LEN];
size_t lenDeviceType = MAX_BUFF_LEN;
//
// Write to boolean node controlling the camera's heartbeat
//
// *** NOTES ***
// This applies only to GEV cameras.
//
// GEV cameras have a heartbeat built in, but when debugging applications the
// camera may time out due to its heartbeat. Disabling the heartbeat prevents
// this timeout from occurring, enabling us to continue with any necessary
// debugging.
//
// *** LATER ***
// Make sure that the heartbeat is reset upon completion of the debugging.
// If the application is terminated unexpectedly, the camera may not locked
// to Spinnaker indefinitely due to the the timeout being disabled. When that
// happens, a camera power cycle will reset the heartbeat to its default setting.
//
// Retrieve GenICam device nodemap
spinNodeMapHandle hNodeMap = NULL;
err = spinCameraGetNodeMap(hCam, &hNodeMap);
{
printf("Unable to retrieve GenICam nodemap. Aborting with error %d...\n\n", err);
return err;
}
// Retrieve TL device nodemap
spinNodeMapHandle hNodeMapTLDevice = NULL;
err = spinCameraGetTLDeviceNodeMap(hCam, &hNodeMapTLDevice);
{
printf("Unable to retrieve TL device nodemap. Non-fatal error %d...\n\n", err);
return err;
}
err = spinNodeMapGetNode(hNodeMapTLDevice, "DeviceType", &hDeviceType);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinNodeToString(hDeviceType, deviceType, &lenDeviceType);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
if (strcmp(deviceType, "GigEVision") != 0)
{
return 0;
}
if (enableHeartbeat)
{
printf("Resetting heartbeat...\n\n");
}
else
{
printf("Disabling heartbeat...\n\n");
}
err = spinNodeMapGetNode(hNodeMap, "GevGVCPHeartbeatDisable", &hHeartbeatDisable);
{
printf(
"Unable to disable heartbeat on camera, error %d occurred. Continuing with execution as this "
"may be non-fatal...\n\n",
err);
}
if (!IsWritable(hHeartbeatDisable, "GevGVCPHeartbeatDisable"))
{
printf(
"Unable to disable heartbeat on camera, error %d occurred. Continuing with execution as this "
"may be non-fatal...\n\n",
err);
}
err = spinBooleanSetValue(hHeartbeatDisable, !enableHeartbeat);
{
printf(
"Unable to disable heartbeat on camera (boolean node), error %d occured. Continuing with "
"execution as this may be non-fatal...\n\n",
err);
return err;
}
if (!enableHeartbeat)
{
printf("WARNING: Heartbeat has been disabled for the rest of this example run.\n");
printf(" Heartbeat will be reset upon the completion of this run. If the \n");
printf(" example is aborted unexpectedly before the heartbeat is reset, the\n");
printf(" camera may need to be power cycled to reset the heartbeat.\n\n");
}
else
{
printf("Heartbeat has been reset.\n\n");
}
return err;
}
{
}
{
}
spinError SetStreamMode(spinCamera hCam)
{
// *** NOTES ***
// Enumeration nodes are slightly more complicated to set than other
// nodes. This is because setting an enumeration node requires working
// with two nodes instead of the usual one.
//
// As such, there are a number of steps to setting an enumeration node:
// retrieve the enumeration node from the nodemap, retrieve the desired
// entry node from the enumeration node, retrieve the integer value
// from the entry node, and set the new value of the enumeration node
// with the integer value from the entry node.
//
// It is important to note that there are two sets of functions that might
// produce erroneous results if they were to be mixed up. The first two
// functions, spinEnumerationSetIntValue() and
// spinEnumerationEntryGetIntValue(), use the integer values stored on each
// individual cameras. The second two, spinEnumerationSetEnumValue() and
// spinEnumerationEntryGetEnumValue(), use enum values defined in the
// Spinnaker library. The int and enum values will most likely be
// different from another.
//
spinError err = SPINNAKER_ERR_SUCCESS;
spinNodeHandle hStreamMode = NULL;
spinNodeHandle hStreamModeCustom = NULL;
int64_t streamModeCustom = 0;
char currentEntrySymbolic[MAX_BUFF_LEN];
size_t currentEntrySymbolicLength = MAX_BUFF_LEN;
size_t displayNameLength = MAX_BUFF_LEN;
spinNodeHandle hCurrentEntryNode = NULL;
spinNodeMapHandle hNodeMapStreamDevice = NULL;
err = spinCameraGetTLStreamNodeMap(hCam, &hNodeMapStreamDevice);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// The node "StreamMode" is only available for GEV cameras.
err = spinNodeMapGetNode(hNodeMapStreamDevice, "StreamMode", &hStreamMode);
{
return 0;
}
// Skip setting stream mode if the node is inaccessible.
if (hStreamMode == NULL || !IsReadable(hStreamMode, "StreamMode") || (!IsWritable(hStreamMode, "StreamMode")))
{
return 0;
}
const char* streamMode;
{
streamMode = "LWF";
break;
streamMode = "Socket";
break;
default:
streamMode = "TeledyneGigeVision";
}
// Retrieve the desired entry node
err = spinEnumerationGetEntryByName(hStreamMode, streamMode, &hStreamModeCustom);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve the desired entry node value from the entry node
err = spinEnumerationEntryGetIntValue(hStreamModeCustom, &streamModeCustom);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Set integer as new value for enumeration node
err = spinEnumerationSetIntValue(hStreamMode, streamModeCustom);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Print our result
err = spinEnumerationGetCurrentEntry(hStreamMode, &hCurrentEntryNode);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinEnumerationEntryGetSymbolic(hCurrentEntryNode, currentEntrySymbolic, &currentEntrySymbolicLength);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("Stream Mode set to %s\n", currentEntrySymbolic);
return err;
}
// This function acquires and saves 10 images from a device.
spinError AcquireImages(spinCamera hCam, spinNodeMapHandle hNodeMap, spinNodeMapHandle hNodeMapTLDevice)
{
spinError err = SPINNAKER_ERR_SUCCESS;
printf("\n*** IMAGE ACQUISITION ***\n\n");
//
// Set acquisition mode to continuous
//
// *** NOTES ***
// Because the example acquires and saves 10 images, setting acquisition
// mode to continuous lets the example finish. If set to single frame
// or multiframe (at a lower number of images), the example would just
// hang. This would happen because the example has been written to acquire
// 10 images while the camera would have been programmed to retrieve
// less than that.
//
// Setting the value of an enumeration node is slightly more complicated
// than other node types, and especially so in C. It can roughly be broken
// down into four steps: first, the enumeration node is retrieved from the
// nodemap; second, the entry node is retrieved from the enumeration node;
// third, an integer is retrieved from the entry node; and finally, the
// integer is set as the new value of the enumeration node.
//
// It is important to note that there are two sets of functions that might
// produce erroneous results if they were to be mixed up. The first two
// functions, spinEnumerationSetIntValue() and
// spinEnumerationEntryGetIntValue(), use the integer values stored on each
// individual cameras. The second two, spinEnumerationSetEnumValue() and
// spinEnumerationEntryGetEnumValue(), use enum values defined in the
// Spinnaker library. The int and enum values will most likely be
// different from another.
//
spinNodeHandle hAcquisitionMode = NULL;
spinNodeHandle hAcquisitionModeContinuous = NULL;
int64_t acquisitionModeContinuous = 0;
// Retrieve enumeration node from nodemap
err = spinNodeMapGetNode(hNodeMap, "AcquisitionMode", &hAcquisitionMode);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve entry node from enumeration node
if (IsReadable(hAcquisitionMode, "AcquisitionMode"))
{
err = spinEnumerationGetEntryByName(hAcquisitionMode, "Continuous", &hAcquisitionModeContinuous);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
}
else
{
PrintRetrieveNodeFailure("entry", "AcquisitionMode");
}
// Retrieve integer from entry node
if (IsReadable(hAcquisitionModeContinuous, "AcquisitionModeContinuous"))
{
err = spinEnumerationEntryGetIntValue(hAcquisitionModeContinuous, &acquisitionModeContinuous);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
}
else
{
PrintRetrieveNodeFailure("entry", "AcquisitionMode 'Continuous'");
}
// Set integer as new value of enumeration node
if (IsWritable(hAcquisitionMode, "AcquisitionMode"))
{
err = spinEnumerationSetIntValue(hAcquisitionMode, acquisitionModeContinuous);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
}
else
{
PrintRetrieveNodeFailure("entry", "AcquisitionMode");
}
printf("Acquisition mode set to continuous...\n");
//
// Begin acquiring images
//
// *** NOTES ***
// What happens when the camera begins acquiring images depends on the
// acquisition mode. Single frame captures only a single image, multi
// frame catures a set number of images, and continuous captures a
// continuous stream of images. Because the example calls for the retrieval
// of 10 images, continuous mode has been set.
//
// *** LATER ***
// Image acquisition must be ended when no more images are needed.
//
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("Acquiring images...\n");
//
// Retrieve device serial number for filename
//
// *** NOTES ***
// The device serial number is retrieved in order to keep cameras from
// overwriting one another. Grabbing image IDs could also accomplish this.
//
spinNodeHandle hDeviceSerialNumber = NULL;
char deviceSerialNumber[MAX_BUFF_LEN];
size_t lenDeviceSerialNumber = MAX_BUFF_LEN;
err = spinNodeMapGetNode(hNodeMapTLDevice, "DeviceSerialNumber", &hDeviceSerialNumber);
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
else
{
if (IsReadable(hDeviceSerialNumber, "DeviceSerialNumber"))
{
err = spinStringGetValue(hDeviceSerialNumber, deviceSerialNumber, &lenDeviceSerialNumber);
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
}
else
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
PrintRetrieveNodeFailure("node", "DeviceSerialNumber");
}
printf("Device serial number retrieved as %s...\n", deviceSerialNumber);
}
printf("\n");
// Retrieve, convert, and save images
const unsigned int k_numImages = 10;
unsigned int imageCnt = 0;
//
// Create Image Processor context for post processing images
//
spinImageProcessor hImageProcessor = NULL;
err = spinImageProcessorCreate(&hImageProcessor);
{
printf("Unable to create image processor. Non-fatal error %d...\n\n", err);
}
//
// Set default image processor color processing method
//
// *** NOTES ***
// By default, if no specific color processing algorithm is set, the image
// processor will default to NEAREST_NEIGHBOR method.
//
{
printf("Unable to set image processor color processing method. Non-fatal error %d...\n\n", err);
}
for (imageCnt = 0; imageCnt < k_numImages; imageCnt++)
{
//
// Retrieve next received image
//
// *** NOTES ***
// Capturing an image houses images on the camera buffer. Trying to
// capture an image that does not exist will hang the camera.
//
// *** LATER ***
// Once an image from the buffer is saved and/or no longer needed, the
// image must be released in orer to keep the buffer from filling up.
//
spinImage hResultImage = NULL;
err = spinCameraGetNextImageEx(hCam, 1000, &hResultImage);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
continue;
}
//
// Ensure image completion
//
// *** NOTES ***
// Images can easily be checked for completion. This should be done
// whenever a complete image is expected or required. Further, check
// image status for a little more insight into why an image is
// incomplete.
//
bool8_t isIncomplete = False;
bool8_t hasFailed = False;
err = spinImageIsIncomplete(hResultImage, &isIncomplete);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
hasFailed = True;
}
// Check image for completion
if (isIncomplete)
{
spinImageStatus imageStatus = SPINNAKER_IMAGE_STATUS_NO_ERROR;
err = spinImageGetStatus(hResultImage, &imageStatus);
{
printf("Unable to retrieve image status. Non-fatal error %d...\n\n", imageStatus);
}
else
{
printf("Image incomplete with image status %d...\n", imageStatus);
}
hasFailed = True;
}
// Release incomplete or failed image
if (hasFailed)
{
err = spinImageRelease(hResultImage);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
}
continue;
}
//
// Print image information; height and width recorded in pixels
//
// *** NOTES ***
// Images have quite a bit of available metadata including things such
// as CRC, image status, and offset values, to name a few.
//
size_t width = 0;
size_t height = 0;
printf("Grabbed image %d, ", imageCnt);
// Retrieve image width
err = spinImageGetWidth(hResultImage, &width);
{
printf("width = unknown, ");
}
else
{
printf("width = %u, ", (unsigned int)width);
}
// Retrieve image height
err = spinImageGetHeight(hResultImage, &height);
{
printf("height = unknown\n");
}
else
{
printf("height = %u\n", (unsigned int)height);
}
//
// Convert image to mono 8
//
// *** NOTES ***
// Images not gotten from a camera directly must be created and
// destroyed. This includes any image copies, conversions, or
// otherwise. Basically, if the image was gotten, it should be
// released, if it was created, it needs to be destroyed.
//
// Images can be converted between pixel formats by using the
// appropriate enumeration value. Unlike the original image, the
// converted one does not need to be released as it does not affect the
// camera buffer.
//
// Optionally, the color processing algorithm can also be set using
// the alternate spinImageConvertEx() function.
//
// *** LATER ***
// The converted image was created, so it must be destroyed to avoid
// memory leaks.
//
spinImage hConvertedImage = NULL;
err = spinImageCreateEmpty(&hConvertedImage);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
hasFailed = True;
}
err = spinImageProcessorConvert(hImageProcessor, hResultImage, hConvertedImage, PixelFormat_Mono8);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
hasFailed = True;
}
// Create a unique filename
char filename[MAX_BUFF_LEN];
if (lenDeviceSerialNumber == 0)
{
sprintf(filename, "Acquisition-C-%d.jpg", imageCnt);
}
else
{
sprintf(filename, "Acquisition-C-%s-%d.jpg", deviceSerialNumber, imageCnt);
}
//
// Save image
//
// *** NOTES ***
// The standard practice of the examples is to use device serial
// numbers to keep images of one device from overwriting those of
// another.
//
err = spinImageSave(hConvertedImage, filename, SPINNAKER_IMAGE_FILE_FORMAT_JPEG);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
}
else
{
printf("Image saved at %s\n\n", filename);
}
//
// Destroy converted image
//
// *** NOTES ***
// Images that are created must be destroyed in order to avoid memory
// leaks.
//
err = spinImageDestroy(hConvertedImage);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
}
//
// Release image from camera
//
// *** NOTES ***
// Images retrieved directly from the camera (i.e. non-converted
// images) need to be released in order to keep from filling the
// buffer.
//
err = spinImageRelease(hResultImage);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
}
}
//
// Destroy Image Processor context
//
// *** NOTES ***
// Image processor context needs to be destroyed after all image processing
// are complete to avoid memory leaks.
//
err = spinImageProcessorDestroy(hImageProcessor);
{
printf("Unable to destroy image processor. Non-fatal error %d...\n\n", err);
}
//
// End acquisition
//
// *** NOTES ***
// Ending acquisition appropriately helps ensure that devices clean up
// properly and do not need to be power-cycled to maintain integrity.
//
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
}
return err;
}
// This function prints the device information of the camera from the transport
// layer; please see NodeMapInfo_C example for more in-depth comments on
// printing device information from the nodemap.
{
spinError err = SPINNAKER_ERR_SUCCESS;
unsigned int i = 0;
printf("\n*** DEVICE INFORMATION ***\n\n");
// Retrieve device information category node
spinNodeHandle hDeviceInformation = NULL;
err = spinNodeMapGetNode(hNodeMap, "DeviceInformation", &hDeviceInformation);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve number of nodes within device information node
size_t numFeatures = 0;
if (IsReadable(hDeviceInformation, "DeviceInformation"))
{
err = spinCategoryGetNumFeatures(hDeviceInformation, &numFeatures);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
}
else
{
PrintRetrieveNodeFailure("node", "DeviceInformation");
}
// Iterate through nodes and print information
for (i = 0; i < numFeatures; i++)
{
spinNodeHandle hFeatureNode = NULL;
err = spinCategoryGetFeatureByIndex(hDeviceInformation, i, &hFeatureNode);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
continue;
}
spinNodeType featureType = UnknownNode;
// get feature node name
char featureName[MAX_BUFF_LEN];
size_t lenFeatureName = MAX_BUFF_LEN;
err = spinNodeGetName(hFeatureNode, featureName, &lenFeatureName);
{
strcpy(featureName, "Unknown name");
}
if (IsReadable(hFeatureNode, featureName))
{
err = spinNodeGetType(hFeatureNode, &featureType);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
continue;
}
}
else
{
printf("%s: Node not readable\n", featureName);
continue;
}
char featureValue[MAX_BUFF_LEN];
size_t lenFeatureValue = MAX_BUFF_LEN;
err = spinNodeToString(hFeatureNode, featureValue, &lenFeatureValue);
{
strcpy(featureValue, "Unknown value");
}
printf("%s: %s\n", featureName, featureValue);
}
printf("\n");
return err;
}
// This function acts as the body of the example; please see NodeMapInfo_C
// example for more in-depth comments on setting up cameras.
spinError RunSingleCamera(spinCamera hCam)
{
spinError err = SPINNAKER_ERR_SUCCESS;
// Retrieve TL device nodemap and print device information
spinNodeMapHandle hNodeMapTLDevice = NULL;
err = spinCameraGetTLDeviceNodeMap(hCam, &hNodeMapTLDevice);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
}
else
{
err = PrintDeviceInfo(hNodeMapTLDevice);
}
// Initialize camera
err = spinCameraInit(hCam);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve GenICam nodemap
spinNodeMapHandle hNodeMap = NULL;
err = spinCameraGetNodeMap(hCam, &hNodeMap);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Configure heartbeat for GEV camera
#ifdef _DEBUG
err = DisableGVCPHeartbeat(hCam);
#else
err = ResetGVCPHeartbeat(hCam);
#endif
{
return err;
}
// Set stream mode
err = SetStreamMode(hCam);
{
return err;
}
// Acquire images
err = AcquireImages(hCam, hNodeMap, hNodeMapTLDevice);
{
return err;
}
#ifdef _DEBUG
// Reset heartbeat for GEV camera
err = ResetGVCPHeartbeat(hCam);
{
return err;
}
#endif
// Deinitialize camera
err = spinCameraDeInit(hCam);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
return err;
}
// Example entry point; please see Enumeration_C example for more in-depth
// comments on preparing and cleaning up the system.
int main(/*int argc, char** argv*/)
{
spinError errReturn = SPINNAKER_ERR_SUCCESS;
spinError err = SPINNAKER_ERR_SUCCESS;
unsigned int i = 0;
// Since this application saves images in the current folder
// we must ensure that we have permission to write to this folder.
// If we do not have permission, fail right away.
FILE* tempFile;
tempFile = fopen("test.txt", "w+");
if (tempFile == NULL)
{
printf("Failed to create file in current folder. Please check "
"permissions.\n");
printf("Press Enter to exit...\n");
getchar();
}
fclose(tempFile);
remove("test.txt");
// Print application build information
printf("Application build date: %s %s \n\n", __DATE__, __TIME__);
// Retrieve singleton reference to system object
spinSystem hSystem = NULL;
err = spinSystemGetInstance(&hSystem);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Print out current library version
spinLibraryVersion hLibraryVersion;
spinSystemGetLibraryVersion(hSystem, &hLibraryVersion);
printf(
"Spinnaker library version: %d.%d.%d.%d\n\n",
hLibraryVersion.major,
hLibraryVersion.minor,
hLibraryVersion.type,
hLibraryVersion.build);
// Retrieve list of cameras from the system
spinCameraList hCameraList = NULL;
err = spinCameraListCreateEmpty(&hCameraList);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinSystemGetCameras(hSystem, hCameraList);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve number of cameras
size_t numCameras = 0;
err = spinCameraListGetSize(hCameraList, &numCameras);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("Number of cameras detected: %u\n\n", (unsigned int)numCameras);
// Finish if there are no cameras
if (numCameras == 0)
{
// Clear and destroy camera list before releasing system
err = spinCameraListClear(hCameraList);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinCameraListDestroy(hCameraList);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Release system
err = spinSystemReleaseInstance(hSystem);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("Not enough cameras!\n");
printf("Done! Press Enter to exit...\n");
getchar();
return -1;
}
// Run example on each camera
for (i = 0; i < numCameras; i++)
{
printf("\nRunning example for camera %d...\n", i);
// Select camera
spinCamera hCamera = NULL;
err = spinCameraListGet(hCameraList, i, &hCamera);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
errReturn = err;
}
else
{
// Run example
err = RunSingleCamera(hCamera);
{
errReturn = err;
}
}
// Release camera
err = spinCameraRelease(hCamera);
{
errReturn = err;
}
printf("Camera %d example complete...\n\n", i);
}
// Clear and destroy camera list before releasing system
err = spinCameraListClear(hCameraList);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinCameraListDestroy(hCameraList);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Release system
err = spinSystemReleaseInstance(hSystem);
{
printf("Error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("\nDone! Press Enter to exit...\n");
getchar();
return errReturn;
}
AcquireImages
spinError AcquireImages(spinCamera hCam, spinNodeMapHandle hNodeMap, spinNodeMapHandle hNodeMapTLDevice)
Definition: Acquisition_C.c:350
spinCameraRelease
SPINNAKERC_API spinCameraRelease(spinCamera hCamera)
Releases a camera.
spinCameraGetNodeMap
SPINNAKERC_API spinCameraGetNodeMap(spinCamera hCamera, spinNodeMapHandle *phNodeMap)
Retrieves the GenICam nodemap from a camera.
spinImageGetWidth
SPINNAKERC_API spinImageGetWidth(spinImage hImage, size_t *pWidth)
Retrieves the width of an image.
SPINNAKER_COLOR_PROCESSING_ALGORITHM_HQ_LINEAR
@ SPINNAKER_COLOR_PROCESSING_ALGORITHM_HQ_LINEAR
Well-balanced speed and quality.
Definition: SpinnakerDefsC.h:322
spinCameraListClear
SPINNAKERC_API spinCameraListClear(spinCameraList hCameraList)
Clears a camera list.
GetLastErrorMessage
char * GetLastErrorMessage()
Definition: Acquisition_C.c:68
spinImageIsIncomplete
SPINNAKERC_API spinImageIsIncomplete(spinImage hImage, bool8_t *pbIsIncomplete)
Checks whether an image is incomplete.
spinCameraEndAcquisition
SPINNAKERC_API spinCameraEndAcquisition(spinCamera hCamera)
Has a camera stop acquiring images.
PrintDeviceInfo
spinError PrintDeviceInfo(spinNodeMapHandle hNodeMap)
Definition: Acquisition_C.c:763
STREAM_MODE_SOCKET
@ STREAM_MODE_SOCKET
Definition: Acquisition_C.c:54
spinCameraBeginAcquisition
SPINNAKERC_API spinCameraBeginAcquisition(spinCamera hCamera)
Has a camera start acquiring images.
main
int main()
Definition: Acquisition_C.c:935
ConfigureGVCPHeartbeat
spinError ConfigureGVCPHeartbeat(spinCamera hCam, bool8_t enableHeartbeat)
Definition: Acquisition_C.c:112
spinImageCreateEmpty
SPINNAKERC_API spinImageCreateEmpty(spinImage *phImage)
Creates an empty image; images created this way must be destroyed.
spinSystemReleaseInstance
SPINNAKERC_API spinSystemReleaseInstance(spinSystem hSystem)
Releases the system; make sure handle is cleaned up properly by setting it to NULL after system is re...
spinImage
void * spinImage
Handle for image functionality.
Definition: SpinnakerDefsC.h:91
spinErrorGetLastMessage
SPINNAKERC_API spinErrorGetLastMessage(char *pBuf, size_t *pBufLen)
Retrieves the error message of the last error.
spinSystemGetCameras
SPINNAKERC_API spinSystemGetCameras(spinSystem hSystem, spinCameraList hCameraList)
Retrieves a list of detected (and enumerable) cameras on the system; camera lists must be created and...
spinStringGetValue
SPINNAKERC_API spinStringGetValue(spinNodeHandle hNode, char *pBuf, size_t *pBufLen)
Retrieves the value of a string node as a c-string.
IsReadable
bool8_t IsReadable(spinNodeHandle hNode, char nodeName[])
Definition: Acquisition_C.c:77
spinNodeMapHandle
void * spinNodeMapHandle
Handle for nodemap functionality.
Definition: SpinnakerGenApiDefsC.h:39
SpinnakerC.h
spinEnumerationSetIntValue
SPINNAKERC_API spinEnumerationSetIntValue(spinNodeHandle hEnumNode, int64_t value)
Sets a new entry using its integer value retrieved from a call to spinEnumerationEntryGetIntValue(); ...
STREAM_MODE_PGRLWF
@ STREAM_MODE_PGRLWF
Definition: Acquisition_C.c:53
IsWritable
bool8_t IsWritable(spinNodeHandle hNode, char nodeName[])
Definition: Acquisition_C.c:91
PrintRetrieveNodeFailure
void PrintRetrieveNodeFailure(char node[], char name[])
Definition: Acquisition_C.c:106
spinBooleanSetValue
SPINNAKERC_API spinBooleanSetValue(spinNodeHandle hNode, bool8_t value)
Sets the value of a boolean node; boolean values are represented by 'True' (which equals '0') and 'Fa...
spinNodeGetType
SPINNAKERC_API spinNodeGetType(spinNodeHandle hNode, spinNodeType *pType)
Retrieves the type of a node (as an enum, spinNodeType)
spinNodeGetName
SPINNAKERC_API spinNodeGetName(spinNodeHandle hNode, char *pBuf, size_t *pBufLen)
Retrieves the name of a node (no whitespace)
spinCategoryGetNumFeatures
SPINNAKERC_API spinCategoryGetNumFeatures(spinNodeHandle hCategoryNode, size_t *pValue)
Retrieves the number of a features (or child nodes) or a category node.
spinEnumerationEntryGetIntValue
SPINNAKERC_API spinEnumerationEntryGetIntValue(spinNodeHandle hNode, int64_t *pValue)
Retrieves the integer value of an entry node; note that enumeration entry int and enum values are dif...
spinImageGetHeight
SPINNAKERC_API spinImageGetHeight(spinImage hImage, size_t *pHeight)
Retrieves the height of an image.
spinImageDestroy
SPINNAKERC_API spinImageDestroy(spinImage hImage)
Destroys an image.
spinSystemGetLibraryVersion
SPINNAKERC_API spinSystemGetLibraryVersion(spinSystem hSystem, spinLibraryVersion *hLibraryVersion)
Get current library version of Spinnaker.
SPINNAKER_ERR_ACCESS_DENIED
@ SPINNAKER_ERR_ACCESS_DENIED
Definition: SpinnakerDefsC.h:243
spinSystem
void * spinSystem
Handle for system functionality.
Definition: SpinnakerDefsC.h:51
spinImageProcessor
void * spinImageProcessor
Handle for image processor functionality.
Definition: SpinnakerDefsC.h:107
spinCameraInit
SPINNAKERC_API spinCameraInit(spinCamera hCamera)
Initializes a camera, allowing for much more interaction.
MAX_BUFF_LEN
#define MAX_BUFF_LEN
Definition: Acquisition_C.c:47
DisableGVCPHeartbeat
spinError DisableGVCPHeartbeat(spinCamera hCam)
Definition: Acquisition_C.c:233
False
static const bool8_t False
Definition: SpinnakerDefsC.h:36
spinCameraGetTLStreamNodeMap
SPINNAKERC_API spinCameraGetTLStreamNodeMap(spinCamera hCamera, spinNodeMapHandle *phNodeMap)
Retrieves the transport layer stream nodemap from a camera.
spinImageProcessorConvert
SPINNAKERC_API spinImageProcessorConvert(spinImageProcessor hImageProcessor, spinImage hSrcImage, spinImage hDestImage, spinPixelFormatEnums destFormat)
Converts the source image buffer to the specified destination pixel format and stores the result in t...
spinImageProcessorSetColorProcessing
SPINNAKERC_API spinImageProcessorSetColorProcessing(spinImageProcessor hImageProcessor, spinColorProcessingAlgorithm colorAlgorithm)
Sets the color processing algorithm used at the time of the spinImageProcessorConvert() call,...
spinCameraListDestroy
SPINNAKERC_API spinCameraListDestroy(spinCameraList hCameraList)
Destroys a camera list.
RunSingleCamera
spinError RunSingleCamera(spinCamera hCam)
Definition: Acquisition_C.c:854
UnknownNode
@ UnknownNode
Definition: SpinnakerGenApiDefsC.h:85
spinEnumerationEntryGetSymbolic
SPINNAKERC_API spinEnumerationEntryGetSymbolic(spinNodeHandle hNode, char *pBuf, size_t *pBufLen)
Retrieves the symbolic of an entry node as a c-string.
spinNodeIsWritable
SPINNAKERC_API spinNodeIsWritable(spinNodeHandle hNode, bool8_t *pbResult)
Checks whether a node is writable.
spinCameraList
void * spinCameraList
Handle for interface functionality.
Definition: SpinnakerDefsC.h:75
spinImageProcessorDestroy
SPINNAKERC_API spinImageProcessorDestroy(spinImageProcessor hImageProcessor)
Destroys a image list.
spinSystemGetInstance
SPINNAKERC_API spinSystemGetInstance(spinSystem *phSystem)
Retrieves an instance of the system object; the system is a singleton, so there will only ever be one...
SPINNAKER_IMAGE_FILE_FORMAT_JPEG
@ SPINNAKER_IMAGE_FILE_FORMAT_JPEG
JPEG.
Definition: SpinnakerDefsC.h:355
SPINNAKER_IMAGE_STATUS_NO_ERROR
@ SPINNAKER_IMAGE_STATUS_NO_ERROR
Image is returned from GetNextImage() call without any errors.
Definition: SpinnakerDefsC.h:388
spinCameraGetNextImageEx
SPINNAKERC_API spinCameraGetNextImageEx(spinCamera hCamera, uint64_t grabTimeout, spinImage *phImage)
Retrieves an image from a camera; manually set the timeout in milliseconds.
spinCameraListGet
SPINNAKERC_API spinCameraListGet(spinCameraList hCameraList, size_t index, spinCamera *phCamera)
Retrieves a camera from a camera list using an index.
bool8_t
uint8_t bool8_t
Definition: SpinnakerDefsC.h:35
spinCamera
void * spinCamera
Handle for camera functionality.
Definition: SpinnakerDefsC.h:82
spinNodeHandle
void * spinNodeHandle
Handle for node functionality.
Definition: SpinnakerGenApiDefsC.h:45
spinNodeIsReadable
SPINNAKERC_API spinNodeIsReadable(spinNodeHandle hNode, bool8_t *pbResult)
Checks whether a node is readable.
ResetGVCPHeartbeat
spinError ResetGVCPHeartbeat(spinCamera hCam)
Definition: Acquisition_C.c:228
spinEnumerationGetEntryByName
SPINNAKERC_API spinEnumerationGetEntryByName(spinNodeHandle hEnumNode, const char *pName, spinNodeHandle *phEntry)
Retrieves an entry node from an enum node using the entry's symbolic.
spinEnumerationGetCurrentEntry
SPINNAKERC_API spinEnumerationGetCurrentEntry(spinNodeHandle hEnumNode, spinNodeHandle *phEntry)
Retrieves the currently selected entry node from an enum node.
STREAM_MODE_TELEDYNE_GIGE_VISION
@ STREAM_MODE_TELEDYNE_GIGE_VISION
Definition: Acquisition_C.c:52
spinImageSave
SPINNAKERC_API spinImageSave(spinImage hImage, const char *pFilename, spinImageFileFormat format)
Saves an image using a specified file format (using an enum, spinImageFileFormat)
spinNodeMapGetNode
SPINNAKERC_API spinNodeMapGetNode(spinNodeMapHandle hNodeMap, const char *pName, spinNodeHandle *phNode)
Retrieves a node from the nodemap by name.
chosenStreamMode
const StreamMode chosenStreamMode
Definition: Acquisition_C.c:61
SetStreamMode
spinError SetStreamMode(spinCamera hCam)
Definition: Acquisition_C.c:238
spinCameraListGetSize
SPINNAKERC_API spinCameraListGetSize(spinCameraList hCameraList, size_t *pSize)
Retrieves the number of cameras on a camera list.
lastErrorMessage
char lastErrorMessage[MAX_BUFF_LEN]
Definition: Acquisition_C.c:64
spinCameraDeInit
SPINNAKERC_API spinCameraDeInit(spinCamera hCamera)
Deinitializes a camera, greatly reducing functionality.
spinCameraGetTLDeviceNodeMap
SPINNAKERC_API spinCameraGetTLDeviceNodeMap(spinCamera hCamera, spinNodeMapHandle *phNodeMap)
Retrieves the transport layer device nodemap from a camera.
spinImageProcessorCreate
SPINNAKERC_API spinImageProcessorCreate(spinImageProcessor *phImageProcessor)
Creates an image processor.
lenLastErrorMessage
size_t lenLastErrorMessage
Definition: Acquisition_C.c:65
True
static const bool8_t True
Definition: SpinnakerDefsC.h:37
spinCategoryGetFeatureByIndex
SPINNAKERC_API spinCategoryGetFeatureByIndex(spinNodeHandle hCategoryNode, size_t index, spinNodeHandle *phFeature)
Retrieves a node from a category node using an index.
StreamMode
StreamMode
Definition: Acquisition_C.c:50
spinImageRelease
SPINNAKERC_API spinImageRelease(spinImage hImage)
Releases an image.
spinImageGetStatus
SPINNAKERC_API spinImageGetStatus(spinImage hImage, spinImageStatus *pStatus)
Retrieves the image status of an image.
SPINNAKER_ERR_SUCCESS
@ SPINNAKER_ERR_SUCCESS
An error code of 0 means that the function has run without error.
Definition: SpinnakerDefsC.h:233
spinCameraListCreateEmpty
SPINNAKERC_API spinCameraListCreateEmpty(spinCameraList *phCameraList)
Creates an empty camera list (camera lists created this way must be destroyed)
spinNodeToString
SPINNAKERC_API spinNodeToString(spinNodeHandle hNode, char *pBuf, size_t *pBufLen)
Retrieves the value of any node type as a c-string.
PixelFormat_Mono8
@ PixelFormat_Mono8
Definition: CameraDefsC.h:732