libserial
0.6.0rc3
|
This is the streambuf subclass used by SerialStream. More...
#include <SerialStreamBuf.h>
Public Types | |
enum | BaudRateEnum { BAUD_50 = SerialPort::BAUD_50, BAUD_75 = SerialPort::BAUD_75, BAUD_110 = SerialPort::BAUD_110, BAUD_134 = SerialPort::BAUD_134, BAUD_150 = SerialPort::BAUD_150, BAUD_200 = SerialPort::BAUD_200, BAUD_300 = SerialPort::BAUD_300, BAUD_600 = SerialPort::BAUD_600, BAUD_1200 = SerialPort::BAUD_1200, BAUD_1800 = SerialPort::BAUD_1800, BAUD_2400 = SerialPort::BAUD_2400, BAUD_4800 = SerialPort::BAUD_4800, BAUD_9600 = SerialPort::BAUD_9600, BAUD_19200 = SerialPort::BAUD_19200, BAUD_38400 = SerialPort::BAUD_38400, BAUD_57600 = SerialPort::BAUD_57600, BAUD_115200 = SerialPort::BAUD_115200, BAUD_230400 = SerialPort::BAUD_230400, BAUD_DEFAULT = SerialPort::BAUD_DEFAULT, BAUD_INVALID = -1 } |
The baud rates currently supported by the SUS-2 general terminal interface specification. More... | |
enum | CharSizeEnum { CHAR_SIZE_5 = SerialPort::CHAR_SIZE_5, CHAR_SIZE_6 = SerialPort::CHAR_SIZE_6, CHAR_SIZE_7 = SerialPort::CHAR_SIZE_7, CHAR_SIZE_8 = SerialPort::CHAR_SIZE_8, CHAR_SIZE_DEFAULT = SerialPort::CHAR_SIZE_DEFAULT, CHAR_SIZE_INVALID } |
The allowed values of character sizes that can be used during the serial communication. More... | |
enum | ParityEnum { PARITY_EVEN = SerialPort::PARITY_EVEN, PARITY_ODD = SerialPort::PARITY_ODD, PARITY_NONE = SerialPort::PARITY_NONE, PARITY_DEFAULT = SerialPort::PARITY_DEFAULT, PARITY_INVALID } |
The allowed values of the parity associated with the serial port communications. More... | |
enum | FlowControlEnum { FLOW_CONTROL_HARD = SerialPort::FLOW_CONTROL_HARD, FLOW_CONTROL_SOFT = SerialPort::FLOW_CONTROL_SOFT, FLOW_CONTROL_NONE = SerialPort::FLOW_CONTROL_NONE, FLOW_CONTROL_DEFAULT = SerialPort::FLOW_CONTROL_DEFAULT, FLOW_CONTROL_INVALID } |
The values of the flow control settings for a serial port. More... | |
Public Member Functions | |
SerialStreamBuf () | |
The default constructor. More... | |
~SerialStreamBuf () | |
The destructor. More... | |
bool | is_open () const |
Returns true if a previous call to open() succeeded (returned a non-null value) and there has been no intervening call to close. More... | |
SerialStreamBuf * | open (const std::string filename, std::ios_base::openmode mode=std::ios_base::in|std::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. More... | |
const BaudRateEnum | SetBaudRate (const BaudRateEnum baudRate) |
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 charSize) |
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. More... | |
short | SetNumOfStopBits (short numOfStopBits) |
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 parityType) |
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 flowControlType) |
Use the specified flow control. More... | |
const FlowControlEnum | FlowControl () const |
Return the current flow control setting. More... | |
const short | SetVMin (short vtime) |
Set the minimum number of characters for non-canonical reads. More... | |
const short | VMin () const |
Get the VMIN value for the device. More... | |
const short | SetVTime (short vtime) |
Set character buffer timeout in 10ths of a second. More... | |
const short | VTime () const |
Get the current timeout value for non-canonical reads in deciseconds. More... | |
Static Public Attributes | |
static const BaudRateEnum | DEFAULT_BAUD |
The default value of the baud rate of the serial port. More... | |
static const CharSizeEnum | DEFAULT_CHAR_SIZE |
The default value of the character size used during the serial communication. More... | |
static const short | DEFAULT_NO_OF_STOP_BITS |
The default number of stop bits used. More... | |
static const ParityEnum | DEFAULT_PARITY |
The default parity setting. More... | |
static const FlowControlEnum | DEFAULT_FLOW_CONTROL |
The default flow control setting. More... | |
static const short | DEFAULT_VMIN |
The default character buffer size. More... | |
static const short | DEFAULT_VTIME |
The default character buffer timing. More... | |
Protected Member Functions | |
virtual std::streambuf * | setbuf (char_type *, std::streamsize) |
Performs an operation that is defined separately for each class derived from streambuf. More... | |
virtual std::streamsize | xsgetn (char_type *s, std::streamsize n) |
Reads upto n characters from the serial port and returns them through the character array located at s. More... | |
virtual std::streamsize | showmanyc () |
Check, wether input is available on the port. 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 std::streamsize | xsputn (const char_type *s, std::streamsize n) |
Writes upto n characters from the 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... | |
Static Protected Attributes | |
static const char | CTRL_Q = 0x11 |
Character used to signal that I/O can start while using software flow control with the serial port. More... | |
static const char | CTRL_S = 0x13 |
Character used to signal that I/O should stop while using software flow control with the serial port. More... | |
Private Member Functions | |
SerialStreamBuf (const SerialStreamBuf &) | |
SerialStreamBuf & | operator= (const SerialStreamBuf &) |
Private Attributes | |
boost::scoped_ptr< Implementation > | mImpl |
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.
Definition at line 38 of file SerialStreamBuf.h.
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.
Definition at line 59 of file SerialStreamBuf.h.
The allowed values of character sizes that can be used during the serial communication.
Enumerator | |
---|---|
CHAR_SIZE_5 | |
CHAR_SIZE_6 | |
CHAR_SIZE_7 | |
CHAR_SIZE_8 | |
CHAR_SIZE_DEFAULT | |
CHAR_SIZE_INVALID |
Definition at line 106 of file SerialStreamBuf.h.
The values of the flow control settings for a serial port.
Enumerator | |
---|---|
FLOW_CONTROL_HARD | |
FLOW_CONTROL_SOFT | |
FLOW_CONTROL_NONE | |
FLOW_CONTROL_DEFAULT | |
FLOW_CONTROL_INVALID |
Invalid flow control setting. |
Definition at line 141 of file SerialStreamBuf.h.
The allowed values of the parity associated with the serial port communications.
Enumerator | |
---|---|
PARITY_EVEN | |
PARITY_ODD | |
PARITY_NONE | |
PARITY_DEFAULT | |
PARITY_INVALID |
Invalid parity value. |
Definition at line 124 of file SerialStreamBuf.h.
LibSerial::SerialStreamBuf::SerialStreamBuf | ( | ) |
The default constructor.
LibSerial::SerialStreamBuf::~SerialStreamBuf | ( | ) |
The destructor.
|
private |
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.
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
this
on success, a null pointer otherwise. const FlowControlEnum LibSerial::SerialStreamBuf::FlowControl | ( | ) | const |
Return the current flow control setting.
bool LibSerial::SerialStreamBuf::is_open | ( | ) | const |
Returns true if a previous call to open() succeeded (returned a non-null value) and there has been no intervening call to close.
short LibSerial::SerialStreamBuf::NumOfStopBits | ( | ) | const |
Get the number of stop bits being used during serial communication.
SerialStreamBuf* LibSerial::SerialStreamBuf::open | ( | const std::string | filename, |
std::ios_base::openmode | mode = std::ios_base::in|std::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.c_str(), 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 |
open
() system call succeeds the method returns this
. If the call fails, then it returns a null pointer.
|
private |
|
protectedvirtual |
Writes the specified character to the associated serial port.
const ParityEnum LibSerial::SerialStreamBuf::Parity | ( | ) | const |
Get the current parity setting for the serial port.
|
protectedvirtual |
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 least on character.
const BaudRateEnum LibSerial::SerialStreamBuf::SetBaudRate | ( | const BaudRateEnum | baudRate | ) |
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.
|
protectedvirtual |
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.
In the case of SerialStreamBuf, we want to keep using unbuffered I/O. Hence, using this method has no effect at present.
const CharSizeEnum LibSerial::SerialStreamBuf::SetCharSize | ( | const CharSizeEnum | charSize | ) |
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 | ( | const FlowControlEnum | flowControlType | ) |
Use the specified flow control.
short LibSerial::SerialStreamBuf::SetNumOfStopBits | ( | short | numOfStopBits | ) |
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). |
int LibSerial::SerialStreamBuf::SetParametersToDefault | ( | ) |
Initialize the serial communication parameters to their default values.
const ParityEnum LibSerial::SerialStreamBuf::SetParity | ( | const ParityEnum | parityType | ) |
Set the parity for serial communication.
parity | The parity value. |
const short LibSerial::SerialStreamBuf::SetVMin | ( | short | vtime | ) |
Set the minimum number of characters for non-canonical reads.
See VMIN in man termios(3).
const short LibSerial::SerialStreamBuf::SetVTime | ( | short | vtime | ) |
Set character buffer timeout in 10ths of a second.
This applies to non-canonical reads.
|
protectedvirtual |
Check, wether input is available on the port.
If you call SerialStream::in_avail
, this method will be called to check for available input.
|
protectedvirtual |
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 unbuffered I/O.
|
protectedvirtual |
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.
const short LibSerial::SerialStreamBuf::VMin | ( | ) | const |
Get the VMIN value for the device.
This represents the minimum number of characters for non-canonical reads.
const short LibSerial::SerialStreamBuf::VTime | ( | ) | const |
Get the current timeout value for non-canonical reads in deciseconds.
|
protectedvirtual |
Reads upto n characters from the serial port and returns them through the character array located at s.
|
protectedvirtual |
Writes upto n characters from the character sequence at s to the serial port associated with the buffer.
|
staticprotected |
Character used to signal that I/O can start while using software flow control with the serial port.
Definition at line 428 of file SerialStreamBuf.h.
|
staticprotected |
Character used to signal that I/O should stop while using software flow control with the serial port.
Definition at line 434 of file SerialStreamBuf.h.
|
static |
The default value of the baud rate of the serial port.
Definition at line 160 of file SerialStreamBuf.h.
|
static |
The default value of the character size used during the serial communication.
Definition at line 169 of file SerialStreamBuf.h.
|
static |
The default flow control setting.
Definition at line 193 of file SerialStreamBuf.h.
|
static |
The default number of stop bits used.
Definition at line 177 of file SerialStreamBuf.h.
|
static |
The default parity setting.
Definition at line 185 of file SerialStreamBuf.h.
|
static |
The default character buffer size.
Definition at line 203 of file SerialStreamBuf.h.
|
static |
The default character buffer timing.
Definition at line 213 of file SerialStreamBuf.h.
|
private |
Definition at line 532 of file SerialStreamBuf.h.