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.

rheodyne232objgui(varargin)
function varargout = rheodyne232objgui(varargin)
% RHEODYNE232OBJGUI M-file for rheodyne232objgui.fig
%      RHEODYNE232OBJGUI, by itself, creates a new RHEODYNE232OBJGUI or raises the existing
%      singleton*.
%
%      H = RHEODYNE232OBJGUI returns the handle to a new RHEODYNE232OBJGUI or the handle to
%      the existing singleton*.
%
%      RHEODYNE232OBJGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RHEODYNE232OBJGUI.M with the given input arguments.
%
%      RHEODYNE232OBJGUI('Property','Value',...) creates a new RHEODYNE232OBJGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before rheodyne232objgui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to rheodyne232objgui_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 rheodyne232objgui

% Last Modified by GUIDE v2.5 25-Nov-2009 17:32:01

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @rheodyne232objgui_OpeningFcn, ...
                   'gui_OutputFcn',  @rheodyne232objgui_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 rheodyne232objgui is made visible.
function rheodyne232objgui_OpeningFcn(hObject, eventdata, handles, mainGuiHandle, serialObject)
% 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 rheodyne232objgui (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.serialObject = serialObject;

% don't really need to turn the collect data flag off, since the readall
% command takes its cues from the timer object itself

% Update handles structure
guidata(hObject, handles)

% brings up a waitbar
waitBarHandle = waitbar(0, 'Retrieving data...');

% fills the boxes if the respective fields exist
if isfield(serialObject.UserData, 'nominalLoopSize')
    % fills the box
    set(handles.nominalLoopSize, 'String', num2str(serialObject.UserData.nominalLoopSize))
end

% same with measured loop size
if isfield(serialObject.UserData, 'measuredLoopSize')
    % fills the box
    set(handles.measuredLoopSize, 'String', num2str(serialObject.UserData.measuredLoopSize))
end

% reads in the valve position
try
    % gets it - position 2 is B, 1 is A - so converted to "logicals"
    valvePosition = rheodyne232objreadvalveposition(serialObject) - 1;
    
    % sets it
    set(handles.positionA, 'Value', ~valvePosition)
    set(handles.positionB, 'Value', valvePosition)
    
catch
    % displays a warning
    warning('fibreObjGui:valvePositionError', 'Could not read in the valve position.')
end

% updates the waitbar
waitbar(1 / 4, waitBarHandle)

% reads in the command mode
try
    % sets it
    set(handles.commandMode, 'Value', rheodyne232objreadcommandmode(serialObject))
    
catch
    % displays a warning
    warning('fibreObjGui:commmandModeError', 'Could not read in the command mode.')
end

% updates the waitbar
waitbar(2 / 4, waitBarHandle)

% reads in the valve profile
try
    % sets it
    set(handles.valveProfile, 'String', num2str(rheodyne232objreadvalveprofile(serialObject)))
    
catch
    % displays a warning
    warning('fibreObjGui:valveProfileError', 'Could not read in the valve profile.')
end

% updates the waitbar
waitbar(3 / 4, waitBarHandle)

% reads in the firmware version
try
    % sets it
    set(handles.firmwareVersion, 'String', num2str(rheodyne232objreadversion(serialObject)))
    
catch
    % displays a warning
    warning('fibreObjGui:firmwareVersionError', 'Could not read in the firmware version.')
end

% gets the fast mode (assuming its there)
if isfield(serialObject.UserData, 'fastMode')
    % save it
    set(handles.fastMode, 'Value', double(serialObject.UserData.fastMode))
    
else
    % set it and save it too (for extra robustness)
    set(handles.fastMode, 'Value', 1)
    serialObject.UserData.fastMode = true;
end

% closes the waitbar
close(waitBarHandle)


% --- Outputs from this function are returned to the command line.
function rheodyne232objgui_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 nominalLoopSize_Callback(hObject, eventdata, handles)
% hObject    handle to nominalLoopSize (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 nominalLoopSize as text
%        str2double(get(hObject,'String')) returns contents of nominalLoopSize as a double

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

% checks its OK
if ~isnumber(newValue) && newValue <= 0
    % brings up an error dialog
    warntooltip(hObject, 'Nominal loop size must be a real number greater than 0.')
    
else
    % updates the serial object user data
    handles.serialObject.UserData.nominalLoopSize = newValue;
end


% --- Executes during object creation, after setting all properties.
function nominalLoopSize_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nominalLoopSize (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 measuredLoopSize_Callback(hObject, eventdata, handles)
% hObject    handle to measuredLoopSize (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 measuredLoopSize as text
%        str2double(get(hObject,'String')) returns contents of measuredLoopSize as a double

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

% checks its OK
if ~isnumber(newValue) && newValue <= 0
    % brings up an error dialog
    warntooltip(hObject, 'Measured loop size must be a real number greater than 0.')
    
else
    % updates the timer object user data
    handles.serialObject.UserData.measuredLoopSize = newValue;
end


% --- Executes during object creation, after setting all properties.
function measuredLoopSize_CreateFcn(hObject, eventdata, handles)
% hObject    handle to measuredLoopSize (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 changePosition(hObject, eventdata, handles)
% generic change position callback

% sets the selected thing to 1 (to prevent deselection)
set(hObject, 'Value', 1)

% gets the position A value (the B value is implicit)
positionA = get(handles.positionA, 'Value');

% sends the command
try
    % sends it (modifies it for use with the rheodyne)
    rheodyne232objwritevalveposition(handles.serialObject, positionA)

catch
    % returns the button to its previous state
    set(handles.positionA, ~positionA)
    
    % brings up an error tooltip
    errortooltip(hObject, 'Could not change the valve position.')
end


% --- Executes on button press in positionA.
function positionA_Callback(hObject, eventdata, handles)
% hObject    handle to positionA (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 positionA

% runs the generic callback
changePosition(hObject, eventdata, handles)


% --- Executes on button press in positionB.
function positionB_Callback(hObject, eventdata, handles)
% hObject    handle to positionB (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 positionB

% runs the generic callback
changePosition(hObject, eventdata, handles)


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

% defines the filename
fileName = 'Rheodyne Communications Protocols.pdf';

% opens the pdf
if ispc
    % opens it
    winopen(fileName)
    
else
    % gets the root
    filePath = mfilename('fullpath');
        
    % opens up a message box with the file name in it
    msgbox('The file can be found in ', [fileparts(filePath), filesep, fileName])
end

function resetBox
% brings up a box to tell the user that that command will not kick in until
% the unit has been turned off then back on
msgbox('This parameter will not take effect until the Rheodyne has been switched off and turned back on.', 'Reset Required')


% --- Executes on selection change in commandMode.
function commandMode_Callback(hObject, eventdata, handles)
% hObject    handle to commandMode (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns commandMode contents as cell array
%        contents{get(hObject,'Value')} returns selected item from commandMode

% tries to change it
try
    % sends it
    rheodyne232objwritecommandmode(handles.serialObject, get(hObject, 'Value'))
    
    % brings up the message box
    resetBox
    
catch
    % it didn't work
    
    % bring up an error tooltip
    errortooltip(hObject, 'Could not write the command mode.')
    
    % retrieve the old value
    try
        % try
        set(hObject, 'Value', rheodyne232objreadcommandmode(handles.serialObject))

    catch
        % do nothing
    end
end


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

% Hint: popupmenu 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 selection change in baudRate.
function baudRate_Callback(hObject, eventdata, handles)
% hObject    handle to baudRate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns baudRate contents as cell array
%        contents{get(hObject,'Value')} returns selected item from baudRate

% tries to change it
try
    % sends it
    rheodyne232objwritebaudrate(handles.serialObject, get(hObject, 'Value'))
    
    % brings up the message box
    resetBox
    
catch
    % it didn't work - bring up an error tooltip
    errortooltip(hObject, 'Could not write the new baud rate.')
end


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

% Hint: popupmenu 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 slaveAddress_Callback(hObject, eventdata, handles)
% hObject    handle to slaveAddress (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 slaveAddress as text
%        str2double(get(hObject,'String')) returns contents of slaveAddress as a double

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

% checks it
if isnan(slaveAddress) || slaveAddress / 2 ~= round(slaveAddress / 2) || slaveAddress < 14 || slaveAddress > 254
    % errors
    warntooltip(hObject, 'Must be an even integer from 14 to 254.')
    
    % empties it
    set(hObject, 'String', '')
end


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

% gets the slave address
slaveAddress = str2double(get(handles.slaveAddress, 'String'));

% if its a NaN, don't do it
if isnan(slaveAddress)
    % warning
    warntooltip(hObject, 'Invalid slave address.')

else
    % tries to change it
    try
        % sends it
        rheodyne232objwriteslaveaddress(handles.serialObject, slaveAddress)

        % brings up the message box
        resetBox

    catch
        % it didn't work - bring up an error tooltip
        errortooltip(hObject, 'Could not write the new I2C slave address.')
    end
end


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

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

% checks it
if isnan(valveProfile) || valveProfile ~= uint8(valveProfile)
    % errors
    warntooltip(hObject, 'Must be an even integer from 0 to 255.')
    
    % empties it
    set(hObject, 'String', '')
end


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

% gets the slave address
valveProfile = str2double(get(handles.slaveAddress, 'String'));

% if its a NaN, don't do it
if isnan(valveProfile)
    % warning
    warntooltip(hObject, 'Invalid valve profile.')

else
    % tries to change it
    try
        % sends it
        rheodyne232objwritevalveprofile(handles.serialObject, valveProfile)

        % brings up the message box
        resetBox

    catch
        % it didn't work - bring up an error tooltip
        errortooltip(hObject, 'Could not write the new valve profile.')
    end
end


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


% --- Executes during object creation, after setting all properties.
function firmwareVersion_CreateFcn(hObject, eventdata, handles)
% hObject    handle to firmwareVersion (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 command_Callback(hObject, eventdata, handles)
% hObject    handle to command (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 command as text
%        str2double(get(hObject,'String')) returns contents of command as a double

% gets the string
command = get(hObject, 'String');

% complains if the command is longer than 3 characters, or has non-printing
% characters
if numel(command) > 3
    % complain
    warntooltip(hObject, 'Must be no longer than 3 characters.')
    
    % empty it
    set(hObject, 'String', '')
    
elseif any(~isstrprop(command, 'alphanum'))
    % complain
    warntooltip(hObject, 'Printable characters only.')
    
    % empty it
    set(hObject, 'String', '')
end


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

% gets the command and the command type
command = get(handles.command, 'String');
read = get(handles.read, 'Value');

% sends the command
try
    % depends on type
    if read
        % sends it and sets it
        set(handles.response, 'String', rheodyne232objcomm(handles.serialObject, command))

    else
        % empties out the response box
        set(handles.response, 'String', '')
        
        % sends it
        rheodyne232objcomm(handles.serialObject, command)        
    end

catch
    % it didn't work
    errortooltip(hObject, 'Command did not work.')
end


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


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

% changes the fastmode
handles.serialObject.UserData.fastMode = logical(get(handles.fastMode, 'Value'));

Contact us