Flexiport  2.0.0
Public Member Functions | List of all members
flexiport::SerialPort Class Reference

Serial implementation of the Port class. More...

#include <flexiport/serialport.h>

Inheritance diagram for flexiport::SerialPort:
Inheritance graph
[legend]
Collaboration diagram for flexiport::SerialPort:
Collaboration graph
[legend]

Public Member Functions

 SerialPort (std::map< std::string, std::string > options)
 
 ~SerialPort ()
 
void Open ()
 Open the port. More...
 
void Close ()
 Close the port. More...
 
ssize_t Read (void *const buffer, size_t count)
 Read from the port. More...
 
ssize_t ReadFull (void *const buffer, size_t count)
 Read the requested quantity of data from the port. More...
 
ssize_t BytesAvailable ()
 Get the number of bytes waiting to be read at the port. Returns immediatly. More...
 
ssize_t BytesAvailableWait ()
 Get the number of bytes waiting after blocking for the timeout. More...
 
ssize_t Write (const void *const buffer, size_t count)
 Write data to the port. More...
 
void Flush ()
 Flush the port's input and output buffers, discarding all data. More...
 
void Drain ()
 Drain the port's input and output buffers. More...
 
std::string GetStatus () const
 Get the status of the port (type, device, etc). More...
 
void SetTimeout (Timeout timeout)
 Set the timeout value in milliseconds. More...
 
void SetCanRead (bool canRead)
 Set the read permissions of the port. More...
 
void SetCanWrite (bool canWrite)
 Set the write permissions of the port. More...
 
bool IsOpen () const
 Check if the port is open. More...
 
void SetBaudRate (unsigned int baud)
 Change the baud rate. More...
 
unsigned int GetBaudRate () const
 Get the current baud rate. More...
 
- Public Member Functions inherited from flexiport::Port
virtual ~Port ()
 
virtual ssize_t ReadString (std::string &buffer)
 Read a string. More...
 
virtual ssize_t ReadUntil (void *const buffer, size_t count, uint8_t terminator)
 Read data until a specified termination byte is received. More...
 
virtual ssize_t ReadStringUntil (std::string &buffer, char terminator)
 Read a string until the specified termination character is received. More...
 
virtual ssize_t ReadLine (char *const buffer, size_t count)
 Read a new-line terminated string of data. More...
 
virtual ssize_t ReadLine (std::string &buffer)
 Read a new-line terminated string of data. More...
 
virtual ssize_t Skip (size_t count)
 Dump data until the specified number of bytes have been read. More...
 
virtual ssize_t SkipUntil (uint8_t terminator, unsigned int count)
 Read and dump data until the specified termination character has been seen count times. More...
 
virtual ssize_t WriteFull (const void *const buffer, size_t count)
 Write all the data to the port. More...
 
virtual ssize_t WriteString (const char *const buffer)
 Write a string to the port. More...
 
virtual ssize_t WriteString (const std::string &buffer)
 
std::string GetPortType () const
 Get the port type. More...
 
void SetDebug (int debug)
 Set the debug level. More...
 
int GetDebug () const
 Get the debug level. More...
 
virtual Timeout GetTimeout () const
 Get the timeout. More...
 
virtual bool IsBlocking () const
 Get the blocking property of the port. More...
 
virtual bool CanRead () const
 Get the read permissions of the port. More...
 
virtual bool CanWrite () const
 Get the write permissions of the port. More...
 

Additional Inherited Members

- Protected Member Functions inherited from flexiport::Port
 Port ()
 
 Port (unsigned int debug, Timeout timeout, bool canRead, bool canWrite, bool alwaysOpen)
 
void ProcessOptions (const std::map< std::string, std::string > &options)
 
- Protected Attributes inherited from flexiport::Port
std::string _type
 
unsigned int _debug
 
Timeout _timeout
 
bool _canRead
 
bool _canWrite
 
bool _alwaysOpen
 

Detailed Description

Serial implementation of the Port class.

See the Port class documentation for how to use the common API.

Note
Under Windows, the timeout resolution is milliseconds, not microseconds. The timeout value will be rounded to the nearest millisecond when used.
Options
  • device <string>
    • Serial device to use.
    • Default: /dev/ttyS0
  • parity none|even|odd
    • Data parity.
    • Default: none
  • baud <integer>
    • Baud rate. Valid values are 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 34800, 57600, 115200, 230400.
    • Default: 9600
  • databits <integer>
    • Default: 8
  • stopbits 1|2
    • Number of stop bits: 1 or 2.
    • Default: 1
  • hwflowctrl
    • Turn hardware flow control on.
    • Default: off

Definition at line 74 of file serialport.h.

Constructor & Destructor Documentation

flexiport::SerialPort::SerialPort ( std::map< std::string, std::string >  options)
flexiport::SerialPort::~SerialPort ( )

Member Function Documentation

ssize_t flexiport::SerialPort::BytesAvailable ( )
virtual

Get the number of bytes waiting to be read at the port. Returns immediatly.

Implements flexiport::Port.

ssize_t flexiport::SerialPort::BytesAvailableWait ( )
virtual

Get the number of bytes waiting after blocking for the timeout.

Note
Currently this function performs differently under Win32. It will block for the entire length of the timeout if data is not immediatly available. This will be fixed in the future.

Implements flexiport::Port.

void flexiport::SerialPort::Close ( )
virtual

Close the port.

Implements flexiport::Port.

void flexiport::SerialPort::Drain ( )
virtual

Drain the port's input and output buffers.

Implements flexiport::Port.

void flexiport::SerialPort::Flush ( )
virtual

Flush the port's input and output buffers, discarding all data.

Implements flexiport::Port.

unsigned int flexiport::SerialPort::GetBaudRate ( ) const
inline

Get the current baud rate.

Definition at line 116 of file serialport.h.

std::string flexiport::SerialPort::GetStatus ( ) const
virtual

Get the status of the port (type, device, etc).

Reimplemented from flexiport::Port.

bool flexiport::SerialPort::IsOpen ( ) const
inlinevirtual

Check if the port is open.

Implements flexiport::Port.

Definition at line 111 of file serialport.h.

void flexiport::SerialPort::Open ( )
virtual

Open the port.

Implements flexiport::Port.

ssize_t flexiport::SerialPort::Read ( void *const  buffer,
size_t  count 
)
virtual

Read from the port.

Implements flexiport::Port.

ssize_t flexiport::SerialPort::ReadFull ( void *const  buffer,
size_t  count 
)
virtual

Read the requested quantity of data from the port.

Implements flexiport::Port.

void flexiport::SerialPort::SetBaudRate ( unsigned int  baud)

Change the baud rate.

void flexiport::SerialPort::SetCanRead ( bool  canRead)
virtual

Set the read permissions of the port.

Implements flexiport::Port.

void flexiport::SerialPort::SetCanWrite ( bool  canWrite)
virtual

Set the write permissions of the port.

Implements flexiport::Port.

void flexiport::SerialPort::SetTimeout ( Timeout  timeout)
virtual

Set the timeout value in milliseconds.

Implements flexiport::Port.

ssize_t flexiport::SerialPort::Write ( const void *const  buffer,
size_t  count 
)
virtual

Write data to the port.

Implements flexiport::Port.


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