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.

usbtc08connect(types, tc08Path)
function [tc08Handle, tc08Buffer, tc08OverflowBuffer] = usbtc08connect(types, tc08Path)
% USBTC08CONNECT configures the USB Pico Technology TC-08 data logger
% [tc08Handle, tc08Buffer, tc08OverflowBuffer] = usbtc08connect(types, folder)
% configures the USB Pico Technology TC-08 data logger where types is a
% string or a vector array of strings of the respective channel types e.g.
% 'K' for type K thermocouples, and 'X' for measuring the voltage.
% tc08Handle is the handle of the TC-08 for using usbtc08query, or is 0 if
% any of the steps were unsuccessful, and tc08Buffer and tc08OverflowBuffer
% are pointers for the callib function used in usbtc08query.  If the tc08
% folder is supplied, it must point to the folder containing the DLLs.

% This is the much slower but more reliable method which calls on the DLLs
% provided by Pico Technology, i.e. it does not require the PicoLog program
% to be running at the time, like the other method does.

% e.g. usbtc08connect('KKX') sets up a USB TC-08 with
% 2 type K thermocouples and 1 voltage measurement, numbered as channels
% 2, 3 and 4 (the cold junction is #1).  Returns the handle and '4' as the
% number of channels.

% Range

% types = string or vector array of strings: 'B', 'E', 'J', 'K', 'N', 'R',
% 'S', 'T' for different thermocouples, or 'X' for measuring voltages

% number of arguments error check
error(nargchk(1, 2, nargin))

% error handling
if ~ischar(types) || ~any(ismember('BEJKNRSTX', types)) || numel(types) > 8
    % errors
    error('types must be a string or a vector array of strings no longer than 8, being either: B, E, J, K, N, R, S, T or X')
elseif nargin >= 2 && ~exist(tc08Path, 'file')
    % errors
    error('The folder must be a valid folder containing the correct DLLs and header file.')

% variables for location and filenames (done like this for easier
% subsequent conversion to the serial data logger)
tc08LibraryName = 'usbtc08';
tc08Call = 'usb_tc08';

% defines the file locations
tc08dllLocation = [tc08Path, filesep, tc08LibraryName '.dll'];
tc08hLocation = [tc08Path, filesep, tc08LibraryName, '.h'];

% if either doesn't exist, give a warning about using default path
if ~exist(tc08dllLocation, 'file') || ~exist(tc08hLocation, 'file')
    % warning
    warning('usbtc08Connect:incorrectPath', 'Either the dll or the h file could not be found, reverting to default location...')

    % changes the path
    tc08Path = 'C:\Program Files\Pico\Drivers\win32';
    % redefines the file locations
    tc08dllLocation = [tc08Path, filesep, tc08LibraryName '.dll'];
    tc08hLocation = [tc08Path, filesep, tc08LibraryName, '.h'];

% loads the dll library and accompanying header file
if ~libisloaded(tc08LibraryName)
    % loads function library - this will error if it doesn't exist
    loadlibrary(tc08dllLocation, tc08hLocation)

% opens communication
tc08Handle = calllib(tc08LibraryName, [tc08Call, '_open_unit']);

% displays error message if it did not connect properly (handle will be 0
% if it didn't)
if ~tc08Handle
    % errors
    error('TC-08 not successfully connected')

% adds an additional thermocouple for the cold junction and then
% converts it into int16 format for the dll call
types = int8(['K', types]);

% sets up all of the channels - +1 since the matrix starts at channel 0
% (cold junction) - includes a pre-allocation matrix for speed
checkChannel = zeroes(numel(types));

% loops to calibrate all the channels
for m = 1:numel(types)
    % returns 0 if OK (stored for later comparison)
    checkChannel(m) = calllib(tc08LibraryName, [tc08Call, '_set_channel'], tc08Handle, int16(m), types(m));

% sets up the correct objects for fetching data - 1 is the cold junction
% temperature
tc08Buffer = libpointer('singlePtr', 1:tc08Channels);
tc08OverflowBuffer = libpointer('int16Ptr', int16(9));

% response is 0 if any operations not carried out properly (otherwise
% returns tc08Handle as defined earlier)
if ~all(checkChannel)
    % displays a warning
    warning('usbtc08connect:channelsNotRegistered', '%d of the %d channels were not registered.', sum(~checkChannel), numel(checkChannel))

Contact us