# Cinder

# cinder::Serial Class Reference

`#include <Serial.h>`

List of all members.

## Classes
class | Device
struct | Obj
## Public Member Functions
| Serial ()
| Serial (const Serial::Device &device, int baudRate)
const Device & | getDevice () const
| Returns the Device associated with this Serial port.
void | readBytes (void *data, size_t numBytes)
| Reads numBytes bytes of data from the serial port to data.
size_t | 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 | writeBytes (const void *data, size_t numBytes)
| Writes numBytes bytes of data to the serial port from data.
void | writeByte (uint8_t data)
| Writes a single byte data to the serial port.
uint8_t | readByte ()
| Returns a single byte read from the serial port.
char | readChar ()
| Returns a single character read from the serial port.
std::string | 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 | writeString (const std::string &str)
| Writes a string str to the serial port, excluding the null terminator.
void | flush (bool input=true, bool output=true)
| Forces the device to flush any buffered input and/or output bytes.
size_t | getNumBytesAvailable () const
| Returns the number of bytes available for reading from the device.
## Static Public Member Functions
static const std::vector < Serial::Device > & | getDevices (bool forceRefresh=false)
| Returns a vector of all serial devices available on the machine. Uses a cached list unless forceRefresh.
static Serial::Device | findDeviceByName (const std::string &name, bool forceRefresh=false)
| 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.
static Serial::Device | findDeviceByNameContains (const std::string &searchString, bool forceRefresh=false)
| 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.
## Protected Attributes
shared_ptr< Obj > | mObj

## Constructor & Destructor Documentation

cinder::Serial::Serial | ( |  | ) |

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

## 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.

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.

## Member Data Documentation

shared_ptr<Obj> cinder::Serial::mObj`[protected]`

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

- include/cinder/Serial.h
- src/cinder/Serial.cpp