LibSerial 1.0.0
LibSerial provides a convenient, object oriented approach to accessing serial ports on POSIX systems.
|
SerialStreamBuf 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. More...
#include <SerialStreamBuf.h>
Classes | |
class | Implementation |
SerialStreamBuf::Implementation is the SerialStreamBuf implementation class. More... | |
Public Member Functions | |
SerialStreamBuf () | |
Default Constructor. | |
SerialStreamBuf (const std::string &fileName, const BaudRate &baudRate=BaudRate::BAUD_DEFAULT, const CharacterSize &characterSize=CharacterSize::CHAR_SIZE_DEFAULT, const FlowControl &flowControlType=FlowControl::FLOW_CONTROL_DEFAULT, const Parity &parityType=Parity::PARITY_DEFAULT, const StopBits &stopBits=StopBits::STOP_BITS_DEFAULT) | |
Constructor that allows a SerialStreamBuf instance to be created and opened, initializing the corresponding serial port with the specified parameters. | |
virtual | ~SerialStreamBuf () |
Default Destructor for a SerialStreamBuf object. Closes the serial port associated with mFileDescriptor if open. | |
SerialStreamBuf (const SerialStreamBuf &otherSerialStreamBuf)=delete | |
Copy construction is disallowed. | |
SerialStreamBuf (const SerialStreamBuf &&otherSerialStreamBuf)=delete | |
Move construction is disallowed. | |
SerialStreamBuf & | operator= (const SerialStreamBuf &otherSerialStreamBuf)=delete |
Copy assignment is disallowed. | |
SerialStreamBuf & | operator= (const SerialStreamBuf &&otherSerialStreamBuf)=delete |
Move assignment is disallowed. | |
void | Open (const std::string &fileName, const std::ios_base::openmode &openMode=std::ios_base::in|std::ios_base::out) |
Opens the serial port associated with the specified file name and the specified mode. | |
void | Close () |
Closes the serial port. All settings of the serial port will be lost and no more I/O can be performed on the serial port. | |
void | DrainWriteBuffer () |
Waits until the write buffer is drained and then returns. | |
void | FlushInputBuffer () |
Flushes the serial port input buffer. | |
void | FlushOutputBuffer () |
Flushes the serial port output buffer. | |
void | FlushIOBuffers () |
Flushes the serial port input and output buffers. | |
bool | IsDataAvailable () |
Checks if data is available at the input of the serial port. | |
bool | IsOpen () const |
Determines if the serial port is open for I/O. | |
void | SetDefaultSerialPortParameters () |
Sets all serial port paramters to their default values. | |
void | SetBaudRate (const BaudRate &baudRate) |
Sets the baud rate for the serial port to the specified value. | |
BaudRate | GetBaudRate () const |
Gets the current baud rate for the serial port. | |
void | SetCharacterSize (const CharacterSize &characterSize) |
Sets the character size for the serial port. | |
CharacterSize | GetCharacterSize () const |
Gets the character size being used for serial communication. | |
void | SetFlowControl (const FlowControl &flowControlType) |
Sets flow control for the serial port. | |
FlowControl | GetFlowControl () const |
Gets the current flow control setting. | |
void | SetParity (const Parity &parityType) |
Sets the parity type for the serial port. | |
Parity | GetParity () const |
Gets the parity type for the serial port. | |
void | SetStopBits (const StopBits &stopBits) |
Sets the number of stop bits to be used with the serial port. | |
StopBits | GetStopBits () const |
Gets the number of stop bits currently being used by the serial. | |
void | SetVMin (const short vmin) |
Sets the minimum number of characters for non-canonical reads. | |
short | GetVMin () const |
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonical reads. | |
void | SetVTime (const short vtime) |
Sets character buffer timeout for non-canonical reads in deciseconds. | |
short | GetVTime () const |
Gets the current timeout value for non-canonical reads in deciseconds. | |
void | SetDTR (const bool dtrState=true) |
Sets the DTR line to the specified value. | |
bool | GetDTR () const |
Gets the status of the DTR line. | |
void | SetRTS (const bool rtsState=true) |
Set the RTS line to the specified value. | |
bool | GetRTS () const |
Get the status of the RTS line. | |
bool | GetCTS () |
Get the status of the CTS line. | |
bool | GetDSR () |
Get the status of the DSR line. | |
int | GetFileDescriptor () const |
Gets the serial port file descriptor. | |
int | GetNumberOfBytesAvailable () |
Gets the number of bytes available in the read buffer. | |
Protected Member Functions | |
virtual std::streambuf * | setbuf (char_type *character, std::streamsize numberOfBytes) override |
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. | |
virtual std::streamsize | xsputn (const char_type *character, std::streamsize numberOfBytes) override |
Writes up to n characters from the character sequence at char s to the serial port associated with the buffer. | |
virtual std::streamsize | xsgetn (char_type *character, std::streamsize numberOfBytes) override |
Reads up to n characters from the serial port and returns them through the character array located at s. | |
virtual int_type | overflow (const int_type character) override |
Writes the specified character to the associated serial port. | |
virtual int_type | underflow () override |
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. | |
virtual int_type | uflow () override |
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. | |
virtual int_type | pbackfail (const int_type character) override |
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 one character. | |
virtual std::streamsize | showmanyc () override |
Checks whether input is available on the port. If you call SerialStream::in_avail , this method will be called to check for available input. | |
SerialStreamBuf 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 58 of file SerialStreamBuf.h.
|
explicit |
Default Constructor.
Definition at line 382 of file SerialStreamBuf.cpp.
|
explicit |
Constructor that allows a SerialStreamBuf instance to be created and opened, initializing the corresponding serial port with the specified parameters.
fileName | The file name of the serial stream. |
baudRate | The communications baud rate. |
characterSize | The size of the character buffer for storing read/write streams. |
parityType | The parity type for the serial stream. |
stopBits | The number of stop bits for the serial stream. |
flowControlType | The flow control type for the serial stream. |
Definition at line 388 of file SerialStreamBuf.cpp.
|
virtualdefault |
Default Destructor for a SerialStreamBuf object. Closes the serial port associated with mFileDescriptor if open.
|
delete |
Copy construction is disallowed.
|
delete |
Move construction is disallowed.
void LibSerial::SerialStreamBuf::Close | ( | ) |
Closes the serial port. All settings of the serial port will be lost and no more I/O can be performed on the serial port.
Definition at line 415 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::DrainWriteBuffer | ( | ) |
Waits until the write buffer is drained and then returns.
Definition at line 421 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::FlushInputBuffer | ( | ) |
Flushes the serial port input buffer.
Definition at line 427 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::FlushIOBuffers | ( | ) |
Flushes the serial port input and output buffers.
Definition at line 439 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::FlushOutputBuffer | ( | ) |
Flushes the serial port output buffer.
Definition at line 433 of file SerialStreamBuf.cpp.
BaudRate LibSerial::SerialStreamBuf::GetBaudRate | ( | ) | const |
Gets the current baud rate for the serial port.
Definition at line 469 of file SerialStreamBuf.cpp.
CharacterSize LibSerial::SerialStreamBuf::GetCharacterSize | ( | ) | const |
Gets the character size being used for serial communication.
Definition at line 481 of file SerialStreamBuf.cpp.
bool LibSerial::SerialStreamBuf::GetCTS | ( | ) |
Get the status of the CTS line.
Definition at line 571 of file SerialStreamBuf.cpp.
bool LibSerial::SerialStreamBuf::GetDSR | ( | ) |
Get the status of the DSR line.
Definition at line 577 of file SerialStreamBuf.cpp.
bool LibSerial::SerialStreamBuf::GetDTR | ( | ) | const |
Gets the status of the DTR line.
Definition at line 553 of file SerialStreamBuf.cpp.
int LibSerial::SerialStreamBuf::GetFileDescriptor | ( | ) | const |
Gets the serial port file descriptor.
Definition at line 583 of file SerialStreamBuf.cpp.
FlowControl LibSerial::SerialStreamBuf::GetFlowControl | ( | ) | const |
Gets the current flow control setting.
Definition at line 493 of file SerialStreamBuf.cpp.
int LibSerial::SerialStreamBuf::GetNumberOfBytesAvailable | ( | ) |
Gets the number of bytes available in the read buffer.
Definition at line 589 of file SerialStreamBuf.cpp.
Parity LibSerial::SerialStreamBuf::GetParity | ( | ) | const |
Gets the parity type for the serial port.
Definition at line 505 of file SerialStreamBuf.cpp.
bool LibSerial::SerialStreamBuf::GetRTS | ( | ) | const |
Get the status of the RTS line.
Definition at line 565 of file SerialStreamBuf.cpp.
StopBits LibSerial::SerialStreamBuf::GetStopBits | ( | ) | const |
Gets the number of stop bits currently being used by the serial.
Definition at line 517 of file SerialStreamBuf.cpp.
short LibSerial::SerialStreamBuf::GetVMin | ( | ) | const |
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonical reads.
Definition at line 529 of file SerialStreamBuf.cpp.
short LibSerial::SerialStreamBuf::GetVTime | ( | ) | const |
Gets the current timeout value for non-canonical reads in deciseconds.
Definition at line 541 of file SerialStreamBuf.cpp.
bool LibSerial::SerialStreamBuf::IsDataAvailable | ( | ) |
Checks if data is available at the input of the serial port.
Definition at line 445 of file SerialStreamBuf.cpp.
bool LibSerial::SerialStreamBuf::IsOpen | ( | ) | const |
Determines if the serial port is open for I/O.
Definition at line 451 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::Open | ( | const std::string & | fileName, |
const std::ios_base::openmode & | openMode = std::ios_base::in | std::ios_base::out |
||
) |
Opens the serial port associated with the specified file name and the specified mode.
fileName | The file name of the serial port. |
openMode | The communication mode status when the serial communication port is opened. |
Definition at line 407 of file SerialStreamBuf.cpp.
|
delete |
Move assignment is disallowed.
|
delete |
Copy assignment is disallowed.
|
overrideprotectedvirtual |
Writes the specified character to the associated serial port.
character | The character to be written to the serial port. |
Definition at line 621 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
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 one character.
character | The character to putback. |
Definition at line 639 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetBaudRate | ( | const BaudRate & | baudRate | ) |
Sets the baud rate for the serial port to the specified value.
baudRate | The baud rate to be set for the serial port. |
Definition at line 463 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
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 SerialStreamBuffer, we want to keep using unbuffered I/O. Hence, using this method has no effect at present.
character | Pointer to the character buffer to write to the serial port. |
numberOfBytes | The number of characters to write to the serial port. |
Definition at line 603 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetCharacterSize | ( | const CharacterSize & | characterSize | ) |
Sets the character size for the serial port.
characterSize | The character size to be set. |
Definition at line 475 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetDefaultSerialPortParameters | ( | ) |
Sets all serial port paramters to their default values.
Definition at line 457 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetDTR | ( | const bool | dtrState = true | ) |
Sets the DTR line to the specified value.
dtrState | The line voltage state to be set, (true = high, false = low). |
Definition at line 547 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetFlowControl | ( | const FlowControl & | flowControlType | ) |
Sets flow control for the serial port.
flowControlType | The flow control type to be set. |
Definition at line 487 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetParity | ( | const Parity & | parityType | ) |
Sets the parity type for the serial port.
parityType | The parity type to be set. |
Definition at line 499 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetRTS | ( | const bool | rtsState = true | ) |
Set the RTS line to the specified value.
rtsState | The line voltage state to be set, (true = high, false = low). |
Definition at line 559 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetStopBits | ( | const StopBits & | stopBits | ) |
Sets the number of stop bits to be used with the serial port.
stopBits | The number of stop bits to set. |
Definition at line 511 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetVMin | ( | const short | vmin | ) |
Sets the minimum number of characters for non-canonical reads.
vmin | the number of minimum characters to be set. |
Definition at line 523 of file SerialStreamBuf.cpp.
void LibSerial::SerialStreamBuf::SetVTime | ( | const short | vtime | ) |
Sets character buffer timeout for non-canonical reads in deciseconds.
vtime | The timeout value in deciseconds to be set. |
Definition at line 535 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
Checks whether input is available on the port. If you call SerialStream::in_avail
, this method will be called to check for available input.
Definition at line 645 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
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.
Definition at line 633 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
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.
Definition at line 627 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
Reads up to n characters from the serial port and returns them through the character array located at s.
character | Pointer to the character buffer to write to the serial port. |
numberOfBytes | The number of characters to write to the serial port. |
Definition at line 615 of file SerialStreamBuf.cpp.
|
overrideprotectedvirtual |
Writes up to n characters from the character sequence at char s to the serial port associated with the buffer.
character | Pointer to the character buffer to write to the serial port. |
numberOfBytes | The number of characters to write to the serial port. |
Definition at line 609 of file SerialStreamBuf.cpp.