Counter and Timer functionality is only available for BFS and Oryx Cameras. Some cameras lack all the functionality required to output PWM. We have included a demonstration to acquire an image every 2 seconds via the counter in this example. For details on the hardware setup, see our kb article, "Using Counter and
Timer Control"; https://www.flir.com/support-center/iis/machine-vision/application-note/using-counter-and-timer-control
#include <iostream>
#include <sstream>
using namespace std;
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
if (IsReadable(category))
{
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 readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
if (!IsReadable(enumPtr) ||
!IsWritable(enumPtr))
{
cout << "Unable to get or set " << enumName << "(enum retrieval). Aborting..." << endl;
return -1;
}
{
cout << "Unable to get " << entryName << "(entry retrieval). Aborting..." << endl;
return -1;
}
enumPtr->SetIntValue(entryPtr->GetValue());
return 0;
}
{
int result = 0;
cout << endl << "Configuring Pulse Width Modulation signal" << endl;
try
{
{
return -1;
}
{
return -1;
}
CIntegerPtr ptrCounterDuration = nodeMap.GetNode(
"CounterDuration");
{
cout << "Unable to get or set Counter Duration (integer retrieval). Aborting..." << endl << endl;
return -1;
}
ptrCounterDuration->SetValue(14000);
CIntegerPtr ptrCounterDelay = nodeMap.GetNode(
"CounterDelay");
{
cout << "Unable to get or set Counter Delay (integer retrieval). Aborting..." << endl << endl;
return -1;
}
ptrCounterDelay->SetValue(6000);
int64_t dutyCycle = (int64_t)(
(float)ptrCounterDuration->GetValue() /
((float)ptrCounterDuration->GetValue() + (float)ptrCounterDelay->GetValue()) * 100);
cout << endl << "The duty cycle has been set to " << dutyCycle << "%" << endl;
int64_t pulseRate =
(int64_t)(1000000 / ((float)ptrCounterDuration->GetValue() + (float)ptrCounterDelay->GetValue()));
cout << endl << "The pulse rate has been set to " << pulseRate << "Hz" << endl;
{
return -1;
}
{
return -1;
}
}
{
cout <<
"Error: " << e.
what() << endl << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "Configuring Reduced CounterAndTimer Demo" << endl << endl;
try
{
{
return -1;
}
cout << "Turning off counter mode to enable counter configuration changes" << endl;
{
return -1;
}
{
return -1;
}
CIntegerPtr ptrCounterDuration = nodeMap.GetNode(
"counterDuration");
{
cout << "Unable to get or set Counter Duration (integer retrieval). Aborting..." << endl;
return -1;
}
ptrCounterDuration->SetValue(2000000);
cout << "Set Counter Duration to 2 seconds" << endl;
{
return -1;
}
{
return -1;
}
{
return -1;
}
{
return -1;
}
CFloatPtr ptrExposureTime = nodeMap.GetNode(
"ExposureTime");
{
cout << "Unable to get or set Exposure Time (integer retrieval). Aborting..." << endl;
return -1;
}
ptrExposureTime->SetValue(15000.0);
cout << "Set Exposure Time to 15,000us" << endl;
cout << "Re-activating counter mode" << endl;
{
return -1;
}
cout << endl << "Configuration finished" << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl << endl;
result = -1;
}
return result;
}
{
int result = 0;
const gcstring cameraFamilyOryx =
"ORX";
cout << endl << "Configuring GPIO strobe output" << endl;
try
{
CStringPtr ptrDeviceModelName = nodeMap.GetNode(
"DeviceModelName");
{
cout << "Unable to determine camera family. Aborting..." << endl << endl;
return -1;
}
gcstring cameraModel = ptrDeviceModelName->GetValue();
if (cameraModel.
find(cameraFamilyBFS) != std::string::npos)
{
{
return -1;
}
}
else if (cameraModel.
find(cameraFamilyOryx) != std::string::npos)
{
{
return -1;
}
{
return -1;
}
}
{
return -1;
}
if (cameraModel.
find(cameraFamilyBFS) != std::string::npos)
{
{
return -1;
}
CBooleanPtr ptrVoltageEnable = nodeMap.GetNode(
"V3_3Enable");
{
cout << "Unable to set Voltage Enable (boolean retrieval). Aborting..." << endl << endl;
return -1;
}
ptrVoltageEnable->SetValue(true);
}
}
{
cout <<
"Error: " << e.
what() << endl << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "Configuring Exposure and Trigger" << endl;
try
{
{
return -1;
}
CFloatPtr ptrExposureTime = nodeMap.GetNode(
"ExposureTime");
{
cout << "Unable to set Exposure Time (float retrieval). Aborting..." << endl << endl;
return -1;
}
ptrExposureTime->SetValue(5000);
{
return -1;
}
{
return -1;
}
{
return -1;
}
{
return -1;
}
}
{
cout <<
"Error: " << e.
what() << endl << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
return -1;
}
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;
if (reduced)
{
CCommandPtr ptrSoftwareTrigger = nodeMap.GetNode(
"TriggerSoftware");
{
cout << "Failed to execute software trigger... Aborting" << endl;
}
ptrSoftwareTrigger->Execute();
}
for (
unsigned int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
try
{
ImagePtr pResultImage = pCam->GetNextImage(3000);
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;
ImagePtr convertedImage = processor.
Convert(pResultImage, PixelFormat_Mono8);
ostringstream filename;
filename << "CounterAndTimer-";
if (deviceSerialNumber != "")
{
filename << deviceSerialNumber.c_str() << "-";
}
filename << imageCnt << ".jpg";
convertedImage->Save(filename.str().c_str());
cout << "Image saved at " << filename.str() << endl;
}
pResultImage->Release();
cout << endl;
}
{
cout <<
"Error: " << e.
what() << endl << endl;
result = -1;
}
}
pCam->EndAcquisition();
}
{
cout <<
"Error: " << e.
what() << endl << 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 <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
int err = 0;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
if (err < 0)
{
cout << "Regular setup failed... Trying reduced functionality demo" << endl;
if (err < 0)
{
return err;
}
err = 1;
}
if (err == 0)
{
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
}
if (err == 0)
{
result = result |
AcquireImages(pCam, nodeMap, nodeMapTLDevice,
false);
}
else if (err == 1)
{
result = result |
AcquireImages(pCam, nodeMap, nodeMapTLDevice,
true);
}
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 Enter to exit..." << endl;
getchar();
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 Enter to exit..." << endl;
getchar();
return -1;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running example for camera " << i << "..." << endl;
cout << endl << "Camera " << i << " example complete..." << endl << endl;
}
pCam = nullptr;
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
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
const unsigned int k_numImages
Definition AcquisitionMultipleCamerasWriteToFile.cpp:55
int ResetTrigger(INodeMap &nodeMap)
Definition BufferHandling.cpp:197
int SetupCounterAndTimer(INodeMap &nodeMap)
Definition CounterAndTimer.cpp:112
int SetupCounterAndTimerReduced(INodeMap &nodeMap)
Definition CounterAndTimer.cpp:178
int AssignEntryToEnum(INodeMap &nodeMap, gcstring enumName, gcstring entryName)
Definition CounterAndTimer.cpp:91
int ConfigureExposureandTrigger(INodeMap &nodeMap)
Definition CounterAndTimer.cpp:334
int ConfigureDigitalIO(INodeMap &nodeMap)
Definition CounterAndTimer.cpp:257
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
virtual size_t find(char ch, size_t offset=0) const
Image post processing class for converting a source image to another pixel format.
Definition ImageProcessor.h:159
void SetColorProcessing(ColorProcessingAlgorithm colorAlgorithm)
Sets the color processing algorithm used at the time of the Convert() call, therefore the most recent...
ImagePtr Convert(const ImagePtr &srcImage, PixelFormatEnums destFormat) const
Converts the source image buffer to the specified destination pixel format and returns the result in ...
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