A stream class for accessing serial ports on POSIX operating systems.
#include <SerialStream.h>
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.
SerialStream (const SerialStream &)
SerialStream & operator= (const SerialStream &)
SerialStreamBuf * mIOBuffer
The SerialStreamBuf object that will be used by the stream to communicate with the serial port.
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 50 of file SerialStream.h.
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:
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.
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.
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.
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:
Get the character size being used for serial communication. Returns:
Close the serial port. No communications can occur with the serial port after calling this routine.
Definition at line 325 of file SerialStream.h.
Return the current flow control setting.
Returns true if the Stream is in a good open state, false otherwise.
Definition at line 338 of file SerialStream.h.
Get the number of stop bits being used during serial communication. Returns:
Open the serial port associated with the specified filename, and the specified mode, mode.
Get the current parity setting for the serial port. Returns:
Set the baud rate for serial communications.
Set the character size associated with the serial port. Parameters:
Use the specified flow control.
Set the number of stop bits used during serial communication. The only valid values are 1 and 2.
Parameters:
Set the parity for serial communication. Parameters:
Set character buffer timing in 10th of a second.
Get current size of character buffer. Look here for more documentation about VTIME and VMIN.
Get current timing of character buffer in 10th of a second. Look here for more documentation about VTIME and VMIN.
The SerialStreamBuf object that will be used by the stream to communicate with the serial port.
Definition at line 274 of file SerialStream.h.
Generated automatically by Doxygen for libserial from the source code.