Exception during discovery

@Adam I think I might be able to answer your questions.
Let’s jump right in:
How did you verify that the IP is not updated? As @parsd pointed out, ForceIP only updates the adress until the next power cycle.
After running the code above, I have used the GenICamBrowser to check the IP of the camera. With my test setup the program did successfully change the IP adress of the camera temporarily.

I was also able to reproduce the writememory error from your earlier post. After ForceIP the camera has to be rediscovered, because it has a new IP now and it cannot be accessed through the old one anymore.

The additional code needed looks almost identical to Step 4 in the tutorial above:

ifaceToOpen = allInterfaces
  .First(iface => iface[DiscoveryProperties.InterfaceId] == cam[DiscoveryProperties.InterfaceId]);
using (var ifaceDevice = DeviceFactory.Open(ifaceToOpen))
{
  StatIP(ifaceDevice.NodeMaps[NodeMapNames.Interface], cam, newIP);
}

StatIP is implemented as follows:

static void StatIP(NodeMap iface, DiscoveryInformation camera, IPAddress newIP)
{
  var macAddress = PhysicalAddress.Parse(camera[DiscoveryProperties.DeviceMac]);
  var subnet = GetInterfaceSubnetMask(camera);
  var updateDeviceList = iface["Std::DeviceUpdateList"] as CommandNode;
  updateDeviceList.Execute();

  var cfgMac = iface["Cust::IPCfg_MAC"] as IntegerNode;
  cfgMac.Value = MacToInt(macAddress);
  var cfgIP = iface["Cust::IPCfg_IP"] as IntegerNode;
  cfgIP.Value = IPToInt(newIP);
  var cfgSubnet = iface["Cust::IPCfg_Subnet"] as IntegerNode;
  cfgSubnet.Value = IPToInt(subnet);
  var cfgStatIP = iface["Cust::IPCfg_SetStatIP"] as CommandNode;
  cfgStatIP.Execute();
}
4 Likes