Public Member Functions | Private Member Functions | Private Attributes | 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:
Inheritance graph
[legend]

Public Member Functions

 Serial (std::string port, unsigned int baud_rate)
 Open a serial port. More...
 
bool set_baud_rate (unsigned int baud_rate)
 Set serial port baud rate. More...
 
 ~Serial ()
 
- Public Member Functions inherited from async_comm::Comm
void close ()
 Closes the port. More...
 
 Comm ()
 
bool init ()
 Initializes and opens 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 send_byte (uint8_t data)
 Send a single byte over the port. More...
 
void send_bytes (const uint8_t *src, size_t len)
 Send bytes from a buffer over the port. More...
 
virtual ~Comm ()
 

Private Member Functions

void do_async_read (const boost::asio::mutable_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler) override
 
void do_async_write (const boost::asio::const_buffers_1 &buffer, boost::function< void(const boost::system::error_code &, size_t)> handler) override
 
void do_close () override
 
bool do_init () override
 
bool is_open () override
 

Private Attributes

unsigned int baud_rate_
 
std::string port_
 
boost::asio::serial_port serial_port_
 

Additional Inherited Members

- Protected Attributes inherited from async_comm::Comm
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
 

Detailed Description

Asynchronous communication class for a serial port.

Definition at line 55 of file serial.h.

Constructor & Destructor Documentation

async_comm::Serial::Serial ( std::string  port,
unsigned int  baud_rate 
)

Open a serial port.

Parameters
portThe port to open (e.g. "/dev/ttyUSB0")
baud_rateThe baud rate for the serial port (e.g. 115200)

Definition at line 47 of file serial.cpp.

async_comm::Serial::~Serial ( )

Definition at line 55 of file serial.cpp.

Member Function Documentation

void async_comm::Serial::do_async_read ( const boost::asio::mutable_buffers_1 &  buffer,
boost::function< void(const boost::system::error_code &, size_t)>  handler 
)
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 106 of file serial.cpp.

void async_comm::Serial::do_async_write ( const boost::asio::const_buffers_1 &  buffer,
boost::function< void(const boost::system::error_code &, size_t)>  handler 
)
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 112 of file serial.cpp.

void async_comm::Serial::do_close ( )
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 101 of file serial.cpp.

bool async_comm::Serial::do_init ( )
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 81 of file serial.cpp.

bool async_comm::Serial::is_open ( )
overrideprivatevirtual

Implements async_comm::Comm.

Definition at line 76 of file serial.cpp.

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.

Member Data Documentation

unsigned int async_comm::Serial::baud_rate_
private

Definition at line 84 of file serial.h.

std::string async_comm::Serial::port_
private

Definition at line 83 of file serial.h.

boost::asio::serial_port async_comm::Serial::serial_port_
private

Definition at line 86 of file serial.h.


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


async_comm
Author(s):
autogenerated on Thu May 16 2019 03:03:47