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.

fibreobjreadconfig(serialObject)
function [ledMode, activeChannels, statusLEDs, channelNames] = fibreobjreadconfig(serialObject)
% FIBREOBJREADCONFIG sets the LED and channel configuration from the FOR
% [ledMode, channel, channel2] = fibreobjreadconfig(serialObject) gets the
% FOR device status: LED on or off, and which channels are to be broadcast.
% The FOR device must not be transmitting, the serial object must be valid,
% and ledMode, channel1 and channel2 are true/false logicals.

% gets the LED status - 2 means its off, 1 means its on (then converted
% into simple true/false logicals) (this only uses the least significant
% two bits)
try
    % sends it
    ledMode = bin2dec(sprintf('%d', bitget(fibreobjcomm('read', serialObject, 2, 1), 2:-1:1)));
    
catch
    % errors
    error('Could not get the led status.')
end

% decides what to do
switch ledMode
    case 1
        % its on
        ledMode = true;

    case 2
        % its off
        ledMode = false;

    case 0
        % this shouldn't happen (but does)
        error('Device appears to be broadcasting.')

    otherwise
        % edge case
        error('Unknown LED status.')
end

% saves the LED mode
serialObject.UserData.ledMode = ledMode;

% if there's another output argument
if nargout >= 2
    % sends the command to get the number of channels
    try
        % gets all the channels
        activeChannels = logical(bitget(fibreobjcomm('read', serialObject, 3, 1), 1:6));
        
        % stores it in the serial object
        serialObject.UserData.activeChannels = activeChannels;
        
    catch
        % errors
        error('Could not read the current active channels.')
    end
end

% only reads the next if there's enough output arguments (seeing as we
% usually don't care)
if nargout >= 3
    % sends the command to read the LEDs on the front panel
    try
        % sends it
        statusLEDs = logical(bitget(fibreobjcomm('read', serialObject, 9, 1), 2:4));
        
        % often this doesn't add up - could repair it here too
        %fibreobjcomm('write', serialObject, 9, 1, (8 * activeChannels(2)) + (4 * activeChannels(1)) + (2 * ledMode))

    catch
        % errors
        error('Unable to get the status of the LEDs on the front panel.')
    end
end

% if there is another output argument, return the channel names for
% reference
if nargout >= 4
    % returns them
    channelNames = {'Channel 1';...
                    'Channel 2';...
                    'Internal Diode';...
                    'Noise';...
                    'Temperature';...
                    'Reference'};
end

Contact us