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

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

main.cpp:

// Example for discovering all your interfaces (NICS & USB HCs).
// currently there is no way to filter out USB HCs
#include <cvb/device_factory.hpp>
#include <cvb/driver/driver.hpp>
#include <cvb/image.hpp>
#include <cvb/utilities/utilities.hpp>
#include <cvb/composite.hpp>
#include <cvb/driver/multi_part_image.hpp>
#include <cvb/plane_enumerator.hpp>
#include <cvb/point_cloud.hpp>
#include <iostream>
int main() {
auto interfaceInfoList = Cvb::DeviceFactory::Discover(
Cvb::DiscoverFlags::IgnoreGevFD |
Cvb::DiscoverFlags::IgnoreVins |
Cvb::DiscoverFlags::UpToLevelInterface,
std::chrono::milliseconds(2000));
for (int i = 0; i < interfaceInfoList.size(); i++)
{
std::string mac = "No MAC available";
interfaceInfoList[i].TryGetProperty(Cvb::DiscoveryProperties::InterfaceMac, mac);
std::cout << mac << " | Index: " << i << std::endl;
}
std::cout << "Please enter the index of the interface your device is connected to:" << std::endl;
std::cout << "(You can check the mac addresses in the GenICamBrowser)" << std::endl;
int index = -1;
std::cin >> index;
while (index < 0 || index > interfaceInfoList.size() || std::cin.fail())
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid index, please enter a valid number:" << std::endl;
std::cin >> index;
}
auto& interfaceInfo = interfaceInfoList[index];
// Do a broadcast discovery and allow devices from another subnet to answer.
interfaceInfo.SetGenApiFeature(CVB_LIT("TLInterface"), CVB_LIT("Cust::DisableSubnetMatch"), CVB_LIT("1"));
interfaceInfo.SetGenApiFeature(CVB_LIT("TLInterface"), CVB_LIT("Cust::AllowBroadcastDiscoveryResponse"), CVB_LIT("1"));
// Discover again only devices connected to your interface!
// Include also devices that are inaccessible (might be because they are in use or in a different subnet)
Cvb::DiscoverFlags::IgnoreGevFD |
Cvb::DiscoverFlags::IgnoreVins |
Cvb::DiscoverFlags::UpToLevelDevice |
Cvb::DiscoverFlags::IncludeInaccessible,
std::chrono::milliseconds(2000));
{
auto interfaceDevice = Cvb::DeviceFactory::Open(interfaceInfo.AccessToken());
auto interfaceNM = interfaceDevice->NodeMap(CVB_LIT("TLInterface"));
// get all required nodes
auto deviceUpdateListNode = interfaceNM->Node<Cvb::CommandNode>(CVB_LIT("DeviceUpdateList"));
auto ipNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("GevDeviceForceIPAddress"));
auto subnetNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("GevDeviceForceIPSubnetMask"));
auto forceIPNode = interfaceNM->Node<Cvb::CommandNode>(CVB_LIT("GevDeviceForceIP"));
auto configurationStatusNode = interfaceNM->Node<Cvb::EnumerationNode>(CVB_LIT("GevDeviceIPConfigurationStatus"));
// make node map aware of the device
deviceUpdateListNode->Execute();
// we want to set the ip static, but before, it has to be set temporarily
// needs to be set before ip so ip node is writeable
configurationStatusNode->SetValue("TemporaryIP");
// IP can be 10.0.0.2.
ipNode->SetValue(0x0A000002);
// Subnet 255.255.255.0
subnetNode->SetValue(0xFFFFFF00);
// Force the new IP
forceIPNode->Execute();
// make node map aware of new IP
deviceUpdateListNode->Execute();
// now we can set it persistently
configurationStatusNode->SetValue("PersistentIP");
// same address
ipNode->SetValue(0x0A000002);
// Subnet 255.255.255.0
subnetNode->SetValue(0xFFFFFF00);
// Force the new IP
forceIPNode->Execute();
// make node map aware of new IP
deviceUpdateListNode->Execute();
}
};
// 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()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
void SetValue(std::int64_t value)