SGSerial Class Reference

A serial I/O class based on SGIOChannel. More...

#include <sg_serial.hxx>

Inheritance diagram for SGSerial:
SGIOChannel

List of all members.

Public Member Functions

 SGSerial (const string &device_name, const string &baud_rate)
 Create an instance of SGSerial.
 ~SGSerial ()
 Destructor.
bool open (const SGProtocolDir d)
 Open a channel.
int read (char *buf, int length)
 The read() method is modeled after the read() Unix system call.
int readline (char *buf, int length)
 The readline() method is similar to read() except that it will stop at the first end of line encountered in the input buffer.
int write (const char *buf, const int length)
 The write() method is modeled after the write() Unix system call and is analogous to the read() method.
int writestring (const char *str)
 The writestring() method is a simple wrapper that will calculate the length of a null terminated character array and write it to the output channel.
bool close ()
 The close() method is modeled after the close() Unix system call and will close an open device.
string get_device () const
string get_baud () const

Detailed Description

A serial I/O class based on SGIOChannel.

Definition at line 48 of file sg_serial.hxx.


Constructor & Destructor Documentation

SGSerial::SGSerial ( const string &  device_name,
const string &  baud_rate 
)

Create an instance of SGSerial.

This creates an instance of the SGSerial class. You need to provide the serial device name and desired baud rate. For Unix style systems, device names will be similar to ``/dev/ttyS0''. For DOS style systems you may want to use something similar to ``COM1:''. As with the SGFile class, device is not opened immediately, but instead will be opened when the open() method is called.

Parameters:
device_name name of serial device
baud_rate speed of communication

Definition at line 38 of file sg_serial.cxx.


Member Function Documentation

bool SGSerial::close (  )  [virtual]

The close() method is modeled after the close() Unix system call and will close an open device.

You should call this method when you are done using your IO class, before it is destructed.

Returns:
result of close

Reimplemented from SGIOChannel.

Definition at line 153 of file sg_serial.cxx.

string SGSerial::get_baud (  )  const [inline]
Returns:
the baud rate

Definition at line 98 of file sg_serial.hxx.

string SGSerial::get_device (  )  const [inline]
Returns:
the serial port device name

Definition at line 95 of file sg_serial.hxx.

bool SGSerial::open ( const SGProtocolDir  d  )  [virtual]

Open a channel.

Parameters:
d channel communication "direction" Direction can be one of:

  • SG_IO_IN - data will be flowing into this object to the application.
  • SG_IO_OUT - data will be flowing out of this object from the application.
  • SG_IO_BI - data will be flowing in both directions.
  • SG_IO_NONE - data will not be flowing in either direction. This is here for the sake of completeness.
Returns:
result of open

Reimplemented from SGIOChannel.

Definition at line 52 of file sg_serial.cxx.

int SGSerial::read ( char *  buf,
int  length 
) [virtual]

The read() method is modeled after the read() Unix system call.

You must provide a pointer to a character buffer that has enough allocated space for your potential read. You can also specify the maximum number of bytes allowed for this particular read. The actual number of bytes read is returned. You are responsible to ensure that the size of buf is large enough to accomodate your input message

Parameters:
buf a char pointer to your input buffer
length max number of bytes to read
Returns:
number of bytes read

Reimplemented from SGIOChannel.

Definition at line 75 of file sg_serial.cxx.

int SGSerial::readline ( char *  buf,
int  length 
) [virtual]

The readline() method is similar to read() except that it will stop at the first end of line encountered in the input buffer.

Parameters:
buf a char pointer to your input buffer
length max number of bytes to read
Returns:
number of bytes read

Reimplemented from SGIOChannel.

Definition at line 96 of file sg_serial.cxx.

int SGSerial::write ( const char *  buf,
const int  length 
) [virtual]

The write() method is modeled after the write() Unix system call and is analogous to the read() method.

You provide a pointer to a buffer of data, and then length of that data to be written out. The number of bytes written is returned.

Parameters:
buf a char pointer to your output buffer
length number of bytes to write
Returns:
number of bytes written

Reimplemented from SGIOChannel.

Definition at line 134 of file sg_serial.cxx.

int SGSerial::writestring ( const char *  str  )  [virtual]

The writestring() method is a simple wrapper that will calculate the length of a null terminated character array and write it to the output channel.

Parameters:
buf a char pointer to your output buffer
Returns:
number of bytes written

Reimplemented from SGIOChannel.

Definition at line 146 of file sg_serial.cxx.


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

Generated on 23 Feb 2010 for SimGear by  doxygen 1.6.1