Why am I getting a timeout when using getsnapshot?

87 views (last 30 days)
jonathan
jonathan on 17 Oct 2013
Edited: John Kelly on 28 Nov 2017
I'm currently using a GigE camera using a pleora PT1000 IP engine with Matlab 2012a. I've successfuly been able to grab and display images as a realtime video with Matlab's image acquistion toolbox. However, I'm running into a timeout error when I use my code. It's not predictable since the amount of time it took for the error to occur went from anywhere between 9 seconds to 7 minutes with no apparent pattern. When I get the error, all I do is imaqreset and then run the code again to display video until I get the error again. My code is shown below. If anyone has has an idea as to what is going on, help would greatly be appreciated. Thank you.
%Camera setup
vid = videoinput('gige',1,'Mono16'); src = getselectedsource(vid); vid.FramesPerTrigger = inf; vid.FrameGrabInterval = 3; src.PacketSize = '9014'; start(vid);
%image setup
h = imagesc(zeros(480,640)); axis image; axis off;
%Load .mat files of processRAW parameters
load 'gain.mat'; load 'bias.mat'; load 'r.mat'; load 'badmap.mat'; load 'bbimages.mat'; load 't.mat';
tic
while 1,
%Error check so buffer doesn't overflow
if imaqmem('FrameMemoryUsed') < 100000000
%Check memory
imaqmem
%Grab a frame, if timeout occurs display how long process took
try
liveFeed = getsnapshot(vid);
catch
toc
return;
end
%Process image
[S rawData] = processRAW(liveFeed,gain,bias,r,badmap,bbimages);
%Format data for displaying
R = single(S(:,:,1));
R(R<280)=275;
R(R>300)=285;
%Display image, end program if window is closed
try
set(h,'cdata',R);
drawnow;
catch
break;
end
%If buffer nearing capacity, clear the data and continue process
else
flushdata(vid);
liveFeed = getsnapshot(vid);
[S rawData] = processRAW(liveFeed,gain,bias,r,badmap,bbimages);
R = single(S(:,:,1));
R(R<280)=275;
R(R>300)=285;
set(h,'cdata',R);
drawnow;
end
end
%Reset camera
flushdata(vid); stop(vid); delete(vid); imaqreset;

Accepted Answer

Mark Jones
Mark Jones on 23 Oct 2013
Edited: John Kelly on 28 Nov 2017
Hi Jonathan,
I would encourage you to try setting the camera to use manual triggering when using GETSNAPSHOT in a loop, as shown here:
Also, you may need to properly set the PacketDelay property on the source given the expected bandwidth for the image size and format, and PacketSize in order to avoid reliability issues. Also, you should ensure you have set the receive buffers (descriptors) as high as possible (likely 2048) as described here:
The technical support department can assist you with calculating a proper PacketDelay value.
Mark
  1 Comment
jonathan
jonathan on 25 Oct 2013
It seems that setting the PacketDelay to the correct value fixed the issue. I'm still unsure if my PacketSize is set to the correct value, but setting a high enough delay allows my PacketSize of 9014 to work fine. Here is what I used to determine the PacketDelay:
Thank you for your advice!
Jonathan

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!