Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Image Manager/Cvb++/CppStreamGenDCContainer

This example program is located in your CVB installation under %CVB%Tutorial/Image Manager/Cvb++/CppStreamGenDCContainer.

main.cpp:

// Demonstrates how GenDC container-based image acquisition can be accomplished by using a mock GenTL
// Producer, so called CVMockTL.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <sstream>
#include <cvb/device_factory.hpp>
#include <cvb/global.hpp>
#include <cvb/driver/composite_stream.hpp>
static const constexpr int DELIVERABLE_COUNT = 10; // Number of deliverables to be acquired.
static const constexpr int ITEM_COUNT =
2; // Number of items in a Composite object that are transmitted over a set of GenDC flows.
static const constexpr int CVB_FLOW_SET_COUNT = 3; // Number of CVB Flow Set, i.e., a set of memory buffers as the
// acquired data destination that is transmitted over GenDC flows.
int main()
{
try
{
// Retrieve CVMockTL in the given system.
auto infoList = Cvb::DeviceFactory::Discover(Cvb::DiscoverFlags::IgnoreVins | // Ignores all of the CVB VINs.
Cvb::DiscoverFlags::IncludeMockTL // Include CVMockTL.
);
// Make sure if CVMockTL is on the candidate list.
Cvb::String accessToken;
for (auto n = 0; (n < infoList.size()) && accessToken.empty(); ++n)
if (infoList.at(n).AccessToken().find("MockTL") != std::string::npos)
accessToken = infoList.at(n).AccessToken();
if (accessToken.empty())
throw std::runtime_error("Could not find CVMockTL.");
// Instantiate a GenICam device from the CVMockTL.
auto device = Cvb::DeviceFactory::Open<Cvb::GenICamDevice>(accessToken, Cvb::AcquisitionStack::GenTL);
// Instantiate its device node map.
auto deviceNodeMap = device->NodeMap("Device");
// The following code block is for demonstration purpose. They are not public features.
{
auto configurationNode = deviceNodeMap->Node<Cvb::EnumerationNode>(CVB_LIT("GenDCFlowMappingConfiguration"));
configurationNode->SetValue(CVB_LIT("MultipleFlow"));
auto imageCountNode = deviceNodeMap->Node<Cvb::IntegerNode>(CVB_LIT("TestGenDCImageCount"));
imageCountNode->SetValue(ITEM_COUNT);
}
// Turn on the GenDC streaming mode.
auto streamingModeNode = deviceNodeMap->Node<Cvb::EnumerationNode>(CVB_LIT("GenDCStreamingMode"));
streamingModeNode->SetValue(CVB_LIT("On"));
// Get the first stream of the device.
auto stream = device->Stream<Cvb::CompositeStream>();
// Let it allocate the required amount of memory resource.
stream->RegisterManagedFlowSetPool(CVB_FLOW_SET_COUNT);
// Let it start data streaming.
stream->Start();
for (auto m = 0; m < DELIVERABLE_COUNT; ++m)
{
std::cout << "Acquisition #" << m << "\n";
// Wait for a single deliverable with a 10-second timeout value.
auto waitResultTuple = stream->WaitFor(std::chrono::seconds(10));
if (std::get<Cvb::WaitStatus>(waitResultTuple) == Cvb::WaitStatus::Timeout)
throw std::runtime_error("Acquisition timeout.");
// Retrieve VIN buffer node map and get the timestamp of the delivered image.
auto &enumerator = std::get<Cvb::NodeMapEnumerator>(waitResultTuple);
const auto names = enumerator.Names();
const auto keyName = CVB_LIT("VinBuffer");
if (std::all_of(names.begin(), names.end(), [keyName](const Cvb::String &name) { return name != keyName; }))
throw std::runtime_error("It must contain the node map of Vin buffer.");
auto vinBufferNodeMap = enumerator.NodeMap(keyName);
auto frameIDNode = vinBufferNodeMap->Node<Cvb::IntegerNode>(CVB_LIT("FrameID"));
auto timestampNode = vinBufferNodeMap->Node<Cvb::IntegerNode>(CVB_LIT("Timestamp"));
auto payloadTypeNode = vinBufferNodeMap->Node<Cvb::EnumerationNode>(CVB_LIT("BufferPayloadType"));
// Verify the acquired deliverable contents.
auto deliverable = std::get<Cvb::CompositePtr>(waitResultTuple);
std::cout << "Frame ID: " << frameIDNode->Value()
<< ", Type: " << payloadTypeNode->Value() << ", Timestamp: 0x" << std::hex
<< timestampNode->Value() << ", Item count: " << deliverable->ItemCount() << "\n";
// Identify the item in the deliverable.
for (auto n = 0; n < deliverable->ItemCount(); ++n)
{
auto item = deliverable->ItemAt(n);
std::stringstream strStream;
strStream << "Type: ";
{
auto image = Cvb::get<Cvb::ImagePtr>(item);
strStream << "Image, Width: " << image->Width() << ", Height: " << image->Height();
}
strStream << "Plane";
strStream << "Plane enumerator";
strStream << "Buffer";
strStream << "PFNC buffer";
else
strStream << "Unknown";
std::cout << "Item index: " << n << ", " << strStream.str() << "\n";
}
}
// Try aborting data streaming.
stream->TryAbort();
}
catch (const std::exception &e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
void RegisterManagedFlowSetPool(int flowSetCount)
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
void SetValue(const String &value)
void SetValue(std::int64_t value)
std::int64_t Value() const
std::string String
const variant_alternative_t< I, variant< TS... > > & get(const variant< TS... > &var)
bool holds_alternative(const variant< TS... > &var) noexcept