SerialPort Class Reference

#include <SerialPort.h>

List of all members.

Public Member Functions

 SerialPort (unsigned int baudRate, unsigned char dataBits=8, Parity parity=kParity_None, StopBits stopBits=kStopBits_One)
 ~SerialPort ()
void SetFlowControl (FlowControl flowControl)
void EnableTermination (char terminator= '\n')
void DisableTermination ()
int GetBytesReceived (void)
void Printf (const char *writeFmt,...)
void Scanf (const char *readFmt,...)
unsigned int Read (char *buffer, int count)
unsigned int Write (const char *buffer, int count)
void SetTimeout (int timeout_ms)
void SetWriteBufferMode (WriteBufferMode mode)
void Flush (void)
void Reset (void)


Detailed Description

Driver for the RS-232 serial port on the cRIO.

The current implementation uses the VISA formatted I/O mode. This means that all traffic goes through the fomatted buffers. This allows the intermingled use of Printf(), Scanf(), and the raw buffer accessors Read() and Write().

More information can be found in the NI-VISA User Manual here: http://www.ni.com/pdf/manuals/370423a.pdf and the NI-VISA Programmer's Reference Manual here: http://www.ni.com/pdf/manuals/370132c.pdf


Constructor & Destructor Documentation

SerialPort::SerialPort ( unsigned int  baudRate,
unsigned char  dataBits = 8,
SerialPort::Parity  parity = kParity_None,
SerialPort::StopBits  stopBits = kStopBits_One 
)

Create an instance of a Serial Port class.

Parameters:
baudRate The baud rate to configure the serial port. The cRIO-9074 supports up to 230400 Baud.
dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits.
parity Select the type of parity checking to use.
stopBits The number of stop bits to use as defined by the enum StopBits.

SerialPort::~SerialPort (  ) 

Destructor.


Member Function Documentation

void SerialPort::SetFlowControl ( SerialPort::FlowControl  flowControl  ) 

Set the type of flow control to enable on this port.

By default, flow control is disabled.

void SerialPort::EnableTermination ( char  terminator = '\n'  ) 

Enable termination and specify the termination character.

Termination is currently only implemented for receive. When the the terminator is recieved, the Read() or Scanf() will return fewer bytes than requested, stopping after the terminator.

Parameters:
terminator The character to use for termination.

void SerialPort::DisableTermination (  ) 

Disable termination behavior.

int SerialPort::GetBytesReceived ( void   ) 

Get the number of bytes currently available to read from the serial port.

Returns:
The number of bytes available to read.

void SerialPort::Printf ( const char *  writeFmt,
  ... 
)

Output formatted text to the serial port.

Bug:
All pointer-based parameters seem to return an error.
Parameters:
writeFmt A string that defines the format of the output.

void SerialPort::Scanf ( const char *  readFmt,
  ... 
)

Input formatted text from the serial port.

Bug:
All pointer-based parameters seem to return an error.
Parameters:
readFmt A string that defines the format of the input.

unsigned int SerialPort::Read ( char *  buffer,
int  count 
)

Read raw bytes out of the buffer.

Parameters:
buffer Pointer to the buffer to store the bytes in.
count The maximum number of bytes to read.
Returns:
The number of bytes actually read into the buffer.

unsigned int SerialPort::Write ( const char *  buffer,
int  count 
)

Write raw bytes to the buffer.

Parameters:
buffer Pointer to the buffer to read the bytes from.
count The maximum number of bytes to write.
Returns:
The number of bytes actually written into the port.

void SerialPort::SetTimeout ( int  timeout_ms  ) 

Configure the timeout of the serial port.

This defines the timeout for transactions with the hardware. It will affect reads and very large writes.

Parameters:
timeout_ms The number of milliseconds to to wait for I/O.

void SerialPort::SetWriteBufferMode ( SerialPort::WriteBufferMode  mode  ) 

Specify the flushing behavior of the output buffer.

When set to kFlushOnAccess, data is synchronously written to the serial port after each call to either Printf() or Write().

When set to kFlushWhenFull, data will only be written to the serial port when the buffer is full or when Flush() is called.

Parameters:
mode The write buffer mode.

void SerialPort::Flush ( void   ) 

Force the output buffer to be written to the port.

This is used when SetWriteBufferMode() is set to kFlushWhenFull to force a flush before the buffer is full.

void SerialPort::Reset ( void   ) 

Reset the serial port driver to a known state.

Empty the transmit and receive buffers in the device and formatted I/O.


The documentation for this class was generated from the following files:

Generated on Thu Oct 2 14:01:31 2008 for WPI Robotics Library by  doxygen 1.5.5