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.

function tempobjconnect(serialObject)
% TEMPOBJCONNECT initialises communication with Eurotherm controllers
% tempobjconnect(serialObject) initialises communication with Eurotherm
% series 2000 and 3000 temperature controllers, given serialObject as a
% valid temperature controller serial object (generated by tempobj).

% e.g. tempobjconnect(tempobj(7)) - initialises communication with the
% temperature controller attached to COM7.

% Range:

% serialObject = valid serial port object (preferably generated by tempobj)

% 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.')

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

    % opens communication

% default device address
deviceAddress = 1;

% short pause for Vista (unknown if this is necessary when using Realterm))

% tries to gets the Eurotherm type and store it in user data
    % sends command
    maxWords = dec2hex(tempobjcomm('read', serialObject, deviceAddress, 122, 1));
    % displays a warning (the tempobjcomm protocols will see the absence of
    % the field and cope with it accordingly)
    warning('tempObjConnect:UnknownEurotherm', 'Could not retrieve Eurotherm controller type - read and write commands will be limited to the minimum allowed for series 2000 controllers for this serialObject (32).')

    % defines a default
    maxWords = '22';
% only want the first two hex digits really
switch maxWords(1:2);
    case '22'
        % sets the maximum number of words that can be sent/received
        maxWords = 32;
    case '24'
        % much more words can be received by the 2400 series
        % controllers
        maxWords = 125;
        % defaults to 32 - note that the 3216 responds as '8D8A8' for some
        % reason
        maxWords = 32;
% saves the data
serialObject.UserData = catstructs(serialObject.UserData, struct('maxWords', maxWords));

Contact us