Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

pumpobjgui(varargin)
function varargout = pumpobjgui(varargin)
% PUMPOBJGUI M-file for pumpobjgui.fig
%      PUMPOBJGUI, by itself, creates a new PUMPOBJGUI or raises the existing
%      singleton*.
%
%      H = PUMPOBJGUI returns the handle to a new PUMPOBJGUI or the handle to
%      the existing singleton*.
%
%      PUMPOBJGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PUMPOBJGUI.M with the given input arguments.
%
%      PUMPOBJGUI('Property','Value',...) creates a new PUMPOBJGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before pumpobjgui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to pumpobjgui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help pumpobjgui

% Last Modified by GUIDE v2.5 19-Aug-2009 10:35:32

% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @pumpobjgui_OpeningFcn, ...
                   'gui_OutputFcn',  @pumpobjgui_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 pumpobjgui is made visible.
function pumpobjgui_OpeningFcn(hObject, eventdata, handles, mainGuiHandle, serialObj)
% 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 pumpobjgui (see VARARGIN)

% checks the number of arguments
error(nargchk(5, 5, nargin))

% stashes away the main gui handle
handles.mainGuiHandle = mainGuiHandle;

% stashes the serial object away for later use
handles.serialObj = serialObj;

% Update handles structure
guidata(hObject, handles);

% gets the number from the serial object
serialObjUserData = serialObj.UserData;

% defines the collect data flag field
collectDataFlag = sprintf('collectDataFlag%d', serialObjUserData.objectNumber);

% turns the collect data flag off temporarily - this is necessary to prevent the
% serial timer interrupting the collection of all the data
setappdata(mainGuiHandle, collectDataFlag, 0)

% try-catches everything in case something interrupts any of the commands
try
    % gets the main GUI handles
    mainGuiHandles = guidata(mainGuiHandle);
    
    % fetches the flow rate from the mainGui (assuming the flow rate box is
    % filled)
    flowRate = str2double(get(mainGuiHandles.(sprintf('flow%d', serialObjUserData.objectNumber)), 'String'));
    
    % it it wasn't a NaN or 0, fill the consumption time box
    if ~isnan(flowRate) && flowRate
        % fill the box
        set(handles.consumptionTime, 'String', sprintf('%.1f', ((2.5 * 1000) / flowRate) / 60))
    end
    
    % fills the maximum pressure box
    set(handles.maxPressBox, 'String', num2str(pumpobjreadmaxpress(serialObj)))

    % fills the minimum pressure box
    set(handles.minPressBox, 'String', num2str(pumpobjreadminpress(serialObj)))
    
    % fills the flow mode box
    if pumpobjreadflowmode(serialObj)
        % sets the flow mode to constant pressure
        set(handles.constantPressure, 'Value', 1)
        
    else
        % sets the flow mode to constant flow
        set(handles.constantFlow, 'Value', 1)
    end
    
catch
    % brings up an question dialog to ask use what they want to do if the
    % data couldn't be fetched
    selection = questdlg(   'The pump configuration could not be retrieved.  Would you like to continue anyway?',...
                            'More Options Menu Confirmation',...
                            'Yes', 'No',...
                            'Yes');

    % close the GUI if 'No' was selected
    if strcmp(selection, 'No')
        % deletes the GUI
        delete(hObject)
    end
end

% turns the collect data flag back on
setappdata(mainGuiHandle, collectDataFlag, 1)


% --- Outputs from this function are returned to the command line.
function pumpobjgui_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)



function minPressBox_Callback(hObject, eventdata, handles)
% hObject    handle to minPressBox (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 minPressBox as text
%        str2double(get(hObject,'String')) returns contents of minPressBox as a double

% gets the new value
newValue = str2double(get(hObject, 'String'));

% if the value is OK, send the command (try-catched in case it errors)
if ~isnumberbetween(newValue, 0, 350)
    % displays an error message
    warntooltip(hObject, 'New minimum pressure must be a number between 0 and 350 bar')
    
    % resets field to the previous value
    set(hObject, 'String', num2str(pumpobjreadminpress(handles.serialObj)))
    
else
    % sets the new minimum pressure
    try
        % sends the command
        pumpobjwriteminpress(handles.serialObj, newValue)
        
    catch
        % displays an error message
        errortooltip(hObject, 'Could not write new minimum pressure')
    end
end


% --- Executes during object creation, after setting all properties.
function minPressBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to minPressBox (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 constantFlow.
function constantFlow_Callback(hObject, eventdata, handles)
% hObject    handle to constantFlow (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of constantFlow

% always sets the value to 1 (prevents it from being unchecked)
set(hObject, 'Value', 1)

% run the radio callback
flowMode_Callback(hObject, eventdata, handles)


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

% Hint: get(hObject,'Value') returns toggle state of constantPressure

% always sets the value to 1 (prevents it from being unchecked)
set(hObject, 'Value', 1)

% run the radio callback
flowMode_Callback(hObject, eventdata, handles)


% --- Executes on button press in flowMode panel
function flowMode_Callback(callingObject, eventdata, handles)
% callingObject	handle to callingObject (see GCBO)
% eventdata     reserved - to be defined in a future version of MATLAB
% handles       structure with handles and user data (see GUIDATA)

% if constant flow is chosen...
if get(handles.constantFlow, 'Value')
    % sets the flow mode
    flowMode = 0;
    
else
    % sets the flow mode
    flowMode = 1;
end

% try-catch for error handling
try
    % send the command to change it
    pumpobjwriteflowmode(handles.serialObj, flowMode)
    
catch
    % displays an error dialog
    errortooltip(hObject, 'Could not change the flow mode')
end



function commandBox_Callback(hObject, eventdata, handles)
% hObject    handle to commandBox (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 commandBox as text
%        str2double(get(hObject,'String')) returns contents of commandBox as a double


% --- Executes during object creation, after setting all properties.
function commandBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to commandBox (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 commandButton.
function commandButton_Callback(hObject, eventdata, handles)
% hObject    handle to commandButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% fetches the command mode
if get(handles.responseOption, 'Value')
    % sends the command, setting the response box to the contents of the
    % response
    set(handles.responseBox, 'String', pumpobjcomm('read', handles.serialObj, get(handles.commandBox, 'String')));
    
else
    % sends the command
    pumpobjcomm('write', handles.serialObj, get(handles.commandBox, 'String'))
    
    % clears out the response box
    set(handles.responseBox, 'String', '')
end


function responseBox_Callback(hObject, eventdata, handles)
% hObject    handle to responseBox (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 responseBox as text
%        str2double(get(hObject,'String')) returns contents of responseBox as a double


% --- Executes during object creation, after setting all properties.
function responseBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to responseBox (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 responseOption.
function responseOption_Callback(hObject, eventdata, handles)
% hObject    handle to responseOption (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of responseOption




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

% launches the PDF of the communications manual
open('Jasco PU-2000 RS-232 Protocols.pdf')



function maxPressBox_Callback(hObject, eventdata, handles)
% hObject    handle to maxPressBox (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 maxPressBox as text
%        str2double(get(hObject,'String')) returns contents of maxPressBox as a double

% gets the new value
newValue = str2double(get(hObject, 'String'));

% if the value is OK, send the command (try-catched in case it errors)
if ~isnumberbetween(newValue, 0, 350)
    % displays an error message
    warntooltip(hObject, 'New maximum pressure must be a number between 0 and 350 bar')
    
    % resets field to the previous value
    set(hObject, 'String', num2str(pumpobjreadmaxpress(handles.serialObj)))
    
else
    % sets the new maximum pressure
    try
        % sends the command
        pumpobjwritemaxpress(handles.serialObj, newValue)
        
    catch
        % displays an error message
        errortooltip(hObject, 'Could not write new maximum pressure')
    end
end


% --- Executes during object creation, after setting all properties.
function maxPressBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to maxPressBox (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 commandListButton.
function commandListButton_Callback(hObject, eventdata, handles)
% hObject    handle to commandListButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% opens the jasco commands file into the editor
edit('JascoCommands')


function consumptionTime_Callback(hObject, eventdata, handles)
% hObject    handle to consumptionTime (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 consumptionTime as text
%        str2double(get(hObject,'String')) returns contents of consumptionTime as a double


% --- Executes during object creation, after setting all properties.
function consumptionTime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to consumptionTime (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


Contact us