Public Member Functions | Private Member Functions | Private Attributes
cereal::CerealPort Class Reference

C++ serial port class for ROS. More...

#include <md49_serialport.h>

List of all members.

Public Member Functions

int baudRate ()
 Get the current baud rate.
 CerealPort ()
 Constructor.
void close ()
 Close the serial port.
int flush ()
 Wrapper around tcflush.
void open (const char *port_name, int baud_rate=115200)
 Open the serial port.
void pauseStream ()
 Pause streaming.
bool portOpen ()
 Check whether the port is open or not.
int read (char *data, int max_length, int timeout=-1)
 Read from the port.
bool readBetween (std::string *data, char start, char end, int timeout=-1)
 Read from the serial port between a start char and an end char.
int readBytes (char *data, int length, int timeout=-1)
 Read a fixed number of bytes from the serial port.
int readLine (char *data, int length, int timeout=-1)
 Read a line from the serial port.
bool readLine (std::string *data, int timeout=-1)
 Read a line from the serial port.
void resumeStream ()
 Resume streaming.
bool startReadBetweenStream (boost::function< void(std::string *)> f, char start, char end)
 Start a stream of readBetween()
bool startReadLineStream (boost::function< void(std::string *)> f)
 Start a stream of readLine(std::string*, int)
bool startReadStream (boost::function< void(char *, int)> f)
 Start a stream of read()
void stopStream ()
 Stop streaming.
int write (const char *data, int length=-1)
 Write to the port.
 ~CerealPort ()
 Destructor.

Private Member Functions

void readBetweenThread (char start, char end)
 Thread for a stream of readBetween()
void readLineThread ()
 Thread for a stream of readLine(std::string*, int)
void readThread ()
 Thread for a stream of read()

Private Attributes

int baud_
 Baud rate.
int fd_
 File descriptor.
boost::function< void(std::string *) readBetweenCallback )
 Stream readBetween callback boost function.
boost::function< void(char *, int) readCallback )
 Stream read callback boost function.
boost::function< void(std::string *) readLineCallback )
 Stream readLine callback boost function.
bool stream_paused_
 Whether streaming is paused or not.
bool stream_stopped_
 Whether streaming is stopped or not.
boost::thread * stream_thread_
 Stream thread.

Detailed Description

C++ serial port class for ROS.

This class was based on the serial port code found on the hokuyo_node as suggested by Blaise Gassend on the ros-users mailling list.

Definition at line 34 of file md49_serialport.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 23 of file md49_serialport.cpp.

Destructor.

Definition at line 28 of file md49_serialport.cpp.


Member Function Documentation

int cereal::CerealPort::baudRate ( ) [inline]

Get the current baud rate.

Definition at line 62 of file md49_serialport.h.

Close the serial port.

This call essentially wraps close.

Definition at line 97 of file md49_serialport.cpp.

Wrapper around tcflush.

Definition at line 323 of file md49_serialport.cpp.

void cereal::CerealPort::open ( const char *  port_name,
int  baud_rate = 115200 
)

Open the serial port.

This opens the serial port for communication. Wrapper for open.

Parameters:
port_nameA null terminated character array containing the name of the port.
baud_rateBaud rate of the serial port. Defaults to 115200.
Todo:
tcsetattr returns true if at least one attribute was set. Hence, we might not have set everything on success.

Definition at line 33 of file md49_serialport.cpp.

Pause streaming.

Definition at line 449 of file md49_serialport.cpp.

bool cereal::CerealPort::portOpen ( ) [inline]

Check whether the port is open or not.

Definition at line 59 of file md49_serialport.h.

int cereal::CerealPort::read ( char *  data,
int  max_length,
int  timeout = -1 
)

Read from the port.

This function allows to read data from the serial port. Simple wrapper for read.

Parameters:
dataData coming from the serial port.
max_lengthMaximum length of the incoming data.
timeoutTimeout in milliseconds.
Returns:
Number of bytes read.

Definition at line 124 of file md49_serialport.cpp.

bool cereal::CerealPort::readBetween ( std::string *  data,
char  start,
char  end,
int  timeout = -1 
)

Read from the serial port between a start char and an end char.

This function allows to read data from the serial port between a start and an end char.

Parameters:
dataData coming from the serial port.
startStart character of the incoming data stream.
endEnd character of the incoming data stream.
timeoutTimeout in milliseconds.
Returns:
Whether the read was successful or not.

Definition at line 254 of file md49_serialport.cpp.

void cereal::CerealPort::readBetweenThread ( char  start,
char  end 
) [private]

Thread for a stream of readBetween()

Stream version of the readBetween function.

Parameters:
startStart character of the incoming data stream.
endEnd character of the incoming data stream.

Definition at line 419 of file md49_serialport.cpp.

int cereal::CerealPort::readBytes ( char *  data,
int  length,
int  timeout = -1 
)

Read a fixed number of bytes from the serial port.

This function allows to read a fixed number of data bytes from the serial port, no more, no less.

Parameters:
dataData coming from the serial port.
lengthFixed length of the incoming data.
timeoutTimeout in milliseconds.
See also:
read()
Returns:
Number of bytes read.

Definition at line 148 of file md49_serialport.cpp.

int cereal::CerealPort::readLine ( char *  data,
int  length,
int  timeout = -1 
)

Read a line from the serial port.

This function allows to read a line from the serial port. Data is return as char*

Parameters:
dataData coming from the serial port.
lengthLength of the incoming data.
timeoutTimeout in milliseconds.
See also:
readLine(std::string*, int)
Returns:
Number of bytes read.

Definition at line 177 of file md49_serialport.cpp.

bool cereal::CerealPort::readLine ( std::string *  data,
int  timeout = -1 
)

Read a line from the serial port.

This function allows to read a line from the serial port. Data is return as std::string

Parameters:
dataData coming from the serial port.
timeoutTimeout in milliseconds.
See also:
readLine(char*, int, int)
Returns:
Whether the read was successful or not.

Definition at line 210 of file md49_serialport.cpp.

Thread for a stream of readLine(std::string*, int)

Stream version of the readLine function.

Definition at line 385 of file md49_serialport.cpp.

void cereal::CerealPort::readThread ( ) [private]

Thread for a stream of read()

Stream version of the read function.

Definition at line 344 of file md49_serialport.cpp.

Resume streaming.

Definition at line 454 of file md49_serialport.cpp.

bool cereal::CerealPort::startReadBetweenStream ( boost::function< void(std::string *)>  f,
char  start,
char  end 
)

Start a stream of readBetween()

Stream version of the readBetween() function.

Parameters:
fCallback boost function to receive the data.
startStart character of the incoming data stream.
endEnd character of the incoming data stream.
See also:
readBetween()
Returns:
True if successful false if a stream is already running.

Definition at line 406 of file md49_serialport.cpp.

bool cereal::CerealPort::startReadLineStream ( boost::function< void(std::string *)>  f)

Start a stream of readLine(std::string*, int)

Stream version of the readLine(std::string*, int) function.

Parameters:
fCallback boost function to receive the data.
See also:
readLine(std::string*, int)
Returns:
True if successful false if a stream is already running.

Definition at line 372 of file md49_serialport.cpp.

bool cereal::CerealPort::startReadStream ( boost::function< void(char *, int)>  f)

Start a stream of read()

Stream version of the read function.

Parameters:
fCallback boost function to receive the data.
See also:
read()
Returns:
True if successful false if a stream is already running.

Definition at line 331 of file md49_serialport.cpp.

Stop streaming.

Definition at line 440 of file md49_serialport.cpp.

int cereal::CerealPort::write ( const char *  data,
int  length = -1 
)

Write to the port.

This function allows to send data through the serial port. Wraper for write.

Parameters:
dataData to send in a character array or null terminated c string.
lengthNumber of bytes being sent. Defaults to -1 if sending a c string.
Returns:
Number of bytes writen.

Definition at line 109 of file md49_serialport.cpp.


Member Data Documentation

Baud rate.

Definition at line 197 of file md49_serialport.h.

int cereal::CerealPort::fd_ [private]

File descriptor.

Definition at line 195 of file md49_serialport.h.

boost::function<void(std::string*) cereal::CerealPort::readBetweenCallback) [private]

Stream readBetween callback boost function.

Definition at line 231 of file md49_serialport.h.

boost::function<void(char*, int) cereal::CerealPort::readCallback) [private]

Stream read callback boost function.

Definition at line 227 of file md49_serialport.h.

boost::function<void(std::string*) cereal::CerealPort::readLineCallback) [private]

Stream readLine callback boost function.

Definition at line 229 of file md49_serialport.h.

Whether streaming is paused or not.

Definition at line 234 of file md49_serialport.h.

Whether streaming is stopped or not.

Definition at line 236 of file md49_serialport.h.

boost::thread* cereal::CerealPort::stream_thread_ [private]

Stream thread.

Definition at line 224 of file md49_serialport.h.


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


md49_serialport
Author(s): Fabian Prinzing
autogenerated on Thu Jun 6 2019 17:30:29