# Force IP of a GEV-Camera programmatically

**URL:** https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957
**Category:** C++ API
**Tags:** genicam
**Created:** [November 15, 2019, 10:45am UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957 "2019-11-15T10:45:36Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![EmKo](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@EmKo](https://forum.commonvisionblox.com/u/EmKo)
#### Post date: [November 15, 2019, 10:45am UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957/1 "2019-11-15T10:45:36Z")

</div>

Hi,  
I’m trying to programmatically set the IP address of a GEV camera.  
I tried to set the IP address as described in this [post](https://forum.commonvisionblox.com/t/how-to-set-a-the-ip-address-of-gev-camera-programmatically-in-cvb/274/5). Unfortunately, an exception is thrown when i run the Cust::IPCfg\_SetStatIP command.

After some research, I found someone who had the same [problem](https://forum.commonvisionblox.com/t/exception-during-discovery/318/16). That did not work either. Again, an exception is thrown when I try to execute the Cust::IPCfg\_SetStatIP.

The strange thing is, when I try to force only the IP, everything looks fine and the value of the “BOOL\_IPCFG\_Successfull” node is true. However, in the Common Vision Blox Management Console -\> Device Configurator, the IP address still does not changed.  
Neither the camera nor the network card are defective. I changed the network card and the camera twice. I can successfully set the IP address in Common Vision Blox Management Console -\> Device Configurator.

Does anyone have some ideas?

---

<div class="post-metadata">

### Author: ![rtp\_derahs](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/rtp_derahs/32/79_2.png) [@rtp\_derahs](https://forum.commonvisionblox.com/u/rtp_derahs)
#### Post date: [November 15, 2019, 2:18pm UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957/2 "2019-11-15T14:18:59Z")

</div>

HI @EmKo,

Did you follow the [answer](https://forum.commonvisionblox.com/t/exception-during-discovery/318/16) given in the post you mentioned?  
Please try to first set the IP with the _ForceIP_ command, then rediscover the camera and do the same thing again but with the _StatIP_ command instead 🙂

---

<div class="post-metadata">

### Author: ![EmKo](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@EmKo](https://forum.commonvisionblox.com/u/EmKo)
#### Post date: [November 15, 2019, 3:11pm UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957/3 "2019-11-15T15:11:42Z")

</div>

Thanks for you reply.

I have already followed the instructions as in the answer you marked.  
But I used the C ++ Api and not the .Net Api.  
ForceIP didn’t set the IP-Address and “BOOL\_IPCFG\_Successfull” returnd true.  
Again executing “IPCfg\_SetStatIP” throw an exception with unknown error.

Have now taken the code from this [answer] ([Exception during discovery](https://forum.commonvisionblox.com/t/exception-during-discovery/318/8)) and copied it one-to-one.  
However, I came across another problem.  
When I invoke DiscoverGevInterfaces(),  
I only see the devices under %CVB%\Drivers.

By the way I’m using CVB version 13.02.002 on Windows 7 (64 bit).

Thank you.

---

<div class="post-metadata">

### Author: ![EmKo](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@EmKo](https://forum.commonvisionblox.com/u/EmKo)
#### Post date: [November 19, 2019, 10:50am UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957/4 "2019-11-19T10:50:27Z")

</div>

Hey,  
with the example (%CVB%Tutorial\Hardware\GenICam\VC\VCGEVForceIP) provided by CVB I managed to change the IP-Address by code. However, I want to use the C++ Api, so I rewrote the ForceIP(…) method and used the C++ methods. But then the example didn’t work anymore. The IP-Address remains the same.

Here are the changes I made:

```auto
void ForceIP_CPP(Cvb::DiscoveryInformation& info, const char *Mac, const char *IP, const char *Subnet)
{
    const auto nm_name = L"TLInterface";

    // set the features accordingly
    wchar_t buf[_MAX_U64TOSTR_BASE10_COUNT];

    auto err = _i64tow_s(StringToMac(Mac), buf, _MAX_U64TOSTR_BASE10_COUNT, 10);
    info.SetGenApiFeature(nm_name, L"IPCfg_MAC", buf);

    err = _ui64tow_s(htonl(String2IP(IP)), buf, _MAX_U64TOSTR_BASE10_COUNT, 10);
    info.SetGenApiFeature(nm_name, L"IPCfg_IP", buf);
    err = _ui64tow_s(htonl(String2IP(Subnet)), buf, _MAX_U64TOSTR_BASE10_COUNT, 10);
    info.SetGenApiFeature(nm_name, L"IPCfg_Subnet", buf);

    info.SetGenApiFeature(nm_name, L"Cust::DisableSubnetMatch", L"1");
    info.SetGenApiFeature(nm_name, L"Cust::AllowBroadcastDiscoveryResponse", L"1");

    //Execute ForceIP
    info.SetGenApiFeature(nm_name, L"IPCfg_SetForceIP", L"1");
}

```

```auto
void Mine(int argc, char* argv[])
{
    auto infos = Cvb::DeviceFactory::Discover(Cvb::DiscoverFlags::IgnoreVins | Cvb::DiscoverFlags::UpToLevelInterface);    

    for (auto& info : infos)
    {
        wstring tlType;
        bool res = info.TryGetProperty(Cvb::DiscoveryProperties::InterfaceTLType, tlType);
        wstring tlVendor;
        res = info.TryGetProperty(Cvb::DiscoveryProperties::TransportLayerVendor, tlVendor);
        if (tlType.compare(L"GEV") == 0 && tlVendor.compare(L"GEV"))
        {
            ForceIP_CPP(info, argv[1], argv[2], argv[3]); 
        }
    }
}
```

---

<div class="post-metadata">

### Author: ![rtp\_derahs](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/rtp_derahs/32/79_2.png) [@rtp\_derahs](https://forum.commonvisionblox.com/u/rtp_derahs)
#### Post date: [November 26, 2019, 9:17am UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957/5 "2019-11-26T09:17:05Z")

</div>

Hi @EmKo,

please make sure to follow the instruction in [this post](https://forum.commonvisionblox.com/t/how-to-set-a-the-ip-address-of-gev-camera-programmatically-in-cvb/274/5) step by step and don’t miss anything! There is always an explanation given why the current step is necessary.  
You e.g. don’t execute the DeviceUpdateList node.

Anyway, it’s strange that you don’t get any error message at all… 🤔

---

<div class="post-metadata">

### Author: ![EmKo](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@EmKo](https://forum.commonvisionblox.com/u/EmKo)
#### Post date: [December 3, 2019, 3:04pm UTC](https://forum.commonvisionblox.com/t/force-ip-of-a-gev-camera-programmatically/957/6 "2019-12-03T15:04:10Z")

</div>

Hey,  
I don’t know why, but this time it worked.  
I think i had problems with my firewall.

If I find out something new, I’ll let you know.

Thank you for your help 🙂
