Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members | Related Pages

LibSerial::SerialStream Class Reference

A stream class for accessing serial ports on POSIX operating systems. More...

#include <SerialStream.h>

List of all members.

Public Member Functions

Constructors and Destructor
 SerialStream (const std::string filename, std::ios_base::openmode mode=std::ios::in|std::ios::out)
 This constructor takes a filename and an openmode to construct a SerialStream object.
 SerialStream ()
 Create a new SerialStream object but do not open it.
virtual ~SerialStream ()
 The destructor.
Other Public Methods
void Open (const std::string filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
 Open the serial port associated with the specified filename, s and the specified mode, mode.
void Close ()
 Close the serial port.
const bool IsOpen () const
 Returns true if the Stream is in a good open state, false otherwise.
void SetBaudRate (SerialStreamBuf::BaudRateEnum baud_rate)
 Set the baud rate for serial communications.
const SerialStreamBuf::BaudRateEnum BaudRate ()
 Get the current baud rate being used for serial communication.
void SetCharSize (const SerialStreamBuf::CharSizeEnum size)
 Set the character size associated with the serial port.
const SerialStreamBuf::CharSizeEnum CharSize ()
 Get the character size being used for serial communication.
void SetNumOfStopBits (short stop_bits)
 Set the number of stop bits used during serial communication.
const short NumOfStopBits ()
 Get the number of stop bits being used during serial communication.
void SetParity (const SerialStreamBuf::ParityEnum parity)
 Set the parity for serial communication.
const SerialStreamBuf::ParityEnum Parity ()
 Get the current parity setting for the serial port.
void SetFlowControl (const SerialStreamBuf::FlowControlEnum flow_c)
 Use the specified flow control.
const SerialStreamBuf::FlowControlEnum FlowControl ()
 Return the current flow control setting.
const short SetVMin (short vtime)
 Set character buffer size.
const short VMin ()
 Get current size of character buffer.
const short SetVTime (short vtime)
 Set character buffer timing in 10th of a second.
const short VTime ()
 Get current timing of character buffer in 10th of a second.

Private Attributes

SerialStreamBufmIOBuffer
 The SerialStreamBuf object that will be used by the stream to communicate with the serial port.


Detailed Description

A stream class for accessing serial ports on POSIX operating systems.

A lot of the functionality of this class has been obtained by looking at the code of libserial package by Linas Vepstas (linas@linas.org) and the excellent document on serial programming by Michael R. Sweet. This document can be found at http://www.easysw.com/~mike/serial/serial.html. The libserial package can be found at http://www.linas.org/serial/. This class allows one to set various parameters of a serial port and then access it like a simple fstream. In fact, that is exactly what it does. It sets the parameters of the serial port by maintaining a file descriptor for the port and uses the basic_fstream functions for the IO. We have not implemented any file locking yet but it will be added soon.

Make sure you read the documentation of the standard fstream template before using this class because most of the functionality is inherited from fstream. Also a lot of information about the various system calls used in the implementation can also be found in the Single Unix Specification (Version 2). A copy of this document can be obtained from http://www.UNIX-systems.org/. We will refer to this document as SUS-2.

Author:
Author
wedesoft
Manish P. Pagey
Version:
$Id: SerialStream.h,v 1.5 2004/05/06 18:32:02 crayzeewulf

Definition at line 65 of file SerialStream.h.


Constructor & Destructor Documentation

LibSerial::SerialStream::SerialStream const std::string  filename,
std::ios_base::openmode  mode = std::ios::in|std::ios::out
[explicit]
 

This constructor takes a filename and an openmode to construct a SerialStream object.

This results in a call to basic_fstream::open(s,mode). This is the only way to contruct an object of this class. We have to enforce this instead of providing a default constructor because we want to get a file descriptor whenever the basic_fstream::open() function is called. However, this function is not made virtual in the STL hence it is probably not very safe to overload it. We may decide to overload it later but the users of this class will have to make sure that this class is not used as an fstream class. The SerialStream will be in the "open" state (same state as after calling the Open() method) after calling this constructor.

If the constructor has problems opening the serial port or getting the file-descriptor for the port, it will set the failbit for the stream. So, one must make sure that the stream is in a good state before using it for any further I/O operations.

Parameters:
filename The filename of the serial port.
mode The openmode for the serial port file.

LibSerial::SerialStream::SerialStream  )  [inline, explicit]
 

Create a new SerialStream object but do not open it.

The Open() method will need to be called explicitly on the object to communicate with the serial port.

Definition at line 317 of file SerialStream.h.

References Close().

LibSerial::SerialStream::~SerialStream  )  [inline, virtual]
 

The destructor.

It closes the stream associated with mFileDescriptor. The rest is done by the fstream destructor.

Definition at line 326 of file SerialStream.h.

References mIOBuffer.


Member Function Documentation

const SerialStreamBuf::BaudRateEnum LibSerial::SerialStream::BaudRate  ) 
 

Get the current baud rate being used for serial communication.

This routine queries the serial port for its current settings and returns the baud rate that is being used by the serial port.

Returns:
The current baud rate for the serial port. Note: this is not a constant function because it checks to see that it is dealing with a SerialStream with a non-null buffer. If the buffer is null, it attempts to set the state of the stream accordingly.

const SerialStreamBuf::CharSizeEnum LibSerial::SerialStream::CharSize  ) 
 

Get the character size being used for serial communication.

Returns:
The current character size.

void LibSerial::SerialStream::Close  )  [inline]
 

Close the serial port.

No communications can occur with the serial port after calling this routine.

Definition at line 338 of file SerialStream.h.

References mIOBuffer.

Referenced by SerialStream().

const SerialStreamBuf::FlowControlEnum LibSerial::SerialStream::FlowControl  ) 
 

Return the current flow control setting.

const bool LibSerial::SerialStream::IsOpen  )  const [inline]
 

Returns true if the Stream is in a good open state, false otherwise.

Definition at line 351 of file SerialStream.h.

References LibSerial::SerialStreamBuf::is_open(), and mIOBuffer.

const short LibSerial::SerialStream::NumOfStopBits  ) 
 

Get the number of stop bits being used during serial communication.

Returns:
The number of stop bits.

void LibSerial::SerialStream::Open const std::string  filename,
std::ios_base::openmode  mode = std::ios_base::in|std::ios_base::out
 

Open the serial port associated with the specified filename, s and the specified mode, mode.

const SerialStreamBuf::ParityEnum LibSerial::SerialStream::Parity  ) 
 

Get the current parity setting for the serial port.

Returns:
The parity setting for the serial port.

void LibSerial::SerialStream::SetBaudRate SerialStreamBuf::BaudRateEnum  baud_rate  ) 
 

Set the baud rate for serial communications.

void LibSerial::SerialStream::SetCharSize const SerialStreamBuf::CharSizeEnum  size  ) 
 

Set the character size associated with the serial port.

Parameters:
size The character size will be set to this value.

void LibSerial::SerialStream::SetFlowControl const SerialStreamBuf::FlowControlEnum  flow_c  ) 
 

Use the specified flow control.

void LibSerial::SerialStream::SetNumOfStopBits short  stop_bits  ) 
 

Set the number of stop bits used during serial communication.

The only valid values are 1 and 2.

Parameters:
stop_bits The number of stop bits. (1 or 2).

void LibSerial::SerialStream::SetParity const SerialStreamBuf::ParityEnum  parity  ) 
 

Set the parity for serial communication.

Parameters:
parity The parity value.

const short LibSerial::SerialStream::SetVMin short  vtime  ) 
 

Set character buffer size.

const short LibSerial::SerialStream::SetVTime short  vtime  ) 
 

Set character buffer timing in 10th of a second.

const short LibSerial::SerialStream::VMin  ) 
 

Get current size of character buffer.

Look here for more documentation about VTIME and VMIN.

const short LibSerial::SerialStream::VTime  ) 
 

Get current timing of character buffer in 10th of a second.

Look here for more documentation about VTIME and VMIN.


Member Data Documentation

SerialStreamBuf* LibSerial::SerialStream::mIOBuffer [private]
 

The SerialStreamBuf object that will be used by the stream to communicate with the serial port.

Definition at line 287 of file SerialStream.h.

Referenced by Close(), IsOpen(), and ~SerialStream().


The documentation for this class was generated from the following file:
Generated on Sat Oct 1 14:15:51 2005 for libserial by  doxygen 1.4.2