Buffer handling determines the ordering in which images are retrieved, and what occurs when an image is transmitted while the buffer is full. There are four different buffer handling modes available; NewestFirst, NewestOnly, OldestFirst and OldestFirstOverwrite.
This example explores retrieving images in a set pattern; triggering the camera while not retrieving an image (letting the buffer fill up), and retrieving images while not triggering. We cycle through the different buffer handling modes to see which images are retrieved, confirming their identities via their Frame ID values.
#include <iostream>
#include <sstream>
using namespace std;
{
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
Sleep(milliseconds);
#else
usleep(1000 * milliseconds);
#endif
}
{
if (IsReadable(ptrDeviceType) && ptrDeviceType->GetIntValue() == DeviceType_GigEVision)
{
if (!IsAvailable(ptrStreamMode) || !IsReadable(ptrStreamMode))
{
cout << "Unable to get device's stream mode. Aborting..." << endl << endl;
return -1;
}
if (ptrStreamMode->GetIntValue() == StreamMode_TeledyneGigeVision)
{
}
}
}
{
int result = 0;
cout << endl << "*** CONFIGURING TRIGGER ***" << endl;
try
{
{
cout << "Unable to enable trigger mode (node retrieval). Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrTriggerModeOn = ptrTriggerMode->GetEntryByName(
"On");
{
cout << "Unable to enable trigger mode (enum entry retrieval). Aborting..." << endl;
return -1;
}
ptrTriggerMode->SetIntValue(ptrTriggerModeOn->GetValue());
cout << endl << "Trigger mode enabled..." << endl;
{
cout << "Unable to get or set trigger mode (node retrieval). Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrTriggerSourceSoftware = ptrTriggerSource->GetEntryByName(
"Software");
{
cout << "Unable to set trigger mode (enum entry retrieval). Aborting..." << endl;
return -1;
}
ptrTriggerSource->SetIntValue(ptrTriggerSourceSoftware->GetValue());
cout << "Trigger source set to software..." << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
CCommandPtr ptrSoftwareTriggerCommand = nodeMap.GetNode(
"TriggerSoftware");
{
cout << "Unable to execute trigger. Aborting..." << endl;
return -1;
}
ptrSoftwareTriggerCommand->Execute();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
{
cout << "Unable to disable trigger mode (node retrieval). Non-fatal error..." << endl;
return -1;
}
CEnumEntryPtr ptrTriggerModeOff = ptrTriggerMode->GetEntryByName(
"Off");
{
cout << "Unable to disable trigger mode (enum entry retrieval). Non-fatal error..." << endl;
return -1;
}
ptrTriggerMode->SetIntValue(ptrTriggerModeOff->GetValue());
cout << endl << endl << "Trigger mode disabled..." << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
{
FeatureList_t features;
category->GetFeatures(features);
for (FeatureList_t::const_iterator 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 readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
cout << "Unable to set acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to set acquisition mode to continuous (entry 'continuous' retrieval). Aborting..." << endl
<< endl;
return -1;
}
ptrAcquisitionMode->SetIntValue(ptrAcquisitionModeContinuous->GetValue());
cout << "Acquisition mode set to continuous..." << endl;
{
cout << "Unable to set Pixel Format mode (node retrieval). Aborting..." << endl << endl;
return false;
}
CEnumEntryPtr ptrMono8 = ptrPixelFormat->GetEntryByName(
"Mono8");
{
cout << "Unable to set pixel format (entry 'mono8' retrieval). Aborting..." << endl << endl;
return false;
}
ptrPixelFormat->SetIntValue(ptrMono8->GetValue());
cout << "Pixel format set to " << ptrPixelFormat->GetCurrentEntry()->GetName() << endl;
CStringPtr ptrStringSerial = nodeMapTLDevice.GetNode(
"DeviceSerialNumber");
{
deviceSerialNumber = ptrStringSerial->GetValue();
cout << "Device serial number retrieved as " << deviceSerialNumber << "..." << endl;
}
CEnumerationPtr ptrHandlingMode = sNodeMap.GetNode(
"StreamBufferHandlingMode");
{
cout << "Unable to set Buffer Handling mode (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrHandlingModeEntry = ptrHandlingMode->GetCurrentEntry();
{
cout << "Unable to get Buffer Handling mode (Entry retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumerationPtr ptrStreamBufferCountMode = sNodeMap.GetNode(
"StreamBufferCountMode");
{
cout << "Unable to get or set Buffer Count Mode (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrStreamBufferCountModeManual = ptrStreamBufferCountMode->GetEntryByName(
"Manual");
{
cout << "Unable to get Buffer Count Mode entry (Entry retrieval). Aborting..." << endl << endl;
return -1;
}
ptrStreamBufferCountMode->SetIntValue(ptrStreamBufferCountModeManual->GetValue());
cout << "Stream Buffer Count Mode set to manual..." << endl;
CIntegerPtr ptrBufferCount = sNodeMap.GetNode(
"StreamBufferCountManual");
{
cout << "Unable to get or set Buffer Count (Integer node retrieval). Aborting..." << endl << endl;
return -1;
}
cout << endl << "Default Buffer Handling Mode: " << ptrHandlingModeEntry->GetDisplayName() << endl;
cout << "Default Buffer Count: " << ptrBufferCount->GetValue() << endl;
cout << "Maximum Buffer Count: " << ptrBufferCount->GetMax() << endl;
cout << "Buffer count now set to: " << ptrBufferCount->GetValue() << endl;
cout << endl
<< " image retrieval attempts" << endl;
cout << endl << "Note - Buffer behaviour is different for USB3 and GigE cameras" << endl;
cout << " - USB3 cameras buffer images internally if no host buffers are available" << endl;
cout << " - Once the stream buffer is released, the USB3 camera will fill that buffer" << endl;
cout << " - GigE cameras do not buffer images" << endl;
cout << " - In TeledyneGigEVision stream mode an extra buffer will be reserved for trashing" << endl;
const std::vector<gcstring> bufferHandlingModes = {
"NewestFirst", "OldestFirst", "NewestOnly", "OldestFirstOverwrite"};
for (unsigned int i = 0; i < bufferHandlingModes.size(); i++)
{
ptrHandlingModeEntry = ptrHandlingMode->GetEntryByName(bufferHandlingModes[i]);
ptrHandlingMode->SetIntValue(ptrHandlingModeEntry->GetValue());
const std::string bufferModeName = ptrHandlingMode->GetCurrentEntry()->GetDisplayName().c_str();
cout << endl << endl << "*** Buffer Handling Mode has been set to " << bufferModeName << " ***" << endl;
pCam->BeginAcquisition();
if (i == 0)
{
}
try
{
{
}
cout << endl <<
"Camera triggered " <<
numTriggers <<
" times" << endl;
cout << endl << "Retrieving images from library until no image data is returned (errors out)" << endl;
{
ostringstream filename;
filename << ptrHandlingModeEntry->GetSymbolic() << "-";
if (!deviceSerialNumber.empty())
{
filename << deviceSerialNumber.c_str() << "-";
}
filename << j << ".jpg";
const ImagePtr pResultImage = pCam->GetNextImage(500);
if (pResultImage->IsIncomplete())
{
cout << "Image #" << j << " incomplete with image status " << pResultImage->GetImageStatus()
<< "..." << endl
<< endl;
}
pResultImage->Save(filename.str().c_str());
cout << "GetNextImage() #" << j << ", Frame ID: " << pResultImage->GetFrameID()
<< ", Image saved at " << filename.str() << endl;
pResultImage->Release();
}
}
{
cout <<
"Error: " << e.
what() << endl << endl;
if (ptrHandlingModeEntry->GetSymbolic() == "NewestFirst" ||
ptrHandlingModeEntry->GetSymbolic() == "OldestFirst")
{
cout << endl << "EXPECTED: error getting image # " << expectedImageCount + 1
<< " with handling mode set "
"to NewestFirst or OldestFirst in GigE Streaming"
<< endl;
}
else if (ptrHandlingModeEntry->GetSymbolic() == "NewestOnly")
{
cout << endl << "EXPECTED: error occur when getting image #2 with handling mode set to NewestOnly" << endl;
}
if (ptrHandlingModeEntry->GetSymbolic() == "OldestFirstOverwrite")
{
cout << endl <<
"EXPECTED: error occur when getting image #" <<
numBuffers - 1
<< " with handling mode set to"
" OldestFirstOverwrite"
<< endl;
}
result = -1;
}
pCam->EndAcquisition();
}
}
{
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;
}
pCam->DeInit();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
FILE* tempFile = fopen("test.txt", "w+");
if (tempFile == nullptr)
{
cout << "Failed to create file in current folder. Please check "
"permissions."
<< endl;
cout << "Press any key to exit..." << endl;
cin.ignore();
return -1;
}
fclose(tempFile);
remove("test.txt");
int result = 0;
cout << "Application build date: " << __DATE__ << " " << __TIME__ << 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 any key to exit..." << endl;
cin.ignore();
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 any key to exit..." << endl;
cin.ignore();
return result;
}
int AcquireImages(CameraPtr pCam, INodeMap &nodeMap, INodeMap &nodeMapTLDevice)
Definition Acquisition.cpp:199
int main(int, char **)
Definition Acquisition.cpp:527
int RunSingleCamera(CameraPtr pCam)
Definition Acquisition.cpp:479
int PrintDeviceInfo(INodeMap &nodeMap)
Definition Acquisition.cpp:441
void SleepyWrapper(int milliseconds)
Definition AcquisitionMultipleCameraRecovery.cpp:144
int ConfigureTrigger(INodeMap &nodeMap)
Definition BufferHandling.cpp:103
int GrabNextImageByTrigger(INodeMap &nodeMap)
Definition BufferHandling.cpp:170
constexpr int numGrabs
Definition BufferHandling.cpp:52
constexpr int numTriggers
Definition BufferHandling.cpp:49
constexpr int numBuffers
Definition BufferHandling.cpp:46
int GetExpectedImageCount(INodeMap &nodeMapTLDevice, INodeMap &snodeMap)
Definition BufferHandling.cpp:73
int ResetTrigger(INodeMap &nodeMap)
Definition BufferHandling.cpp:197
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().
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:75
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
Definition Autovector.h:36