RADLib
RADical C++ application framework
RADSerial::RADSerialPort Class Reference

Linux serial port backed by termios and RADCore::RADIODevice. More...

#include <RADSerial.h>

+ Inheritance diagram for RADSerial::RADSerialPort:
+ Collaboration diagram for RADSerial::RADSerialPort:

Public Member Functions

 RADSerialPort (RADCore::EventLoop &loop)
 Creates a serial port whose events are posted to loop. More...
 
 ~RADSerialPort () override
 Closes the port. More...
 
void setPortName (std::string path)
 Sets device path. More...
 
const std::string & portName () const
 Returns device path. More...
 
void setConfig (SerialConfig config)
 Sets serial configuration. More...
 
SerialConfig config () const
 Returns serial configuration. More...
 
bool open (RADCore::OpenMode mode) override
 Opens the serial port. More...
 
void close () override
 Closes the serial port. More...
 
bool isOpen () const override
 Returns true when open. More...
 
ssize_t readData (void *buffer, size_t maxBytes) override
 Reads bytes from the internal async buffer. More...
 
ssize_t writeData (const void *data, size_t size) override
 Writes bytes to the serial fd. More...
 
- Public Member Functions inherited from RADCore::RADIODevice
virtual ~RADIODevice ()=default
 Destroys the IO device. More...
 
std::vector< uint8_t > read (size_t maxBytes)
 Reads up to maxBytes into a byte vector. More...
 
std::vector< uint8_t > readAll (size_t chunkSize=8192)
 Reads all available data in chunks. More...
 
ssize_t write (const std::vector< uint8_t > &data)
 Writes a byte vector. More...
 
ssize_t write (const std::string &text)
 Writes string bytes. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Static Public Member Functions

static std::vector< SerialPortInfolistPorts ()
 Returns likely serial devices under /dev. More...
 

Public Attributes

RADCore::Event< void() > opened
 Raised when the port is opened. More...
 
RADCore::Event< void() > closed
 Raised when the port is closed. More...
 
- Public Attributes inherited from RADCore::RADIODevice
RADCore::Event< void() > readyRead
 Raised when data is available to read. More...
 
RADCore::Event< void(size_t) > bytesWritten
 Raised after bytes are written. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when an IO error occurs. More...
 

Detailed Description

Linux serial port backed by termios and RADCore::RADIODevice.

Constructor & Destructor Documentation

◆ RADSerialPort()

RADSerial::RADSerialPort::RADSerialPort ( RADCore::EventLoop loop)
explicit

Creates a serial port whose events are posted to loop.

◆ ~RADSerialPort()

RADSerial::RADSerialPort::~RADSerialPort ( )
override

Closes the port.

Member Function Documentation

◆ close()

void RADSerial::RADSerialPort::close ( )
overridevirtual

Closes the serial port.

Implements RADCore::RADIODevice.

◆ config()

SerialConfig RADSerial::RADSerialPort::config ( ) const

Returns serial configuration.

◆ isOpen()

bool RADSerial::RADSerialPort::isOpen ( ) const
overridevirtual

Returns true when open.

Implements RADCore::RADIODevice.

◆ listPorts()

static std::vector<SerialPortInfo> RADSerial::RADSerialPort::listPorts ( )
static

Returns likely serial devices under /dev.

◆ open()

bool RADSerial::RADSerialPort::open ( RADCore::OpenMode  mode)
overridevirtual

Opens the serial port.

Implements RADCore::RADIODevice.

◆ portName()

const std::string& RADSerial::RADSerialPort::portName ( ) const

Returns device path.

◆ readData()

ssize_t RADSerial::RADSerialPort::readData ( void *  buffer,
size_t  maxBytes 
)
overridevirtual

Reads bytes from the internal async buffer.

Implements RADCore::RADIODevice.

◆ setConfig()

void RADSerial::RADSerialPort::setConfig ( SerialConfig  config)

Sets serial configuration.

◆ setPortName()

void RADSerial::RADSerialPort::setPortName ( std::string  path)

Sets device path.

◆ writeData()

ssize_t RADSerial::RADSerialPort::writeData ( const void *  data,
size_t  size 
)
overridevirtual

Writes bytes to the serial fd.

Implements RADCore::RADIODevice.

Member Data Documentation

◆ closed

RADCore::Event<void () > RADSerial::RADSerialPort::closed

Raised when the port is closed.

◆ opened

RADCore::Event<void () > RADSerial::RADSerialPort::opened

Raised when the port is opened.


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