Spinnaker C
4.3.0.189
 
Enumeration_C.c

Enumeration_C.c shows how to enumerate interfaces and cameras.Knowing this is mandatory for doing anything with the Spinnaker SDK, and is therefore the best place to start learning how to use the SDK.

This example introduces the preparation, use, and cleanup of the system object, interface and camera lists, interfaces, and cameras. It also touches on retrieving both nodes from nodemaps and information from nodes.

Once comfortable with enumeration, we suggest checking out either the Acquisition_C or NodeMapInfo_C examples. Acquisition_C demonstrates using a camera to acquire images while NodeMapInfo_C explores retrieving information from various node types.

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
// 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 queries an interface for its cameras and then prints out
// device information.
spinError QueryInterface(spinInterface hInterface)
{
spinError err = SPINNAKER_ERR_SUCCESS;
unsigned int i = 0;
//
// Retrieve TL nodemap from interface
//
// *** NOTES ***
// Each interface has a nodemap that can be retrieved in order to access
// information about the interface itself, any devices connected, or
// addressing information if applicable.
//
spinNodeMapHandle hNodeMapInterface = NULL;
err = spinInterfaceGetTLNodeMap(hInterface, &hNodeMapInterface);
{
printf("Unable to retrieve interface nodemap. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
//
// Print interface display name
//
// *** NOTES ***
// Each interface has a nodemap that can be retrieved in order to access
// information about the interface itself, any devices connected, or
// addressing information if applicable.
//
spinNodeHandle hInterfaceDisplayName = NULL;
// Retrieve node
err = spinNodeMapGetNode(hNodeMapInterface, "InterfaceDisplayName", &hInterfaceDisplayName);
{
printf(
"Unable to retrieve node (interface display name). Aborting with error: %s [%d]\n\n",
err);
return err;
}
// Check readability
bool8_t interfaceDisplayNameIsReadable = False;
err = spinNodeIsReadable(hInterfaceDisplayName, &interfaceDisplayNameIsReadable);
{
printf(
"Unable to check node readability (interface display name). Aborting with error: %s [%d]\n\n",
err);
return err;
}
// Print
char interfaceDisplayName[MAX_BUFF_LEN];
size_t lenInterfaceDisplayName = MAX_BUFF_LEN;
if (interfaceDisplayNameIsReadable)
{
err = spinStringGetValue(hInterfaceDisplayName, interfaceDisplayName, &lenInterfaceDisplayName);
{
printf(
"Unable to retrieve value (interface display name). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
strcpy(interfaceDisplayName, "Interface display name not readable");
}
printf("%s\n", interfaceDisplayName);
//
// Retrieve list of cameras from the interface
//
// *** NOTES ***
// Camera lists can be retrieved from an interface or the system object.
// Camera lists retrieved from an interface, such as this one, only return
// cameras attached on that specific interface whereas camera lists
// retrieved from the system will return all cameras on all interfaces.
//
// *** LATER ***
// Camera lists must be cleared manually. This must be done prior to
// releasing the system and while the camera list is still in scope.
//
spinCameraList hCameraList = NULL;
size_t numCameras = 0;
// Create empty camera list
err = spinCameraListCreateEmpty(&hCameraList);
{
printf("Unable to create camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve cameras
err = spinInterfaceGetCameras(hInterface, hCameraList);
{
printf("Unable to retrieve camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve number of cameras
err = spinCameraListGetSize(hCameraList, &numCameras);
{
printf("Unable to retrieve number of cameras. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Return if no cameras detected
if (numCameras == 0)
{
printf("\tNo devices detected.\n\n");
//
// Clear and destroy camera list before losing scope
//
// *** NOTES ***
// Camera lists do not automatically clean themselves up. This must be done
// manually. The same is true of interface lists.
//
err = spinCameraListClear(hCameraList);
{
printf("Unable to clear camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinCameraListDestroy(hCameraList);
{
printf("Unable to destroy camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
return err;
}
// Print device vendor and model name for each camera on the interface
for (i = 0; i < numCameras; i++)
{
//
// Select camera
//
// *** NOTES ***
// Each camera is retrieved from a camera list with an index. If the
// index is out of range, an exception is thrown.
//
// *** LATER ***
// Each camera handle needs to be released before losing scope or the
// system is released.
//
spinCamera hCam = NULL;
err = spinCameraListGet(hCameraList, i, &hCam);
{
printf("Unable to retrieve camera. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve TL device nodemap; please see NodeMapInfo_C example for
// additional comments on transport layer nodemaps.
spinNodeMapHandle hNodeMapTLDevice = NULL;
err = spinCameraGetTLDeviceNodeMap(hCam, &hNodeMapTLDevice);
{
printf(
"Unable to retrieve TL device nodemap. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
//
// Retrieve device vendor name
//
// *** NOTES ***
// Grabbing node information requires first retrieving the node and
// then retrieving its information. There are two things to keep in
// mind. First, a node is distinguished by type, which is related
// to its value's data type. Second, nodes should be checked for
// availability and readability/writability prior to making an
// attempt to read from or write to the node.
//
spinNodeHandle hDeviceVendorName = NULL;
bool8_t deviceVendorNameIsReadable = False;
// Retrieve node
err = spinNodeMapGetNode(hNodeMapTLDevice, "DeviceVendorName", &hDeviceVendorName);
{
printf(
"Unable to retrieve device information (vendor name node). Aborting with error: %s [%d]\n\n",
err);
return err;
}
// Check readability
err = spinNodeIsReadable(hDeviceVendorName, &deviceVendorNameIsReadable);
{
printf(
"Unable to check node readability (vendor name node). Aborting with error: %s [%d]\n\n",
err);
return err;
}
//
// Retrieve device model name
//
// *** NOTES ***
// Because C has no try-catch blocks, each function returns an error
// code to suggest whether an error has occurred. Errors can be
// sufficiently handled with these return codes. Checking availability
// and readability/writability makes for safer and more complete code;
// however, keeping in mind example conciseness and legibility, only
// this example and NodeMapInfo_C demonstrate checking node
// availability and readability/writability while other examples
// handle errors with error codes alone.
//
spinNodeHandle hDeviceModelName = NULL;
bool8_t deviceModelNameIsReadable = False;
err = spinNodeMapGetNode(hNodeMapTLDevice, "DeviceModelName", &hDeviceModelName);
{
printf(
"Unable to retrieve device information (model name node). Aborting with error: %s [%d]\n\n",
err);
return err;
}
err = spinNodeIsReadable(hDeviceModelName, &deviceModelNameIsReadable);
{
printf(
"Unable to check node readability (model name node). Aborting with error: %s [%d]\n\n",
err);
return err;
}
//
// Print device vendor and model names
//
// *** NOTES ***
// Generally it is best to check readability when it is required to read
// information from a node and writability when it is required to write
// to a node. For most nodes, writability implies readability while
// readability does not imply writability.
//
char deviceVendorName[MAX_BUFF_LEN];
size_t lenDeviceVendorName = MAX_BUFF_LEN;
char deviceModelName[MAX_BUFF_LEN];
size_t lenDeviceModelName = MAX_BUFF_LEN;
// Print device vendor name
if (deviceVendorNameIsReadable)
{
err = spinStringGetValue(hDeviceVendorName, deviceVendorName, &lenDeviceVendorName);
{
printf(
"Unable to retrieve device information (vendor name value). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
strcpy(deviceVendorName, "Not readable");
}
// Print device model name
if (deviceModelNameIsReadable)
{
err = spinStringGetValue(hDeviceModelName, deviceModelName, &lenDeviceModelName);
{
printf(
"Unable to retrieve device information (model name value). Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
else
{
strcpy(deviceModelName, "Not readable");
}
printf("\tDevice %d %s %s\n\n", i, deviceVendorName, deviceModelName);
//
// Release camera before losing scope
//
// *** NOTES ***
// Every handle that is created for a camera must be released before
// the system is released or an exception will be thrown.
//
err = spinCameraRelease(hCam);
{
printf("Unable to release camera. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
}
//
// Clear and destroy camera list before losing scope
//
// *** NOTES ***
// Camera lists do not automatically clean themselves up. This must be done
// manually. The same is true of interface lists.
//
err = spinCameraListClear(hCameraList);
{
printf("Unable to clear camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinCameraListDestroy(hCameraList);
{
printf("Unable to destroy camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
return err;
}
// Example entry point; this function sets up the system and retrieves
// interfaces for the example.
int main(/*int argc, char** argv*/)
{
spinError errReturn = SPINNAKER_ERR_SUCCESS;
spinError err = SPINNAKER_ERR_SUCCESS;
unsigned int i = 0;
// Print application build information
printf("Application build date: %s %s \n\n", __DATE__, __TIME__);
//
// Retrieve singleton reference to system object
//
// *** NOTES ***
// Everything originates with the system object. It is important to notice
// that it has a singleton implementation, so it is impossible to have
// multiple system objects at the same time.
//
// *** LATER ***
// The system object should be cleared prior to program completion. If not
// released explicitly, it will be released automatically.
//
spinSystem hSystem = NULL;
err = spinSystemGetInstance(&hSystem);
{
printf("Unable to retrieve system instance. Aborting with 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 interfaces from the system
//
// *** NOTES ***
// Interface lists are retrieved from the system object.
//
// *** LATER ***
// Interface lists must be cleared and destroyed manually. This must be
// done prior to releasing the system and while the interface list is still
// in scope.
//
spinInterfaceList hInterfaceList = NULL;
size_t numInterfaces = 0;
// Create empty interface list
err = spinInterfaceListCreateEmpty(&hInterfaceList);
{
printf("Unable to create empty interface list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve interfaces from system
err = spinSystemGetInterfaces(hSystem, hInterfaceList);
{
printf("Unable to retrieve interface list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve number of interfaces
err = spinInterfaceListGetSize(hInterfaceList, &numInterfaces);
{
printf("Unable to retrieve number of interfaces. Aborting with err %d...\n\n", err);
return err;
}
printf("Number of interfaces detected: %u\n\n", (unsigned int)numInterfaces);
//
// Retrieve list of cameras from the system
//
// *** NOTES ***
// Camera lists can be retrieved from an interface or the system object.
// Camera lists retrieved from the system, such as this one, return all
// cameras available on the system.
//
// *** LATER ***
// Camera lists must be cleared and destroyed manually. This must be done
// prior to releasing the system and while the camera list is still in
// scope.
//
spinCameraList hCameraList = NULL;
size_t numCameras = 0;
// Create empty camera list
err = spinCameraListCreateEmpty(&hCameraList);
{
printf("Unable to create camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve cameras from system
err = spinSystemGetCameras(hSystem, hCameraList);
{
printf("Unable to retrieve camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Retrieve number of cameras
err = spinCameraListGetSize(hCameraList, &numCameras);
{
printf("Unable to retrieve number of cameras. Aborting with 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 || numInterfaces == 0)
{
// Clear and destroy camera list before releasing system
err = spinCameraListClear(hCameraList);
{
printf("Unable to clear camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinCameraListDestroy(hCameraList);
{
printf("Unable to destroy camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Clear and destroy interface list before releasing system
err = spinInterfaceListClear(hInterfaceList);
{
printf("Unable to clear interface list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinInterfaceListDestroy(hInterfaceList);
{
printf("Unable to destroy interface list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
// Release system
err = spinSystemReleaseInstance(hSystem);
{
printf("Unable to release system instance. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("\nNot enough cameras/interfaces!\n");
printf("Done! Press Enter to exit...\n");
getchar();
return -1;
}
printf("\n*** QUERYING INTERFACES ***\n\n");
//
// Run example on each interface
//
// *** NOTES ***
// In order to run all interfaces in a loop, each interface needs to
// retrieved using its index.
//
for (i = 0; i < numInterfaces; i++)
{
// Select interface
spinInterface hInterface = NULL;
err = spinInterfaceListGet(hInterfaceList, i, &hInterface);
{
printf("Unable to retrieve interface from list (error %d)...\n", err);
errReturn = err;
continue;
}
// Run example
err = QueryInterface(hInterface);
{
errReturn = err;
}
// Release interface
err = spinInterfaceRelease(hInterface);
{
errReturn = err;
}
}
//
// Clear and destroy camera list before releasing system
//
// *** NOTES ***
// Camera lists are not shared pointers and do not automatically clean
// themselves up and break their own references. Therefore, this must be
// done manually. The same is true of interface lists.
//
err = spinCameraListClear(hCameraList);
{
printf("Unable to clear camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinCameraListDestroy(hCameraList);
{
printf("Unable to destroy camera list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
//
// Clear and destroy interface list before releasing system
//
// *** NOTES ***
// Interface lists are not shared pointers and do not automatically clean
// themselves up and break their own references. Therefore, this must be
// done manually. The same is true of camera lists.
//
err = spinInterfaceListClear(hInterfaceList);
{
printf("Unable to clear interface list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
err = spinInterfaceListDestroy(hInterfaceList);
{
printf("Unable to destroy interface list. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
//
// Release system
//
// *** NOTES ***
// The system should be released, but if it is not, it will do so itself.
// It is often at the release of the system (whether manual or automatic)
// that unbroken references and still registered events will throw an
// exception.
//
err = spinSystemReleaseInstance(hSystem);
{
printf("Unable to release system instance. Aborting with error: %s [%d]\n\n", GetLastErrorMessage(), err);
return err;
}
printf("\nDone! Press Enter to exit...\n");
getchar();
return errReturn;
}
spinCameraRelease
SPINNAKERC_API spinCameraRelease(spinCamera hCamera)
Releases a camera.
lenLastErrorMessage
size_t lenLastErrorMessage
Definition: Enumeration_C.c:48
MAX_BUFF_LEN
#define MAX_BUFF_LEN
Definition: Enumeration_C.c:45
spinInterfaceListGet
SPINNAKERC_API spinInterfaceListGet(spinInterfaceList hInterfaceList, size_t index, spinInterface *phInterface)
Retrieves an interface from an interface list using an index (interfaces retrieved this way must be r...
spinCameraListClear
SPINNAKERC_API spinCameraListClear(spinCameraList hCameraList)
Clears a camera list.
spinInterfaceRelease
SPINNAKERC_API spinInterfaceRelease(spinInterface hInterface)
Releases an interface.
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...
spinInterfaceList
void * spinInterfaceList
Handle for interface list functionality.
Definition: SpinnakerDefsC.h:59
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.
spinNodeMapHandle
void * spinNodeMapHandle
Handle for nodemap functionality.
Definition: SpinnakerGenApiDefsC.h:39
spinInterfaceListCreateEmpty
SPINNAKERC_API spinInterfaceListCreateEmpty(spinInterfaceList *phInterfaceList)
Creates an empty interface list (interface lists created this way must be destroyed)
SpinnakerC.h
main
int main()
Definition: Enumeration_C.c:409
spinInterfaceListGetSize
SPINNAKERC_API spinInterfaceListGetSize(spinInterfaceList hInterfaceList, size_t *pSize)
Retrieves the number of interfaces in an interface list.
spinSystemGetLibraryVersion
SPINNAKERC_API spinSystemGetLibraryVersion(spinSystem hSystem, spinLibraryVersion *hLibraryVersion)
Get current library version of Spinnaker.
spinSystem
void * spinSystem
Handle for system functionality.
Definition: SpinnakerDefsC.h:51
QueryInterface
spinError QueryInterface(spinInterface hInterface)
Definition: Enumeration_C.c:61
False
static const bool8_t False
Definition: SpinnakerDefsC.h:36
spinCameraListDestroy
SPINNAKERC_API spinCameraListDestroy(spinCameraList hCameraList)
Destroys a camera list.
spinCameraList
void * spinCameraList
Handle for interface functionality.
Definition: SpinnakerDefsC.h:75
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...
spinInterfaceListClear
SPINNAKERC_API spinInterfaceListClear(spinInterfaceList hInterfaceList)
Clears an interface list.
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
lastErrorMessage
char lastErrorMessage[MAX_BUFF_LEN]
Definition: Enumeration_C.c:47
spinInterfaceGetTLNodeMap
SPINNAKERC_API spinInterfaceGetTLNodeMap(spinInterface hInterface, spinNodeMapHandle *phNodeMap)
Retrieves the transport layer nodemap from an interface.
spinInterfaceGetCameras
SPINNAKERC_API spinInterfaceGetCameras(spinInterface hInterface, spinCameraList hCameraList)
Retrieves a camera list from an interface; camera lists must be created and destroy.
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.
spinInterfaceListDestroy
SPINNAKERC_API spinInterfaceListDestroy(spinInterfaceList hInterfaceList)
Destroys an interface list.
spinSystemGetInterfaces
SPINNAKERC_API spinSystemGetInterfaces(spinSystem hSystem, spinInterfaceList hInterfaceList)
Retrieves a list of detected (and enumerable) interfaces on the system; interface lists must be creat...
spinInterface
void * spinInterface
Handle for interface functionality.
Definition: SpinnakerDefsC.h:66
spinNodeMapGetNode
SPINNAKERC_API spinNodeMapGetNode(spinNodeMapHandle hNodeMap, const char *pName, spinNodeHandle *phNode)
Retrieves a node from the nodemap by name.
spinCameraListGetSize
SPINNAKERC_API spinCameraListGetSize(spinCameraList hCameraList, size_t *pSize)
Retrieves the number of cameras on a camera list.
spinCameraGetTLDeviceNodeMap
SPINNAKERC_API spinCameraGetTLDeviceNodeMap(spinCamera hCamera, spinNodeMapHandle *phNodeMap)
Retrieves the transport layer device nodemap from a camera.
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)
GetLastErrorMessage
char * GetLastErrorMessage()
Definition: Enumeration_C.c:51