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 data = bprobjvalvedata(BPRObj)
% BPROBJVALVEDATA gets information on the current valve position
% data = bprobjvalvedata(BPRObj) returns information of the current valve
% position of Jasco BPRs.  Caution: this will not work properly if any
% other commands are sent at the same time as this (as the Jasco BPR will
% broadcast data over a short period).

% e.g. data = bprobjvalvedata(bprobj(5)) returns information on the valve
% position from the BPR attached to COM5

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

% sets up the system for broadcasting data at 1.0 second intervals (the
% time must be a minimum of 1 and a maximum of 10, but must be multiplied
% be 10)
bprobjcomm(BPRObj, ['#7 0 ', dec2hex(10)])

% start recording the data
bprobjcomm(BPRObj, '#8 1')

% the next bit is try-catched because the BPR data broadcast MUST be turned
% off at the end
    % define an error flag
    errorFlag = false;
    % leaves a short pause for the buffer to fill with data
    %pause(2) % is this even necessary (will fscanf not just timeout if it
    % reads out some data (uses serialscan to ensure compatibility with
    % Realterm)
    rawData = serialscan(BPRObj);
    % the data is in the format: #2 0 NN PP TT CC VV PP, where #2 0 means
    % it a parameter and its correct, NN is number 0 for first one which is sent straight away after the start
    %recording command, 1..2..3 and so on for each data string after the
    %command, i.e. 1 should be 1 whole time period after the command was sent
    %etc. Can only go to 127 (remember its in hex), after which it starts
    %counting again at 0), PP is the current pressure, TT is the temperature,
    %SP is the set pressure, VV is the value on/off count (not known exactly
    %what this is yet), and PP is the valve position.
    % breaks the data up    
    rawData = textscan(rawData);
    rawData = rawData{1};
    % checks its OK
    if ~strcmp(rawData{1}, '#2') || strcmp(rawData{2}, '0')
        % errors
        error('Error in collecting the data.')
    % converts it all
    rawData(3:end) = hex2dec(rawData(3:end));
    % processes the rest of the data
    data = structure(   'number', rawData{3},...
                        'currentPress', rawData{4},...
                        'currentTemp', rawData{5},...
                        'dataCounter', rawData{6},...
                        'valveCount', rawData{7},...
                        'valvePosition', rawData{8});
    % there was an error
    errorFlag = true;

% stops the data transmission (this is deliberately not sent by the usual
% method, because of the potential overlap of data) - this should respond
% with a final packet of data, with the dataCounter 255
serialprint(BPRObj, '#8 0')

% leave a short pause to allow the BPR to catch up

% now empty the data buffer
if BPRObj.BytesAvailable
    % empty it

% if there was an error, error
if errorFlag
    % error
    error('Error encountered during data collection.')

Contact us