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

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

Public Member Functions

 Implementation ()=default
 Default Constructor.
 
 Implementation (const std::string &fileName, const BaudRate &baudRate, const CharacterSize &characterSize, const FlowControl &flowControlType, const Parity &parityType, const StopBits &stopBits)
 Constructor that allows a SerialPort instance to be created and opened, initializing the corresponding serial port with the specified parameters.
 
 ~Implementation () noexcept
 Default Destructor for a SerialPort object. Closes the serial port associated with mFileDescriptor if open.
 
 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)
 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 ()
 Gets the serial port DTR line status.
 
void SetRTS (const bool rtsState)
 Sets the serial port RTS line status.
 
bool GetRTS ()
 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.
 
void Read (DataBuffer &dataBuffer, size_t numberOfBytes=0, size_t msTimeout=0)
 Reads the specified number of bytes from the serial port. The method will timeout if no data is received in the specified number of milliseconds (msTimeout). If msTimeout is zero, then the method will block until all requested bytes are received. If numberOfBytes is zero and msTimeout is non-zero, the method will continue receiving data for the specified of milliseconds. If numberOfBytes is zero and msTimeout is zero, the method will return immediately. In all cases, any data received remains available in the dataBuffer on return from this method.
 
void Read (std::string &dataString, size_t numberOfBytes=0, size_t msTimeout=0)
 Reads the specified number of bytes from the serial port. The method will timeout if no data is received in the specified number of milliseconds (msTimeout). If msTimeout is 0, then this method will block until all requested bytes are received. If numberOfBytes is zero, then this method will keep reading data till no more data is available at the serial port. In all cases, all read data is available in dataString on return from this method.
 
template<typename ByteType , typename = std::enable_if_t<(sizeof(ByteType) == 1)>>
void ReadByte (ByteType &charBuffer, size_t msTimeout=0)
 Reads a single byte from the serial port. If no data is available within the specified number of milliseconds (msTimeout), then this method will throw a ReadTimeout exception. If msTimeout is 0, then this method will block until data is available.
 
void ReadLine (std::string &dataString, char lineTerminator='\n', size_t msTimeout=0)
 Reads a line of characters from the serial port. The method will timeout if no data is received in the specified number of milliseconds (msTimeout). If msTimeout is 0, then this method will block until a line terminator is received. If a line terminator is read, a string will be returned, however, if the timeout is reached, an exception will be thrown and all previously read data will be lost.
 
void Write (const DataBuffer &dataBuffer)
 Writes a DataBuffer to the serial port.
 
void Write (const std::string &dataString)
 Writes a std::string to the serial port.
 
void WriteByte (char charBuffer)
 Writes a single byte to the serial port.
 
void WriteByte (unsigned char charBuffer)
 Writes a single byte to the serial port.
 
void SetSerialPortBlockingStatus (bool blockingStatus)
 Sets the current state of the serial port blocking status.
 
bool GetSerialPortBlockingStatus () const
 Gets the current state of the serial port blocking status.
 
void SetModemControlLine (int modemLine, bool lineState)
 Set the specified modem control line to the specified value.
 
bool GetModemControlLine (int modemLine)
 Get the current state of the specified modem control line.
 

Detailed Description

SerialPort::Implementation is the SerialPort implementation class.

Definition at line 54 of file SerialPort.cpp.

Constructor & Destructor Documentation

◆ Implementation() [1/4]

LibSerial::SerialPort::Implementation::Implementation ( )
default

Default Constructor.

◆ Implementation() [2/4]

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

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

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

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

Definition at line 807 of file SerialPort.cpp.

◆ ~Implementation()

LibSerial::SerialPort::Implementation::~Implementation ( )
inlinenoexcept

Default Destructor for a SerialPort object. Closes the serial port associated with mFileDescriptor if open.

Definition at line 823 of file SerialPort.cpp.

◆ Implementation() [3/4]

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

Copy construction is disallowed.

◆ Implementation() [4/4]

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

Move construction is disallowed.

Member Function Documentation

◆ Close()

void LibSerial::SerialPort::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 912 of file SerialPort.cpp.

◆ DrainWriteBuffer()

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

Waits until the write buffer is drained and then returns.

Definition at line 962 of file SerialPort.cpp.

◆ FlushInputBuffer()

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

Flushes the serial port input buffer.

Definition at line 978 of file SerialPort.cpp.

◆ FlushIOBuffers()

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

Flushes the serial port input and output buffers.

Definition at line 1010 of file SerialPort.cpp.

◆ FlushOutputBuffer()

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

Flushes the serial port output buffer.

Definition at line 994 of file SerialPort.cpp.

◆ GetBaudRate()

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

Gets the current baud rate for the serial port.

Returns
Returns the baud rate.

Definition at line 1129 of file SerialPort.cpp.

◆ GetCharacterSize()

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

Gets the character size being used for serial communication.

Returns
Returns the current character size.

Definition at line 1357 of file SerialPort.cpp.

◆ GetCTS()

bool LibSerial::SerialPort::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 1826 of file SerialPort.cpp.

◆ GetDSR()

bool LibSerial::SerialPort::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 1839 of file SerialPort.cpp.

◆ GetDTR()

bool LibSerial::SerialPort::Implementation::GetDTR ( )
inline

Gets the serial port DTR line status.

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

Definition at line 1786 of file SerialPort.cpp.

◆ GetFileDescriptor()

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

Gets the serial port file descriptor.

Returns
Returns the serial port file descriptor.

Definition at line 1852 of file SerialPort.cpp.

◆ GetFlowControl()

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

Get the current flow control setting.

Returns
Returns the flow control type of the serial port.

Definition at line 1444 of file SerialPort.cpp.

◆ GetModemControlLine()

bool LibSerial::SerialPort::Implementation::GetModemControlLine ( int  modemLine)
inline

Get the current state of the specified modem control line.

Parameters
modemLineOne of the following four values: TIOCM_DTR, TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR.
Returns
True if the specified line is currently set and false otherwise.

Definition at line 1991 of file SerialPort.cpp.

◆ GetNumberOfBytesAvailable()

int LibSerial::SerialPort::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 1865 of file SerialPort.cpp.

◆ GetParity()

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

Gets the parity type for the serial port.

Returns
Returns the parity type.

Definition at line 1543 of file SerialPort.cpp.

◆ GetRTS()

bool LibSerial::SerialPort::Implementation::GetRTS ( )
inline

Gets the serial port RTS line status.

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

Definition at line 1813 of file SerialPort.cpp.

◆ GetSerialPortBlockingStatus()

bool LibSerial::SerialPort::Implementation::GetSerialPortBlockingStatus ( ) const
inline

Gets the current state of the serial port blocking status.

Returns
True if port is blocking, false if port non-blocking.

Definition at line 2065 of file SerialPort.cpp.

◆ GetStopBits()

StopBits LibSerial::SerialPort::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 1619 of file SerialPort.cpp.

◆ GetVMin()

short LibSerial::SerialPort::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 1687 of file SerialPort.cpp.

◆ GetVTime()

short LibSerial::SerialPort::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 1749 of file SerialPort.cpp.

◆ IsDataAvailable()

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

Determines if data is available at the serial port.

Definition at line 1033 of file SerialPort.cpp.

◆ IsOpen()

bool LibSerial::SerialPort::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 1026 of file SerialPort.cpp.

◆ Open()

void LibSerial::SerialPort::Implementation::Open ( const std::string &  fileName,
const std::ios_base::openmode &  openMode 
)
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.

Definition at line 845 of file SerialPort.cpp.

◆ operator=() [1/2]

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

Move assignment is disallowed.

◆ operator=() [2/2]

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

Copy assignment is disallowed.

◆ Read() [1/2]

void LibSerial::SerialPort::Implementation::Read ( DataBuffer &  dataBuffer,
size_t  numberOfBytes = 0,
size_t  msTimeout = 0 
)
inline

Reads the specified number of bytes from the serial port. The method will timeout if no data is received in the specified number of milliseconds (msTimeout). If msTimeout is zero, then the method will block until all requested bytes are received. If numberOfBytes is zero and msTimeout is non-zero, the method will continue receiving data for the specified of milliseconds. If numberOfBytes is zero and msTimeout is zero, the method will return immediately. In all cases, any data received remains available in the dataBuffer on return from this method.

Parameters
dataBufferThe data buffer to place data into.
numberOfBytesThe number of bytes to read before returning.
msTimeoutThe timeout period in milliseconds.

Definition at line 2253 of file SerialPort.cpp.

◆ Read() [2/2]

void LibSerial::SerialPort::Implementation::Read ( std::string &  dataString,
size_t  numberOfBytes = 0,
size_t  msTimeout = 0 
)
inline

Reads the specified number of bytes from the serial port. The method will timeout if no data is received in the specified number of milliseconds (msTimeout). If msTimeout is 0, then this method will block until all requested bytes are received. If numberOfBytes is zero, then this method will keep reading data till no more data is available at the serial port. In all cases, all read data is available in dataString on return from this method.

Parameters
dataStringThe data string read from the serial port.
numberOfBytesThe number of bytes to read before returning.
msTimeoutThe timeout period in milliseconds.

Definition at line 2347 of file SerialPort.cpp.

◆ ReadByte()

template<typename ByteType , typename = std::enable_if_t<(sizeof(ByteType) == 1)>>
void LibSerial::SerialPort::Implementation::ReadByte ( ByteType &  charBuffer,
size_t  msTimeout = 0 
)
inline

Reads a single byte from the serial port. If no data is available within the specified number of milliseconds (msTimeout), then this method will throw a ReadTimeout exception. If msTimeout is 0, then this method will block until data is available.

Parameters
charBufferThe character read from the serial port.
msTimeoutThe timeout period in milliseconds.

Definition at line 2442 of file SerialPort.cpp.

◆ ReadLine()

void LibSerial::SerialPort::Implementation::ReadLine ( std::string &  dataString,
char  lineTerminator = '\n',
size_t  msTimeout = 0 
)
inline

Reads a line of characters from the serial port. The method will timeout if no data is received in the specified number of milliseconds (msTimeout). If msTimeout is 0, then this method will block until a line terminator is received. If a line terminator is read, a string will be returned, however, if the timeout is reached, an exception will be thrown and all previously read data will be lost.

Parameters
dataStringThe data string read from the serial port.
lineTerminatorThe line termination character to specify the end of a line.
msTimeoutThe timeout value to return if a line termination character is not read.

Definition at line 2504 of file SerialPort.cpp.

◆ SetBaudRate()

void LibSerial::SerialPort::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 1089 of file SerialPort.cpp.

◆ SetCharacterSize()

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

Sets the character size for the serial port.

Parameters
characterSizeThe character size to be set.

Definition at line 1305 of file SerialPort.cpp.

◆ SetDefaultSerialPortParameters()

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

Sets all serial port paramters to their default values.

Definition at line 1061 of file SerialPort.cpp.

◆ SetDTR()

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

Sets the serial port DTR line status.

Parameters
dtrStateThe state to set the DTR line

Definition at line 1772 of file SerialPort.cpp.

◆ SetFlowControl()

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

Sets flow control for the serial port.

Parameters
flowControlTypeThe flow control type to be set.

Definition at line 1382 of file SerialPort.cpp.

◆ SetModemControlLine()

void LibSerial::SerialPort::Implementation::SetModemControlLine ( int  modemLine,
bool  lineState 
)
inline

Set the specified modem control line to the specified value.

Parameters
modemLineOne of the following four values: TIOCM_DTR, TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR.
lineStateState of the modem line after successful call to this method.

Definition at line 1936 of file SerialPort.cpp.

◆ SetParity()

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

Sets the parity type for the serial port.

Parameters
parityTypeThe parity type to be set.

Definition at line 1492 of file SerialPort.cpp.

◆ SetRTS()

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

Sets the serial port RTS line status.

Parameters
rtsStateThe state to set the RTS line

Definition at line 1799 of file SerialPort.cpp.

◆ SetSerialPortBlockingStatus()

void LibSerial::SerialPort::Implementation::SetSerialPortBlockingStatus ( bool  blockingStatus)
inline

Sets the current state of the serial port blocking status.

Parameters
blockingStatusThe serial port blocking status to be set, true if to be set blocking, false if to be set non-blocking.

Definition at line 2031 of file SerialPort.cpp.

◆ SetStopBits()

void LibSerial::SerialPort::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 1576 of file SerialPort.cpp.

◆ SetVMin()

void LibSerial::SerialPort::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 1648 of file SerialPort.cpp.

◆ SetVTime()

void LibSerial::SerialPort::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 1710 of file SerialPort.cpp.

◆ Write() [1/2]

void LibSerial::SerialPort::Implementation::Write ( const DataBuffer &  dataBuffer)
inline

Writes a DataBuffer to the serial port.

Parameters
dataBufferThe DataBuffer to write to the serial port.

Definition at line 2560 of file SerialPort.cpp.

◆ Write() [2/2]

void LibSerial::SerialPort::Implementation::Write ( const std::string &  dataString)
inline

Writes a std::string to the serial port.

Parameters
dataStringThe std::string to be written to the serial port.

Definition at line 2611 of file SerialPort.cpp.

◆ WriteByte() [1/2]

void LibSerial::SerialPort::Implementation::WriteByte ( char  charBuffer)
inline

Writes a single byte to the serial port.

Parameters
charBufferThe byte to be written to the serial port.

Definition at line 2662 of file SerialPort.cpp.

◆ WriteByte() [2/2]

void LibSerial::SerialPort::Implementation::WriteByte ( unsigned char  charBuffer)
inline

Writes a single byte to the serial port.

Parameters
charBufferThe byte to be written to the serial port.

Definition at line 2696 of file SerialPort.cpp.


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