Code covered by the BSD License  

Highlights from
Fire-Wire (DCAM IEEE 1394) camera control

image thumbnail

Fire-Wire (DCAM IEEE 1394) camera control

by

 

24 Sep 2009 (Updated )

Graphical user interface supports your image acquisition session

FWControl(varargin)
function varargout = FWControl(varargin)
%   FWControl - launch a GUI to control Fire-Wire (1394 DCAM) image acquisition session:
% < this application evolved from the VideoControl application >
%   The GUI will help you in:
%       craeting the video object,
%       previewing and snap shotting,
%       controlling acquisition parameters,
%       saving data to a file, creating movies and more...
%   The video object constructor is: videoinput('dcam', 1, 'F7_Y8_1360x1024'); -
%   you can find that line of code in function 'pbVideoInput_Callback'
%   below...
%   NOTE:   Begin session by pressing the 'VideoInput' pushbutton to create the video object.
%                  Most controls (push-buttons etc...) will do nothing unless such a video object exists!!!
%   NOTE:   The application sends its messages to the MATLAB environment.
%                  You should keep the MATLAB environment visible. Suggestion: work
%                  with the GUI docked to the MATLAB window (small arrow
%                  on upper-right corner of the window)
%
%   Quick start:
%       1. Press VideoInput (wait untill the label changes to: 'Delete VideoInput').
%       2. Press Preview (you should see the video stream from the camera,
%           the label changes to: 'Close Preview').
%       3. Press FramesAcquired (=0), FramesAvailable (=0), IsRunning (No), IsLogging (No) -
%           all answers appear in the Matlab environment.
%       4. Press START (the acquisition begins with default parameters: FramesPerTrigger=10 etc...).
%       5. Press FramesAcquired (=10), FramesAvailable(=10).
%       6. Press GetData (to get the acquired data from the video object).
%       7. Press Save ( a dialog box appears suggesting a file-name composed from the Test name and
%           the time yyyymmdd_HHMMSS).
%       8. Press ImageDisplay (it should load another independent GUI to view what you created in FWControl).
%
%   Acquisition:
%       Edit the fields: FrameGrabInterval (take a frame every X frames),
%       FramesPerTrigger, TriggerRepeat (the system expects 1+TriggerRepeat triggers after START),
%       TriggerFrameDelay (number of frames to skip after trigger).
%       Note: When video object is created it always has the defaults values,
%       regardless of what is written in the edit fields.
%   Source:
%       From this pannel you can control Automatic gain, Brightness, Contrast and
%       ROI (Region of interest - the portion of the image that will be acquired).
%   Action:
%       START - make the video object running (ready for logging upon
%       trigger)
%       Trigger - useful at manual trigger only, begins logging.
%       STOP - stop the video object from running.
%       GetData - bring acquired data from video object to the MATLAB
%       environment. You can not save data unless you pressed it before!
%       Save - save the acquired data to a file. You can change the
%       suggested file name as you like.
%       ImageDisplay - launch an independent GUI to display images of the
%       unique structure preduced by FWCONTROL.
%   PowerMeter - I am not sure about the validity of this feature.
%       However it is advised to set the source to AutomaticGain=OFF.
%       The exposure time of your camera is also important - it should not be auto.
%   Trigger:
%       Immediate - begin logging immediately after you will press START.
%       Manual - begin logging after you will press TRIGGER.
%       Hardware (4 options) - begin logging upon the selected signal.
%
%   Logging:
%       LoggingMode - 'memory' (producing data structure that will be saved by SAVE),
%       'disk&memory' (creating also an .avi file) or 'disk'.
%       Compression - select the compression algorithm for the .avi file.
%       Quality [1-100] - select the quality of the compression of the .avi file.
%       FramesPerSecond - .avi file property.
%       CreateAviFile - Only when you are logging to disk. Do not forget to
%       create .avi file before you start logging to a disk. Also, you will
%       not be able to open the .avi file unless you closed it
%       (the push button label changes to CloseAvi. Press it to close the
%       new .avi file).
%
%   MENU:
%       On the menu bar you have 'Trigger' and 'Info' to display the status
%       of the video object, video source and trigger info. If your window
%       is docked into the MATLAB window, the menus will join the MATLAB
%       menu bar on top of the window.
%
%   Data structure:
%       If you had for example 3 triggers with 11 frames per trigger you will create a
%       cell array of length 3.
%       Let us call the data structure 'd', so all the data from a single trigger
%       is stored in:
%       d{#trigger}.frames - this is a 4 dimensional array with (rows,
%       columns, bands, frame_index).
%       The GUI ImageDisplay is designed to display
%       that data structure.
%
%       Shmuel Ben-Ezra, Sep 2007, UltraShape, Yokneam, ISRAEL 
%       (current version: Sep 2009)
%       www.ultrashape.com

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @FWControl_OpeningFcn, ...
    'gui_OutputFcn',  @FWControl_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
%% --- Executes just before FWControl is made visible.
function FWControl_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to FWControl (see VARARGIN)
%
% Choose default command line output for FWControl
handles.output = hObject;
% my global definitions:
handles.data = [];
handles.aviobj =[];
imaqreset
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FWControl wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%% --- Outputs from this function are returned to the command line.
function varargout = FWControl_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure:
varargout{1} = handles.output;
%% --------------------------------------------------------------------
function miFramesPerTrigger_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
fpt = num2str(get(handles.vid, 'FramesPerTrigger'));
disp([' Frames per trigger: ', fpt]);
return
%% --------------------------------------------------------------------
function miTriggerType_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
t = get(handles.vid, 'TriggerType');
disp([' Trigger type: ', t]);
return
%% --------------------------------------------------------------------
function miTriggerCondition_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
tc = get(handles.vid, 'TriggerCondition');
disp([' Trigger condition: ', tc]);
return
%% --------------------------------------------------------------------
function miTriggerSource_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
ts = get(handles.vid, 'TriggerSource');
disp([' Trigger source: ', ts]);
return
%% --------------------------------------------------------------------
function menuTrigger_Callback(hObject, eventdata, handles)
%% --- Executes on button press in pbVideoInput.
function pbVideoInput_Callback(hObject, eventdata, handles)
if get(hObject, 'userdata') == 0, % video is closed maybe use isa or isvalid?
    imaqreset;
    handles.vid = videoinput('dcam', 1, 'F7_Y8_1360x1024'); % next:info=imaqhwinfo('dcam'), formats = info.DeviceInfo.SupportedFormats; vid = videoinput('dcam', 1, formats{3})
    %handles.vid = videoinput('dcam', 1, 'F7_Y8_680x512');
    handles.source = getselectedsource(handles.vid);
    set(hObject, 'string', 'Delete VideoInput');
    set(hObject, 'userdata', 1);
    set(handles.source, 'ShutterMode', 'manual');% my preferences
    set(handles.source, 'ShutterControl', 'Absolute');% my preferences
    guidata(hObject, handles);
    return
else
    delete(handles.vid);
    clear handles.vid;
    set(hObject, 'string', 'VideoInput');
    set(hObject, 'userdata', 0);
    set(handles.pbPreview, 'userdata', 0, 'string', 'Preview');
    %set(handles.pbCreateSource, 'userdata', 0, 'string', 'CreateSource');
    guidata(hObject, handles);
    return
end
%% --- Executes on button press in pbPreview.
function pbPreview_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if get(hObject, 'userdata') == 0, %preview is OFF
    if strcmp(handles.vid.TriggerType, 'hardware'),
        %special settings for HW trigger
        set(handles.vid, 'framegrabinterval', 1);
        set(handles.vid, 'framespertrigger', 1);
        set(handles.vid, 'triggerrepeat', Inf);
        set(handles.vid, 'triggerframedelay', 0);
        %vid.TriggerFcn = @flushdata_callback;
        set(handles.vid, 'TriggerFcn', @flushdata_callback); %should i better place the function in the bottom of the file?
        start(handles.vid); % for HW trigger synched preview!
    end
    preview(handles.vid);
    set(hObject,  'string', 'ClosePreview');
    set(hObject, 'userdata', 1.0);
    guidata(hObject, handles);
    return
else
    if strcmp(handles.vid.TriggerType, 'hardware'),
        %special settings for HW trigger
        stop(handles.vid); % for HW trigger synched preview!
        a = get(handles.edFrameGrabInterval, 'string');
        set(handles.vid, 'framegrabinterval', str2num(a));
        a = get(handles.edFramesPerTrigger, 'string');
        set(handles.vid, 'framespertrigger', str2num(a));
        a = get(handles.edTriggerRepeat, 'string');
        set(handles.vid, 'triggerrepeat', str2num(a));
        a = get(handles.edTriggerFrameDelay, 'string');
        set(handles.vid, 'triggerframedelay', str2num(a));
       set(handles.vid, 'TriggerFcn', []);%sintax?        
    end
    closepreview(handles.vid);
    set(hObject, 'string', 'Preview');
    set(hObject, 'userdata', 0.0);
    guidata(hObject, handles);
    return
end
%% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
handles.vid = [];
handles.source = [];
guidata(hObject, handles);
return
%% --- Executes on button press in rbAutoShutter.
function rbAutoShutter_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if get(hObject, 'value') == 1,
    set(handles.source, 'ShutterMode', 'Auto');
    %set(handles.edShutterRel, 'string', '', 'enable', 'off');
end
%% --- Executes on button press in rbManualShutter.
function rbManualShutter_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if get(hObject, 'value') == 1,
    set(handles.source, 'ShutterMode', 'Manual');
    %set(handles.edShutterRel, 'string', '79', 'enable', 'on');%-should i verify the actual gain?
end
%% --- Executes upon editing.
function edShutterRel_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
%s = str2double(get(hObject, 'string'));
s = str2num(get(hObject, 'string'));
p=propinfo(handles.source, 'shutter');
s = min( max( p.ConstraintValue(1), s), p.ConstraintValue(2));
set(handles.source, 'Shutter', s);
set( hObject, 'string', num2str( get( handles.source, 'Shutter')));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function edShutterRel_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on slider movement.
function slBrightness_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
b = round(get(hObject, 'value'));
set(handles.source, 'Brightness', b);
set(handles.edBrightness, 'string', num2str(b));
return
%% --- Executes during object creation, after setting all properties.
function slBrightness_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes upon editing.
function edBrightness_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
b = round(str2num(get(hObject, 'string')));
set(handles.slBrightness, 'value', b);
set(handles.source, 'Brightness', b);
return
%% --- Executes during object creation, after setting all properties.
function edBrightness_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --------------------------------------------------------------------
function miGetSelectedSource_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
get(handles.source)
return
%% --------------------------------------------------------------------
function menuInfo_Callback(hObject, eventdata, handles)
%% -------------------------------------------------------------------
function edContrast_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
c = round(str2num(get(hObject, 'string')));
set(handles.slContrast, 'value', c);
set(handles.source, 'Contrast', c);
return
%% --- Executes during object creation, after setting all properties.
function edContrast_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on slider movement.
function slContrast_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
c = round(get(hObject, 'value'));
set(handles.source, 'Contrast', c);
set(handles.edContrast, 'string', num2str(c));
return
%% --- Executes during object creation, after setting all properties.
function slContrast_CreateFcn(hObject, eventdata, handles)
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on button press in pbDefaultsSource.
function pbDefaultsSource_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
% Gain
set(handles.slGain, 'value', 0);
set(handles.edGain, 'string', '0');
set(handles.source, 'Gain', 0);
% Brightness
set(handles.slBrightness, 'value', 32);
set(handles.edBrightness, 'string', '32');
set(handles.source, 'Brightness', 32);
% Shutter Mode
set(handles.source, 'ShutterMode', 'manual');
set(handles.rbManualShutter , 'value', 1);
set(handles.rbAutoShutter, 'value', 0);
% Shutter Control
set(handles.source, 'ShutterControl', 'absolute');
set(handles.ppShutterControl, 'value', 1);
% Shutter
set(handles.edShutterAbs, 'string', '60.0e-06');
    set(handles.source, 'ShutterAbsolute', 60.0e-06);
    guidata(hObject, handles);
return
%% --- Executes on selection change in ppTriggerConfig.
function ppTriggerConfig_Callback(hObject, eventdata, handles)
% Hints: contents = get(hObject,'String') returns ppTriggerConfig contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ppTriggerConfig
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
set(handles.pbTrigger, 'Enable',  'off');
if isrunning(handles.vid),
    disp('can NOT change trigger params. while videoinput is running!')
    config = triggerinfo(handles.vid);
    sType = lower(handles.vid.TriggerType);
    sCondition = lower(handles.vid.TriggerCondition);
    sSource = lower(handles.vid.TriggerSource);
    for k = 1:length(config),
        if ~strcmp(lower(config(k).TriggerType), sType), continue, end
        if ~strcmp(lower(config(k).TriggerCondition), sCondition), continue, end
        if ~strcmp(lower(config(k).TriggerSource), sSource), continue, end
        break
    end
        set(hObject, 'value', k);% is the value fixes the tsring also?
    return
end
selection = get(hObject, 'value');
config = triggerinfo(handles.vid);
triggerconfig(handles.vid, config(selection));
if selection == 2, %manual trigger
    set(handles.pbTrigger, 'Enable', 'on')
end
return
%% --- Executes during object creation, after setting all properties.
function ppTriggerConfig_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
return
%% --- Executes on button press in pbFramesAcquired.
function pbFramesAcquired_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
frames = get(handles.vid, 'FramesAcquired');
s = sprintf('%s%g\n', 'Frames acquired: ', frames);
disp(s);
return
%% --------------------------------------------------------------------
function miGetVideoInput_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
get(handles.vid)
return
%% -----------------------
function edFrameGrabInterval_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
set(handles.vid, 'FrameGrabInterval', str2num(get(hObject, 'string')));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function edFrameGrabInterval_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --------------------------------------------
function edFramesPerTrigger_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
set(handles.vid, 'FramesPerTrigger', str2num(get(hObject, 'string')));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function edFramesPerTrigger_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% ----------------------------------------------------------
function edTriggerRepeat_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
set(handles.vid, 'TriggerRepeat', str2num(get(hObject, 'string')));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function edTriggerRepeat_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on button press in pbDefaultsAcquisition.
function pbDefaultsAcquisition_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
set(handles.edFrameGrabInterval, 'string', '1');
set(handles.vid, 'FrameGrabInterval', 1);
set(handles.edFramesPerTrigger, 'string', '10');
set(handles.vid, 'FramesPerTrigger', 10);
set(handles.edTriggerRepeat, 'string', '0');
set(handles.vid, 'TriggerRepeat', 0);
set(handles.edTriggerFrameDelay, 'string', '0');
set(handles.vid, 'TriggerFrameDelay', 0);
guidata(hObject, handles);
return
%% -------------------------------------
function edTriggerFrameDelay_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
set(handles.vid, 'TriggerFrameDelay', str2num(get(hObject, 'string')));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function edTriggerFrameDelay_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on button press in pbGetSnapshot.
function pbGetSnapshot_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end; % video object absent
if isrunning(handles.vid), 
    disp('Cant get a snapshot while videoinput object is running!'),
    return
end
if get(hObject, 'userdata') == 0,
    set(hObject, 'userdata', 1.0);
    s = getsnapshot(handles.vid);
    fig_name='Get Snap-Shot';
    f2 = findobj('type', 'figure', 'name', fig_name)
    if isempty(f2),
        f2 = figure('name', fig_name, 'colormap', gray);
    end
%     
%     f2=figure(2);
%     set(f2, 'name', 'Get Snap-Shot');
    %imshow(s);
    figure(f2);
    imagesc(s);
    set(gca, 'dataAspectRatio', [1 1 1]);
   % colrmap gray
    set(hObject, 'userdata', 0.0);
    guidata(hObject, handles);
    return
end
return
%% --- Executes on button press in pbFramesAvailable.
function pbFramesAvailable_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
frames = get(handles.vid, 'FramesAvailable');
s = sprintf('%s%g\n', 'Frames available: ', frames);
disp(s);
return
%% --- Executes on button press in pbStart.
function pbStart_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if isrunning(handles.vid),
    %     disp('Videoinput object is already running!');
    %     return,
    stop(handles.vid);
    flushdata(handles.vid);
end;
       % refresh acquisition params
        a = get(handles.edFrameGrabInterval, 'string');
        set(handles.vid, 'framegrabinterval', str2num(a));
        a = get(handles.edFramesPerTrigger, 'string');
        set(handles.vid, 'framespertrigger', str2num(a));
        a = get(handles.edTriggerRepeat, 'string');
        set(handles.vid, 'triggerrepeat', str2num(a));
        a = get(handles.edTriggerFrameDelay, 'string');
        set(handles.vid, 'triggerframedelay', str2num(a));
       set(handles.vid, 'TriggerFcn', []);
start(handles.vid);
return
%% --- Executes on button press in pbTrigger.
function pbTrigger_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if ~strcmp(get(handles.vid, 'TriggerType'), 'manual'), return, end;
if ~isrunning(handles.vid), return, end;
if islogging(handles.vid), return, end;
trigger(handles.vid);
return
%% --- Executes on button press in pbStop.
function pbStop_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if ~isrunning(handles.vid), return, end;
stop(handles.vid);
return
%% --- Executes on button press in pbImaqMontage.
% function pbImaqMontage_Callback(hObject, eventdata, handles)
% if get(handles.pbVideoInput, 'userdata') == 0, return, end;
% % figure(2);% TO DO:: use the correct data structure to display...
% % imaqmontage(handles.data);
% return

%% --- Executes on button press in pbFlushData.
function pbFlushData_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
flushdata(handles.vid);
return
%% --- Executes on button press in pbImageDisplay.
function pbImageDisplay_Callback(hObject, eventdata, handles)
ImageDisplay % add varargin with image data structure?
return
%% --- Executes on button press in pbGetData.
function pbGetData_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if get(handles.vid, 'FramesAvailable') == 0, return, end;
if get(handles.vid, 'TriggersExecuted') < 1, return, end;
handles.data = [];
T = get(handles.vid, 'TriggersExecuted');
for t=1:T,
    [handles.data{t}.frames, handles.data{t}.time, handles.data{t}.metadata] = getdata(handles.vid);
end
guidata(hObject, handles);
return
%% --- Executes on button press in pbSave.
function pbSave_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if isempty(handles.data), return, end;
tx = get(handles.edTransducerID, 'string');
d=handles.data;
c = fix(clock);
filename=sprintf('%s_%4d-%02d-%02d_%02d%02d%02d%s', tx, c(1), c(2), c(3), c(4), c(5), c(6), '.mat');
prompt={'Enter file name:'};
name='Save current data to a file';
numlines=1;
defaultanswer= {filename};
filename2='';
filename2=inputdlg(prompt,name,numlines,defaultanswer);
if isempty(filename2), return, end;
save(filename2{1}, 'd');
return
%% --- Executes on button press in pbPowerMeter.
function pbPowerMeter_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
if strcmp(get(hObject, 'string'), 'Stop PM'),
    stop(handles.vid); % why stop vid? see few lines below...
    set(hObject, 'string', 'PowerMeter'); % send a message into the interruptibble loop via the string?
    return;
end
if islogging(handles.vid), disp('Video object is logging - can not run power meter!'), return, end;
if isrunning(handles.vid), disp('Video object is running - can not run power meter!'), return, end;
set(handles.edPowerMeter, 'string', '');
start(handles.vid); % why start? i assume the vid is ...
set(hObject, 'string', 'Stop PM');
while strcmp(get(hObject, 'string'), 'Stop PM'),
    d = getsnapshot(handles.vid); % get 1 frame
    %%     r = get(handles.vid, 'ROI');
    %%     max = ( r(3) - r(1) )*(r(4) - r(2) )*255;
    max = 255*size(d, 1)*size(d, 2); % i assume 8 bit?
    power = sum(sum(d))/max;
    set(handles.edPowerMeter, 'string', num2str(power, 3));
    guidata(hObject, handles);
    pause(0.2);
end
%set(hObject, 'string', 'PowerMeter');
return
%% --- Executes on editing.
function edPowerMeter_Callback(hObject, eventdata, handles)
%% --- Executes during object creation, after setting all properties.
function edPowerMeter_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on editing.
function edROIx_Callback(hObject, eventdata, handles)
% if get(handles.pbVideoInput, 'userdata') == 0, return, end;
% a = get(handles.vid, 'ROI');
% new = str2num(get(hObject, 'string'));
% set(handles.vid, 'ROI', [new a(2) a(3) a(4)]);
return;
%% --- Executes during object creation, after setting all properties.
function edROIx_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on editing.
function edROIy_Callback(hObject, eventdata, handles)
% if get(handles.pbVideoInput, 'userdata') == 0, return, end;
% a = get(handles.vid, 'ROI');
% new = str2num(get(hObject, 'string'));
% set(handles.vid, 'ROI', [a(1) new a(3) a(4)]);
return;
%% --- Executes during object creation, after setting all properties.
function edROIy_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on editing.
function edROIwidth_Callback(hObject, eventdata, handles)
% if get(handles.pbVideoInput, 'userdata') == 0, return, end;
% a = get(handles.vid, 'ROI');
% new = str2num(get(hObject, 'string'));
% set(handles.vid, 'ROI', [a(1) a(2) new a(4)]);
return;
%% --- Executes during object creation, after setting all properties.
function edROIwidth_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on editing.
function edROIheight_Callback(hObject, eventdata, handles)
%% --- Executes during object creation, after setting all properties.
function edROIheight_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on button press in pbROIdefaults.
function pbROIdefaults_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
% a = get(handles.vid, 'videoresolution');
% x = 0; y = 0;
p = propinfo(handles.vid, 'ROIPosition');
roi = p.DefaultValue;
set(handles.vid, 'ROI', roi);
set(handles.edROIx, 'string', num2str(roi(1)));
set(handles.edROIy, 'string', num2str(roi(2)));
set(handles.edROIwidth, 'string', num2str(roi(3)));
set(handles.edROIheight, 'string', num2str(roi(4)));
guidata(hObject, handles);
return
%% --- Executes on button press in pbROIupdate.
function pbROIupdate_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
a = zeros(1,4);
p = propinfo(handles.vid, 'ROIPosition');
roi = p.DefaultValue;
a(1) = max(0, min(str2num(get(handles.edROIx, 'string')), roi(3))); % 0<=x<=MAX_x
a(2) = max(0, min(str2num(get(handles.edROIy, 'string')), roi(4))); % 0<=y<=MAX_y
a(3) = max(1, min(str2num(get(handles.edROIwidth, 'string')), roi(3)-a(1)));% 0<width<=MAX_x - x
a(4) = max(1, min(str2num(get(handles.edROIheight, 'string')), roi(4)-a(2)));% 0<height<=MAX_y - y
set(handles.vid, 'ROI', a);
% update indicators
set(handles.edROIx, 'string', a(1));
set(handles.edROIy, 'string', a(2));
set(handles.edROIwidth, 'string', a(3));
set(handles.edROIheight, 'string', a(4));
guidata(hObject, handles);
return
%% --- Executes on editing.
function edTransducerID_Callback(hObject, eventdata, handles)
%% --- Executes during object creation, after setting all properties.
function edTransducerID_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on button press in pbIsRunning.
function pbIsRunning_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
s = isrunning(handles.vid);
switch s
    case 0
        disp(' Video object is NOT running');
    case 1
        disp(' Video object is running');
end
return
%% --- Executes on button press in pbIsLogging.
function pbIsLogging_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
s = islogging(handles.vid);
switch s
    case 0
        disp(' Video object is NOT logging');
    case 1
        disp(' Video object is logging');
end
return
%% --- Executes on selection change in ppLoggingMode.
function ppLoggingMode_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;

%-modify to avoid system exceptions!
if isrunning(handles.vid),
    disp('can NOT change Logging mode while videoinput is running!')
    %     config = triggerinfo(handles.vid);
    sStr = get(hObject, 'string');
    %     sType = handles.vid.TriggerType;
    %     sCondition = handles.vid.TriggerCondition;
    %     sSource = handles.vid.TriggerSource;
    for k = 1:length(sStr),
        if ~strcmp(lower(sStr{k}), lower(handles.vid.LoggingMode)), continue, end
        %         if ~strcmp(config(k).TriggerCondition, sCondition), continue, end
        %         if ~strcmp(config(k).TriggerSource, sSource), continue, end
        break
    end
    set(hObject, 'value', k);% is the value fixes the tsring also?
    return
end
%-EEE

index = get(hObject, 'value');
str = get(hObject, 'string');
sLoggingMode = str{index};
set(handles.vid, 'LoggingMode', sLoggingMode);
guidata(hObject, handles);
return
%% --- Executes on creation.
function ppLoggingMode_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on selection change in ppCompression.
function ppCompression_Callback(hObject, eventdata, handles)
%% --- Executes during object creation, after setting all properties.
function ppCompression_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes upon editing.
function edQuality_Callback(hObject, eventdata, handles)
%% --- Executes during object creation, after setting all properties.
function edQuality_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on button press in tbAvi.
function tbAvi_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0,
    set(hObject, 'string', 'CreateAvi'); % label 'Create avifile'
    set(hObject, 'userdata', 1);
    return;
end;
logging_mode_index = get(handles.ppLoggingMode, 'value');
if logging_mode_index == 1, return, end; % logging mode = memory
state = get(hObject, 'userdata');
if state == 1, % create avi
    %try
    tx = get(handles.edTransducerID, 'string');
    c = fix(clock);
    filename=sprintf('%s_%4d-%02d-%02d_%02d%02d%02d%s', tx, c(1), c(2), c(3), c(4), c(5), c(6), '.avi');
    prompt={'Enter avi file name:'};
    name='Create avi file for disk logging';
    numlines=1;
    defaultanswer= {filename};
    filename = '';
    filename=inputdlg(prompt,name,numlines,defaultanswer);
    if isempty(filename), return, end;
    sCompression_index = get(handles.ppCompression, 'value');
    sCompressionCell = get(handles.ppCompression, 'string');
    sCompression = sCompressionCell{sCompression_index};
    fps = str2num(get(handles.edFps, 'string'));
    quality = str2num(get(handles.edQuality, 'string'));
    % i assume 8 bit?
    handles.aviobj = avifile(filename{1}, 'Colormap', gray(256), 'Compression', sCompression, 'Quality', quality, 'FPS', fps);
    set(handles.vid, 'DiskLogger', handles.aviobj);
    set(hObject, 'string', 'CloseAvi'); % label 'Close avifile'
    set(handles.tbAvi, 'userdata', 0);
    guidata(hObject, handles);
    %catch
    %     set(hObject, 'string', str{1}); % label 'Create avifile'
    %     value = get(hObject, 'max');
    %     set(hObject, 'value', value);
    %end
elseif state == 0, % close avi
    if isrunning(handles.vid),
        disp('Can not close avi file while video object is running!!!');
        return;
    end
    if get(handles.vid, 'FramesAcquired') > get(handles.vid, 'DiskLoggerFrameCount')
        disp('Logging... please wait!');
        return;
    end
    if ~isempty(handles.aviobj),
        handles.aviobj = close(handles.vid.DiskLogger);
    end
    set(hObject, 'string', 'CreateAvi'); % label 'Create avifile'
    set(handles.tbAvi, 'userdata', 1);
    guidata(hObject, handles);
end
return
%% --- Executes on editing.
function edFps_Callback(hObject, eventdata, handles)
%% --- Executes during object creation, after setting all properties.
function edFps_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%% --- Executes on selection change in ppShutterControl.
function ppShutterControl_Callback(hObject, eventdata, handles)
% Hints: contents = get(hObject,'String') returns ppShutterControl contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ppShutterControl
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
selection = get(hObject, 'value');
p = propinfo(handles.source, 'ShutterControl');
set(handles.source, 'ShutterControl', p.ConstraintValue{1+mod(selection,2)}); %sorry, i just want 'absolute' on top of the list...
disp(get(handles.source, 'ShutterControl'));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function ppShutterControl_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%% --- Executes on slider movement.
function slGain_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
g = round(get(hObject, 'value'));
set(handles.source, 'Gain', g);
set(handles.edGain, 'string', num2str(g));
return

%% --- Executes during object creation, after setting all properties.
function slGain_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slGain (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
%% ----------------------------------------
function edGain_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'String') returns contents of edGain as text
%        str2double(get(hObject,'String')) returns contents of edGain as a double
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
g = round(str2num(get(hObject, 'string')));
p=propinfo(handles.source, 'Gain');
g = min( max( p.ConstraintValue(1), g), p.ConstraintValue(2));
set(handles.source, 'Gain', g);
g = get( handles.source, 'Gain');
set( hObject, 'string', num2str( g));
set(handles.slGain, 'value', g);
guidata(hObject, handles);
return

% --- Executes during object creation, after setting all properties.
function edGain_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edGain (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% 
% function edit21_Callback(hObject, eventdata, handles)
% % hObject    handle to edit21 (see GCBO)
% % eventdata  reserved - to be defined in a future version of MATLAB
% % handles    structure with handles and user data (see GUIDATA)
% 
% % Hints: get(hObject,'String') returns contents of edit21 as text
% %        str2double(get(hObject,'String')) returns contents of edit21 as a double
% 
% 
% % --- Executes during object creation, after setting all properties.
% function edit21_CreateFcn(hObject, eventdata, handles)
% % hObject    handle to edit21 (see GCBO)
% % eventdata  reserved - to be defined in a future version of MATLAB
% % handles    empty - handles not created until after all CreateFcns called
% 
% % Hint: edit controls usually have a white background on Windows.
% %       See ISPC and COMPUTER.
% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
%     set(hObject,'BackgroundColor','white');
% end
% 

%% --------------------------------
function edShutterAbs_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'String') returns contents of edShutterAbs as text
%        str2double(get(hObject,'String')) returns contents of edShutterAbs as a double
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
s = str2num(get(hObject, 'string'));
p=propinfo(handles.source, 'shutterabs');
s = min( max( p.ConstraintValue(1), s), p.ConstraintValue(2));
set(handles.source, 'ShutterAbsolute', s);
set( hObject, 'string', num2str( get( handles.source, 'ShutterAbsolute')));
guidata(hObject, handles);
return
%% --- Executes during object creation, after setting all properties.
function edShutterAbs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edShutterAbs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes on button press in pbImaqMontage.
function pbImaqMontage_Callback(hObject, eventdata, handles)
% hObject    handle to pbImaqMontage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function miFramesAcquired_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
frames = get(handles.vid, 'FramesAcquired');
s = sprintf('%s%g\n', 'Frames acquired: ', frames);
disp(s);
return


% --------------------------------------------------------------------
function miFramesAvailable_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
frames = get(handles.vid, 'FramesAvailable');
s = sprintf('%s%g\n', 'Frames available: ', frames);
disp(s);
return

% --------------------------------------------------------------------
function miIsRunning_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
s = isrunning(handles.vid);
switch s
    case 0
        disp(' Video object is NOT running');
    case 1
        disp(' Video object is running');
end
return

% --------------------------------------------------------------------
function miIsLogging_Callback(hObject, eventdata, handles)
if get(handles.pbVideoInput, 'userdata') == 0, return, end;
s = islogging(handles.vid);
switch s
    case 0
        disp(' Video object is NOT logging');
    case 1
        disp(' Video object is logging');
end
return

Contact us