SerialPort Class Reference

Send and receive messages from e-puck. More...

#include <serialPort.hpp>

Collaboration diagram for SerialPort:
Collaboration graph

Detailed Description

Send and receive messages from e-puck.

This class connects and communicates with the e-puck robot through the serial interface. Only one instance must be created and shared among the device interfaces.

Warning
Not thread safe
Author
Renato Florentino Garcia
Date
August 2008

Public Member Functions

 SerialPort (std::string &serialPort)
 Constructor of SerialPort class. More...
 
std::string getError () const
 Return the last error. More...
 
int initialize ()
 Open the serial port device and set the configurations for it.
 
int recvInt () const
 Receive a signed interger from e-puck. More...
 
unsigned recvUnsigned () const
 Receive an unsigned interger from e-puck. More...
 
char recvChar () const
 Receive a char from e-puck. More...
 
int recvUnsignedCharArray (unsigned char *const array, unsigned length) const
 Receive an array of unsigned char from e-puck. More...
 
void sendInt (int message) const
 Send an integer to e-puck. More...
 
void sendChar (char message) const
 Send a character to e-puck. More...
 

Private Attributes

int fileDescriptor
 
std::string serialPort
 
std::string errorDescription
 
struct termios termios_backup
 

Constructor & Destructor Documentation

◆ SerialPort()

SerialPort::SerialPort ( std::string &  serialPort)

Constructor of SerialPort class.

This constructor only creates the object, it don't open or initialize the serial port device.

Parameters
serialPortA absolute path for the serial port device (e.g. "/dev/rfcomm0").

Member Function Documentation

◆ getError()

std::string SerialPort::getError ( ) const
inline

Return the last error.

Return the description of last error.

Returns
A std::string describing the error.

References initialize(), recvChar(), recvInt(), recvUnsigned(), recvUnsignedCharArray(), sendChar(), and sendInt().

Here is the call graph for this function:

◆ recvChar()

char SerialPort::recvChar ( ) const

Receive a char from e-puck.

Wait indefinitely one byte to arrive from e-puck and converts them to char.

Returns
The received char.

Referenced by EpuckLEDs::EpuckLEDs(), getError(), EpuckCamera::Initialize(), EpuckPosition2d::SetVel(), and EpuckPosition2d::StopMotors().

◆ recvInt()

int SerialPort::recvInt ( ) const

Receive a signed interger from e-puck.

Wait indefinitely two bytes to arrive from e-puck and converts them to signed integer.

Returns
The received signed integer.

Referenced by getError(), EpuckIR::GetIRData(), EpuckPosition2d::SetOdometry(), and EpuckPosition2d::UpdateOdometry().

◆ recvUnsigned()

unsigned SerialPort::recvUnsigned ( ) const

Receive an unsigned interger from e-puck.

Wait indefinitely two bytes to arrive from e-puck and converts them to unsigned integer.

Returns
The received unsigned integer.

Referenced by getError(), and EpuckCamera::Initialize().

◆ recvUnsignedCharArray()

int SerialPort::recvUnsignedCharArray ( unsigned char *const  array,
unsigned  length 
) const

Receive an array of unsigned char from e-puck.

Parameters
arrayPointer to array where the received char will be put.
lengthLength of array that will be received.

Referenced by getError(), and EpuckCamera::GetImage().

◆ sendChar()

void SerialPort::sendChar ( char  message) const

Send a character to e-puck.

Send one character to e-puck.

Parameters
messageThe charecter to be sent.

Referenced by EpuckInterface::EpuckInterface(), EpuckLEDs::EpuckLEDs(), and getError().

◆ sendInt()

void SerialPort::sendInt ( int  message) const

Send an integer to e-puck.

Send two bytes to e-puck. It's an integer number up to 65535.

Parameters
messageThe integer to be sent.

Referenced by getError(), EpuckCamera::Initialize(), and EpuckPosition2d::SetVel().


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