vrpn  07.33
Virtual Reality Peripheral Network
vrpn_SerialPort Class Reference

A simple class wrapping the functionality of vrpn_Serial.h with RAII, object-orientation, and optional STL types. More...

#include <vrpn_SerialPort.h>

Classes

struct  AlreadyOpen
 
struct  CloseFailure
 
struct  DrainFailure
 
struct  FlushFailure
 
struct  NotOpen
 
struct  OpenFailure
 
struct  ReadFailure
 
struct  RTSFailure
 
struct  WriteFailure
 

Public Types

typedef int file_handle_type
 

Public Member Functions

 vrpn_SerialPort (const char *portname, long baud, int charsize=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE)
 Construct and open port. More...
 
 vrpn_SerialPort ()
 Construct without opening. More...
 
 ~vrpn_SerialPort ()
 Destructor - closes port if open. More...
 
Open/Close Methods

Open serial port

See also
vrpn_open_commport
Exceptions
OpenFailure,AlreadyOpen
void open (const char *portname, long baud, int charsize=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE)
 
bool is_open () const
 
void close ()
 Close the serial port. More...
 
Write
Returns
number of bytes written
Exceptions
WriteFailure,NotOpen
int write (std::string const &buffer)
 
int write (const unsigned char *buffer, int bytes)
 
Read

Read available characters from input buffer, up to indicated count.

Exceptions
ReadFailure,NotOpen
int read_available_characters (unsigned char *buffer, int count)
 
std::string read_available_characters (int count=-1)
 Read available characters from input buffer, up to indicated count (or -1 for no limit) More...
 
int read_available_characters (unsigned char *buffer, int count, struct timeval &timeout)
 Read available characters from input buffer, and wait up to the indicated timeout for those remaining, up to indicated count. More...
 
std::string read_available_characters (int count, struct timeval &timeout)
 Read available characters from input buffer, and wait up to the indicated timeout for those remaining, up to indicated count. More...
 
Buffer manipulation
void flush_input_buffer ()
 Throw out any characters within the input buffer. More...
 
void flush_output_buffer ()
 Throw out any characters (do not send) within the output buffer. More...
 
void drain_output_buffer ()
 Wait until all of the characters in the output buffer are sent, then return. More...
 
RTS

Set and clear functions for the RTS ("ready to send") hardware flow- control bit.

These are used on a port that is already open. Some devices (like the Ascension Flock of Birds) use this to reset the device.

Exceptions
RTSFailure,NotOpen
void set_rts ()
 
void clear_rts ()
 
void assign_rts (bool set)
 

Detailed Description

A simple class wrapping the functionality of vrpn_Serial.h with RAII, object-orientation, and optional STL types.

Definition at line 34 of file vrpn_SerialPort.h.

Member Typedef Documentation

◆ file_handle_type

Definition at line 36 of file vrpn_SerialPort.h.

Constructor & Destructor Documentation

◆ vrpn_SerialPort() [1/2]

vrpn_SerialPort::vrpn_SerialPort ( const char *  portname,
long  baud,
int  charsize = 8,
vrpn_SER_PARITY  parity = vrpn_SER_PARITY_NONE 
)

Construct and open port.

See also
vrpn_open_commport
Exceptions
OpenFailure

Definition at line 36 of file vrpn_SerialPort.C.

References is_open().

Here is the call graph for this function:

◆ vrpn_SerialPort() [2/2]

vrpn_SerialPort::vrpn_SerialPort ( )

Construct without opening.

Definition at line 46 of file vrpn_SerialPort.C.

◆ ~vrpn_SerialPort()

vrpn_SerialPort::~vrpn_SerialPort ( )

Destructor - closes port if open.

Definition at line 52 of file vrpn_SerialPort.C.

References close(), and is_open().

Here is the call graph for this function:

Member Function Documentation

◆ assign_rts()

void vrpn_SerialPort::assign_rts ( bool  set)
inline

Definition at line 212 of file vrpn_SerialPort.h.

References clear_rts(), and set_rts().

Here is the call graph for this function:

◆ clear_rts()

void vrpn_SerialPort::clear_rts ( )

Definition at line 197 of file vrpn_SerialPort.C.

References vrpn_clear_rts().

Referenced by assign_rts().

Here is the call graph for this function:

◆ close()

void vrpn_SerialPort::close ( void  )

Close the serial port.

Exceptions
NotOpen,CloseFailure

Definition at line 77 of file vrpn_SerialPort.C.

References vrpn_close_commport().

Referenced by ~vrpn_SerialPort().

Here is the call graph for this function:

◆ drain_output_buffer()

void vrpn_SerialPort::drain_output_buffer ( )

Wait until all of the characters in the output buffer are sent, then return.

Definition at line 179 of file vrpn_SerialPort.C.

References vrpn_drain_output_buffer().

Here is the call graph for this function:

◆ flush_input_buffer()

void vrpn_SerialPort::flush_input_buffer ( )

Throw out any characters within the input buffer.

Exceptions
FlushFailure,NotOpen

Definition at line 161 of file vrpn_SerialPort.C.

References vrpn_flush_input_buffer().

Here is the call graph for this function:

◆ flush_output_buffer()

void vrpn_SerialPort::flush_output_buffer ( )

Throw out any characters (do not send) within the output buffer.

Exceptions
FlushFailure,NotOpen

Definition at line 170 of file vrpn_SerialPort.C.

References vrpn_flush_output_buffer().

Here is the call graph for this function:

◆ is_open()

bool vrpn_SerialPort::is_open ( ) const
inline

Definition at line 210 of file vrpn_SerialPort.h.

Referenced by open(), vrpn_SerialPort(), and ~vrpn_SerialPort().

◆ open()

void vrpn_SerialPort::open ( const char *  portname,
long  baud,
int  charsize = 8,
vrpn_SER_PARITY  parity = vrpn_SER_PARITY_NONE 
)

Definition at line 64 of file vrpn_SerialPort.C.

References is_open(), and vrpn_open_commport().

Here is the call graph for this function:

◆ read_available_characters() [1/4]

std::string vrpn_SerialPort::read_available_characters ( int  count,
struct timeval &  timeout 
)

Read available characters from input buffer, and wait up to the indicated timeout for those remaining, up to indicated count.

overflow safety

Definition at line 149 of file vrpn_SerialPort.C.

References read_available_characters().

Here is the call graph for this function:

◆ read_available_characters() [2/4]

std::string vrpn_SerialPort::read_available_characters ( int  count = -1)

Read available characters from input buffer, up to indicated count (or -1 for no limit)

Definition at line 116 of file vrpn_SerialPort.C.

References min, and read_available_characters().

Here is the call graph for this function:

◆ read_available_characters() [3/4]

int vrpn_SerialPort::read_available_characters ( unsigned char *  buffer,
int  count 
)

Definition at line 105 of file vrpn_SerialPort.C.

References vrpn_read_available_characters().

Referenced by read_available_characters().

Here is the call graph for this function:

◆ read_available_characters() [4/4]

int vrpn_SerialPort::read_available_characters ( unsigned char *  buffer,
int  count,
struct timeval &  timeout 
)

Read available characters from input buffer, and wait up to the indicated timeout for those remaining, up to indicated count.

Definition at line 138 of file vrpn_SerialPort.C.

References vrpn_read_available_characters().

Here is the call graph for this function:

◆ set_rts()

void vrpn_SerialPort::set_rts ( )

Definition at line 188 of file vrpn_SerialPort.C.

References vrpn_set_rts().

Referenced by assign_rts().

Here is the call graph for this function:

◆ write() [1/2]

int vrpn_SerialPort::write ( const unsigned char *  buffer,
int  bytes 
)

Definition at line 95 of file vrpn_SerialPort.C.

References vrpn_write_characters().

Here is the call graph for this function:

◆ write() [2/2]

int vrpn_SerialPort::write ( std::string const &  buffer)

Definition at line 86 of file vrpn_SerialPort.C.


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