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.

fibreobjdisconnect(serialObject)
function fibreobjdisconnect(serialObject)
% FIBREOBJDISCONNECT terminates communication with the FOR
% fibreobjdisconnect(serialObject) terminates communication with the FOR,
% given serialObject as a valid FOR serial object (generated by fibreobj).

% e.g. fibreobjdisconnect(serialObject(9)) - terminates communication with
% the FOR attached to COM9.

% Range:

% serialObject = valid serial port object


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

% error handling
if ~isserial(serialObject) || (~isfield(serialObject.UserData, 'realTermHandle') && ~isrunning(serialObject))
    % errors if the realterm handle isn't there, and the serial object is
    % closed
    error('serial must be a valid closed serial object.')
    
elseif isfield(serialObject.UserData, 'realTermHandle') && ~isrunning(serialObject.UserData.realTermHandle)
    % errors
    error('The realterm application must be connected.')
    
elseif isfield(serialObject.UserData, 'realTermHandle') && (~isfield(serialObject.UserData, 'captureFileID') || ~isfid(serialObject.UserData.captureFileID))
    % if using realterm, the capture file ID must be there
    error('If using Realterm, the capture file handle must be in the serial object''s UserData.')
end

% if the unit is still broadcasting, stop the data transmission
try
    % define an error flag
    errorFlag = false;
    
    % try to fetch some data - it'll error if it didn't work
    fibreobjreadintensity(serialObject);
    
    % if it didn't error - its still broadcasting
    errorFlag = true;
    
catch
end

% if its broadcasting...
if errorFlag
    % error
    error('Could not disconnect: device still appears to be broadcasting.')
end

% this turns off all of the LEDs on the front panel (not really necessary,
% but a nice touch anyway)
try
    % sends command
    fibreobjcomm('write', serialObject, 9, 1, 0)

catch
    % displays a warning
    warning('fibreObjDisconnect:displayLED', 'LEDs on front panel were not correctly switched off.')
end

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

else
    % closes communication conventionally
    fclose(serialObject)
end

% deletes it
delete(serialObject)

Contact us