CVB++ 14.1
Cvb/CppStreamConsoleWithMock
1// ----------------------------------------------------------------------------
4// ----------------------------------------------------------------------------
5
6#include <iostream>
7#include <string>
8
9#include <cvb/device_factory.hpp>
10#include <cvb/global.hpp>
11#include <cvb/driver/image_stream.hpp>
12
13static const constexpr int DELIVERABLE_COUNT = 10; // Number of deliverables to be acquired
14
15int main()
16{
17 try
18 {
19 // Retrieve CVMockTL in the given system.
20 auto infoList = Cvb::DeviceFactory::Discover(Cvb::DiscoverFlags::IgnoreVins | // Ignores all of the CVB VINs.
21 Cvb::DiscoverFlags::IncludeMockTL // Include CVMockTL.
22 );
23
24 // Make sure if CVMockTL is on the candidate list.
25 Cvb::String accessToken;
26 for (auto n = 0; (n < infoList.size()) && accessToken.empty(); ++n)
27 if (infoList.at(n).AccessToken().find("MockTL") != std::string::npos)
28 accessToken = infoList.at(n).AccessToken();
29
30 if (accessToken.empty())
31 throw std::runtime_error("Could not find CVMockTL.");
32
33 // Instantiate a GenICam device from the CVMockTL.
34 auto device = Cvb::DeviceFactory::Open<Cvb::GenICamDevice>(accessToken, Cvb::AcquisitionStack::GenTL);
35
36 // Get the first stream of the device and start data streaming.
37 auto stream = device->Stream<Cvb::ImageStream>();
38 stream->Start();
39
40 for (auto m = 0; m < DELIVERABLE_COUNT; ++m)
41 {
42 std::cout << "Acquisition #" << m <<"\t";
43
44 // Wait for a single deliverable with a 10-second timeout value.
45 auto waitResult = stream->WaitFor(std::chrono::seconds(10));
46 if (std::get<Cvb::WaitStatus>(waitResult) == Cvb::WaitStatus::Timeout)
47 throw std::runtime_error("Acquisition timeout.");
48
49 // Verify the acquired deliverable contents.
50 auto deliverable = std::get<Cvb::MultiPartImagePtr>(waitResult);
51
52 // Retrieve the images in the deliverable.
53 for (auto n = 0; n < deliverable->NumParts(); ++n)
54 {
55 auto item = deliverable->GetPartAt(n);
56 if (Cvb::holds_alternative<Cvb::ImagePtr>(item))
57 {
58 auto& image = Cvb::get<Cvb::ImagePtr>(item);
59 std::cout << "Image property: Part index: " << n << ", Width : " << image->Width()
60 << ", Height : " << image->Height()<<", ";
61 }
62 }
63 // Retrieve VinBuffer node map
64 auto& enumerator = std::get<Cvb::NodeMapEnumerator>(waitResult);
65 const auto names = enumerator.Names();
66 if (std::all_of(names.begin(), names.end(), [](const Cvb::String& name) { return name != "VinBuffer"; }))
67 throw std::runtime_error("The nodemap enumerator of this container does not contain a VinBuffer node map.");
68 auto nodeMap = enumerator.NodeMap(CVB_LIT("VinBuffer"));
69 // Incompleteness indicates a corrupt buffer
70 auto isIncompleteNode = nodeMap->TryGetNode<Cvb::BooleanNode>(CVB_LIT("IsIncomplete"));
71 std::cout << "IsIncomplete: " << isIncompleteNode->Value() << ", ";
72 // The ID of the frame that is transported in the corresponding buffer
73 auto frameIDNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("FrameID"));
74 std::cout << "FrameID: " << frameIDNode->Value() << ", ";
75 // The total number of bytes written into the buffer
76 auto sizeFilledNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("SizeFilled"));
77 std::cout << "SizeFilled: " << sizeFilledNode->Value() << ", ";
78 // The width of the frame transported in the corresponding buffer
79 auto widthNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("Width"));
80 std::cout << "Width: " << widthNode->Value() << ", ";
81 // The height of the frame transported in the corresponding buffer
82 auto heightNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("Height"));
83 std::cout << "Height: " << heightNode->Value() << ", ";
84 // Padding in x-direction
85 auto xPaddingNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("XPadding"));
86 std::cout << "XPadding: " << xPaddingNode->Value() << ", ";
87 // Padding in y-direction
88 auto yPaddingNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("YPadding"));
89 std::cout << "YPadding: " << yPaddingNode->Value() << ", ";
90 // Timestamp (UINT64) the buffer was acquired
91 auto timestampNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("Timestamp"));
92 std::cout << "Timestamp: " << timestampNode->Value()<<std::endl;
93 }
94 // Try aborting data streaming.
95 stream->TryAbort();
96 }
97 catch (const std::exception& e)
98 {
99 std::cout << e.what() << std::endl;
100 }
101 return 0;
102}
static std::vector< DiscoveryInformation > Discover()
Discovers available devices (not vins) with a default time span of 300ms.
Definition: decl_device_factory.hpp:221
void Start() override
Starts the acquisition.
Definition: decl_composite_stream_base.hpp:349
Streams images.
Definition: image_stream.hpp:20
Node representing a true / false value.
Definition: boolean_node.hpp:19
Represents a integer number.
Definition: integer_node.hpp:20
@ Timeout
A timeout occurred, no image buffer has been returned.