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 response = rheodyneobj
% RHEODYNEOBJ Returns the timer object for use with the Rheodyne
% response = rheodyneobj returns the timer object for use with the
% Rheodyne. Because of how the way the audioplayer object deals with the
% audio, this timer is now relegated to just checking the timer status, and
% making sure its still working.

% e.g. timerObj = rheodyneobj - returns a timer object for the rheodyne

% if the rheodyne object already exists, return that (the first element in
% case of there being other timers
response = timerfindall('Tag', 'rheodyne');

% default time period for TWO valve turns - i.e. a whole cycle
period = 10;

% if it is empty
if isempty(response)
    % create the timer object - note that the pulse is actually for 500
    % cycles (so 1000 valve turns) (takes up at least 40 MB :( )
    response = timer(	'ExecutionMode', 'fixedRate',...
                        'Period', 5,...
                        'TimerFcn', @rheodyneTimerCallback,...
                        'Tag', 'rheodyne',...
                        'ErrorFcn', @rheodyneTimerErrorCallback,...
                        'ObjectVisibility', 'off',...
                        'UserData', struct('audioPlayerObject', audioplayer(repmat(rheodyneobjpulse(10), 1, 5), 8192)));
    % sets the response to be the first element only
    response = response(1);

function rheodyneTimerCallback(timerObject, eventdata)
% RHEODYNETIMERCALLBACK plays the pulse noise back

% gets the user data
userData = timerObject.userData;

% plays the sound - this SHOULD work, but doesn't because MATLAB crashes if
% you play too many of these together
%sound(rheodynepulse(timerObject.Period), 8192)

% so instead we use the previously generated audioplayer object -
% unfortunately you cannot change the sound the object is tied to, but you
% CAN change the sample rate, so we can stretch or compress the sound in
% time, e.g. for the default pulse time of 5 s (10 s per cycle remember),
% if we change the sample rate to 4096, then the pulse time becomes 10 s
% (or 20 s per cycle)

% gets the audioplayer object out (same crap as the timers)
audioPlayerObject = userData.audioPlayerObject;

% also have to stop then restart playback
if ~isplaying(audioPlayerObject)
    % try and restart it
        % play

        % display a warning
        warning('rheodyneObj:restartSound', 'Error when trying to restart the sound.')

function rheodyneTimerErrorCallback(timerObject, eventdata)

% brings up an error dialog
errordlg('Rheodyne timer has errored and is now stopped.  Restart the timer only if you know what you''re doing.')

Contact us