latest version v1.9 - last update 10 Apr 2010 |
This serial class provides an unified interface to access serial ports in posix and windows operating systems. More...
#include <ltiSerial.h>
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 |
serial & | copy (const serial &other) |
const parameters & | getParameters () 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 |
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.
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
other | the object to be copied |
virtual lti::serial::~serial | ( | ) | [virtual] |
destructor
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
read exactly theVector.size() characters from the port specified in the parameters.
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.
bool lti::serial::receive | ( | char & | c | ) |
wait for a character to be received in the port specified in the parameters.
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.
bool lti::serial::send | ( | const std::string & | theString | ) |
sends a string through the port specified in the parameters.
bool lti::serial::send | ( | const ubyte | c | ) |
sends an unsigned character c through the port specified in the parameters.
bool lti::serial::send | ( | const char | c | ) |
sends a character c through the port specified in the parameters.
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.
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).
parameters lti::serial::param [protected] |
the parameters in use