Code covered by the BSD License  

Highlights from
GSIOC RS232 communication files

GSIOC RS232 communication files



For communicating with GSIOC devices via RS232

function serialObject = gsiocobj(comPort)
% GSIOCOBJ Returns the serial object for GSIOC devices
% serialObject = gsiocobj(comPort) returns the serial object for GSIOC
% devices 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.

% Normal usage:

% e.g. serialObject = gsiocobj(9) - returns a serial object for the GSIOC
% device on COM9

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

% Error handling
if ~isscalar(comPort) || comPort ~= uint8(comPort) || ~comPort
    % errors
    error('comPort 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' ,19200,...
        'DataBits', 8,...
        'Parity', 'even',...
        'StopBits', 1,...
        'Flowcontrol', 'none',...
        'Terminator', '',...
        'TimeOut', 0.5);

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

Contact us