This example focuses on creating, registering, using, and unregistering callbacks. A callback requires a function signature, which allows it to be registered to and access a node. Events, while slightly more complex, follow this same pattern.
Once comfortable with NodeMapCallback, we suggest checking out any of the events examples: DeviceEvents, EnumerationEvents, ImageEvents, or Logging.
#include <iostream>
#include <sstream>
using namespace Spinnaker;
using namespace Spinnaker::GenApi;
using namespace Spinnaker::GenICam;
using namespace std;
{
cout << "Height callback message:" << endl;
cout << "\tLook! Height changed to " << ptrHeight->GetValue() << "..." << endl << endl;
}
{
cout << "Gain callback message:" << endl;
cout << "\tLook now! Gain changed to " << ptrGain->GetValue() << "..." << endl << endl;
}
{
int result = 0;
cout << endl << endl << "*** CONFIGURING CALLBACKS ***" << endl << endl;
try
{
{
cout << "Unable to disable automatic gain (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrGainAutoOff = ptrGainAuto->GetEntryByName(
"Off");
{
cout << "Unable to disable automatic gain (enum entry retrieval). Aborting..." << endl << endl;
return -1;
}
ptrGainAuto->SetIntValue(ptrGainAutoOff->GetValue());
cout << "Automatic gain disabled..." << endl;
{
cout << "Unable to retrieve height. Aborting..." << endl << endl;
return -1;
}
cout << "Height ready..." << endl;
cout << "Height callback registered..." << endl;
{
cout << "Unable to retrieve gain. Aborting..." << endl << endl;
return -1;
}
cout << "Gain ready..." << endl;
cout << "Gain callback registered..." << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** CHANGE HEIGHT & GAIN ***" << endl << endl;
try
{
if (!
IsAvailable(ptrHeight) || !
IsWritable(ptrHeight) || ptrHeight->GetInc() == 0 || ptrHeight->GetMax() == 0)
{
cout << "Unable to retrieve height. Aborting..." << endl << endl;
return -1;
}
int64_t heightToSet = ptrHeight->GetMax();
cout << "Regular function message:" << endl;
cout << "\tHeight about to be changed to " << heightToSet << "..." << endl << endl;
ptrHeight->SetValue(heightToSet);
{
cout << "Unable to retrieve gain..." << endl;
return -1;
}
double gainToSet = ptrGain->GetMax() / 2.0;
cout << "Regular function message:" << endl;
cout << "\tGain about to be changed to " << gainToSet << "..." << endl << endl;
ptrGain->SetValue(gainToSet);
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
cout << "Callbacks deregistered..." << endl;
{
cout << "Unable to enable automatic gain (node retrieval). Non-fatal error..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrGainAutoContinuous = ptrGainAuto->GetEntryByName(
"Continuous");
{
cout << "Unable to enable automatic gain (enum entry retrieval). Non-fatal error..." << endl << endl;
return -1;
}
ptrGainAuto->SetIntValue(ptrGainAutoContinuous->GetValue());
cout << "Automatic gain enabled..." << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
{
category->GetFeatures(features);
FeatureList_t::const_iterator it;
for (it = features.begin(); it != features.end(); ++it)
{
cout << pfeatureNode->GetName() << " : ";
cout << (
IsReadable(pValue) ? pValue->ToString() :
"Node not readable");
cout << endl;
}
}
else
{
cout << "Device control information not available." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
int err = 0;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
if (err < 0)
{
return err;
}
result = result |
ResetCallbacks(nodeMap, callbackHeight, callbackGain);
pCam->DeInit();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << "Application build date: " << __DATE__ << " " << __TIME__ << endl << endl;
const LibraryVersion spinnakerLibraryVersion = system->GetLibraryVersion();
cout <<
"Spinnaker library version: " << spinnakerLibraryVersion.
major <<
"." << spinnakerLibraryVersion.
minor
<<
"." << spinnakerLibraryVersion.
type <<
"." << spinnakerLibraryVersion.
build << endl
<< endl;
unsigned int numCameras = camList.
GetSize();
cout << "Number of cameras detected: " << numCameras << endl << endl;
if (numCameras == 0)
{
system->ReleaseInstance();
cout << "Not enough cameras!" << endl;
cout << "Done! Press Enter to exit..." << endl;
getchar();
return -1;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running example for camera " << i << "..." << endl;
cout << "Camera " << i << " example complete..." << endl << endl;
}
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return result;
}