How to set a the IP-Address of GEV-Camera programmatically in CVB

Please imagine the following scenario. Due to some reasons a camera needs to be replaced by the costumer. As long the same camera type is used all camera parameter can be easily applied to the new camera, if and only if the communication to the camera can be established. This can be only done if the camera has the right ip-address. I have heart that with CVB 13 there is also a way to discover new devices and set the ip-address programmatically. How do this with C++ on a win 64 system?

Cheers
Gregor

1 Like

Hi Gregor,

you can either do it through the discovery interface but I would propose to use the network interface. So you basically discover the network interface the camera is connected to using the DOxx functions and then open a device object via LoadDeviceObject with that interface. This object then carries a INodemap2 on which you have the nodes to set the IP of the camera.
In order to set the ip to static you need to set the nodes

  • IPCfg_IP
  • IPCfg_Subnet
  • IPCfg_Gateway

and then execute the IPCfg_SetStatIP.

This can only be done if the camera is already accessable on the local subnet. If that is not the case you need to do a ForceIP first.

Hope that helps.

2 Likes

Hi dusalf,

thank you very much for hint. I will give it a try over the weekend.
cheers
Gregor

just to mention because I just ran into that: before you set the according nodes in the interface nodemap you have to update the interface device list. So the nodes you have to set are:

DeviceUpdateList
// this updates the internal device list. After the execution the available devices are in the interface nodemap

IPCfg_IP
IPCfg_Subnet
IPCfg_Gateway
IPCfg_MAC

Be aware of the endianess. So in order to set the IP 169.254.3.4 you set 0xa9FE0304 (because this is handled as a normal int) but in order to set the MAC 00:01:0D:C2:3F:A1 you need to set the mac to 0xa13fc20d0100 (because this is a stream of bytes).
After you have done that you can apply the

IPCfg_SetStatIP

command.

Regards

It has been a wile but as you explicitly asked for C++…

Here is how you can set a static / persistent IP in a camera that is not in your NIC’s subnet with CVB++ (basically what you do with the GenICam Browser)

// discover all your interfaces (NICS & USB HCs)
// currently there is no way to filter out USB HCs
auto interfaceInfoList = Cvb::DeviceFactory::Discover(
      Cvb::DiscoverFlags::IgnoreGevSD | 
      Cvb::DiscoverFlags::IgnoreVins | 
      Cvb::DiscoverFlags::UpToLevelInterface,
      std::chrono::milliseconds(2000));


// Given you know your interface index (GenICam Browser can list them all!)
const int MY_IF = 4;
auto& interfaceInfo = interfaceInfoList[MY_IF];

// 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 you interface! 
    // Include also devices that are inaccessible (might be because they are in use or in a different subnet)
    Cvb::DeviceFactory::Discover(interfaceInfo,
      Cvb::DiscoverFlags::IgnoreGevSD |
      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 deviceMacNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("DeviceMAC"));
      auto cfgIPNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("IPCfg_IP"));
      auto cfgSubnetNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("IPCfg_Subnet"));
      auto cfgMacNode = interfaceNM->Node<Cvb::IntegerNode>(CVB_LIT("IPCfg_MAC"));
      auto cfgForceNode = interfaceNM->Node<Cvb::CommandNode>(CVB_LIT("IPCfg_SetForceIP"));
      auto cfgStaticNode = interfaceNM->Node<Cvb::CommandNode>(CVB_LIT("IPCfg_SetStatIP"));

      // make node map aware of the device
      deviceUpdateListNode->Execute();
      // we want to configure the found device
      cfgMacNode->SetValue(deviceMacNode->Value());
      // IP 10.0.0.1 (given that your NIC has a suitable address like 10.0.0.2)
      cfgIPNode->SetValue(0x0A000001);
      // Subnet 255.255.255.0
      cfgSubnetNode->SetValue(0xFFFFFF00);
      // Force the new IP
      cfgForceNode->Execute();
      // make node map aware of new IP
      deviceUpdateListNode->Execute();
      // permanently write the IP to the camera
      cfgStaticNode->Execute();
}

// Done, now you can see in the GC Browser, that the camera is in the same subnet as the NIC
4 Likes

Hello @Andreas,
I am trying to do the same in C#. I follow your logic, but can’t manage the same steps, things start to go wrong at

auto& interfaceInfo = …

I assume this is different due to the standard CVB versus CVB++

I can detect the interface that I want to use and I think I am detecting a camera that is not in the subnet - but I am not at all sure.

Any clues would be gratefully received.

Hi @LincolnshirePoacher,

I did this in this post with CVB. Net:

https://forum.commonvisionblox.com/t/exception-during-discovery/318/8?u=parsd

2 Likes

@parsd, thank you for the pointer, I will take a look

@parsd - Your CVB.NET instruction ‘recipe’ is great, I am really impressed.

1 Like

Thank you, I am glad it helped! :handshake: