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: EnumerationEvents, ImageEvents, or Logging.
#include <iostream>
#include <sstream>
using namespace std;
{
if (GenApi::IsReadable(ptrHeight))
{
cout << "Height callback message:" << endl;
cout << "\tLook! Height changed to " << ptrHeight->GetValue() << "..." << endl << endl;
}
else
{
cout << "Height callback triggered but node is not readable..." << endl;
}
}
{
if (GenApi::IsReadable(ptrGain))
{
cout << "Gain callback message:" << endl;
cout << "\tLook now! Gain changed to " << ptrGain->GetValue() << "..." << endl << endl;
}
else
{
cout << "Gain callback triggered but node is not readable..." << endl;
}
}
{
{
cout << ptrEventNode->GetName() << " with node type " << nodeType << " was updated" << endl;
return;
}
switch (nodeType)
{
cout << ptrEventNode->GetName() <<
" was changed to " <<
CIntegerPtr(node)->GetValue() << endl;
break;
cout << ptrEventNode->GetName() <<
" was changed to " <<
CBooleanPtr(node)->GetValue() << endl;
break;
cout << ptrEventNode->GetName() <<
" was changed to " <<
CFloatPtr(node)->GetValue() << endl;
break;
cout << ptrEventNode->GetName() <<
" was changed to " <<
CStringPtr(node)->GetValue() << endl;
break;
default:
cout << ptrEventNode->GetName() << " with node type " << nodeType << " was updated" << endl;
break;
}
}
int ConfigureCallbacks(INodeMap& nodeMap, std::vector<CallbackHandleType>& callbackHandles)
{
int result = 0;
cout << endl << endl << "*** CONFIGURING CALLBACKS ***" << endl << endl;
try
{
{
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;
}
else
{
{
cout << "Unable to disable automatic gain (node retrieval). Expected for some models..." << endl << endl;
result = 1;
}
else
{
cout << "Skipping automatic gain disabling... Expected for some models..." << endl;
result = 1;
}
}
{
cout << "Unable to retrieve height. Aborting..." << endl << endl;
return -1;
}
cout << "Height ready..." << endl;
callbackHandles.push_back(callbackHeight);
cout << "Height callback registered..." << endl;
{
cout << "Unable to retrieve gain. Aborting..." << endl << endl;
return -1;
}
cout << "Gain ready..." << endl;
callbackHandles.push_back(callbackGain);
cout << "Gain callback registered..." << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << endl << "*** CONFIGURING EVENT CALLBACKS ***" << endl << endl;
try
{
{
cout << "Unable to retrieve event selector entries. Skipping..." << endl << endl;
return 1;
}
ptrEventSelector->GetEntries(entries);
cout << "Enabling event selector entries..." << endl;
for (unsigned int i = 0; i < entries.size(); i++)
{
{
continue;
}
ptrEventSelector->SetIntValue(ptrEnumEntry->GetValue());
CEnumerationPtr ptrEventNotification = nodeMap.GetNode(
"EventNotification");
{
continue;
}
CEnumEntryPtr ptrEventNotificationOn = ptrEventNotification->GetEntryByName(
"On");
{
continue;
}
{
continue;
}
ptrEventNotification->SetIntValue(ptrEventNotificationOn->GetValue());
cout << "\t" << ptrEnumEntry->GetDisplayName() << ": enabled..." << endl;
auto eventDataCategoryName = "Event" + ptrEnumEntry->GetSymbolic() + "Data";
CCategoryPtr ptrDataCategory = nodeMap.GetNode(eventDataCategoryName);
if (ptrDataCategory)
{
GenApi::FeatureList_t features;
ptrDataCategory->GetFeatures(features);
for (const auto& it : features)
{
callbackHandles.push_back(callbackHandle);
cout << "\t\t" << ptrNode->GetName() << " callback registered..." << endl;
}
}
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** CHANGE HEIGHT & GAIN ***" << endl << endl;
try
{
if (!
IsReadable(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 << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
{
cout << "Unable to retrieve event selector entries. Skipping..." << endl << endl;
return 0;
}
ptrEventSelector->GetEntries(entries);
cout << "Disabling event selector entries..." << endl;
for (unsigned int i = 0; i < entries.size(); i++)
{
{
continue;
}
ptrEventSelector->SetIntValue(ptrEnumEntry->GetValue());
CEnumerationPtr ptrEventNotification = nodeMap.GetNode(
"EventNotification");
{
result = -1;
continue;
}
CEnumEntryPtr ptrEventNotificationOn = ptrEventNotification->GetEntryByName(
"Off");
{
result = -1;
continue;
}
{
result = -1;
continue;
}
ptrEventNotification->SetIntValue(ptrEventNotificationOn->GetValue());
cout << "\t" << ptrEnumEntry->GetDisplayName() << ": disabled..." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
{
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)
{
try
{
cout << pfeatureNode->GetName() << " : ";
cout << (
IsReadable(pValue) ? pValue->ToString() :
"Node not readable");
cout << endl;
}
{
cout << "Node not readable" << endl;
}
}
}
else
{
cout << "Device control information not readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
cout << "Unable to get or set acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to get acquisition mode to continuous (entry 'continuous' retrieval). Aborting..." << endl
<< endl;
return -1;
}
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "Acquisition mode set to continuous..." << endl;
pCam->BeginAcquisition();
cout << "Acquiring images..." << endl;
CStringPtr ptrStringSerial = nodeMapTLDevice.GetNode(
"DeviceSerialNumber");
{
deviceSerialNumber = ptrStringSerial->GetValue();
cout << "Device serial number retrieved as " << deviceSerialNumber << "..." << endl;
}
cout << endl;
for (
unsigned int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
try
{
ImagePtr pResultImage = pCam->GetNextImage(1000);
if (pResultImage->IsIncomplete())
{
cout << "Image incomplete with image status " << pResultImage->GetImageStatus() << "..." << endl
<< endl;
}
else
{
cout << "Grabbed image " << imageCnt << ", width = " << pResultImage->GetWidth()
<< ", height = " << pResultImage->GetHeight() << endl;
}
pResultImage->Release();
cout << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
}
pCam->EndAcquisition();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
int err = 0;
try
{
pCam->Init();
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
INodeMap& nodeMapTLStream = pCam->GetTLStreamNodeMap();
std::vector<CallbackHandleType> callbacks;
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err == 0)
{
}
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;
}
int AcquireImages(CameraPtr pCam, INodeMap &nodeMap, INodeMap &nodeMapTLDevice)
Definition Acquisition.cpp:200
int main(int, char **)
Definition Acquisition.cpp:536
int RunSingleCamera(CameraPtr pCam)
Definition Acquisition.cpp:488
int PrintDeviceInfo(INodeMap &nodeMap)
Definition Acquisition.cpp:442
const unsigned int k_numImages
Definition AcquisitionMultipleCamerasWriteToFile.cpp:55
void OnHeightNodeUpdate(INode *node)
Definition NodeMapCallback.cpp:51
int ResetEvents(INodeMap &nodeMap)
Definition NodeMapCallback.cpp:448
int ResetAutoGain(INodeMap &nodeMap)
Definition NodeMapCallback.cpp:520
int ConfigureEventCallbacks(INodeMap &nodeMap, std::vector< CallbackHandleType > &callbackHandles)
Definition NodeMapCallback.cpp:239
void OnGainNodeUpdate(INode *node)
Definition NodeMapCallback.cpp:69
int ChangeHeightAndGain(INodeMap &nodeMap)
Definition NodeMapCallback.cpp:355
int ConfigureCallbacks(INodeMap &nodeMap, std::vector< CallbackHandleType > &callbackHandles)
Definition NodeMapCallback.cpp:120
void OnEventNodeUpdate(INode *node)
Definition NodeMapCallback.cpp:86
int ResetCallbacks(std::vector< CallbackHandleType > &callbackHandles)
Definition NodeMapCallback.cpp:417
Used to hold a list of camera objects.
Definition CameraList.h:42
void Clear()
Clears the list of cameras and destroys their corresponding reference counted objects.
CameraPtr GetByIndex(unsigned int index) const
Returns a pointer to a camera object at the "index".
unsigned int GetSize() const
Returns the size of the camera list.
A reference tracked pointer to a camera object.
Definition CameraPtr.h:44
The Exception object represents an error that is returned from the library.
Definition Exception.h:51
virtual const char * what() const
virtual override for what().
SmartPointer for IFloat interface pointer.
Definition Pointer.h:421
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:75
Image post processing class for converting a source image to another pixel format.
Definition ImageProcessor.h:160
void SetColorProcessing(ColorProcessingAlgorithm colorAlgorithm)
Sets the color processing algorithm used at the time of the Convert() call, therefore the most recent...
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition INode.h:277
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition INode.h:253
interface SPINNAKER_API_ABSTRACT INodeMap
Interface to access the node map.
Definition INodeMap.h:54
intptr_t Register(INode *pNode, Function f, ECallbackType CallbackType=cbPostInsideLock, bool fireOnValueChangedOnly=false)
Register a C-function as a callback.
Definition NodeCallback.h:235
SPINNAKER_API void Deregister(GenApi::CallbackHandleType pCallbackInfo)
Unregistering callback by handle.
node_vector NodeList_t
a list of node references
Definition INode.h:54
intptr_t CallbackHandleType
the callback handle for nodes
Definition INode.h:59
EInterfaceType
typedef for interface type
Definition Types.h:205
@ intfIFloat
ICommand interface.
Definition Types.h:211
@ intfIInteger
IBase interface.
Definition Types.h:208
@ intfIString
IFloat interface.
Definition Types.h:212
@ intfIBoolean
IInteger interface.
Definition Types.h:209
Definition AutoPollController.h:33
Provides easier access to the current version of Spinnaker.
Definition SpinnakerDefs.h:706
unsigned int minor
Minor version of the library.
Definition SpinnakerDefs.h:711
unsigned int major
Major version of the library.
Definition SpinnakerDefs.h:708
unsigned int type
Version type of the library.
Definition SpinnakerDefs.h:714
unsigned int build
Build number of the library.
Definition SpinnakerDefs.h:717