LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::serial Class Reference

This serial class provides an unified interface to access serial ports in posix and windows operating systems. More...

#include <ltiSerial.h>

Inheritance diagram for lti::serial:
Inheritance graph
[legend]
Collaboration diagram for lti::serial:
Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 the parameters for the class serial More...

Public Member Functions

 serial ()
 serial (const parameters &serialPar)
 serial (const serial &other)
virtual ~serial ()
virtual const char * getTypeName () const
serialcopy (const serial &other)
const parametersgetParameters () const
bool setParameters (const parameters &theParameters)
bool send (const char c)
bool send (const ubyte c)
bool send (const std::string &theString)
bool send (const vector< ubyte > &theVector)
bool receive (char &c)
bool receive (ubyte &c)
bool receive (std::string &theString)
bool receive (vector< ubyte > &theVector)
const char * getStatusString () const
void setStatusString (const char *msg) const

Protected Member Functions

bool openPort ()

Protected Attributes

parameters param

Detailed Description

This serial class provides an unified interface to access serial ports in posix and windows operating systems.

At this time only Linux and Windows are supported.

You just need to set the parameters if you do not want the default ones, and send or receive data with the send() and receive() methods.

If you use a Linux system, do not forget to make the users who needs access to the serial ports to be members of the group uucp or the corresponding group of the /dev/ttyS* devices.


Constructor & Destructor Documentation

lti::serial::serial (  ) 

default constructor

lti::serial::serial ( const parameters serialPar  ) 

construct a serial instance with the given parameters

lti::serial::serial ( const serial other  ) 

copy constructor

Parameters:
other the object to be copied
virtual lti::serial::~serial (  )  [virtual]

destructor


Member Function Documentation

serial& lti::serial::copy ( const serial other  ) 

copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object
const parameters& lti::serial::getParameters (  )  const

returns used parameters

const char* lti::serial::getStatusString (  )  const

return the last message set with setStatusString().

This will never return 0. If no status-string has been set yet an empty string (pointer to a string with only the char(0)) will be returned.

virtual const char* lti::serial::getTypeName (  )  const [virtual]

returns the name of this type ("serial")

Reimplemented from lti::object.

bool lti::serial::openPort (  )  [protected]

open the port using the parameters

bool lti::serial::receive ( vector< ubyte > &  theVector  ) 

read exactly theVector.size() characters from the port specified in the parameters.

Returns:
true if the character has been received, or false if a problem occured. In this case you can read the status string to check the source of the problem. Note that false will also be returned if a timeout occurs.
bool lti::serial::receive ( std::string &  theString  ) 

read all characters until the next new line or zero character, and store them in the given string.

bool lti::serial::receive ( ubyte c  ) 

wait for an unsigned character to be received in the port specified in the parameters.

Returns:
true if the character has been received, or false if a problem occured. In this case you can read the status string to check the source of the problem. Note that false will also be returned if a timeout occurs.
bool lti::serial::receive ( char &  c  ) 

wait for a character to be received in the port specified in the parameters.

Returns:
true if the character has been received, or false if a problem occured. In this case you can read the status string to check the source of the problem. Note that false will also be returned if a timeout occurs.
bool lti::serial::send ( const vector< ubyte > &  theVector  ) 

sends all ubytes contained in the vector through the port specified in the parameters.

The vector is more appropriate if the data to be send has a more "binary" nature than an ASCII string.

Returns:
true if all the string characters are send successfully, or false otherwise.
bool lti::serial::send ( const std::string &  theString  ) 

sends a string through the port specified in the parameters.

Returns:
true if all the string characters are send successfully, or false otherwise.
bool lti::serial::send ( const ubyte  c  ) 

sends an unsigned character c through the port specified in the parameters.

Returns:
true if the character could be send successfully, or false otherwise.
bool lti::serial::send ( const char  c  ) 

sends a character c through the port specified in the parameters.

Returns:
true if the character could be send successfully, or false otherwise.
bool lti::serial::setParameters ( const parameters theParameters  ) 

set the parameters for the serial object

void lti::serial::setStatusString ( const char *  msg  )  const

set a status string.

Parameters:
msg the const string to be reported next time by getStatusString().

This message will be usually set within the send/receive methods to indicate an error cause.

Note that the change of the status string is not considered as a change in the class status (this method is const).


Member Data Documentation

the parameters in use


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

Generated on Sat Apr 10 15:28:53 2010 for LTI-Lib by Doxygen 1.6.1