NAME
LibSerial::SerialStream -
A stream class for accessing serial ports on POSIX operating systems.
SYNOPSIS
#include <SerialStream.h>
Public Member Functions
Constructors and Destructor
SerialStream (const std::string fileName, std::ios_base::openmode
openMode=std::ios::in|std::ios::out)
This constructor takes a filename and an openmode to construct
a SerialStream object.
SerialStream (const std::string fileName, const
SerialStreamBuf::BaudRateEnum
baudRate=SerialStreamBuf::DEFAULT_BAUD, const
SerialStreamBuf::CharSizeEnum
charSize=SerialStreamBuf::DEFAULT_CHAR_SIZE, const
SerialStreamBuf::ParityEnum
parityType=SerialStreamBuf::DEFAULT_PARITY, const short
numOfStopBits=SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS, const
SerialStreamBuf::FlowControlEnum
flowControlType=SerialStreamBuf::DEFAULT_FLOW_CONTROL)
Constructor that allows one to create a SerialStream instance
and also initialize the corresponding serial port with the
specified parameters.
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
openMode=std::ios_base::in|std::ios_base::out)
Open the serial port associated with the specified filename,
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 baudRate)
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 charSize)
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 numOfStopBits)
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 parityType)
Set the parity for serial communication.
const SerialStreamBuf::ParityEnum Parity ()
Get the current parity setting for the serial port.
void SetFlowControl (const SerialStreamBuf::FlowControlEnum
flowControlType)
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 Member Functions
SerialStream (const SerialStream &)
SerialStream & operator= (const SerialStream &)
Private Attributes
SerialStreamBuf * mIOBuffer
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.RS 4 crayzeewulf
Manish P. Pagey
Version:
$Id: SerialStream.h,v 1.5 2004/05/06 18:32:02 crayzeewulf
Definition at line 50 of file SerialStream.h.
Constructor & Destructor Documentation
LibSerial::SerialStream::SerialStream (const std::string fileName,
std::ios_base::openmode openMode = 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.
openMode The openmode for the serial port file.
LibSerial::SerialStream::SerialStream (const std::string fileName, const
SerialStreamBuf::BaudRateEnum baudRate = SerialStreamBuf::DEFAULT_BAUD,
const SerialStreamBuf::CharSizeEnum charSize =
SerialStreamBuf::DEFAULT_CHAR_SIZE, const SerialStreamBuf::ParityEnum
parityType = SerialStreamBuf::DEFAULT_PARITY, const short numOfStopBits
= SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS, const
SerialStreamBuf::FlowControlEnum flowControlType =
SerialStreamBuf::DEFAULT_FLOW_CONTROL)
Constructor that allows one to create a SerialStream instance and also
initialize the corresponding serial port with the specified parameters.
This was suggested by Witek Adamus (wit3k).
See
https://sourceforge.net/tracker/index.php?func=detail&aid=2137885&group_id=9432&atid=359432
:TODO: Add documentation for all parameters here.
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 304 of file SerialStream.h.
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 313 of file SerialStream.h.
LibSerial::SerialStream::SerialStream (const SerialStream &) [private]
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 325 of file SerialStream.h.
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 338 of file SerialStream.h.
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 openMode =
std::ios_base::in|std::ios_base::out)
Open the serial port associated with the specified filename, and the
specified mode, mode.
SerialStream& LibSerial::SerialStream::operator= (const SerialStream &)
[private]
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
baudRate)
Set the baud rate for serial communications.
void LibSerial::SerialStream::SetCharSize (const
SerialStreamBuf::CharSizeEnum charSize)
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 flowControlType)
Use the specified flow control.
void LibSerial::SerialStream::SetNumOfStopBits (short numOfStopBits)
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
parityType)
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 274 of file SerialStream.h.
Author
Generated automatically by Doxygen for libserial from the source code.