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.

fibreobjconnect(serialObject)
function fibreobjconnect(serialObject)
% FIBREOBJCONNECT initialises communication with the FOR
% fibreobjconnect(serialObject) initialises communication with the FOR, given
% serialObject as a valid FOR serial object (generated by fibreobj).

% e.g. fibreobjconnect(fibreobj(9)) - initialises communication with the
% FOR 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.')
end

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

else
    % opens communication
    fopen(serialObject)
end

% if errorChecking flag wasn't added
if ~isfield(serialObject.UserData, 'errorChecking')
    % add it as off by default
    serialObject.UserData.errorChecking = false;
end

% configures the instrument immediately
try
    % sends the command to enable both channels and turn the LED on (and
    % turn the other channels off)
    fibreobjwriteconfig(serialObject, true, [true, true, false, false, false, false])
    
catch
    % errors DEBUG probably want to change that - don't see why you'd want
    % to explicitly turn it off on connection
    warning('fibreObjConnect:turnOffAllChannelsFailure', 'Could not configure the channels on connection.')
end
                        
% the rest of the commands configure the device for subsequent use

% if the averages hasn't been defined, set it to 1000
if ~isfield(serialObject.UserData, 'averages')
    % set it
    serialObject.UserData.averages = 1000;
end

% sets 1000 averages
try
    % sends the command
    fibreobjwriteaverages(serialObject, serialObject.UserData.averages)

catch
    % gives a warning
    warning('fibreObjConnect:writeAveragesFailure', 'Did not correctly configure the number of averages on connection.')
end

% same for the delay time
if ~isfield(serialObject.UserData, 'delayTime')
    % saves it
    serialObject.UserData.delayTime = 20;
end

% sets a delay time of 20 ms
try
    % sends the command
    fibreobjwritedelaytime(serialObject, serialObject.UserData.delayTime)
    
catch
    % gives another warning
    warning('fibreObjConnect:writeDelayTimeFailure', 'Did not correctly configure the delay time on connection.')
end

Contact us