36#include <libserial/SerialPortConstants.h>
76 explicit SerialPort(
const std::string& fileName,
77 const BaudRate& baudRate = BaudRate::BAUD_DEFAULT,
78 const CharacterSize& characterSize = CharacterSize::CHAR_SIZE_DEFAULT,
79 const FlowControl& flowControlType = FlowControl::FLOW_CONTROL_DEFAULT,
80 const Parity& parityType = Parity::PARITY_DEFAULT,
81 const StopBits& stopBits = StopBits::STOP_BITS_DEFAULT) ;
116 void Open(const std::
string& fileName,
117 const std::ios_base::openmode& openMode = std::ios_base::in | std::ios_base::out) ;
202 void SetParity(const Parity& parityType) ;
227 void SetVMin(const
short vmin) ;
255 void SetDTR(const
bool dtrState = true) ;
268 void SetRTS(const
bool rtsState = true) ;
306 std::vector<std::string> GetAvailableSerialPorts()
const ;
324 void Read(DataBuffer& dataBuffer,
325 size_t numberOfBytes = 0,
326 size_t msTimeout = 0) ;
343 void Read(std::string& dataString,
344 size_t numberOfBytes = 0,
345 size_t msTimeout = 0) ;
357 size_t msTimeout = 0) ;
368 void ReadByte(
unsigned char& charBuffer,
369 size_t msTimeout = 0) ;
384 void ReadLine(std::string& dataString,
385 char lineTerminator =
'\n',
386 size_t msTimeout = 0) ;
392 void Write(
const DataBuffer& dataBuffer) ;
398 void Write(
const std::string& dataString) ;
410 void WriteByte(
unsigned char charbuffer) ;
456 std::unique_ptr<Implementation> mImpl;
500 template<
typename Fn,
typename... Args>
501 typename std::result_of<Fn(Args...)>::type
502 call_with_retry(Fn func, Args... args)
504 using result_type =
typename std::result_of<Fn(Args...)>::type ;
507 result = func(std::forward<Args>(args)...);
508 }
while((result == -1) and (errno == EINTR)) ;
SerialPort::Implementation is the SerialPort implementation class.
SerialPort allows an object oriented approach to serial port communication. A serial port object can ...
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
void SetModemControlLine(int modemLine, bool lineState)
Set the specified modem control line to the specified value.
void SetParity(const Parity &parityType)
Sets the parity type for the serial port.
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.
bool GetCTS()
Get the status of the CTS line.
bool GetSerialPortBlockingStatus() const
Gets the current state of the serial port blocking status.
void WriteByte(char charbuffer)
Writes a single byte to the serial port.
void FlushInputBuffer()
Flushes the serial port input buffer.
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
void SetDefaultSerialPortParameters()
Sets all serial port paramters to their default values.
SerialPort()
Default Constructor.
FlowControl GetFlowControl() const
Gets the current flow control setting.
CharacterSize GetCharacterSize() const
Gets the character size being used for serial communication.
void Write(const DataBuffer &dataBuffer)
Writes a DataBuffer to the serial port.
bool GetDTR() const
Gets the status of the DTR line.
void SetRTS(const bool rtsState=true)
Set the RTS line to the specified value.
void SetVMin(const short vmin)
Sets the minimum number of characters for non-canonical reads.
virtual ~SerialPort() noexcept
Default Destructor for a SerialPort object. Closes the serial port associated with mFileDescriptor if...
StopBits GetStopBits() const
Gets the number of stop bits currently being used by the serial.
bool GetRTS() const
Get the status of the RTS line.
void Close()
Closes the serial port. All settings of the serial port will be lost and no more I/O can be performed...
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
bool IsDataAvailable()
Checks if data is available at the input of the serial port.
BaudRate GetBaudRate() const
Gets the current baud rate for the serial port.
void SetVTime(const short vtime)
Sets character buffer timeout for non-canonical reads in deciseconds.
void FlushIOBuffers()
Flushes the serial port input and output buffers.
void FlushOutputBuffer()
Flushes the serial port output buffer.
Parity GetParity() const
Gets the parity type for the serial port.
short GetVMin() const
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonic...
bool GetModemControlLine(int modemLine)
Get the current state of the specified modem control line.
short GetVTime() const
Gets the current timeout value for non-canonical reads in deciseconds.
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 recei...
bool GetDSR()
Get the status of the DSR line.
void ReadByte(char &charBuffer, size_t msTimeout=0)
Reads a single byte from the serial port. If no data is available within the specified number of mill...
int GetNumberOfBytesAvailable()
Gets the number of bytes available in the read buffer.
int GetFileDescriptor() const
Gets the serial port file descriptor.
void SetDTR(const bool dtrState=true)
Sets the DTR line to the specified value.
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 th...
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
bool IsOpen() const
Determines if the serial port is open for I/O.
void SetSerialPortBlockingStatus(bool blockingStatus)
Sets the current state of the serial port blocking status.
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.