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

LibSerial::SerialStreamBuf Class Reference

This is the streambuf subclass used by SerialStream. More...

#include <SerialStreamBuf.h>

Inheritance diagram for LibSerial::SerialStreamBuf:

LibSerial::LIBSERIAL_STD::streambuf List of all members.

Public Types

Enumerations
enum  BaudRateEnum {
  BAUD_50 = B50,
  BAUD_75 = B75,
  BAUD_110 = B110,
  BAUD_134 = B134,
  BAUD_150 = B150,
  BAUD_200 = B200,
  BAUD_300 = B300,
  BAUD_600 = B600,
  BAUD_1200 = B1200,
  BAUD_1800 = B1800,
  BAUD_2400 = B2400,
  BAUD_4800 = B4800,
  BAUD_9600 = B9600,
  BAUD_19200 = B19200,
  BAUD_38400 = B38400,
  BAUD_INVALID
}
 The baud rates currently supported by the SUS-2 general terminal interface specification. More...

enum  CharSizeEnum {
  CHAR_SIZE_5 = CS5,
  CHAR_SIZE_6 = CS6,
  CHAR_SIZE_7 = CS7,
  CHAR_SIZE_8 = CS8,
  CHAR_SIZE_INVALID
}
 The allowed values of character sizes that can be used during the serial communication. More...

enum  ParityEnum {
  PARITY_EVEN,
  PARITY_ODD,
  PARITY_NONE,
  PARITY_INVALID
}
 The allowed values of the parity associated with the serial port communications. More...

enum  FlowControlEnum {
  FLOW_CONTROL_HARD,
  FLOW_CONTROL_SOFT,
  FLOW_CONTROL_INVALID
}
 The values of the flow control settings for a serial port. More...


Public Methods

Constructors and Destructor
 SerialStreamBuf ()
 The default constructor.

 ~SerialStreamBuf ()
 The destructor.

Other Public Methods
bool is_open () const
 Returns true if a previos call to open() succeeded (returned a non-null value) and there has been no intervening call to close.

SerialStreamBuf* open ( const string filename, ios_base::openmode mode = ios_base::in | ios_base::out )
 If is_open() != false, returns a null pointer. More...

SerialStreamBuf* close ()
 If is_open() == false, returns a null pointer. More...

int SetParametersToDefault ()
 Initialize the serial communication parameters to their default values.

const BaudRateEnum SetBaudRate (const BaudRateEnum baud_rate)
 If is_open() != true, return -1. More...

const BaudRateEnum BaudRate () const
 Return the current baud rate of the serial port. More...

const CharSizeEnum SetCharSize (const CharSizeEnum char_size)
 Set the character size to be used during serial communication. More...

const CharSizeEnum CharSize () const
 Return the character size currently being used for serial communication.

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

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

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

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

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

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


Static Public Attributes

Public static members.
const BaudRateEnum DEFAULT_BAUD
 The default value of the baud rate of the serial port.

const CharSizeEnum DEFAULT_CHAR_SIZE
 The default value of the character size used during the serial communication.

const short DEFAULT_NO_OF_STOP_BITS
 The default number of stop bits used.

const ParityEnum DEFAULT_PARITY
 The default parity setting.

const FlowControlEnum DEFAULT_FLOW_CONTROL
 The default flow control setting.


Protected Methods

virtual streambuf* setbuf (char_type *, streamsize)
 Performs an operation that is defined separately for each class derived from streambuf. More...

virtual int sync ()
 Synchronizes the controlled sequence with the arrays. More...

virtual int showmanyc ()
 This method returns an estimate of the number of characters available in the sequence or -1 if no estimate is available. More...

virtual streamsize xsgetn (char_type *s, streamsize n)
 Reads upto n characters from the serial port and returns them through the character array located at s. More...

virtual int_type underflow ()
 Reads and returns the next character from the associated serial port if one otherwise returns traits::eof(). More...

virtual int_type uflow ()
 Reads and returns the next character from the associated serial port if one otherwise returns traits::eof(). More...

virtual int_type pbackfail (int_type c = traits_type::eof())
 This function is called when a putback of a character fails. More...

virtual streamsize xsputn (const char_type* s, streamsize n)
 Writes upto n characters from tha character sequence at s to the serial port associated with the buffer. More...

virtual int_type overflow (int_type c)
 Writes the specified character to the associated serial port. More...


Private Methods

int InitializeSerialPort ()
 This routine is called by open() in order to initialize some parameters of the serial port and setting its parameters to default values. More...


Private Attributes

char mPutbackChar
 We use unbuffered I/O for the serial port. More...

bool mPutbackAvailable
 True if a putback value is available in mPutbackChar.

int mFileDescriptor
 The file descriptor associated with the serial port.


Detailed Description

This is the streambuf subclass used by SerialStream.

This subclass takes care of opening the serial port file in the required modes and providing the corresponding file descriptor to SerialStream so that various parameters associated with the serial port can be set. Several features of this streambuf class resemble those of std::filebuf, however this class it not made a subclass of filebuf because we need access to the file descriptor associated with the serial port and the standard filebuf does not provide access to it.

At present, this class uses unbuffered I/O and all calls to setbuf() will be ignored.

Author(s):
$Author: pagey $ Manish P. Pagey
Version:
$Id: SerialStreamBuf.h,v 1.1 2000/08/08 08:33:36 pagey Exp $

Definition at line 45 of file SerialStreamBuf.h.


Member Enumeration Documentation

enum LibSerial::SerialStreamBuf::BaudRateEnum

The baud rates currently supported by the SUS-2 general terminal interface specification.

Note that B0 is not supported because it is not really a baud rate (it causes the modem to hang up i.e. drop DTR). Use the close() method instead.

Enumeration values:
BAUD_50   50 baud.
BAUD_75   75 baud.
BAUD_110   110 baud.
BAUD_134   134.5 baud. Yes 134.5. I did not mistype that.
BAUD_150   150 baud.
BAUD_200   200 baud.
BAUD_300   300 baud.
BAUD_600   600 baud.
BAUD_1200   1200 baud.
BAUD_1800   1800 baud.
BAUD_2400   2400 baud.
BAUD_4800   4800 baud.
BAUD_9600   9600 baud.
BAUD_19200   19200 baud.
BAUD_38400   38400 baud.
BAUD_INVALID   Invalid baud rate.

Definition at line 63 of file SerialStreamBuf.h.

enum LibSerial::SerialStreamBuf::CharSizeEnum

The allowed values of character sizes that can be used during the serial communication.

Enumeration values:
CHAR_SIZE_5   5 bit characters.
CHAR_SIZE_6   6 bit characters.
CHAR_SIZE_7   7 bit characters.
CHAR_SIZE_8   8 bit characters.
CHAR_SIZE_INVALID   Invalid character size.

Definition at line 86 of file SerialStreamBuf.h.

enum LibSerial::SerialStreamBuf::FlowControlEnum

The values of the flow control settings for a serial port.

Enumeration values:
FLOW_CONTROL_HARD   Hardware flow control.
FLOW_CONTROL_SOFT   Software flow control.
FLOW_CONTROL_INVALID   Invalid flow control setting.

Definition at line 109 of file SerialStreamBuf.h.

enum LibSerial::SerialStreamBuf::ParityEnum

The allowed values of the parity associated with the serial port communications.

Enumeration values:
PARITY_EVEN   Even parity.
PARITY_ODD   Odd parity.
PARITY_NONE   No parity i.e. parity checking disabled.
PARITY_INVALID   Invalid parity value.

Definition at line 98 of file SerialStreamBuf.h.


Constructor & Destructor Documentation

LibSerial::SerialStreamBuf::SerialStreamBuf ( ) [inline]

The default constructor.

Definition at line 464 of file SerialStreamBuf.h.

LibSerial::SerialStreamBuf::~SerialStreamBuf ( ) [inline]

The destructor.

Definition at line 472 of file SerialStreamBuf.h.


Member Function Documentation

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

Return the current baud rate of the serial port.

If the baud rate is not set to a valid value then it returns BAUD_INVALID.

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

Return the character size currently being used for serial communication.

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

Return the current flow control setting.

int LibSerial::SerialStreamBuf::InitializeSerialPort ( ) [private]

This routine is called by open() in order to initialize some parameters of the serial port and setting its parameters to default values.

Returns:
-1 on failure and some other value on success.

short LibSerial::SerialStreamBuf::NumOfStopBits ( ) const

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

Returns:
The number of stop bits.

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

Get the current parity setting for the serial port.

Returns:
The parity setting for the serial port.

const BaudRateEnum LibSerial::SerialStreamBuf::SetBaudRate ( BaudRateEnum baud_rate )

If is_open() != true, return -1.

Otherwise, set the baud rate of the associated serial port. Return the baud rate on success and BAUD_INVALID on failure.

const CharSizeEnum LibSerial::SerialStreamBuf::SetCharSize ( CharSizeEnum char_size )

Set the character size to be used during serial communication.

It returns the character size on success and CHAR_SIZE_INVALID on failure.

const FlowControlEnum LibSerial::SerialStreamBuf::SetFlowControl ( FlowControlEnum flow_c )

Use the specified flow control.

short LibSerial::SerialStreamBuf::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).

int LibSerial::SerialStreamBuf::SetParametersToDefault ( )

Initialize the serial communication parameters to their default values.

const ParityEnum LibSerial::SerialStreamBuf::SetParity ( ParityEnum parity )

Set the parity for serial communication.

Parameters:
parity   The parity value.

SerialStreamBuf * LibSerial::SerialStreamBuf::close ( )

If is_open() == false, returns a null pointer.

If a put area exists, calls overflow(EOF) to flush characters. Finally it closes the file by calling std::close(mFileDescriptor) where mFileDescriptor is the value returned by the last call to open().

For the implementation of the corresponding function in class filebuf, if the last virtual member function called on *this (between underflow, overflow, seekoff, and seekpos) was overflow then it calls a_codecvt.unshift (possible several times) to determine a termination sequence, inserts those characters and calls overflow(EOF) again. However, this is not implemented here yet.

Postcondition: is_open() == false

Returns:
this on success, a null pointer otherwise.

bool LibSerial::SerialStreamBuf::is_open ( ) const [inline]

Returns true if a previos call to open() succeeded (returned a non-null value) and there has been no intervening call to close.

Definition at line 480 of file SerialStreamBuf.h.

SerialStreamBuf * LibSerial::SerialStreamBuf::open ( string filename,
ios_base::openmode mode = ios_base::in | ios_base::out )

If is_open() != false, returns a null pointer.

Otherwise, initializes the streambuf as required. It then opens a file, if possible, whose name is given as the string filename using the system call std::open(filename.data(), flags). The value of parameter flags is obtained from the value of the parameter mode. At present, only ios_base::in, ios_base::out, and (ios_base::in|ios_base::out) make sense for a serial port and hence all other settings result in the call to fail. The value of flags is obtained as:

flags = u_flags | O_NOCTTY

where u_flags is obtained from the following table depending on the value of the parameter mode:

in out u_flags
+ O_RDONLY
+ O_WRONLY
+ + O_RDWR

Returns:
If the open() system call succeeds the method returns this. If the call fails, then it returns a null pointer.

int_type LibSerial::SerialStreamBuf::overflow ( int_type c ) [protected, virtual]

Writes the specified character to the associated serial port.

Returns:
The character c.

int_type LibSerial::SerialStreamBuf::pbackfail ( int_type c = traits_type::eof() ) [protected, virtual]

This function is called when a putback of a character fails.

This must be implemented for unbuffered I/O as all streambuf subclasses are required to provide putback of at lease on character.

streambuf * LibSerial::SerialStreamBuf::setbuf ( char_type *,
streamsize ) [protected, virtual]

Performs an operation that is defined separately for each class derived from streambuf.

The default behavior is to do nothing if gptr() is non-null and gptr()!=egptr(). Also, setbuf(0, 0) usually means unbuffered I/O and setbuf(p, n) means use p[0]...p[n-1] to hold the buffered characters. In general, this method implements the subclass's notion of getting memory for the buffered characters.

int LibSerial::SerialStreamBuf::showmanyc ( ) [protected, virtual]

This method returns an estimate of the number of characters available in the sequence or -1 if no estimate is available.

If it returns a positive value, then succesive calls to underflow() will not return traits::eof() until at least that number of characters have been supplied. If showmanyc() returns -1, then calls to underflow() or uflow() may fail. The default implementation returns zero.

int LibSerial::SerialStreamBuf::sync ( ) [protected, virtual]

Synchronizes the controlled sequence with the arrays.

That is, if pbase() is non-null the characters between pbase() and pptr() are written to the controlled sequence. The pointers may then be reset as appropriate.

Returns:
-1 on failure and some other number otherwise. The default behavior is to return 0.

int_type LibSerial::SerialStreamBuf::uflow ( ) [protected, virtual]

Reads and returns the next character from the associated serial port if one otherwise returns traits::eof().

This method is used for unbuffered I/O while underflow() is called for buffer I/O.

Returns:
The next character from the serial port.

int_type LibSerial::SerialStreamBuf::underflow ( ) [protected, virtual]

Reads and returns the next character from the associated serial port if one otherwise returns traits::eof().

This method is used for buffered I/O while uflow() is called for unbuffered I/O.

Returns:
The next character from the serial port.

streamsize LibSerial::SerialStreamBuf::xsgetn ( char_type * s,
streamsize n ) [protected, virtual]

Reads upto n characters from the serial port and returns them through the character array located at s.

Returns:
The number of characters actually read from the serial port.

streamsize LibSerial::SerialStreamBuf::xsputn ( const char_type * s,
streamsize n ) [protected, virtual]

Writes upto n characters from tha character sequence at s to the serial port associated with the buffer.

Returns:
The number of characters that were successfully written to the serial port.

Member Data Documentation

const BaudRateEnum LibSerial::SerialStreamBuf::DEFAULT_BAUD [static]

The default value of the baud rate of the serial port.

Definition at line 127 of file SerialStreamBuf.h.

const CharSizeEnum LibSerial::SerialStreamBuf::DEFAULT_CHAR_SIZE [static]

The default value of the character size used during the serial communication.

Definition at line 133 of file SerialStreamBuf.h.

const FlowControlEnum LibSerial::SerialStreamBuf::DEFAULT_FLOW_CONTROL [static]

The default flow control setting.

Definition at line 148 of file SerialStreamBuf.h.

const short LibSerial::SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS [static]

The default number of stop bits used.

Definition at line 138 of file SerialStreamBuf.h.

const ParityEnum LibSerial::SerialStreamBuf::DEFAULT_PARITY [static]

The default parity setting.

Definition at line 143 of file SerialStreamBuf.h.

int LibSerial::SerialStreamBuf::mFileDescriptor [private]

The file descriptor associated with the serial port.

Definition at line 449 of file SerialStreamBuf.h.

bool LibSerial::SerialStreamBuf::mPutbackAvailable [private]

True if a putback value is available in mPutbackChar.

Definition at line 444 of file SerialStreamBuf.h.

char LibSerial::SerialStreamBuf::mPutbackChar [private]

We use unbuffered I/O for the serial port.

However, we need to provide the putback of atleast one character. This character contains the putback character.

Definition at line 439 of file SerialStreamBuf.h.


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