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.

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

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

% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @tharbprobjgui_OpeningFcn, ...
                   'gui_OutputFcn',  @tharbprobjgui_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 tharbprobjgui is made visible.
function tharbprobjgui_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 tharbprobjgui (see VARARGIN)

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

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

% only does this but if the mainGuiHandle was empty
if ~isempty(mainGuiHandle)
    % 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)
end

% collects some handles together for convenience
handles.tempBoxes = [handles.extSetTempA, handles.extSetTempB, handles.extAlarmTempA, handles.extAlarmTempB];

% updates the handles
guidata(hObject, handles)

% try-catches everything in case something interrupts any of the commands
% (as the whole thing takes quite a long time)
try
    % starts a waitbar off
    waitBarHandle = waitbar(0, 'Retrieving information... (this will take about 30 seconds)');
    
    % stashes the main gui handle away
    handles.mainGuiHandle = mainGuiHandle;
    
    % stashes the serial object away in handles
    handles.serialObj = serialObj;
    
    % Update handles structure
    guidata(hObject, handles);

    % gets the profile setup for A
    [setPressA, alarmPressA, extSetTempA, extAlarmTempA] = tharbprobjreadprofilesetup(serialObj, 'A');

    % fills the boxes
    set(handles.setPressA, 'String', num2str(setPressA))
    set(handles.alarmPressA, 'String', num2str(alarmPressA))
    set(handles.extSetTempA, 'String', num2str(extSetTempA))
    set(handles.extAlarmTempA, 'String', num2str(extAlarmTempA))

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

    % gets the profile setup for B
    [setPressB, alarmPressB, extSetTempB, extAlarmTempB] = tharbprobjreadprofilesetup(serialObj, 'B');

    % fills the boxes
    set(handles.setPressB, 'String', num2str(setPressB))
    set(handles.alarmPressB, 'String', num2str(alarmPressB))
    set(handles.extSetTempB, 'String', num2str(extSetTempB))
    set(handles.extAlarmTempB, 'String', num2str(extAlarmTempB))

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

    % gets the profile config for A
    [profileNameA, kpA, kiA, kdA, maxOutA] = tharbprobjreadprofileconfig(serialObj, 'A');

    % fills the boxes
    set(handles.nameA, 'String', profileNameA)
    set(handles.kpA, 'String', num2str(kpA))
    set(handles.kiA, 'String', num2str(kiA))
    set(handles.kdA, 'String', num2str(kdA))
    set(handles.maxOutA, 'String', num2str(maxOutA))

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

    % gets the profile config for B
    [profileNameB, kpB, kiB, kdB, maxOutB] = tharbprobjreadprofileconfig(serialObj, 'B');

    % fills the boxes
    set(handles.nameB, 'String', profileNameB)
    set(handles.kpB, 'String', num2str(kpB))
    set(handles.kiB, 'String', num2str(kiB))
    set(handles.kdB, 'String', num2str(kdB))
    set(handles.maxOutB, 'String', num2str(maxOutB))

    % updates the waitbar
    waitbar(4 / 8, waitBarHandle)
    
    % reads the current profile, the valve position, and the control status
    response = tharbprobjdisplaymenu(serialObj);

    % sets the current profile
    set(handles.currentProfile, 'String', response{2}(9))

    % updates the waitbar
    waitbar(5 / 8, waitBarHandle)

    % sets the current valve position
    set(handles.valvePosition, 'String', num2str(str2double(response{3}(5:8))))
    
    % updates the waitbar
    waitbar(6 / 8, waitBarHandle)
    
    % gets the control status
    valveControlStatus = onoff(lower(strtrim(response{2}(18:20))));

    % disables/enables the set valve position button
    set(handles.setValvePosition, 'Enable', onoff(~valveControlStatus))

    % updates the waitbar
    waitbar(7 / 8, waitBarHandle)

    % gets the external heater control status
    extHeaterStatus = tharbprobjreadextheaterstatus(serialObj);
    
    % sets the checkbox value
    set(handles.extHeaterControlStatus, 'Value', extHeaterStatus)

    % if the heater was turned on...
    if extHeaterStatus
        % disables and clears the boxes
        set(handles.tempBoxes,  'Enable', 'off',...
                                'String', '')
        
    else
        % enables them
        set(handles.tempBoxes, 'Enable', 'on')
    end
    
    % updates the waitbar
    waitbar(1, waitBarHandle)
    
catch
    % brings up an question dialog to ask use what they want to do if the
    % data couldn't be fetched
    selection = questdlg(   'The BPR 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)
        
    else
        % tries to navigate back to the main menu to ensure that other
        % things do not break
        try
            % sends command and tries to fill the read box
            set(handles.readbox, 'String', tharbprobjdisplaymenu(serialObj))
            
        catch
        end
    end
end

% closes the waitbar
close(waitBarHandle)

% only does this if the main gui handle was supplied
if ~isempty(mainGuiHandle)
    % turns the collect data flag back on
    setappdata(mainGuiHandle, collectDataFlag, 1)
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 600) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New set pressure must be an integer between 0 and 600 bar.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 650) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New alarm pressure must be an integer between 0 and 650 bar.')
    
    % empties the box
    set(hObject, 'String', '')
end



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

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

% checks the value
if ~isnumberbetween(newValue, 0, 75) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New set temperature must be an integer between 0 and 75 C.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

%try-catch for error behaviour
try
    % brings up a waitbar
    waitBarHandle = waitbar(0.5, 'Changing external heater control status...');
    
    % if it has just been checked
    if get(hObject, 'Value')
        % starts control
        tharbprobjstartextheater(handles.serialObj)
    else
        % stops control
        tharbprobjstopextheater(handles.serialObj)
    end
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not change external heater control status.')

    % changes the checkbox back
    set(hObject, 'Value', ~get(hObject, 'Value'))
end

% enables or disables the external temperature buttons accordingly
if get(hObject, 'Value')
    % disables and clears the boxes
    set(handles.tempBoxes, 'Enable', 'off', 'String', '')
else
    % enables them
    set(handles.tempBoxes, 'Enable', 'on')
end

% closes the waitbar
close(waitBarHandle)


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 75) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New alarm temperature must be an integer between 0 and 75 C.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 600) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New set pressure must be an integer between 0 and 600 bar.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 650) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New alarm pressure must be an integer between 0 and 650 bar.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 75) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New set temperature must be an integer between 0 and 75 C.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 75) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'New alarm temperature must be an integer between 0 and 75 C.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Updating setup... (this will take about 15 seconds)');

% try-catch to deal with errors
try
    % sends command (the last two are str2num on purpose so that if they
    % are blank they get turned into '' - str2double would turn them into
    % NaNs
    tharbprobjwriteprofilesetup(handles.serialObj, str2double(get(handles.setPressA, 'String')), str2double(get(handles.alarmPressA, 'String')), str2num(get(handles.extSetTempA, 'String')), str2num(get(handles.extAlarmTempA, 'String')), 'A')
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not update the profile setup.')
end

% updates the current profile
refreshCurrentProfile_Callback(handles.refreshCurrentProfile, eventdata, handles);

% removes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Updating setup... (this will take about 15 seconds)');

% try-catch to deal with errors
try
    % sends command
    tharbprobjwriteprofilesetup(handles.serialObj, str2double(get(handles.setPressB, 'String')), str2double(get(handles.alarmPressB, 'String')), str2num(get(handles.extSetTempB, 'String')), str2num(get(handles.extAlarmTempB, 'String')), 'B')
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not update the profile setup.')
end

% updates the current profile
refreshCurrentProfile_Callback(handles.refreshCurrentProfile, eventdata, handles);

% removes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Updating configuration... (this will take about 20 seconds)');

% try-catch to deal with errors
try
    % sends command
    tharbprobjwriteprofileconfig(handles.serialObj, get(handles.nameA, 'String'), str2double(get(handles.kpA, 'String')), str2double(get(handles.kiA, 'String')), str2double(get(handles.kdA, 'String')), str2double(get(handles.maxOutA, 'String')), 'A')
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not update the profile configuration.')
end

% updates the current profile
refreshCurrentProfile_Callback(handles.refreshCurrentProfile, eventdata, handles);

% removes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Updating configuration... (this will take about 20 seconds)');

% try-catch to deal with errors
try
    % sends command
    tharbprobjwriteprofileconfig(handles.serialObj, get(handles.nameA, 'String'), str2double(get(handles.kpA, 'String')), str2double(get(handles.kiA, 'String')), str2double(get(handles.kdA, 'String')), str2double(get(handles.maxOutA, 'String')), 'A')
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not update the profile configuration.')
end

% updates the current profile
refreshCurrentProfile_Callback(handles.refreshCurrentProfile, eventdata, handles);

% removes the waitbar
close(waitBarHandle)


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

% new value
newString = get(hObject, 'String');

% checks the value
if ~isempty(newString) && (~ischar(newString) || isempty(newString) || length(newString) > 7 || any(newString > 126) || any(newString < 32))
    % brings up an error dialog
    warntooltip(hObject, 'Profile name must be no longer than 7 characters long, and contain only standard printable ASCII characters.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 300) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'Kp must be an integer between 0 and 300.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 1000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'Ki must be an integer between 0 and 1000.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 30000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'MaxOut must be an integer between 0 and 30000.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

% new value
newString = get(hObject, 'String');

% checks the value
if ~isempty(newString) && (~ischar(newString) || isempty(newString) || length(newString) > 7 || any(newString > 126) || any(newString < 32))
    % brings up an error dialog
    warntooltip(hObject, 'Profile name must be no longer than 7 characters long, and contain only standard printable ASCII characters.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 300) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip('Kp must be an integer between 0 and 300.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 1000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'Ki must be an integer between 0 and 1000.')
    
    % empties the box
    set(hObject, 'String', '')
end


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


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

% checks the value
if ~isnumberbetween(newValue, 0, 30000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'MaxOut must be an integer between 0 and 30000.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 1000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'Kd must be an integer between 0 and 1000.')
    
    % empties the box
    set(hObject, 'String', '')
end



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

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

% checks the value
if ~isnumberbetween(newValue, 0, 1000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'Kd must be an integer between 0 and 1000.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

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

% checks the value
if ~isnumberbetween(newValue, 0, 6000) || ~isInteger(newValue)
    % brings up an error dialog
    warntooltip(hObject, 'Valve position must be an integer between 0 and 6000.')
    
    % empties the box
    set(hObject, 'String', '')
end


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

% can only do this if the control status is 0 (this box should be enabled
% in that case anyway
if ~get(handles.valveControlStatus, 'Value')
    % tries to set the valve position
    try
        % sends command
        tharbprobjwritevalveposition(handles.serialObj, str2double(get(handles.valvePosition, 'String')))
        
    catch
        % brings up an error dialog
        errortooltip(hObject, 'Could not set new valve position.')
    end
    
else
    % brings up an error dialog
    errortooltip(hObject, 'Cannot set valve position when automatic valve control is turned on.')
end


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

% refreshes the box
try
    % starts up a waitbar
    waitBarHandle = waitbar(0.5, 'Reading valve position...');
    
    % sends command and sets it
    set(handles.valvePosition, 'String', num2str(tharbprobjreadvalveposition(handles.serialObj)))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not read new valve position.')
end

% closes the waitbar
close(waitBarHandle)


% --- Executes on selection change in readBox.
function readBox_Callback(hObject, eventdata, handles)
% hObject    handle to readBox (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 readBox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from readBox


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

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

% reads in data
try
    % brings up a waitbar
    waitBarHandle = waitbar(0.5, 'Collecting data...');

    % fills the readBox with new data
    set(handles.readBox, 'String', tharbprobjcomm('read', handles.serialObj))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not retrieve data.')
end

% closes the waitbar
close(waitBarHandle)

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

% reads out data
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Retrieving data...');

    % fills the readBox with new data
    set(handles.readBox, 'String', tharbprobjcomm('readnoflush', handles.serialObj))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not retrieve data...')
end

% closes the waitbar
close(waitBarHandle)


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


% --- 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)

% sends the command in the command box
try
    % brings up a waitbar
    waitBarHandle = waitbar(0.5, 'Sending command...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, get(handles.command, 'String'))
    
catch
    % brings up an error dialog
	errortooltip(hObject, 'Could not send command.')
end

% close waitbar
close(waitBarHandle)


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

% opens manual
open('Thar MN04-20CE- ABPR-20 Operator Manual.pdf')


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

% if its a pc...
if ispc
    % opens the protocols document
    winopen('Thar Protocols.docx')

else
    % displays an info box with the path to the document in
    msgbox(['The document can be be found in: ', fileparts(mfilename('fullpath')), '\Thar Protocols.docx'], 'Information')
end


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

% emulates sending the F1 key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 17)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the F2 key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handeles.serialObj, 18)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the F3 key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 19)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the F4 key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 20)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the F5 key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 21)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the ESC key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 27)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the ENTER key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 13)
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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


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

% changes the profile
try
    % brings up a waitbar
    waitBarHandle = waitbar(0.5, 'Changing the profile...');
    
    % sends command
    tharbprobjsetprofile(handles.serialObj, get(handles.currentProfile, 'String'))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not change the current profile.')
end

% closes the waitbar
close(waitBarHandle)


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

% gets the current profile
try
    % brings up a waitbar
    waitBarHandle = waitbar(0.5, 'Getting the current profile...');
    
    % sends command
    set(handles.currentProfile, 'String', tharbprobjreadcurrentprofile(handles.serialObj))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send retrieve updated current profile.')
end

% closes the waitbar
close(waitBarHandle)


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

% attempts to reset the BPR - this currently does not work correctly
try
    % starts a waitbar
    waitBarHandle = waitbar(0.5, 'Resetting the BPR...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, '[0n')
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send reset BPR command.')
end

% closes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Retrieving Setup A....');

% attempts to get the profile setup for A
try
    % gets the profile setup for A
    [setPressA, alarmPressA, extSetTempA, extAlarmTempA] = tharbprobjreadprofilesetup(handles.serialObj, 'A');

    % fills the boxes
    set(handles.setPressA, 'String', num2str(setPressA))
    set(handles.alarmPressA, 'String', num2str(alarmPressA))
    set(handles.extSetTempA, 'String', num2str(extSetTempA))
    set(handles.extAlarmTempA, 'String', num2str(extAlarmTempA))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not fetch profile setup.')
end

% closes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Retrieving Setup B....');

% attempts to get the profile setup for B
try
    % gets the profile setup for B
    [setPressB, alarmPressB, extSetTempB, extAlarmTempB] = tharbprobjreadprofilesetup(handles.serialObj, 'B');

    % fills the boxes
    set(handles.setPressB, 'String', num2str(setPressB))
    set(handles.alarmPressB, 'String', num2str(alarmPressB))
    set(handles.extSetTempB, 'String', num2str(extSetTempB))
    set(handles.extAlarmTempB, 'String', num2str(extAlarmTempB))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not fetch profile setup.')
end

% closes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Retrieving Profile A....');

% attempts to get the profile setup for A
try
    % gets the profile config for A
    [profileNameA, kpA, kiA, kdA, maxOutA] = tharbprobjreadprofileconfig(handles.serialObj, 'A');

    % fills the boxes
    set(handles.nameA, 'String', profileNameA)
    set(handles.kpA, 'String', num2str(kpA))
    set(handles.kiA, 'String', num2str(kiA))
    set(handles.kdA, 'String', num2str(kdA))
    set(handles.maxOutA, 'String', num2str(maxOutA))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not fetch profile configuration.')
end

% closes the waitbar
close(waitBarHandle)


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

% brings up a waitbar
waitBarHandle = waitbar(0.5, 'Retrieving Profile B....');

% attempts to get the profile setup for B
try
    % gets the profile config for B
    [profileNameB, kpB, kiB, kdB, maxOutB] = tharbprobjreadprofileconfig(handles.serialObj, 'B');

    % fills the boxes
    set(handles.nameB, 'String', profileNameB)
    set(handles.kpB, 'String', num2str(kpB))
    set(handles.kiB, 'String', num2str(kiB))
    set(handles.kdB, 'String', num2str(kdB))
    set(handles.maxOutB, 'String', num2str(maxOutB))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not fetch profile configuration.')
end

% closes the waitbar
close(waitBarHandle)


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

% emulates sending the F1 key on the handheld
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');
    
    % sends command
    tharbprobjcomm('write', handles.serialObj, 'M')
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% navigates to the main display menu
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');

    % navigates to the 1st display menu, returning the response to the read box
    set(handles.readBox, 'String', tharbprobjdisplaymenu(handles.serialObj))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)


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

% navigates to the second display menu
try
    % sets up a waitbar
    waitBarHandle = waitbar(0.5, 'Pressing key...');

    % navigates to the 2nd display menu, returning the response to the read box
    set(handles.readBox, 'String', tharbprobjdisplaymenu2(handles.serialObj))
    
catch
    % brings up an error dialog
    errortooltip(hObject, 'Could not send command.')
end

% closes the waitbar
close(waitBarHandle)

Contact us