Code covered by the BSD License  

Highlights from
Jasco BPR RS232 communication

Jasco BPR RS232 communication



20 May 2013 (Updated )

Drivers and higher level commands for controlling Jasco BPRs via RS232.

function serialObject = bprobj(comPort)
% BPROBJ Returns the serial object for Jasco back-pressure regulators
% serialObject = bprobj(comPort) returns the serial object for Jasco
% back-pressure regulators given a suitable COM port number (unsigned
% integer: 1-255). If an object already exists on that COM port (open or
% otherwise), returns an error.

% e.g. serialObject = bprobj(5) - returns a serial object for the BPR on
% COM5

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

% checks it is an integer from 1 to 255
if ~isscalar(comPort) || comPort ~= uint8(comPort) || ~comPort
    % errors
    error('com must be an unsigned integer from 1 to 255')

% if object on specified COM port exists, errors, otherwise creates serial
% object

% initialises variables
serialPort = sprintf('COM%d', comPort);

% if serial object does not exist, defines serial object and opens it
if isempty(instrfindall('Port', serialPort))
    % creates serial object
    serialObject = serial(  serialPort,...
        'BaudRate', 9600,...
        'DataBits', 8,...
        'Parity', 'none',...
        'StopBits', 2,...
        'Flowcontrol', 'hardware',...
        'Terminator', 'CR',...
        'TimeOut', 2);

    % errors
    error('Object(s) already exist on this serial port')

Contact us