All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::SerialPort Class Reference

A serial port handler. More...

#include <Radiant/SerialPort.hpp>

Inheritance diagram for Radiant::SerialPort:
Radiant::BinaryStream

Public Member Functions

bool close ()
 Close the serial port.
 
const QString & deviceName ()
 Returns the name of the device. More...
 
bool isOpen () const
 Checks if the port is open. More...
 
bool open (const char *device, bool stopBit, bool parityBit, int baud, int bits, int waitBytes, int waitTimeUS)
 Opens a serial port for communications. More...
 
virtual int read (void *buf, int bytes, bool waitfordata=true)
 Read bytes from the port. More...
 
 SerialPort ()
 Constructor.
 
virtual int write (const void *buf, int bytes)
 Write bytes to the port. More...
 
int writeByte (uint8_t byte)
 Writes a byte to the port. More...
 
virtual ~SerialPort ()
 Delete the object and close the port.
 
- Public Member Functions inherited from Radiant::BinaryStream
 BinaryStream ()
 Constructor.
 
virtual bool isHungUp () const
 Returns true if the stream has been closed. More...
 
virtual bool isPendingInput (unsigned int waitMicroSeconds=0)
 Returns true if the stream has at least one byte waiting to be read; otherwise returns false. More...
 
virtual ~BinaryStream ()
 Destructor.
 

Detailed Description

A serial port handler.

This class is for binary IO with serial ports.

Author
Tommi Ilmonen

Member Function Documentation

const QString& Radiant::SerialPort::deviceName ( )
inline

Returns the name of the device.

Returns
Name of the device
bool Radiant::SerialPort::isOpen ( ) const
virtual

Checks if the port is open.

Returns
True if the port is open, false otherwise

Reimplemented from Radiant::BinaryStream.

bool Radiant::SerialPort::open ( const char *  device,
bool  stopBit,
bool  parityBit,
int  baud,
int  bits,
int  waitBytes,
int  waitTimeUS 
)

Opens a serial port for communications.

If the port was open, this method will close it before opening it.

Parameters
devicename of the device to open
stopBitUse two stop bits instead of one
parityBitUse parity stop bit?
baudThe baud rate
bitsThe number of data bits
waitBytesThe number of bytes to read before returning
waitTimeUSTime to wait in microseconds
Returns
true on success
virtual int Radiant::SerialPort::read ( void *  buf,
int  bytes,
bool  waitfordata = true 
)
virtual

Read bytes from the port.

Parameters
[out]bufoutput buffer
bytesmax bytes to read
waitfordataignored
Returns
number of bytes read

Implements Radiant::BinaryStream.

virtual int Radiant::SerialPort::write ( const void *  buf,
int  bytes 
)
virtual

Write bytes to the port.

Parameters
bufbuffer to write from
bytesbytes to write
Returns
number of bytes written

Implements Radiant::BinaryStream.

int Radiant::SerialPort::writeByte ( uint8_t  byte)

Writes a byte to the port.

Parameters
byteByte to write
Returns
Number of bytes written