SerialStream#

rb::SerialStream exposes an SDK-managed serial-device connection. It sits next to the main robot client and is useful when you need asynchronous serial I/O through the same SDK surface.

Header

Header

#include <rby1-sdk/robot.h>

Declaration

Namespace

rb

Kind

class

Primary role

Open, monitor, and write to an SDK-managed serial stream.

Public Member Functions

Method

Purpose

Notes

Connect(...) and Disconnect()

Open or close the serial stream.

Connect(...) optionally prints verbose diagnostics.

IsOpened(), IsDone(), IsCancelled()

Inspect the current state of the stream.

Useful when the stream is managed asynchronously.

SetReadCallback(...)

Register a callback for incoming serial data.

The callback receives decoded strings.

Write(...) and WriteByte(...)

Send bytes or strings to the device.

Overloads cover raw byte buffers and string payloads.

Wait() and WaitFor(...)

Block until the stream finishes.

WaitFor(...) is the timed variant.

Numeric Parameters & Encodings

Method

Unit / encoding

Notes

WaitFor(timeout_ms)

ms

Timeout for waiting on stream shutdown.

WriteByte(...)

Byte value

Raw serial byte payload, not an SDK-level physical unit.

Detailed Reference

class SerialStream#

Serial communication stream interface.

Provides bidirectional serial communication with devices connected to the robot. Supports asynchronous read/write operations with callback-based data handling.

Public Functions

~SerialStream()#
bool Connect(bool verbose) const#

Connect to the serial device.

Establishes a connection to the serial device with the configured parameters.

Parameters:

verbose – Enable verbose logging during connection (default: false).

Returns:

True if connection was successful, false otherwise.

void Disconnect() const#

Disconnect from the serial device.

Closes the serial connection and releases associated resources.

bool IsCancelled() const#

Check if the serial stream has been cancelled.

Returns:

True if the stream was cancelled, false otherwise.

bool IsDone() const#

Check if the serial stream is done.

Returns:

True if the stream has completed or been closed, false otherwise.

bool IsOpened() const#

Check if the serial port is opened.

Returns:

True if the serial port is currently open, false otherwise.

void SetReadCallback(const std::function<void(const std::string&)> &cb)#

Set callback function for incoming data.

Registers a callback function that will be called whenever data is received from the serial device.

Parameters:

cb – Callback function that receives incoming data as a string.

void Wait() const#

Wait for the serial stream to complete.

Blocks until the serial stream is closed or an error occurs.

bool WaitFor(int timeout_ms) const#

Wait for the serial stream to complete with timeout.

Parameters:

timeout_ms – Timeout in milliseconds.

Returns:

True if stream completed normally, false if timeout occurred.

bool Write(const char *data)#

Write null-terminated string data to the serial port.

Parameters:

data – Null-terminated string data to write.

Returns:

True if write was successful, false otherwise.

bool Write(const char *data, int n)#

Write binary data to the serial port.

Parameters:
  • data – Pointer to data buffer.

  • n – Number of bytes to write.

Returns:

True if write was successful, false otherwise.

bool Write(const std::string &data)#

Write string data to the serial port.

Parameters:

data – String data to write.

Returns:

True if write was successful, false otherwise.

bool WriteByte(char ch)#

Write a single byte to the serial port.

Parameters:

ch – Byte to write.

Returns:

True if write was successful, false otherwise.

Related Types

Examples

  • module_test/* examples are the closest reference points when the workflow involves direct peripheral communication.