DESERT 4.0.0
UwSerial Class Reference

#include <uwserial.h>

Inheritance diagram for UwSerial:
Inheritance graph
Collaboration diagram for UwSerial:
Collaboration graph

Public Member Functions

 UwSerial ()
 
virtual ~UwSerial ()
 
virtual bool openConnection (const std::string &path)
 
virtual bool closeConnection ()
 
virtual const bool isConnected ()
 
virtual int writeToDevice (const std::string &msg)
 
virtual int readFromDevice (void *wpos, int maxlen)
 
virtual int configurePort (const std::string &path)
 
virtual bool refreshConnection (const std::string &path)
 
- Public Member Functions inherited from UwConnector
 UwConnector ()
 
virtual ~UwConnector ()
 
virtual void setServer ()
 
virtual void setTCP ()
 
virtual void setUDP ()
 
virtual const int getErrno ()
 

Private Attributes

int serialfd
 
struct termios tty
 

Additional Inherited Members

- Protected Attributes inherited from UwConnector
int local_errno
 

Detailed Description

Class that implements serial port connection.

Constructor & Destructor Documentation

◆ UwSerial()

UwSerial::UwSerial ( )

Constructor of the UwSerial class

References UwConnector::local_errno.

◆ ~UwSerial()

UwSerial::~UwSerial ( )
virtual

Destructor of the UwSerial class

Member Function Documentation

◆ closeConnection()

bool UwSerial::closeConnection ( )
virtual

Method that closes an active connection to a device

Returns
boolean true if connection is correctly closed, false otherwise

Implements UwConnector.

References serialfd.

Referenced by refreshConnection().

◆ configurePort()

int UwSerial::configurePort ( const std::string &  path)
virtual

Method that loads the termios struct with the serial port parameters.

Parameters
pathconst std::string with address and flag

References UwConnector::local_errno, serialfd, and tty.

Referenced by openConnection().

◆ isConnected()

const bool UwSerial::isConnected ( )
virtual

Returns true if serial port fd differs from -1, that means the connection is up

Returns
if serial port file descriptor is valid

Implements UwConnector.

References serialfd.

◆ openConnection()

bool UwSerial::openConnection ( const std::string &  path)
virtual

Method that opens a serial connection, the input string has to be with a format like <port_name>:parity:stop:flow:baud, e.g. tty0:p=0:s=1:f=0:b=123456

Returns
boolean true if connection is correctly opened, false otherwise

Implements UwConnector.

References configurePort(), UwConnector::local_errno, and serialfd.

Referenced by refreshConnection().

Here is the call graph for this function:

◆ readFromDevice()

int UwSerial::readFromDevice ( void *  wpos,
int  maxlen 
)
virtual

Function that receives data from the device's port to a backup buffer. The unloaded data is saved to a temporary buffer, to be parsed later.

Parameters
posposition to start writing data to: a pointer to some buffer
Returns
integer number of read bytes

Implements UwConnector.

References UwConnector::local_errno, and serialfd.

◆ refreshConnection()

bool UwSerial::refreshConnection ( const std::string &  path)
virtual

Method that refreshes an existing connection creating a new file descriptor.

Parameters
pathconst std::string with address and flag

References closeConnection(), openConnection(), and serialfd.

Here is the call graph for this function:

◆ writeToDevice()

int UwSerial::writeToDevice ( const std::string &  msg)
virtual

Method that writes a command to the port interface

Parameters
msgstd::string command to be sent through the port

Implements UwConnector.

References serialfd.

Member Data Documentation

◆ serialfd

int UwSerial::serialfd
private

Integer value that stores the serial port descriptor as generated by the function UwSerial:openConnection().

Referenced by closeConnection(), configurePort(), isConnected(), openConnection(), readFromDevice(), refreshConnection(), and writeToDevice().

◆ tty

struct termios UwSerial::tty
private

Referenced by configurePort().


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