Using DeviceFactory.Discover

Hi,

I have just started using CVB and for my first program I thought to write some routines to discover cameras as well as displaying the images. For discovery and displaying the image I am using the very simplified routine below,

private Device _device;

    private Device MyDevice
    {
        get
        {
            return _device;
        }
        set
        {
            if (!ReferenceEquals(value, _device))
            {
                display.Image = value.DeviceImage;
                _device?.Dispose(); 
                _device = value;
            }
        }
    }

    private void Test()
    {
        DiscoveryInformationList foundDevices = DeviceFactory.Discover();

        if (foundDevices.Count > 0)
        {
            MyDevice = DeviceFactory.Open(foundDevices[0]);
        }
    }

Say I have 4 devices on the network which can be discovered. The issue I have is when I choose a device from the foundDevices list and assign it to MyDevice. If after this I try to discover the devices again, I will only see 3 devices remaining. If I assign this device to MyDevice, on the next discovery routine I will only see 2 devices. I expected to discover all 4 devices every time. What am I doing wrong or misunderstand ?

A good number of examples for C-Style API are available, however I have not seen many examples for .Net API. Where can I find more examples of .net API. My aim is to write code for using both Polimago’s tools.

Thanks.

Hi @Farid,

what you see is partly expected.

First, DeviceFactory.Discover filters the list of the devices only showing you the ones that are reachable and not opened. Thus if you discover and open one device, you see one device less on your next discover. And here comes the unexpected part. After disposing of your Device object you should see one device more again. This is at least the behavior I see on my laptop when I just tested it with two devices. Am I right in assuming that you open the devices also in your app and keep them open? That would explain the behavior.

Second, you can configure the discovery case. The default DeviceFactory.Discover() is like calling:

DeviceFactory.Discover(DiscoverFlags.IgnoreGevSD | DiscoverFlags.IgnoreVins)

You can add also other flags. If you want to also see opened devices:

DeviceFactory.Discover(DiscoverFlags.IgnoreGevSD | DiscoverFlags.IgnoreVins | DiscoverFlags.IncludeInaccessible)

If you try to open an open device from another process (i.e. app or computer) it will fail, normally. There are advanced uses cases where this is still possible (like Ethernet multicast). If you open the device again in the same process, DeviceFactory.Open will give you the same object it did for the first call on this device.

The default behavior is to make device usage easier and prevent errors and additional checks on your side.

1 Like

Thank you. It is working fine now, after disposing of the opened devices.