Async Comm
A library for asynchronous serial communication
Public Member Functions | List of all members
async_comm::Serial Class Reference

Asynchronous communication class for a serial port. More...

#include <serial.h>

Inheritance diagram for async_comm::Serial:
async_comm::Comm

Public Member Functions

 Serial (std::string port, unsigned int baud_rate, MessageHandler &message_handler=default_message_handler_)
 Open a serial port. More...
 
bool set_baud_rate (unsigned int baud_rate)
 Set serial port baud rate. More...
 
- Public Member Functions inherited from async_comm::Comm
 Comm (MessageHandler &message_handler=default_message_handler_)
 Set up asynchronous communication base class. More...
 
bool init ()
 Initializes and opens the port. More...
 
void close ()
 Closes the port.
 
void send_bytes (const uint8_t *src, size_t len)
 Send bytes from a buffer over the port. More...
 
void send_byte (uint8_t data)
 Send a single byte over the port. More...
 
void register_receive_callback (std::function< void(const uint8_t *, size_t)> fun)
 Register a callback function for when bytes are received on the port. More...
 
void register_listener (CommListener &listener)
 Register a listener for when bytes are received on the port. More...
 

Additional Inherited Members

- Protected Attributes inherited from async_comm::Comm
MessageHandlermessage_handler_
 
boost::asio::io_service io_service_
 
- Static Protected Attributes inherited from async_comm::Comm
static constexpr size_t READ_BUFFER_SIZE = 1024
 
static constexpr size_t WRITE_BUFFER_SIZE = 1024
 
static DefaultMessageHandler default_message_handler_
 

Detailed Description

Asynchronous communication class for a serial port.

Definition at line 56 of file serial.h.

Constructor & Destructor Documentation

§ Serial()

async_comm::Serial::Serial ( std::string  port,
unsigned int  baud_rate,
MessageHandler message_handler = default_message_handler_ 
)

Open a serial port.

Parameters
portThe port to open (e.g. "/dev/ttyUSB0")
baud_rateThe baud rate for the serial port (e.g. 115200)
message_handlerCustom message handler, or omit for default handler

Definition at line 47 of file serial.cpp.

Member Function Documentation

§ set_baud_rate()

bool async_comm::Serial::set_baud_rate ( unsigned int  baud_rate)

Set serial port baud rate.

Parameters
baud_rateThe baud rate for the serial port (e.g. 115200)
Returns
True if successful

Definition at line 60 of file serial.cpp.


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