CVB++ 14.0
Cvb/CameraConfig
1// ---------------------------------------------------------------------------
4// ---------------------------------------------------------------------------
5
6
7#include <iostream>
8
9#pragma warning(push)
10#pragma warning(disable : 4127)
11
12
13#pragma warning(pop)
14
15#include <cvb/device_factory.hpp>
16
20Cvb::NodeMapPtr DataStreamNodeMap(Cvb::DevicePtr dev)
21{
22 // Get all nodemaps
23 auto nodeMaps = dev->NodeMaps();
24 //for (std::map<Cvb::String, Cvb::NodeMapPtr>::iterator it = nodeMaps.begin(); it != nodeMaps.end(); ++it)
25 // std::cout << it->first << std::endl;
26 return dev->NodeMap("TLDatastream");
27}
28
32int64_t LostFrames(Cvb::DevicePtr dev)
33{
34 if (auto dataStreamNodeMap = DataStreamNodeMap(dev))
35 {
36 auto node = dataStreamNodeMap->Node<Cvb::IntegerNode>(Cvb::String("Cust::NumBuffersLost"));
37 std::cout << "Number of lost frames: " << node->Value() << std::endl;
38 return node->Value();
39 }
40 return 0;
41}
42
46void EnablePacketResend(Cvb::DevicePtr dev)
47{
48 if (auto dataStreamNodeMap = DataStreamNodeMap(dev))
49 {
50 if (auto node = dataStreamNodeMap->Node<Cvb::BooleanNode>(Cvb::String("EnablePacketResend")))
51 {
52 node->SetValue(true);
53 std::cout << "Successfully enabled packet resend." << std::endl;
54 }
55 }
56}
57
61void DiscardCorruptFrames(Cvb::DevicePtr dev)
62{
63 if (auto dataStreamNodeMap = DataStreamNodeMap(dev))
64 {
65 if (auto node = dataStreamNodeMap->Node<Cvb::BooleanNode>(Cvb::String("PassCorruptFrames")))
66 {
67 try
68 {
69 node->SetValue(false);
70 std::cout << "Successfully disabled passing corrupt frames." << std::endl;
71 }
72 catch (const std::exception & e)
73 {
74 std::cout << "Pass Corrupt Frames: Error disabling feature!" << std::endl;
75 }
76 }
77 }
78}
79
80
81int main(int argc, char* argv[])
82{
83 auto path = Cvb::InstallPath();
84 path += CVB_LIT("drivers/GenICam.vin");
85 // use command line argument if provided.
86 if (argc > 1)
87 {
88 std::string inputPath(argv[1]);
89 path = Cvb::String(inputPath.begin(), inputPath.end());
90 }
91
92 Cvb::DevicePtr dev = nullptr;
93 try
94 {
95 // open a device
96 dev = Cvb::DeviceFactory::Open(Cvb::ExpandPath(path), Cvb::AcquisitionStack::Vin);
97 }
98 catch (const std::exception& error)
99 {
100 std::cout << "Failed to open the device: " << error.what() << std::endl;
101 return 1;
102 }
103
104 // get the number of lost frames
105 auto lostFrames = LostFrames(dev);
106
107 // enable packet resend to increase performance
108 EnablePacketResend(dev);
109
110 // discard corrupt frames
111 DiscardCorruptFrames(dev);
112
113 return 0;
114}
115
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given provider with its default board and port (if applicable).
Definition: decl_device_factory.hpp:50
Node representing a true / false value.
Definition: boolean_node.hpp:19
Represents a integer number.
Definition: integer_node.hpp:20
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:45