Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

LibSerial::SerialStream Class Reference

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

#include <SerialStream.h>

Inheritance diagram for LibSerial::SerialStream:

LibSerial::iostream List of all members.

Public Methods

Constructors and Destructor
 SerialStream ( const string filename, ios_base::openmode mode = ios::in|ios::out)
 This constructor takes a filename and an openmode to construct a SerialStream object. More...

virtual ~SerialStream ()
 The destructor. More...

Other Public Methods
void SetBaudRate (BaudRateEnum baud_rate)
 Set the baud rate for serial communications.

const SerialStreamBuf::BaudRateEnum BaudRate () const
 Get the current baud rate being used for serial communication. More...

void SetCharSize (const CharSizeEnum size)
 Set the character size associated with the serial port. More...

const SerialStreamBuf::CharSizeEnum CharSize () const
 Get the character size being used for serial communication. More...

void SetNumOfStopBits (short stop_bits)
 Set the number of stop bits used during serial communication. More...

const short NumOfStopBits () const
 Get the number of stop bits being used during serial communication. More...

void SetParity (const ParityEnum parity)
 Set the parity for serial communication. More...

const SerialStreamBuf::ParityEnum Parity () const
 Get the current parity setting for the serial port. More...

const SerialStreamBuf::FlSetFlowControl SetFlowControl (const SerialStreamBuf::FlowControlEnum flow_c)
 Use the specified flow control.

const SerialStreamBuf::FlowControlEnum FlowControl () const
 Return the current flow control setting.


Private Methods

void IgnoreModemStatusLines (bool ignore=true)
 Set the serial port to ignore the modem status lines. More...

void EnableReceiver (bool enable=true)
 Enable the serial port receiver. More...


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(s):
$Author: pagey $ Manish P. Pagey
Version:
$Id: SerialStream.h,v 1.11 2000/08/08 08:36:02 pagey Exp $

Definition at line 54 of file SerialStream.h.


Constructor & Destructor Documentation

LibSerial::SerialStream::SerialStream ( string filename,
ios_base::openmode mode = ios::in|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.

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, virtual]

The destructor.

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

Definition at line 264 of file SerialStream.h.


Member Function Documentation

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

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.

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

Get the character size being used for serial communication.

Returns:
The current character size.

void LibSerial::SerialStream::EnableReceiver ( bool enable = true ) [private]

Enable the serial port receiver.

This will allow us to read data from the serial port.

Parameters:
enable   If true then the received will be enabled. Otherwise it will be disabled.

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

Return the current flow control setting.

void LibSerial::SerialStream::IgnoreModemStatusLines ( bool ignore = true ) [private]

Set the serial port to ignore the modem status lines.

If the specified boolean parameter is false then the meaning of this function is reversed i.e. the serial port will start using the modem status lines.

Parameters:
ignore   If true then the modem status lines will be ignored otherwise they will be used during the communication.

const short LibSerial::SerialStream::NumOfStopBits ( ) const

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

Returns:
The number of stop bits.

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

Get the current parity setting for the serial port.

Returns:
The parity setting for the serial port.

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

Set the baud rate for serial communications.

void LibSerial::SerialStream::SetCharSize ( CharSizeEnum size )

Set the character size associated with the serial port.

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

const SerialStreamBuf::FlSetFlowControl LibSerial::SerialStream::SetFlowControl ( 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 ( ParityEnum parity )

Set the parity for serial communication.

Parameters:
parity   The parity value.

The documentation for this class was generated from the following file:
Generated at Tue Aug 8 01:37:56 2000 for libgpib by doxygen1.1.4 written by Dimitri van Heesch, © 1997-2000