Cross-platform serial communication CinderBlock thinly wrapping the serial library.
// dump all serial ports
for (auto port : SerialPort::getPorts()) {
console() << port->getName() << endl;
console() << "descr: " << port->getDescription() << endl;
console() << "ident: " << port->getHardwareIdentifier() << endl;
}
// find a port
auto port = SerialPort::findPortByNameMatching(std::regex("\\/dev\\/cu\\.usbmodem.*"));
// create a device
auto device = SerialDevice::create(port, 115200);
// read
uint8_t inBuffer[16];
while (device->getNumBytesAvailable() > 0) {
size_t size = device->readBytes(inBuffer, 16);
}
// write
uint8_t outBuffer[5] = {
0, 255, 255, // cyan RGB
'\r', '\n', // EOL
};
device->writeBytes(outBuffer, 5);
SLIP and COBS encode / decode is available separately via the Cinder-Encoding CinderBlock.
- William Woodall and John Harrison for the serial library
- Christopher Baker and his ofxSerial openFrameworks addon