LibSerial 1.0.0
LibSerial provides a convenient, object oriented approach to accessing serial ports on POSIX systems.
|
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. | |
Implementation & | operator= (const Implementation &otherImplementation)=delete |
Copy assignment is disallowed. | |
Implementation & | operator= (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. | |
SerialPort::Implementation is the SerialPort implementation class.
Definition at line 54 of file SerialPort.cpp.
|
default |
Default Constructor.
|
inline |
Constructor that allows a SerialPort instance to be created and opened, initializing the corresponding serial port with the specified parameters.
fileName | The file name of the serial port. |
baudRate | The communications baud rate. |
characterSize | The size of the character buffer for storing read/write streams. |
parityType | The parity type for the serial port. |
stopBits | The number of stop bits for the serial port. |
flowControlType | The flow control type for the serial port. |
-----------------------— Implementation -----------------------—
Definition at line 807 of file SerialPort.cpp.
|
inlinenoexcept |
Default Destructor for a SerialPort object. Closes the serial port associated with mFileDescriptor if open.
Definition at line 823 of file SerialPort.cpp.
|
delete |
Copy construction is disallowed.
|
delete |
Move construction is disallowed.
|
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.
|
inline |
Waits until the write buffer is drained and then returns.
Definition at line 962 of file SerialPort.cpp.
|
inline |
Flushes the serial port input buffer.
Definition at line 978 of file SerialPort.cpp.
|
inline |
Flushes the serial port input and output buffers.
Definition at line 1010 of file SerialPort.cpp.
|
inline |
Flushes the serial port output buffer.
Definition at line 994 of file SerialPort.cpp.
|
inline |
Gets the current baud rate for the serial port.
Definition at line 1129 of file SerialPort.cpp.
|
inline |
Gets the character size being used for serial communication.
Definition at line 1357 of file SerialPort.cpp.
|
inline |
Gets the serial port CTS line status.
Definition at line 1826 of file SerialPort.cpp.
|
inline |
Gets the serial port DSR line status.
Definition at line 1839 of file SerialPort.cpp.
|
inline |
Gets the serial port DTR line status.
Definition at line 1786 of file SerialPort.cpp.
|
inline |
Gets the serial port file descriptor.
Definition at line 1852 of file SerialPort.cpp.
|
inline |
Get the current flow control setting.
Definition at line 1444 of file SerialPort.cpp.
|
inline |
Get the current state of the specified modem control line.
modemLine | One of the following four values: TIOCM_DTR, TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR. |
Definition at line 1991 of file SerialPort.cpp.
|
inline |
Gets the number of bytes available in the read buffer.
Definition at line 1865 of file SerialPort.cpp.
|
inline |
Gets the parity type for the serial port.
Definition at line 1543 of file SerialPort.cpp.
|
inline |
Gets the serial port RTS line status.
Definition at line 1813 of file SerialPort.cpp.
|
inline |
Gets the current state of the serial port blocking status.
Definition at line 2065 of file SerialPort.cpp.
|
inline |
Gets the number of stop bits currently being used by the serial.
Definition at line 1619 of file SerialPort.cpp.
|
inline |
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonical reads.
Definition at line 1687 of file SerialPort.cpp.
|
inline |
Gets the current timeout value for non-canonical reads in deciseconds.
Definition at line 1749 of file SerialPort.cpp.
|
inline |
Determines if data is available at the serial port.
Definition at line 1033 of file SerialPort.cpp.
|
inline |
Determines if the serial port is open for I/O.
Definition at line 1026 of file SerialPort.cpp.
|
inline |
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 845 of file SerialPort.cpp.
|
delete |
Move assignment is disallowed.
|
delete |
Copy assignment is disallowed.
|
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.
dataBuffer | The data buffer to place data into. |
numberOfBytes | The number of bytes to read before returning. |
msTimeout | The timeout period in milliseconds. |
Definition at line 2253 of file SerialPort.cpp.
|
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.
dataString | The data string read from the serial port. |
numberOfBytes | The number of bytes to read before returning. |
msTimeout | The timeout period in milliseconds. |
Definition at line 2347 of file SerialPort.cpp.
|
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.
charBuffer | The character read from the serial port. |
msTimeout | The timeout period in milliseconds. |
Definition at line 2442 of file SerialPort.cpp.
|
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.
dataString | The data string read from the serial port. |
lineTerminator | The line termination character to specify the end of a line. |
msTimeout | The timeout value to return if a line termination character is not read. |
Definition at line 2504 of file SerialPort.cpp.
|
inline |
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 1089 of file SerialPort.cpp.
|
inline |
Sets the character size for the serial port.
characterSize | The character size to be set. |
Definition at line 1305 of file SerialPort.cpp.
|
inline |
Sets all serial port paramters to their default values.
Definition at line 1061 of file SerialPort.cpp.
|
inline |
Sets the serial port DTR line status.
dtrState | The state to set the DTR line |
Definition at line 1772 of file SerialPort.cpp.
|
inline |
Sets flow control for the serial port.
flowControlType | The flow control type to be set. |
Definition at line 1382 of file SerialPort.cpp.
|
inline |
Set the specified modem control line to the specified value.
modemLine | One of the following four values: TIOCM_DTR, TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR. |
lineState | State of the modem line after successful call to this method. |
Definition at line 1936 of file SerialPort.cpp.
|
inline |
Sets the parity type for the serial port.
parityType | The parity type to be set. |
Definition at line 1492 of file SerialPort.cpp.
|
inline |
Sets the serial port RTS line status.
rtsState | The state to set the RTS line |
Definition at line 1799 of file SerialPort.cpp.
|
inline |
Sets the current state of the serial port blocking status.
blockingStatus | The 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.
|
inline |
Sets the number of stop bits to be used with the serial port.
stopBits | The number of stop bits to set. |
Definition at line 1576 of file SerialPort.cpp.
|
inline |
Sets the minimum number of characters for non-canonical reads.
vmin | the number of minimum characters to be set. |
Definition at line 1648 of file SerialPort.cpp.
|
inline |
Sets character buffer timeout for non-canonical reads in deciseconds.
vtime | The timeout value in deciseconds to be set. |
Definition at line 1710 of file SerialPort.cpp.
|
inline |
Writes a DataBuffer to the serial port.
dataBuffer | The DataBuffer to write to the serial port. |
Definition at line 2560 of file SerialPort.cpp.
|
inline |
Writes a std::string to the serial port.
dataString | The std::string to be written to the serial port. |
Definition at line 2611 of file SerialPort.cpp.
|
inline |
Writes a single byte to the serial port.
charBuffer | The byte to be written to the serial port. |
Definition at line 2662 of file SerialPort.cpp.
|
inline |
Writes a single byte to the serial port.
charBuffer | The byte to be written to the serial port. |
Definition at line 2696 of file SerialPort.cpp.