Why am I unable to use the auto-focus command to focus my DCAM camera in Image Acquisition Toolbox 2.1(R2007a)? I am using the Image Acquisition Toolbox with the WINVIDEO adaptor in order to connect to my DCAM camera. The camera works fine in AMCap, and is in-focus when I first open a PREVIEW window in MATLAB. However, it goes out of focus, as though it were trying to focus on a point far in the distance. In addition, if I send it an auto-focus command, the camera goes into focus, but then again goes out of focus when I execute the START or PREVIEW commands in MATLAB. My camera connects to MATLAB via both a firewire cable, and through a separate cable to the serial port. The camera's "auto-focus" command is sent through the serial port.
Kshitij Singh answered .
2025-11-20
% Create the videoinput object:
vid = videoinput('winvideo',1,'Y800_320x240');
triggerconfig(vid, 'manual');
% Start the acquisition
start(vid)
% Open the preview window (this step can be transposed with the start
command
preview(vid);
% Focus the camera using the SERIAL command
port = 'COM8';
baud = 19200;
databits = 8;
parity = 'none';
stopbits = 1;
terminator = 'CR';
flowcntrl = 'none';
FLIRSerialPortObject = serial(port, 'BAUD', baud, 'DataBits', databits, ...
'Parity', parity, 'FlowControl', flowcntrl, 'StopBits', stopbits, ...
'Terminator', terminator);
fopen(FLIRSerialPortObject);
fprintf(FLIRSerialPortObject, 'autofocus now');
pause(2);
fclose(FLIRSerialPortObject);
% Start an acquisition
trigger(vid);
data = getdata(vid);