Code covered by the BSD License  

Highlights from
Gilson HPLC Pump RS232 communication

Gilson HPLC Pump RS232 communication



Communicates with Gilson HPLC pumps via RS232 (and 508 interface module)

gilsonpumpobj(comPort, userData)
function serialObject = gilsonpumpobj(comPort, userData)
% GILSONPUMPOBJ Returns the serial object for Gilson pumps
% serialObject = gilsonpumpobj(comPort) returns the serial object for
% Gilson pumps 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. Information can be passed into the serial object through the
% optional userData argument.  Information is stored here during a
% communication session with the pump for more efficient communication.

% Normal usage:

% e.g. serialObject = gilsonpumpobj(9) - returns a serial object for the
% Jasco pump on COM9

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

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

    % if userData was provided, modify the object
    if nargin >= 2
        % changes it
        serialObject.UserData = userData;

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

Contact us