Problem using start and getsnapshot

8 views (last 30 days)
Emilie
Emilie on 12 Feb 2024
Commented: Emilie on 12 Feb 2024
Hello,
I am trying to take pictures with a Basler Camera using a trigger sent by an Arduino card via the serial port (the camera and the arduino are connected to my laptop but are not connected together).
My code works sometimes, but most of the time it doesn't... I keep getting various error messages from my code, but I can't find the solution. I also have to unplug and plug again the arduino card everytime I want to run my code.
Here is an example of an error message I get:
Error using imaqdevice/start
Multiple image acquisition objects cannot access the same device simultaneously.
Error in testTriggerBasic (line 7)
start(vid);
Warning: Error updating Image.
Here is my code:
s=serialport('COM4', 9600);
vid=videoinput("gentl",1,"Mono8");
triggerconfig(vid,"immediate"); %I don't if this line is necessary%
start(vid);
stopprog=0;
while stopprog<100000 %I did this just so that the loop would end and the last lines could be executed
if s.NumBytesAvailable>0
data=read(s,s.NumBytesAvailable, 'uint8');
image=getsnapshot(vid);
imshow(image)
end
stopprog=stopprog+1;
end
stop(vid);
delete(vid);
clear(vid);
clear(s);
Thank you for your help.

Answers (1)

Walter Roberson
Walter Roberson on 12 Feb 2024
You have an existing videoinput active. For example you might have used control-C to stop acquisition, and so missed out on deleting the object.
The easiest approach is to exit MATLAB and restart it.
  1 Comment
Emilie
Emilie on 12 Feb 2024
Thank you for your answer, but even after restarting matlab and making sure the videoinput wasn't active, I still get the same error message... I managed to make it work once this morning but I have no idea how.

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!