I could solve it by using evalc
in MATLAB using
evalc('img = getsnapshot(obj);')
instead of
img = getsnapshot(obj);
in the above code :-)
質問
That's why I coded a wrapper-function which tries to handle the error so that in case of a dropped frame, it simply get's captured again and doesn't abort the running code:
function img = getsnapshotfcn(obj, maxRetries, pausing)
% Default args
if(nargin < 3)
pausing = 4; % in sec
end
if(nargin < 2)
maxRetries = 20;
end
% Try to capture snapshot...
i = 0;
while(1)
i = i+1;
try
img = getsnapshot(obj);
% success? -> break loop
break;
catch err
% Pause shortly before retry
pause(pausing);
end
% maxRetries reached? -> error
if(i > maxRetries)
error('snapshot:maxRetriesReached', 'blaaa...');
end
end
end
When now using getsnapshotfcn()
I'm sometimes still still getting the above posted error message shown in the console and I'm wondering why. I didn't expect the error to disappear (and please don't help me about this, I already know that I need to set the PacketDelay
which I already did but in rare occasions it still happens even though running on a fast CPU) but I expected it to NOT being displayed as I expected it to simply be catched via try-catch
.
What could be the case it's still being shown in the console? Thank you very much in advance.
解決
I could solve it by using evalc
in MATLAB using
evalc('img = getsnapshot(obj);')
instead of
img = getsnapshot(obj);
in the above code :-)