CVB++ 14.1
Cvb/CppCameraIPConfig
1// discover all your interfaces (NICS & USB HCs)
2// currently there is no way to filter out USB HCs
3
4#include <cvb/device_factory.hpp>
5#include <cvb/driver/driver.hpp>
6#include <cvb/image.hpp>
7#include <cvb/utilities/utilities.hpp>
8#include <cvb/composite.hpp>
9#include <cvb/driver/multi_part_image.hpp>
10#include <cvb/plane_enumerator.hpp>
11#include <cvb/point_cloud.hpp>
12
13#include <iostream>
14
15
16int main() {
17
18 auto interfaceInfoList = Cvb::DeviceFactory::Discover(
19 Cvb::DiscoverFlags::IgnoreGevFD |
20 Cvb::DiscoverFlags::IgnoreVins |
21 Cvb::DiscoverFlags::UpToLevelInterface,
23
24 for (int i = 0; i < interfaceInfoList.size(); i++)
25 {
26 std::string mac = "No MAC available";
27 interfaceInfoList[i].TryGetProperty(Cvb::DiscoveryProperties::InterfaceMac, mac);
28 std::cout << mac << " | Index: " << i << std::endl;
29 }
30
31 std::cout << "Please enter the index of the interface your device is connected to:" << std::endl;
32 std::cout << "(You can check the mac addresses in the GenICamBrowser)" << std::endl;
33 int index = -1;
34 std::cin >> index;
35 while (index < 0 || index > interfaceInfoList.size() || std::cin.fail())
36 {
37 std::cin.clear();
39 std::cout << "Invalid index, please enter a valid number:" << std::endl;
40 std::cin >> index;
41 }
42
43 auto& interfaceInfo = interfaceInfoList[index];
44 // Do a broadcast discovery and allow devices from another subnet to answer.
45 interfaceInfo.SetGenApiFeature(CVB_LIT("TLInterface"), CVB_LIT("Cust::DisableSubnetMatch"), CVB_LIT("1"));
46 interfaceInfo.SetGenApiFeature(CVB_LIT("TLInterface"), CVB_LIT("Cust::AllowBroadcastDiscoveryResponse"), CVB_LIT("1"));
47
48 // Discover again only devices connected to your interface!
49 // Include also devices that are inaccessible (might be because they are in use or in a different subnet)
50 Cvb::DeviceFactory::Discover(interfaceInfo,
51 Cvb::DiscoverFlags::IgnoreGevFD |
52 Cvb::DiscoverFlags::IgnoreVins |
53 Cvb::DiscoverFlags::UpToLevelDevice |
54 Cvb::DiscoverFlags::IncludeInaccessible,
56 {
57 auto interfaceDevice = Cvb::DeviceFactory::Open(interfaceInfo.AccessToken());
58 auto interfaceNM = interfaceDevice->NodeMap(CVB_LIT("TLInterface"));
59
60 // get all required nodes
61 auto deviceUpdateListNode = interfaceNM->Node<Cvb::CommandNode>(CVB_LIT("DeviceUpdateList"));
62 auto ipNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("GevDeviceForceIPAddress"));
63 auto subnetNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("GevDeviceForceIPSubnetMask"));
64 auto forceIPNode = interfaceNM->Node<Cvb::CommandNode>(CVB_LIT("GevDeviceForceIP"));
65 auto configurationStatusNode = interfaceNM->Node<Cvb::EnumerationNode>(CVB_LIT("GevDeviceIPConfigurationStatus"));
66
67 // make node map aware of the device
68 deviceUpdateListNode->Execute();
69 // we want to set the ip static, but before, it has to be set temporarily
70 // needs to be set before ip so ip node is writeable
71 configurationStatusNode->SetValue("TemporaryIP");
72 // IP can be 10.0.0.2.
73 ipNode->SetValue(0x0A000002);
74 // Subnet 255.255.255.0
75 subnetNode->SetValue(0xFFFFFF00);
76 // Force the new IP
77 forceIPNode->Execute();
78 // make node map aware of new IP
79 deviceUpdateListNode->Execute();
80
81 // now we can set it persistently
82 configurationStatusNode->SetValue("PersistentIP");
83
84 // same address
85 ipNode->SetValue(0x0A000002);
86 // Subnet 255.255.255.0
87 subnetNode->SetValue(0xFFFFFF00);
88 // Force the new IP
89 forceIPNode->Execute();
90 // make node map aware of new IP
91 deviceUpdateListNode->Execute();
92
93 }
94};
95// Done, now you can see in the GC Browser, that the camera is in the same subnet as the NIC
static std::vector< DiscoveryInformation > Discover()
Discovers available devices (not vins) with a default time span of 300ms.
Definition: decl_device_factory.hpp:221
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:55
A node that can be executed.
Definition: command_node.hpp:20
A node that presents a choice of values.
Definition: enumeration_node.hpp:18
Represents a integer number.
Definition: integer_node.hpp:20
void SetValue(std::int64_t value)
Sets the value of this integer node.
Definition: integer_node.hpp:46