Problem of grabbing after a network loss of connection in cvb.net using the class Device

We have a system using 5 GIGE cameras such as Teledyne DALSA Linea.
We use the class Device of CVB.NET via DeviceFactory.Discover(); to initialize them and subscribe to device.Stream to start the acquisition.
We use the code below to detect disconnection and reconnection
device.Notify[NotifyDictionary.DeviceDisconnected].Event += Disconnected;
device.Notify[NotifyDictionary.DeviceReconnect].Event += Reconnect;

The problem is if we disabled and enable the ethernet adapter to simulate a loss of connection
we cannot restart the grabbing of the stream. Any action such as stopping or Aborting the stream result in a crash. It seems the the device and stream are corrupted.

We are under Windows Server 2016 Standard x64
We use CVB 13.04.005 (64-bit)

Have you a solution to regrab on a device stream after a Network deconnection that works ?

Best regards

Emilio

Hi @Emilio

could you describe what exactly you are doing in Disconnected and Reconnect (i.e. code snippet).

Hi Mister Hartmann
My code is inspired by the cvb monitoring example that you can find here:
https://help.commonvisionblox.com/GenICam-User-Guide/index.html?html_english_genicam_connectionmonitoring_english.htm

I change the IMG object to a Device object
here is what I do in Disconnect and Reconnect. It only logging and change the IsConnected boolean variable:

private void Disconnected(object sender, NotifyEventArgs e)
{
try
{
IsConnected = false;
Task.Run(() =>
{
Console.WriteLine($" Device disconnected");
});
}

            catch (CvbException ex)
            {
                Console.WriteLine($"Disconnected exception{ex.Message}");
            }
        }
        public virtual void Reconnect(object sender, NotifyEventArgs e)
        {
            try
            {

                IsConnected = true;
                Task.Run(() =>
                {
                    Console.WriteLine($" Device reconnected");
                });


            }
            catch (CvbException ex)
            {
                Console.WriteLine($"Reconnect exception{ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Reconnect exception{ex.Message}");
            }

        }

then I have a task that tries to stop the stream after a reconnection when IsConnected becomes true again;

        void Unload()
        {
            try
            {
                if (_handle.Stream.IsRunning)
                {
                    Console.WriteLine("Stream.IsRunning");
                    while (true)
                    {
                        Console.WriteLine("TryStop stream");
                        var result = _handle.Stream.TryStop();
                        if (result)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {

                Console.WriteLine("Exception in Dispose");
            }

            Console.WriteLine("Camera unloaded!");
        }

but the line var result = _handle.Stream.TryStop();
results on an unhandled exception.

Hi,

thanks for the code. We will take a look.

Hi @Emilio

could you do me a favour and test the following code:

var device = DeviceFactory.Open("GenICam.vin"); 
device.Notify[NotifyDictionary.DeviceDisconnected].Event += Disconnect; 
device.Notify[NotifyDictionary.DeviceReconnect].Event += Reconnect;  

private static void Disconnect(object sender, NotifyEventArgs e) 
{ 
Console.WriteLine("Device disconnected"); 
// do stuff 
} 

private static void Reconnect(object sender, NotifyEventArgs e) 
{ 
Console.WriteLine("Device reconnected"); 
// do stuff 
}

It would be great, if you could test this by unplugging the loaded camera from you machine and then plugging it back in. This at least was tested and should work.

Let me know if you have new information on this.

Cheers
Chris

Hi Chris !
I have already tested that and the notification works at the deconnection and reconnection.
The problem is when I have a running Stream.
When i add this line after the construction of the device: device.Stream.Start();
Add I try to disable and enable the Ethernet Adapter the program crash after the reconnection

What I understand it that unplugging and repluging the camera has not the same behavior that disabling/enabling the ethernet adapter

Best regards

Emilio

Hi @Emilio
thanks for the info.

I tested with disabling network interfaces years ago, it worked then.
But essentially disabling the interface might remove resources the driver needs.

Your use-case just includes normal connection loss, right?
And you just want to simulate that?
Instead of disabling the network interface you could simply block ALL(!) UDP packet via the firewall?

I.e. block application specific ofcourse :expressionless:

Hi @c.hartmann .
Thanks for the advice you are right, disabling the network adapter to simulate a loss of connection is corrupting the camera driver. I will continue my tests with a manual disconnection of the camera ethernet cable or as you said blocking UDP packets. Do you know if it’s possible to only block UDP packets from only one specific camera ?
Best regards

Emilio

Hi @Emilio

I would not not block a specific camera, simply because GigE Vision uses dynamic ports (which is communicated/negotiated in a “bootstrap” mechanism).

Instead i would block specific applications or network adapter.

i know how to do it with the gui, but sadly i can’t help you with a console command.
But this is standard network stuff. There should be plenty of material about it.

Sorry.

Theoretically it is possible to read the used ports for communication (for control and streaming) in the camera and then block these ports.

Hi @c.hartmann
Thank for the advice. I found a way. I disable/enable IPv4 in the Network adapter of the camera and that works to simulate a connection loss.
Best regards

2 Likes