LibSerial::SerialStream(3) | libserial | LibSerial::SerialStream(3) |
NAME¶
LibSerial::SerialStream - A stream class for accessing serial ports on POSIX operating systems.
SYNOPSIS¶
#include <SerialStream.h>
Inherits iostream.
Public Member Functions¶
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. 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
Manish P. Pagey
Version:
Definition at line 52 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:
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 () [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.
virtual LibSerial::SerialStream::~SerialStream () [virtual]¶
The destructor. It closes the stream associated with mFileDescriptor. The rest is done by the fstream destructor.
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:
const SerialStreamBuf::CharSizeEnum LibSerial::SerialStream::CharSize ()¶
Get the character size being used for serial communication.
Returns:
void LibSerial::SerialStream::Close ()¶
Close the serial port. No communications can occur with the serial port after calling this routine.
const SerialStreamBuf::FlowControlEnum LibSerial::SerialStream::FlowControl ()¶
Return the current flow control setting.
const bool LibSerial::SerialStream::IsOpen () const¶
Returns true if the Stream is in a good open state, false otherwise.
const short LibSerial::SerialStream::NumOfStopBits ()¶
Get the number of stop bits being used during serial communication.
Returns:
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:
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:
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:
void LibSerial::SerialStream::SetParity (const SerialStreamBuf::ParityEnum parityType)¶
Set the parity for serial communication.
Parameters:
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 266 of file SerialStream.h.
Author¶
Generated automatically by Doxygen for libserial from the source code.
Mon Sep 14 2015 | Version 0.6.0rc3 |