Class which manages the logic relative to send/receive messages from Serial Port. This class implements all the logic necessary to communicate with UART port.

#include <serialPort.h>

Inheritance diagram for SerialPort:

Public Types

enum  TypeRec { canonical = 0, nocanonical = 1 }
 Enum to indicate how serial port must be configured. More...
 

Public Member Functions

 SerialPort (boost::asio::io_service &io, const char *port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow, TypeRec type=nocanonical)
 Constructor of the class. More...
 
 SerialPort (boost::asio::io_service &io)
 Constructor of the class. More...
 
virtual ~SerialPort ()
 Destructor of the class.
 
bool setPort (const char *port, int baud_rate, boost::asio::serial_port_base::flow_control::type flow)
 Method to establish serial port when it is not established in constructor. More...
 
const char * getPort () const
 Method to take the serial port path. More...
 
bool open (boost::system::error_code &ec)
 Method to open serial port. More...
 
bool isOpened () const
 Method to query if serial port is opened by the current app. More...
 
bool isBusy () const
 Method to query if serial port is opened by any app. More...
 
bool isBusyOp () const
 Method to query if serial port is opened by any app. More...
 
void close ()
 Method to close serial port.
 
bool flush ()
 Method to clear the serial port buffer. More...
 
virtual bool send (const char *buffer, int size)=0
 Method to send data to serial port synchronously. More...
 

Protected Types

typedef std::vector< char > VC_DATA
 vector of characters
 

Protected Attributes

boost::asio::serial_port m_serial_port
 Serial Port Object.
 
std::string m_port
 Port Path name.
 
int m_baud_rate
 Baud Rate to communicate.
 
boost::asio::serial_port_base::flow_control::type m_flow_control
 UART flow control.
 
TypeRec m_TypeR
 Canonical or non-canonical.
 

Member Enumeration Documentation

enum TypeRec
Enumerator
canonical 

canonical

nocanonical 

no-canonical

Constructor & Destructor Documentation

SerialPort ( boost::asio::io_service &  io,
const char *  port,
int  baud_rate,
boost::asio::serial_port_base::flow_control::type  flow,
TypeRec  type = nocanonical 
)
Parameters
ioInput/Output Service Object reference
portPath to the serial port
baud_rateRate of serial port to work
flowUART flow control
typeType of serial port configuration
SerialPort ( boost::asio::io_service &  io)
explicit
Parameters
ioio_service for input/output operations

Member Function Documentation

bool flush ( )
Returns
true if clear was possible
const char* getPort ( ) const
Returns
A pointer to the serial port path
bool isBusy ( ) const
Returns
true if it is busy
bool isBusyOp ( ) const
Returns
true if it is busy
bool isOpened ( ) const
Remarks
This method just reports if the serial port has been opened from the current application.
This method does not inform about the open/close status performed from other applications.
Returns
true if it is opened
bool open ( boost::system::error_code &  ec)
Parameters
ecerror code
Remarks
This method may return an error if another app is making use of the port within this library, in this case the error code would be DPY_PORT_OPEN_LOCK_ERROR.
Returns
true if it is opened
virtual bool send ( const char *  buffer,
int  size 
)
pure virtual
Parameters
bufferData buffer to be sent
sizeData length in bytes of the data buffer
Returns
true if serial port is opened and write took place

Implemented in AsyncSerialPort, and SyncSerialPort.

bool setPort ( const char *  port,
int  baud_rate,
boost::asio::serial_port_base::flow_control::type  flow 
)
Parameters
portPath to the serial port
baud_rateRate of serial port to send/receive data
flowUART flow control
Returns
true/false if the port is fixed.