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.

fibreobjwriteconfig(serialObject, ledMode, activeChannels)
function fibreobjwriteconfig(serialObject, ledMode, activeChannels)
% FIBREOBJWRITECONFIG sets the LED and channel configuration of the FOR
% fibreobjwriteconfig(serialObject, ledMode, activeChannels) tells the FOR
% device to turn the LED on or off, and which channels to broadcast. In
% order, each element of activeChannels represents channel1, channel2,
% internalDiode, noise, temperature, and reference.  The FOR device must
% not be transmitting, the serial object must be valid, and ledMode,
% activeChannels must be a 6 element logical.


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

% checks the logicals
if ~islogical(ledMode) || ~isscalar(ledMode)
    % errors
    error('ledMode must be a valid logical scalar.')
    
elseif ~islogical(activeChannels) || numel(activeChannels) ~= 6
    % errors
    error('activeChannels must be a 6-element logical array.')
end

% turns the LED on or off
if ledMode
    % sends one to turn the LED on
    try
        % sends it
        fibreobjcomm('write', serialObject, 2, 1, 1)
        
    catch
        % errors
        error('Could not turn the LED on.')
    end

else
    % sends a different one to turn it off
    try
        % sends it
        fibreobjcomm('write', serialObject, 2, 1, 2)
        
    catch
        % errors
        error('Could not turn the LED off.')
    end
end

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

% pre-defines the answer
channelByte = 0;

% converts the channels into the correct format (there must be a built-in
% MATLAB function for doing this already)
for m = 1:numel(activeChannels)
    % changes it
    channelByte = channelByte + activeChannels(m) * 2 ^ (m - 1);
end

% sends the command to set the number of channels - this could possible be
% extended to include: the 3rd bit for the internal diode, the 4th bit for
% the noise, the 5th bit for the temperature, and the 6th bit for the
% reference intensity - whether this is information worth collecting is
% another matter
try
    % sends the command
    fibreobjcomm('write', serialObject, 3, 1, channelByte)

catch
    % errors
    error('Could not select the correct channels.')
end

% store the number of channels
serialObject.UserData.activeChannels = activeChannels;

% sends the command to update the LEDs on the front panel
try
    % sends it
    fibreobjcomm('write', serialObject, 9, 1, (8 * activeChannels(2)) + (4 * activeChannels(1)) + (2 * ledMode))

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

Contact us