Code covered by the BSD License  

Highlights from
cport

  • cportclose; function stat=cportclose(H) closes an open serial or parallel port
  • cportconfig; function stat=cportconfig(H,Name,Value,Name,Value,Name,Value...)
  • cportgetchar; function Params[ch,err]=cportstate(H,nchar) retrieves characters from a
  • cportopen; function H=cportopen(Port) opens a serial or parallel communication port
  • cportpurge; function stat=cportpurge(H) discards all characters from the output or
  • cportreset; function [stat,ErrStr]=cportreset(H) resets a previously opened communications
  • cportstate; function Params=cportstate(H) retrieves the configuration and timeout
  • cportwrite; function nW=cportwrite(H,Data,EOL) sends data to a previously opened
  • s=cportgetline(H,nMax,EOL,Tim... function s=cportgetline(H,nMax,EOL,Timeout) reads in one line of character
  • Contents.m
  • View all files
from cport by Eyal Doron
The CPORT minitoolbox supplies basic functions to open, configure, read from,etc to ports.

cportconfig;
function cportconfig;
%function stat=cportconfig(H,Name,Value,Name,Value,Name,Value...) 
%configures a serial or parallel port previously opened by cportopen, 
%and/or returns the current or modified configuration. The parameters are:
%
%Input:
%------
%H     - The port handle returned by cportopen.
%Name  - A character string containing a configuration parameter name. It
%        is enough to specity just enough characters to make a unique
%        identification, e.g. "Ba" instead of "BaudRate".
%Value - A scalar or character string containing the new parameter value.
%
%Output:
%-------
%stat  - Optional. If present, contains the port configuration in a record
%        whose fields are the parameter names and whose values are the
%        configuration values. The parameter names and values are the same
%        as for the input parameters.
%
%* zero or more input parameter pairs may be specified.
%* 1/ON/YES/TRUE are synonomous, as are 0/OFF/NO/FALSE.
%* All strings may be replaced by their equivalent numbers, as defined
%  in Windows.h.
%* The commands are case insensitive.
%
%Supported parameters and their allowed values are given below
%
%Port Configuration:
%-------------------
%   BaudRate:     Specifies the device communication rate in bits per second.
%   ByteSize:     Specifies the bits per byte transmitted and received, 
%                 can be 4-8.
%   StopBits:     Specifies the number of stop bits. Aloowed values are
%                 1, 1.5 and 2. The common value is 1.
%   Parity:       Specifies the parity scheme: NONE,ODD,EVEN,MARK,SPACE (0-4).
%                 Do not confuse this member with the fParity member, which 
%                 turns parity on or off. Because parity is rarely used, this 
%                 member is usually NONE.
%   fParity:      ON/OFF toggles parity checking.
%   fOutX, fInX:  ON/OFF toggles software flow control (XON/XOFF) using the
%                 XonChar/XoffChar characters.
%   fRtsControl:  ON/OFF toggles the RTS line on and off during the 
%                 connection. HANDSHAKE turns on RTS handshaking. TOGGLE
%                 sets the RTS line high if bytes are available for 
%                 transmission, later putting it to low.
%   fOutxCtsFlow: ON/OFF Turn the CTS flow control on and off. To use RTS/CTS 
%                 flow control, specify ON for this member and HANDSHAKE for 
%                 the fRtsControl member.
%   fOutxDsrFlow: ON/OFF toggles the DSR flow control. DSR flow control is 
%                 rarely used. A typical port configuration is to set this 
%                 member to OFF, while enabling the DTR line.
%   fDtrControl:  ON/OFF turns the DTR line on and off during the connection. 
%                 HANDSHAKE turns on DTR handshaking.
%   fDsrSensitivity: ON/OFF specifies whether the comm driver is sensitive to the
%                 state of the DSR line. If ON, the driver ignores any bytes 
%                 received while the DSR line is low.
%   fTXContinueOnXoff: ON/OFF Specifies whether transmission stops when the input 
%                 buffer is full and the driver has transmitted the XOFF 
%                 character. .
%   fErrorChar:   ON/OFF specifies whether bytes received with parity errors are 
%                 replaced by the ErrorChar character. This will be operative 
%                 only if fParity is also ON.
%   fNull:        ON/OFF specifies whether null bytes are discarded.
%   fAbortOnError: ON/OFF specifies whether read and write operations are 
%                 terminated if an error occurs. The driver will then not accept
%                 further communication until it is cleared using CPORTRESET.
%   XonLim:       The minimum number of bytes allowed in the input buffer before 
%                 flow control is activated to inhibit the sender. This assumes
%                 that either Xon/Xoff, RTS, or DTR input flow control is
%                 specified in fInX, fRtsControl or fDtrControl. Note that the
%                 sender may transmit characters after the flow control signal
%                 has been activated, so this value should never be zero.
%   XoffLim:      The maximum number of bytes allowed in the input buffer before
%                 flow control is activated to allow transmission by the sender.
%                 This assumes that either Xon/Xoff, RTS, or DTR input flow 
%                 control is specified in fInX, fRtsControl or fDtrControl. The
%                 maximum number of bytes allowed is calculated by subtracting
%                 this value from the size, in bytes, of the input buffer.
%   XonChar,XoffChar: The ASCII value of the characters used for Xon/Xoff 
%                 software flow control.
%   ErrorChar:    The ASCII value of the character used to replaced bytes 
%                 received with a parity error.
%   EofChar:      The ASCII value of the character used to signal the end of data.
%   EvtChar:      The ASCII value of the character used to signal an event.
%
%Port timeouts:
%--------------
%   ReadIntervalTimeout:
%                 The maximum number of milliseconds that can elapse between
%                 two characters without a time-out occurring with the 
%                 ReadIntervalTimeout member.
%   ReadTotalTimeoutMultiplier:
%                 For each read operation, this number is multiplied by the 
%                 number of bytes that the read operation expects to receive.
%   ReadTotalTimeoutConstant:
%                 This member is the number of milliseconds added to the 
%                 result of multiplying the total number of bytes to read by 
%                 ReadTotalTimeoutMultiplier. The result is the number of 
%                 milliseconds that must elapse before a time-out for the 
%                 read operation occurs.    
%   WriteTotalTimeoutMultiplier:
%                 For each write operation, this number is multiplied by the 
%                 number of bytes that the write operation expects to receive.
%   WriteTotalTimeoutConstant:
%                 This member is the number of milliseconds added to the 
%                 result of multiplying the total number of bytes to write 
%                 by WriteTotalTimeoutMultiplier. The result is the number 
%                 of milliseconds that must elapse before a time-out for the 
%                 write operation occurs.
%
%To assist with multitasking, it is common practice to configure so that read
%operations immediately return with the characters to be read. To do this, 
%set ReadIntervalTimeout to -1 and set both ReadTotalTimeoutMultiplier and 
%ReadTotalTimeoutMultiplier to zero.

% Written by Eyal Doron, July 1999

error('CPORTCONFIG is implemented in a MEX file.');

Contact us at files@mathworks.com