Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation



06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

function pumpobjconnect(serialObject)
% PUMPOBJCONNECT initialises communication with Jasco pumps
% pumpobjconnect(serialObject) initialises communication with Jasco pumps,
% given serialObject as a valid pump serial object (generated by pumpobj).

% e.g. pumpobjconnect(pumpobj(9)) - initialises communication with the pump
% attached to COM9

% Range:

% serialObject = valid serial port object

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

% error handling
if ~isserial(serialObject) || isrunning(serialObject)
    % errors
    error('serialObject must be a valid closed serial object.')
elseif isfield(serialObject.UserData, 'realTermHandle') && isrunning(serialObject.UserData.realTermHandle)
    % errors
    error('The realterm application must not be connected.')

% if the real term handle is there, do a different sequence of events
if isfield(serialObject.UserData, 'realTermHandle')
    % run the real term opener
    serialObject.UserData.captureFileID = realtermfopen(serialObject.UserData.realTermHandle);

    % opens communication

% Vista needs a brief pause to behave itself correctly - I've left his is
% for XP too, but in case you wanted to shave off that whole 400 ms, you
% could try...BUT old MATLAB versions detect Vista as "Microsoft Windows
% 2000" - whether this is required or not for realterm has not been tested
%if isempty(strfind(system_dependent('getos'), 'XP'))

% reads in the pressure - currently disabled until I can think of a good
% way of obtaining the main GUI handle (so I can access objectConfig)
    % only does this if the objectNumber field is present (so we can get
    % the name of the instrument)
    if isfield(serialObject.UserData, 'objectNumber')
        % obtain the main GUI handle (gets it from the Pico timer, if it
        % doesn't exist, this is empty)
        mainGuiHandle = getguihandles;

        % only go further if its there
        if ~isempty(mainGuiHandle)
            % gets the objectConfig
            objectConfig = getappdata(mainGuiHandle, 'objectConfig');

            % gets the instrument name
            pumpName = objectConfig(serialObject.UserData.objectNumber).name;

            % modifies it for searching
            searchPumpName = lower(pumpName);

            % only does the next part if the name features 'co2' or 'carbon
            % dioxide'
            if strfind(searchPumpName, 'co2') || strfind(searchPumpName, 'carbon dioxide')
                % gets the current pressure
                currentPress = pumpobjcurrentpress(serialObject);

                % defines the pressure for the cylinder emptying
                lowPressure = 46;

                % if its less than 46, bring up a dialog box for the user
                if currentPress <= lowPressure
                    % msgbox
                    warndlg(['The ', pumpName, ' current pressure is less than ', num2str(lowPressure), ' bar - the cylinder may be near emptying.'], 'Cylinder Empty Warning')
    % do nothing at let it through if it errored

Contact us