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 |
|
Declaration
Namespace |
|
Kind |
|
Primary role |
Open, monitor, and write to an SDK-managed serial stream. |
Public Member Functions
Method |
Purpose |
Notes |
|---|---|---|
|
Open or close the serial stream. |
|
|
Inspect the current state of the stream. |
Useful when the stream is managed asynchronously. |
|
Register a callback for incoming serial data. |
The callback receives decoded strings. |
|
Send bytes or strings to the device. |
Overloads cover raw byte buffers and string payloads. |
|
Block until the stream finishes. |
|
Numeric Parameters & Encodings
Method |
Unit / encoding |
Notes |
|---|---|---|
|
|
Timeout for waiting on stream shutdown. |
|
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.
-
~SerialStream()#
Related Types
Examples
module_test/*examples are the closest reference points when the workflow involves direct peripheral communication.