33#include "libserial/SerialStream.h"
45 const BaudRate& baudRate,
46 const CharacterSize& characterSize,
47 const FlowControl& flowControlType,
48 const Parity& parityType,
49 const StopBits& stopBits,
51 std::iostream(nullptr)
53 this->
Open(fileName, std::ios_base::in | std::ios_base::out, exclusive) ;
85 const std::ios_base::openmode& openMode,
90 if (mIOBuffer ==
nullptr)
92 mIOBuffer = std::make_unique<SerialStreamBuf>() ;
93 assert(mIOBuffer !=
nullptr) ;
94 this->rdbuf(mIOBuffer.get()) ;
98 mIOBuffer->Open(fileName, openMode, exclusive) ;
100 catch (
const std::exception&)
102 setstate(std::ios_base::failbit) ;
111 mIOBuffer = nullptr ;
123 if (my_buffer !=
nullptr)
138 catch (
const std::exception&)
140 setstate(std::ios_base::failbit) ;
153 if (my_buffer !=
nullptr)
168 catch (
const std::exception&)
170 setstate(std::ios_base::failbit) ;
183 if (my_buffer !=
nullptr)
198 catch (
const std::exception&)
200 setstate(std::ios_base::failbit) ;
213 if (my_buffer !=
nullptr)
228 catch (
const std::exception&)
230 setstate(std::ios_base::failbit) ;
243 if (my_buffer !=
nullptr)
256 catch (
const std::exception&)
258 setstate(std::ios_base::failbit) ;
268 if (mIOBuffer ==
nullptr)
272 return mIOBuffer->IsOpen() ;
274 catch (
const std::exception&)
276 setstate(std::ios_base::failbit) ;
289 if (my_buffer !=
nullptr)
304 catch (
const std::exception&)
306 setstate(std::ios_base::failbit) ;
319 if (my_buffer !=
nullptr)
331 return BaudRate::BAUD_INVALID;
333 catch (
const std::exception&)
335 setstate(std::ios_base::failbit) ;
348 if (my_buffer !=
nullptr)
363 catch (
const std::exception&)
365 setstate(std::ios_base::failbit) ;
378 if (my_buffer !=
nullptr)
390 return CharacterSize::CHAR_SIZE_INVALID;
392 catch (
const std::exception&)
394 setstate(std::ios_base::failbit) ;
407 if (my_buffer !=
nullptr)
423 catch (
const std::exception&)
425 setstate(std::ios_base::failbit) ;
438 if (my_buffer !=
nullptr)
450 return FlowControl::FLOW_CONTROL_INVALID;
452 catch (
const std::exception&)
454 setstate(std::ios_base::failbit) ;
467 if (my_buffer !=
nullptr)
483 catch (
const std::exception&)
485 setstate(std::ios_base::failbit) ;
498 if (my_buffer !=
nullptr)
510 return Parity::PARITY_INVALID;
512 catch (
const std::exception&)
514 setstate(std::ios_base::failbit) ;
527 if (my_buffer !=
nullptr)
543 catch (
const std::exception&)
545 setstate(std::ios_base::failbit) ;
558 if (my_buffer !=
nullptr)
570 return StopBits::STOP_BITS_INVALID;
572 catch (
const std::exception&)
574 setstate(std::ios_base::failbit) ;
587 if (my_buffer !=
nullptr)
601 catch (
const std::exception&)
603 setstate(std::ios_base::failbit) ;
616 if (my_buffer !=
nullptr)
628 catch (
const std::exception&)
630 setstate(std::ios_base::failbit) ;
643 if (my_buffer !=
nullptr)
657 catch (
const std::exception&)
659 setstate(std::ios_base::failbit) ;
672 if (my_buffer !=
nullptr)
684 catch (
const std::exception&)
686 setstate(std::ios_base::failbit) ;
699 if (my_buffer !=
nullptr)
702 my_buffer->
SetDTR(dtrState) ;
713 catch (
const std::exception&)
715 setstate(std::ios_base::failbit) ;
728 if (my_buffer !=
nullptr)
731 return my_buffer->
GetDTR() ;
740 catch (
const std::exception&)
742 setstate(std::ios_base::failbit) ;
755 if (my_buffer !=
nullptr)
758 my_buffer->
SetRTS(rtsState) ;
769 catch (
const std::exception&)
771 setstate(std::ios_base::failbit) ;
784 if (my_buffer !=
nullptr)
787 return my_buffer->
GetRTS() ;
796 catch (
const std::exception&)
798 setstate(std::ios_base::failbit) ;
811 if (my_buffer !=
nullptr)
814 return my_buffer->
GetCTS() ;
823 catch (
const std::exception&)
825 setstate(std::ios_base::failbit) ;
838 if (my_buffer !=
nullptr)
841 return my_buffer->
GetDSR() ;
850 catch (
const std::exception&)
852 setstate(std::ios_base::failbit) ;
865 if (my_buffer !=
nullptr)
877 catch (
const std::exception&)
879 setstate(std::ios_base::failbit) ;
892 if (my_buffer !=
nullptr)
905 catch (
const std::exception&)
907 setstate(std::ios_base::failbit) ;
912 std::vector<std::string>
916 auto my_buffer =
dynamic_cast<SerialStreamBuf *
>(this->rdbuf()) ;
921 if (my_buffer !=
nullptr)
924 return my_buffer->GetAvailableSerialPorts() ;
933 catch (
const std::exception&)
935 setstate(std::ios_base::failbit) ;
SerialStreamBuf is the streambuf subclass used by SerialStream. This subclass takes care of opening t...
CharacterSize GetCharacterSize() const
Gets the character size being used for serial communication.
bool GetCTS()
Get the status of the CTS line.
int GetNumberOfBytesAvailable()
Gets the number of bytes available in the read buffer.
bool IsDataAvailable()
Checks if data is available at the input of the serial port.
void FlushOutputBuffer()
Flushes the serial port output buffer.
StopBits GetStopBits() const
Gets the number of stop bits currently being used by the serial.
void SetDTR(const bool dtrState=true)
Sets the DTR line to the specified value.
short GetVMin() const
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonic...
bool GetDSR()
Get the status of the DSR line.
void SetVTime(const short vtime)
Sets character buffer timeout for non-canonical reads in deciseconds.
bool GetRTS() const
Get the status of the RTS line.
short GetVTime() const
Gets the current timeout value for non-canonical reads in deciseconds.
bool GetDTR() const
Gets the status of the DTR line.
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
void SetVMin(const short vmin)
Sets the minimum number of characters for non-canonical reads.
FlowControl GetFlowControl() const
Gets the current flow control setting.
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
BaudRate GetBaudRate() const
Gets the current baud rate for the serial port.
void SetParity(const Parity &parityType)
Sets the parity type for the serial port.
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
Parity GetParity() const
Gets the parity type for the serial port.
void FlushIOBuffers()
Flushes the serial port input and output buffers.
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
void FlushInputBuffer()
Flushes the serial port input buffer.
int GetFileDescriptor() const
Gets the serial port file descriptor.
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.
void SetRTS(const bool rtsState=true)
Set the RTS line to the specified value.
void FlushIOBuffers()
Flushes the serial port input and output buffers.
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
short GetVMin()
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonic...
BaudRate GetBaudRate()
Gets the current baud rate for the serial port.
bool GetDSR()
Get the status of the DSR line.
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
bool GetCTS()
Get the status of the CTS line.
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
int GetNumberOfBytesAvailable()
Gets the number of bytes available in the read buffer.
bool IsDataAvailable()
Checks if data is available at the input of the serial port.
void FlushInputBuffer()
Flushes the serial port input buffer.
short GetVTime()
Gets the current timeout value for non-canonical reads in deciseconds.
void Close()
Closes the serial port. All settings of the serial port will be lost and no more I/O can be performed...
virtual ~SerialStream()
Default Destructor for a SerialStream object Closes the stream associated with mFileDescriptor,...
StopBits GetStopBits()
Gets the number of stop bits currently being used by the serial.
void SetDTR(const bool dtrState=true)
Sets the DTR line to the specified value.
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
int GetFileDescriptor()
Gets the serial port file descriptor.
SerialStream()
Default Contructor. Creates a new SerialStream object but does not open it. The Open() method will ne...
FlowControl GetFlowControl()
Gets the current flow control setting.
void SetVMin(const short vmin)
Sets the minimum number of characters for non-canonical reads.
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.
void SetVTime(const short vtime)
Sets character buffer timeout for non-canonical reads in deciseconds.
bool IsOpen()
Determines if the serial port is open for I/O.
void Open(const std::string &fileName, const std::ios_base::openmode &openMode=std::ios_base::in|std::ios_base::out, bool exclusive=true)
Opens the serial port associated with the specified file name and the specified mode.
bool GetDTR()
Gets the status of the DTR line.
CharacterSize GetCharacterSize()
Gets the character size being used for serial communication.
void SetRTS(const bool rtsState=true)
Set the RTS line to the specified value.
std::vector< std::string > GetAvailableSerialPorts()
Gets a list of available serial ports.
void FlushOutputBuffer()
Flushes the serial port output buffer.
Parity GetParity()
Gets the parity type for the serial port.
bool GetRTS()
Get the status of the RTS line.
void SetParity(const Parity &parityType)
Sets the parity type for the serial port.