Grabbing continousely with from camera with external trigger

This ist my first CVB project and I think it´s a basic issue but i could not find what I needed in the forum.

I want to grab and save the images sent by two cameras which are connected via GigeVision. The cameras recieve an external trigger signal from a measurement device.

while (cbGrab.Checked)
{
    try
    {
        using (StreamImage image = await Device0.Stream.WaitAsync())
        {
            if (cbSaveImages.Checked)
            {
                var cloneIMG = image.Clone();
                Task t = Task.Run(() => asyncWriteToRingBuffer(cloneIMG, 0, RecPacks[0].iGrabedImages++, DateTime.Now));
            }
            RecPacks[0].iGrabCheck += 1;
        }

            using (StreamImage image = await Device1.Stream.WaitAsync())
            {
                if (cbSaveImages.Checked)
                {
                    var cloneIMG = image.Clone();
                    Task t = Task.Run(() => asyncWriteToRingBuffer(cloneIMG, 1, RecPacks[1].iGrabedImages++, DateTime.Now));
                }
                RecPacks[1].iGrabCheck += 1;
            }
        }
        catch (InvalidOperationException ex)
        {
            Console.WriteLine("Exception in cbGrab: " + ex.Message);
        }
        catch (TaskCanceledException ex)
        {
            Console.WriteLine("Exception in cbGrab: " + ex.Message);
        }
}

(asyncWriteToRingBuffer is my funktion to convert and save the Images)

Problems accure when the Cameras dont get triggers and dont sent images for a while. This is unavoidable in my project. When there are no Images for more than 3 or 4 seconds there will be no more recieved, even if the cameras continue sending after this pause. Nothing else happens. There is no exception thrown or anythis. The streams are still running but do not get any more images.

I assume that the Device objects or their Streams do have an internal timeout which ends the recieving.

At the moment I handle this issue by stopping and restarting the streams of both cameras with a timer if the Cameras don´t sent anything for a while. After this the timeout is resetted and i can wait another 3 seconds for new images bevor i have to restart another time.
Obviously this way is not optimal. When an image arrives just while i restart the streams it might be damaged or lost. When i restart this way it takes up to 1.5 seconds.

Is there a way to avoid this timeout? Or how could i improve my workaround?

Thank you for your support!

Hi @parse32,

the .WaitAsync method does have an internal timeout – 2147483647 milliseconds.
Which should be more than enough time for the stream to still be in a valid state when your next image arrives, so I don’t think that that is the problem.

Does the problem still occur when only using one camera?
Does the problem always happen after the same amount of images, or is it “random”?
Does the problem happen if you remove the image save code and leave only the acquisition part?

I don’t see anything inherently wrong with the code snippet you posted.
Could you maybe try to write a small but complete test program to reproduce this issue?
Since it seems that there is some more than just acquisition going on in your program.

Regards,
Tim

Thank You for Your anwere!

Mean while I found the timeout I was looking for. The GieEVision camera I´m using has an internal Heartbeat Timeout TLDeviceNodeMap[“Cust::HeartbeatTimeout”] which stops the communication when no data is sent for a while. It´s standard value is 3000. I found it here:

https://forum.commonvisionblox.com/t/gvcp-heartbeat-disable/1103?u=parse32

I don´t know if i can deactivate it, but at least i can set it to value 65535 so I have to restart the streams only once a minute to keep it alive.

The number of cameras or the amount of images didn´t affect this issue. But the acquisition part affected the performance and led to less saved images with strong flaws when I receve. So I think about rewriting the code so that I use Events to process the images. I Hope this might boost the performance.

Regrats,
Parse32