libtasks Documentation  1.6
tasks::serial::term Class Reference

A class that allows to read and write from/to terminal devices. More...

#include <term.h>

Inheritance diagram for tasks::serial::term:
Collaboration diagram for tasks::serial::term:

Public Member Functions

 term ()
 Contruct an object. More...
 
 term (int fd)
 Contruct an object by providing a terminal file descriptor. More...
 
void open (std::string port, speed_t baudrate=B9600, charsize_t charsize=charsize_t::_8, parity_t parity=parity_t::NONE, stopbits_t stopbits=stopbits_t::_1)
 Open a terminal device. More...
 
void open (std::string port, speed_t baudrate=B9600, termmode_t mode=termmode_t::_8N1)
 Open a terminal device. More...
 
struct termios options ()
 Access terminal options. More...
 
void set_options (struct termios &opts)
 Set terminal options. More...
 
speed_t baudrate () const
 Access the baudrate. More...
 
void baudrate (speed_t br)
 Set the baudrate. More...
 
void close ()
 Close the terminal. More...
 
std::streamsize write (const char *data, std::size_t len)
 Write data to the terminal. More...
 
std::streamsize read (char *data, std::size_t len)
 Read data from the terminal. More...
 
- Public Member Functions inherited from io_base
 io_base ()
 
 io_base (int fd)
 
virtual ~io_base ()
 
int fd () const
 

Additional Inherited Members

- Protected Attributes inherited from io_base
int m_fd = -1
 

Detailed Description

A class that allows to read and write from/to terminal devices.

This is a wrapper class around the POSIX terminal interface. Not all capabilities have been implemented. You can use the options() method to set unsupported options like flow control etc for example.

Definition at line 35 of file term.h.

Constructor & Destructor Documentation

tasks::serial::term::term ( )
inline

Contruct an object.

Definition at line 38 of file term.h.

tasks::serial::term::term ( int  fd)
inline

Contruct an object by providing a terminal file descriptor.

Parameters
fdThe file descriptor.

Definition at line 45 of file term.h.

Member Function Documentation

speed_t tasks::serial::term::baudrate ( ) const

Access the baudrate.

void tasks::serial::term::baudrate ( speed_t  br)

Set the baudrate.

void tasks::serial::term::close ( )
virtual

Close the terminal.

Reimplemented from io_base.

Definition at line 130 of file term.cpp.

Here is the caller graph for this function:

void tasks::serial::term::open ( std::string  port,
speed_t  baudrate = B9600,
charsize_t  charsize = charsize_t::_8,
parity_t  parity = parity_t::NONE,
stopbits_t  stopbits = stopbits_t::_1 
)

Open a terminal device.

Parameters
portThe device port (eg: /dev/ttyUSB0)
baudrateThe baudrate (default: 9600)
charsizeThe size of a character (default: chrarsize_t::CS8 for 8 bits)
parityThe parity (default: parity_t::NONE)
stopbitsThe number of stopbits (default: stopbits_t::SB1)

Definition at line 40 of file term.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void tasks::serial::term::open ( std::string  port,
speed_t  baudrate = B9600,
termmode_t  mode = termmode_t::_8N1 
)

Open a terminal device.

Parameters
portThe device port (eg: /dev/ttyUSB0)
baudrateThe baudrate (default: 9600)
modeThe mode the device should be opened with (default: termmode_t::_8N1 for 8N1 mode)

Definition at line 111 of file term.cpp.

Here is the call graph for this function:

struct termios tasks::serial::term::options ( )

Access terminal options.

Definition at line 16 of file term.cpp.

Here is the caller graph for this function:

std::streamsize tasks::serial::term::read ( char *  data,
std::size_t  len 
)

Read data from the terminal.

Parameters
dataA poiter to the data buffer.
lenThe number of bytes to read.
Returns
The number of bytes read from the terminal.

Definition at line 144 of file term.cpp.

void tasks::serial::term::set_options ( struct termios &  opts)

Set terminal options.

Definition at line 29 of file term.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::streamsize tasks::serial::term::write ( const char *  data,
std::size_t  len 
)

Write data to the terminal.

Parameters
dataA poiter to the data buffer.
lenThe number of bytes to write.
Returns
The number of bytes written to the terminal.

Definition at line 137 of file term.cpp.


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