SerialPort Class Reference

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

#include <serialPort.hpp>

List of all members.

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.

Not thread safe
Renato Florentino Garcia
August 2008

Public Member Functions

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

Private Attributes

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

Constructor & Destructor Documentation

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.

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

Member Function Documentation

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

Return the last error.

Return the description of last error.

A std::string describing the error.
char SerialPort::recvChar ( ) const

Receive a char from e-puck.

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

The received char.

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

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.

The received signed integer.

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

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.

The received unsigned integer.

Referenced by EpuckCamera::Initialize().

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

Receive an array of unsigned char from e-puck.

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

Referenced by EpuckCamera::GetImage().

void SerialPort::sendChar ( char  message) const

Send a character to e-puck.

Send one character to e-puck.

messageThe charecter to be sent.
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.

messageThe integer to be sent.

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

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