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.

tc08connect(fileName)
function tc08Handle = tc08connect(fileName)
% TC08CONNECT initialises communication with the PicoLog program
% tc08Handle = tc08connect initialises communication with the PicoLog
% program via the DDE interface, and returns the DDE handle as a response.
% If the fileName is supplied, it uses that for the location of the EXE IF
% required.

% e.g. tc08Handle = tc08connect - opens the PicoLog program if it is not
% already open, then connects to the program and returns the handle e.g.
% 7.292e-304

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

% initialises communication and gets handle (returns 0 if it didn't work)
tc08Handle = ddeinit('PLW', 'Current');

% if program not working, opens program in the default location then
% requests handle again
if ~tc08Handle
    % checks the supplied filename
    if nargin && exist(fileName, 'file') && strcmp(fileName(end - 3:end), '.exe')
        % opens the program
        open(fileName)
        
    else
        % only display the warning if there were any arguments
        if nargin
            % gives a warning
            warning('tc08Connect:invalidPath', 'Supplied filename is not valid, so reverting to default...')
        end

        % opens program (can't get it to minimise from the command line yet)
        open('C:\Program Files\Pico\plw32.exe')
    end

    % waits for program to start up, and to ignore the first dodgy set of
    % data (increased from 5 because of issues wtih the current version of
    % Pico Log and Vista)
    pause(10)

    % invents a dummy handle
    tc08Handle = false;
    
    % keeps on trying to connect
    for m = 1:15
        % tries
        try
            % tries to initialises communication
            tc08Handle = ddeinit('PLW', 'Current');
            
            % breaks out of the for loop if it worked (takes about 5 tries,
            % i.e. 2.5 seconds)
            if tc08Handle
                % leaves
                break
            end
            
        catch
        end
        
        % pauses per attempt
        pause(0.5)
    end
    
    % if it STILL doesn't work, then returns an error message
    if ~tc08Handle
        % errors
        error('Could not initialise communication with PicoLog program')
    end
    
    % tries to query until the data makes sense
    for n = 1:20
        % tries
        try
            % tries to collect data
            data = tc08query(tc08Handle);
            
            % leaves if any of the data is not 0 (it is all 0s until it is
            % ready to go) - this takes about 2 seconds (4 goes)
            if any(data)
                % leaves
                break
            end
            
        catch
        end
        
        % pauses per attempt
        pause(0.5)
    end
    
    % if the last data is STILL all empty then error
    if all(~data)
        % if it got this far then error because the data is still all zeros
        error('Pico software is probably not connect to the device correctly.')
    end
end

Contact us