#include <SerialStream.h>
Inheritance diagram for LibSerial::SerialStream:
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... |
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.
Definition at line 54 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.
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.
filename | The filename of the serial port. |
mode | The openmode for the serial port file. |
|
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.
|
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.
|
Get the character size being used for serial communication.
|
Enable the serial port receiver.
This will allow us to read data from the serial port.
enable | If true then the received will be enabled. Otherwise it will be disabled. |
|
Return the current flow control setting.
|
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.
ignore | If true then the modem status lines will be ignored otherwise they will be used during the communication. |
|
Get the number of stop bits being used during serial communication.
|
Get the current parity setting for the serial port.
|
Set the baud rate for serial communications.
|
Set the character size associated with the serial port.
size | The character size will be set to this value. |
|
Use the specified flow control.
|
Set the number of stop bits used during serial communication.
The only valid values are 1 and 2.
stop_bits | The number of stop bits. (1 or 2). |
|
Set the parity for serial communication.
parity | The parity value. |