Cinder  0.9.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cinder::Serial Class Reference

#include <Serial.h>

Inherits cinder::Noncopyable.

Classes

class  Device
 

Public Member Functions

 ~Serial ()
 
const DevicegetDevice () const
 
void readBytes (void *data, size_t numBytes)
 
size_t readAvailableBytes (void *data, size_t maximumBytes)
 
void writeBytes (const void *data, size_t numBytes)
 
void writeByte (uint8_t data)
 
uint8_t readByte ()
 
char readChar ()
 
std::string readStringUntil (char token, size_t maxLength=0, double timeoutSeconds=-1.0)
 
void writeString (const std::string &str)
 
void flush (bool input=true, bool output=true)
 
size_t getNumBytesAvailable () const
 

Static Public Member Functions

static const std::vector< Serial::Device > & getDevices (bool forceRefresh=false)
 
static Serial::Device findDeviceByName (const std::string &name, bool forceRefresh=false)
 
static Serial::Device findDeviceByNameContains (const std::string &searchString, bool forceRefresh=false)
 
static SerialRef create (const Serial::Device &device, int baudRate)
 

Protected Member Functions

 Serial (const Serial::Device &device, int baudRate)
 

Constructor & Destructor Documentation

cinder::Serial::~Serial ( )
cinder::Serial::Serial ( const Serial::Device device,
int  baudRate 
)
protected

Member Function Documentation

const std::vector< Serial::Device > & cinder::Serial::getDevices ( bool  forceRefresh = false)
static

Returns a vector of all serial devices available on the machine. Uses a cached list unless forceRefresh.

Serial::Device cinder::Serial::findDeviceByName ( const std::string &  name,
bool  forceRefresh = false 
)
static

Returns the first Serial::Device whose name is name. Returns a null Serial::Device if none are found. Uses a cached list of the serial devices unless forceRefresh.

Serial::Device cinder::Serial::findDeviceByNameContains ( const std::string &  searchString,
bool  forceRefresh = false 
)
static

Returns the first Serial::Device whose name contains the string searchString. Returns a null Serial::Device if none are found. Uses a cached list of the serial devices unless forceRefresh.

static SerialRef cinder::Serial::create ( const Serial::Device device,
int  baudRate 
)
static

Creates and returns a shared Serial object.

const Serial::Device & cinder::Serial::getDevice ( ) const

Returns the Device associated with this Serial port.

void cinder::Serial::readBytes ( void *  data,
size_t  numBytes 
)

Reads numBytes bytes of data from the serial port to data.

size_t cinder::Serial::readAvailableBytes ( void *  data,
size_t  maximumBytes 
)

Reads up to maximumBytes bytes of data from the serial port to data. Returns the number of bytes read.

void cinder::Serial::writeBytes ( const void *  data,
size_t  numBytes 
)

Writes numBytes bytes of data to the serial port from data.

void cinder::Serial::writeByte ( uint8_t  data)

Writes a single byte data to the serial port.

uint8_t cinder::Serial::readByte ( )

Returns a single byte read from the serial port.

char cinder::Serial::readChar ( )

Returns a single character read from the serial port.

std::string cinder::Serial::readStringUntil ( char  token,
size_t  maxLength = 0,
double  timeoutSeconds = -1.0 
)

Returns a string composed of bytes read until a character token is found, or up to maxLength bytes have been read and maxLength > 0. Throws a SerialTimeoutExc() if timeoutSeconds > 0 and timeoutSeconds seconds pass before token is found.

void cinder::Serial::writeString ( const std::string &  str)

Writes a string str to the serial port, excluding the null terminator.

void cinder::Serial::flush ( bool  input = true,
bool  output = true 
)

Forces the device to flush any buffered input and/or output bytes.

size_t cinder::Serial::getNumBytesAvailable ( ) const

Returns the number of bytes available for reading from the device.


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