LibSerial 1.0.0
LibSerial provides a convenient, object oriented approach to accessing serial ports on POSIX systems.
Loading...
Searching...
No Matches
LibSerial::SerialStreamBuf::Implementation Class Reference

SerialStreamBuf::Implementation is the SerialStreamBuf implementation class. More...

Public Member Functions

 Implementation ()=default
 Default Constructor.
 
 ~Implementation ()
 Default Destructor.
 
 Implementation (const std::string &fileName, const BaudRate &baudRate, const CharacterSize &characterSize, const FlowControl &flowControlType, const Parity &parityType, const StopBits &stopBits, bool exclusive)
 Constructor that allows a SerialStreamBuf instance to be created and opened, initializing the corresponding serial port with the specified parameters.
 
 Implementation (const Implementation &otherImplementation)=delete
 Copy construction is disallowed.
 
 Implementation (const Implementation &&otherImplementation)=delete
 Move construction is disallowed.
 
Implementationoperator= (const Implementation &otherImplementation)=delete
 Copy assignment is disallowed.
 
Implementationoperator= (const Implementation &&otherImplementation)=delete
 Move assignment is disallowed.
 
void Open (const std::string &fileName, const std::ios_base::openmode &openMode, bool exclusive)
 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 ()
 Determines if data is available at 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
 Get 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)
 Sets the serial port DTR line status.
 
bool GetDTR () const
 Gets the serial port DTR line status.
 
void SetRTS (const bool rtsState)
 Sets the serial port RTS line status.
 
bool GetRTS () const
 Gets the serial port RTS line status.
 
bool GetCTS ()
 Gets the serial port CTS line status.
 
bool GetDSR ()
 Gets the serial port DSR line status.
 
int GetFileDescriptor () const
 Gets the serial port file descriptor.
 
int GetNumberOfBytesAvailable ()
 Gets the number of bytes available in the read buffer.
 
std::streamsize xsputn (const char_type *character, std::streamsize numberOfBytes)
 Writes up to n characters from the character sequence at char s to the serial port associated with the buffer.
 
std::streamsize xsgetn (char_type *character, std::streamsize numberOfBytes)
 Reads up to n characters from the serial port and returns them through the character array located at s.
 
std::streambuf::int_type overflow (int_type character)
 Writes the specified character to the associated serial port.
 
std::streambuf::int_type underflow ()
 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.
 
std::streambuf::int_type uflow ()
 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.
 
std::streambuf::int_type pbackfail (int_type character)
 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.
 
std::streamsize showmanyc ()
 Checks whether input is available on the port.
 

Public Attributes

bool mPutbackAvailable {false}
 True if a putback value is available in mPutbackChar.
 
char mPutbackChar {0}
 We use unbuffered I/O for the serial port. However, we need to provide the putback of at least one character. This character contains the putback character.
 

Detailed Description

SerialStreamBuf::Implementation is the SerialStreamBuf implementation class.

Definition at line 48 of file SerialStreamBuf.cpp.

Constructor & Destructor Documentation

◆ Implementation() [1/4]

LibSerial::SerialStreamBuf::Implementation::Implementation ( )
default

Default Constructor.

◆ ~Implementation()

LibSerial::SerialStreamBuf::Implementation::~Implementation ( )
inline

Default Destructor.

Definition at line 685 of file SerialStreamBuf.cpp.

◆ Implementation() [2/4]

LibSerial::SerialStreamBuf::Implementation::Implementation ( const std::string &  fileName,
const BaudRate &  baudRate,
const CharacterSize &  characterSize,
const FlowControl &  flowControlType,
const Parity &  parityType,
const StopBits &  stopBits,
bool  exclusive 
)
inline

Constructor that allows a SerialStreamBuf instance to be created and opened, initializing the corresponding serial port with the specified parameters.

Parameters
fileNameThe file name of the serial stream.
baudRateThe communications baud rate.
characterSizeThe size of the character buffer for storing read/write streams.
parityTypeThe parity type for the serial stream.
stopBitsThe number of stop bits for the serial stream.
flowControlTypeThe flow control type for the serial stream.
exclusiveSet exclusive access for the serial stream.

-----------------------— Implementation -----------------------—

Definition at line 662 of file SerialStreamBuf.cpp.

◆ Implementation() [3/4]

LibSerial::SerialStreamBuf::Implementation::Implementation ( const Implementation otherImplementation)
delete

Copy construction is disallowed.

◆ Implementation() [4/4]

LibSerial::SerialStreamBuf::Implementation::Implementation ( const Implementation &&  otherImplementation)
delete

Move construction is disallowed.

Member Function Documentation

◆ Close()

void LibSerial::SerialStreamBuf::Implementation::Close ( )
inline

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 734 of file SerialStreamBuf.cpp.

◆ DrainWriteBuffer()

void LibSerial::SerialStreamBuf::Implementation::DrainWriteBuffer ( )
inline

Waits until the write buffer is drained and then returns.

Definition at line 741 of file SerialStreamBuf.cpp.

◆ FlushInputBuffer()

void LibSerial::SerialStreamBuf::Implementation::FlushInputBuffer ( )
inline

Flushes the serial port input buffer.

Definition at line 748 of file SerialStreamBuf.cpp.

◆ FlushIOBuffers()

void LibSerial::SerialStreamBuf::Implementation::FlushIOBuffers ( )
inline

Flushes the serial port input and output buffers.

Definition at line 762 of file SerialStreamBuf.cpp.

◆ FlushOutputBuffer()

void LibSerial::SerialStreamBuf::Implementation::FlushOutputBuffer ( )
inline

Flushes the serial port output buffer.

Definition at line 755 of file SerialStreamBuf.cpp.

◆ GetBaudRate()

BaudRate LibSerial::SerialStreamBuf::Implementation::GetBaudRate ( ) const
inline

Gets the current baud rate for the serial port.

Returns
Returns the baud rate.

Definition at line 797 of file SerialStreamBuf.cpp.

◆ GetCharacterSize()

CharacterSize LibSerial::SerialStreamBuf::Implementation::GetCharacterSize ( ) const
inline

Gets the character size being used for serial communication.

Returns
Returns the current character size.

Definition at line 811 of file SerialStreamBuf.cpp.

◆ GetCTS()

bool LibSerial::SerialStreamBuf::Implementation::GetCTS ( )
inline

Gets the serial port CTS line status.

Returns
Returns true iff the status of the CTS line is high.

Definition at line 916 of file SerialStreamBuf.cpp.

◆ GetDSR()

bool LibSerial::SerialStreamBuf::Implementation::GetDSR ( )
inline

Gets the serial port DSR line status.

Returns
Returns true iff the status of the DSR line is high.

Definition at line 923 of file SerialStreamBuf.cpp.

◆ GetDTR()

bool LibSerial::SerialStreamBuf::Implementation::GetDTR ( ) const
inline

Gets the serial port DTR line status.

Returns
Returns true iff the status of the DTR line is high.

Definition at line 895 of file SerialStreamBuf.cpp.

◆ GetFileDescriptor()

int LibSerial::SerialStreamBuf::Implementation::GetFileDescriptor ( ) const
inline

Gets the serial port file descriptor.

Returns
Returns the serial port file descriptor.

Definition at line 930 of file SerialStreamBuf.cpp.

◆ GetFlowControl()

FlowControl LibSerial::SerialStreamBuf::Implementation::GetFlowControl ( ) const
inline

Get the current flow control setting.

Returns
Returns the flow control type of the serial port.

Definition at line 825 of file SerialStreamBuf.cpp.

◆ GetNumberOfBytesAvailable()

int LibSerial::SerialStreamBuf::Implementation::GetNumberOfBytesAvailable ( )
inline

Gets the number of bytes available in the read buffer.

Returns
Returns the number of bytes avilable in the read buffer.

Definition at line 937 of file SerialStreamBuf.cpp.

◆ GetParity()

Parity LibSerial::SerialStreamBuf::Implementation::GetParity ( ) const
inline

Gets the parity type for the serial port.

Returns
Returns the parity type.

Definition at line 839 of file SerialStreamBuf.cpp.

◆ GetRTS()

bool LibSerial::SerialStreamBuf::Implementation::GetRTS ( ) const
inline

Gets the serial port RTS line status.

Returns
Returns true iff the status of the RTS line is high.

Definition at line 909 of file SerialStreamBuf.cpp.

◆ GetStopBits()

StopBits LibSerial::SerialStreamBuf::Implementation::GetStopBits ( ) const
inline

Gets the number of stop bits currently being used by the serial.

Returns
Returns the number of stop bits.

Definition at line 853 of file SerialStreamBuf.cpp.

◆ GetVMin()

short LibSerial::SerialStreamBuf::Implementation::GetVMin ( ) const
inline

Gets the VMIN value for the device, which represents the minimum number of characters for non-canonical reads.

Returns
Returns the minimum number of characters for non-canonical reads.

Definition at line 867 of file SerialStreamBuf.cpp.

◆ GetVTime()

short LibSerial::SerialStreamBuf::Implementation::GetVTime ( ) const
inline

Gets the current timeout value for non-canonical reads in deciseconds.

Returns
Returns the character buffer timeout for non-canonical reads in deciseconds.

Definition at line 881 of file SerialStreamBuf.cpp.

◆ IsDataAvailable()

bool LibSerial::SerialStreamBuf::Implementation::IsDataAvailable ( )
inline

Determines if data is available at the serial port.

Definition at line 776 of file SerialStreamBuf.cpp.

◆ IsOpen()

bool LibSerial::SerialStreamBuf::Implementation::IsOpen ( ) const
inline

Determines if the serial port is open for I/O.

Returns
Returns true iff the serial port is open.

Definition at line 769 of file SerialStreamBuf.cpp.

◆ Open()

void LibSerial::SerialStreamBuf::Implementation::Open ( const std::string &  fileName,
const std::ios_base::openmode &  openMode,
bool  exclusive 
)
inline

Opens the serial port associated with the specified file name and the specified mode.

Parameters
fileNameThe file name of the serial port.
openModeThe communication mode status when the serial communication port is opened.
exclusiveSet exclusive access for this serial port.

Definition at line 707 of file SerialStreamBuf.cpp.

◆ operator=() [1/2]

Implementation & LibSerial::SerialStreamBuf::Implementation::operator= ( const Implementation &&  otherImplementation)
delete

Move assignment is disallowed.

◆ operator=() [2/2]

Implementation & LibSerial::SerialStreamBuf::Implementation::operator= ( const Implementation otherImplementation)
delete

Copy assignment is disallowed.

◆ overflow()

std::streambuf::int_type LibSerial::SerialStreamBuf::Implementation::overflow ( int_type  character)
inline

Writes the specified character to the associated serial port.

Parameters
characterThe character to be written to the serial port.
Returns
Returns the character.

Definition at line 1068 of file SerialStreamBuf.cpp.

◆ pbackfail()

std::streambuf::int_type LibSerial::SerialStreamBuf::Implementation::pbackfail ( int_type  character)
inline

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.

Parameters
characterThe character to putback.
Returns
Returns The character iff successful, otherwise eof to signal an error.

Definition at line 1177 of file SerialStreamBuf.cpp.

◆ SetBaudRate()

void LibSerial::SerialStreamBuf::Implementation::SetBaudRate ( const BaudRate &  baudRate)
inline

Sets the baud rate for the serial port to the specified value.

Parameters
baudRateThe baud rate to be set for the serial port.

Definition at line 790 of file SerialStreamBuf.cpp.

◆ SetCharacterSize()

void LibSerial::SerialStreamBuf::Implementation::SetCharacterSize ( const CharacterSize &  characterSize)
inline

Sets the character size for the serial port.

Parameters
characterSizeThe character size to be set.

Definition at line 804 of file SerialStreamBuf.cpp.

◆ SetDefaultSerialPortParameters()

void LibSerial::SerialStreamBuf::Implementation::SetDefaultSerialPortParameters ( )
inline

Sets all serial port paramters to their default values.

Definition at line 783 of file SerialStreamBuf.cpp.

◆ SetDTR()

void LibSerial::SerialStreamBuf::Implementation::SetDTR ( const bool  dtrState)
inline

Sets the serial port DTR line status.

Parameters
dtrStateThe state to set the DTR line

Definition at line 888 of file SerialStreamBuf.cpp.

◆ SetFlowControl()

void LibSerial::SerialStreamBuf::Implementation::SetFlowControl ( const FlowControl &  flowControlType)
inline

Sets flow control for the serial port.

Parameters
flowControlTypeThe flow control type to be set.

Definition at line 818 of file SerialStreamBuf.cpp.

◆ SetParity()

void LibSerial::SerialStreamBuf::Implementation::SetParity ( const Parity &  parityType)
inline

Sets the parity type for the serial port.

Parameters
parityTypeThe parity type to be set.

Definition at line 832 of file SerialStreamBuf.cpp.

◆ SetRTS()

void LibSerial::SerialStreamBuf::Implementation::SetRTS ( const bool  rtsState)
inline

Sets the serial port RTS line status.

Parameters
rtsStateThe state to set the RTS line

Definition at line 902 of file SerialStreamBuf.cpp.

◆ SetStopBits()

void LibSerial::SerialStreamBuf::Implementation::SetStopBits ( const StopBits &  stopBits)
inline

Sets the number of stop bits to be used with the serial port.

Parameters
stopBitsThe number of stop bits to set.

Definition at line 846 of file SerialStreamBuf.cpp.

◆ SetVMin()

void LibSerial::SerialStreamBuf::Implementation::SetVMin ( const short  vmin)
inline

Sets the minimum number of characters for non-canonical reads.

Parameters
vminthe number of minimum characters to be set.

Definition at line 860 of file SerialStreamBuf.cpp.

◆ SetVTime()

void LibSerial::SerialStreamBuf::Implementation::SetVTime ( const short  vtime)
inline

Sets character buffer timeout for non-canonical reads in deciseconds.

Parameters
vtimeThe timeout value in deciseconds to be set.

Definition at line 874 of file SerialStreamBuf.cpp.

◆ showmanyc()

std::streamsize LibSerial::SerialStreamBuf::Implementation::showmanyc ( )
inline

Checks whether input is available on the port.

Returns
Returns 1 if characters are available at the serial port, 0 if no characters are available, and -1 if unsuccessful.

Definition at line 1208 of file SerialStreamBuf.cpp.

◆ uflow()

std::streambuf::int_type LibSerial::SerialStreamBuf::Implementation::uflow ( )
inline

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.

Returns
Returns the next character from the serial port.

Definition at line 1160 of file SerialStreamBuf.cpp.

◆ underflow()

std::streambuf::int_type LibSerial::SerialStreamBuf::Implementation::underflow ( )
inline

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.

Returns
Returns the next character from the serial port.

Definition at line 1103 of file SerialStreamBuf.cpp.

◆ xsgetn()

std::streamsize LibSerial::SerialStreamBuf::Implementation::xsgetn ( char_type *  character,
std::streamsize  numberOfBytes 
)
inline

Reads up to n characters from the serial port and returns them through the character array located at s.

Parameters
characterPointer to the character buffer to write to the serial port.
numberOfBytesThe number of characters to write to the serial port.
Returns
Returns the number of characters actually read from the serial port.

Definition at line 987 of file SerialStreamBuf.cpp.

◆ xsputn()

std::streamsize LibSerial::SerialStreamBuf::Implementation::xsputn ( const char_type *  character,
std::streamsize  numberOfBytes 
)
inline

Writes up to n characters from the character sequence at char s to the serial port associated with the buffer.

Parameters
characterPointer to the character buffer to write to the serial port.
numberOfBytesThe number of characters to write to the serial port.
Returns
Returns the number of characters that were successfully written to the serial port.

Definition at line 953 of file SerialStreamBuf.cpp.

Member Data Documentation

◆ mPutbackAvailable

bool LibSerial::SerialStreamBuf::Implementation::mPutbackAvailable {false}

True if a putback value is available in mPutbackChar.

:TODO: Should this be private?

Definition at line 367 of file SerialStreamBuf.cpp.

◆ mPutbackChar

char LibSerial::SerialStreamBuf::Implementation::mPutbackChar {0}

We use unbuffered I/O for the serial port. However, we need to provide the putback of at least one character. This character contains the putback character.

:TODO: Should this be private?

Definition at line 376 of file SerialStreamBuf.cpp.


The documentation for this class was generated from the following file: