rby1-sdk
Loading...
Searching...
No Matches
rb::SerialStream Class Reference

Serial communication stream interface. More...

#include <robot.h>

Public Member Functions

bool Connect (bool verbose) const
 Connect to the serial device.
 
void Disconnect () const
 Disconnect from the serial device.
 
bool IsCancelled () const
 Check if the serial stream has been cancelled.
 
bool IsDone () const
 Check if the serial stream is done.
 
bool IsOpened () const
 Check if the serial port is opened.
 
void SetReadCallback (const std::function< void(const std::string &)> &cb)
 Set callback function for incoming data.
 
void Wait () const
 Wait for the serial stream to complete.
 
bool WaitFor (int timeout_ms) const
 Wait for the serial stream to complete with timeout.
 
bool Write (const char *data)
 Write null-terminated string data to the serial port.
 
bool Write (const char *data, int n)
 Write binary data to the serial port.
 
bool Write (const std::string &data)
 Write string data to the serial port.
 
bool WriteByte (char ch)
 Write a single byte to the serial port.
 

Friends

template<typename T >
class RobotImpl
 

Detailed Description

Serial communication stream interface.

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

Member Function Documentation

◆ Connect()

bool rb::SerialStream::Connect ( bool verbose) const

Connect to the serial device.

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

Parameters
verboseEnable verbose logging during connection (default: false).
Returns
True if connection was successful, false otherwise.

◆ Disconnect()

void rb::SerialStream::Disconnect ( ) const

Disconnect from the serial device.

Closes the serial connection and releases associated resources.

◆ IsCancelled()

bool rb::SerialStream::IsCancelled ( ) const

Check if the serial stream has been cancelled.

Returns
True if the stream was cancelled, false otherwise.

◆ IsDone()

bool rb::SerialStream::IsDone ( ) const

Check if the serial stream is done.

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

◆ IsOpened()

bool rb::SerialStream::IsOpened ( ) const

Check if the serial port is opened.

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

◆ SetReadCallback()

void rb::SerialStream::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
cbCallback function that receives incoming data as a string.

◆ Wait()

void rb::SerialStream::Wait ( ) const

Wait for the serial stream to complete.

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

◆ WaitFor()

bool rb::SerialStream::WaitFor ( int timeout_ms) const

Wait for the serial stream to complete with timeout.

Parameters
timeout_msTimeout in milliseconds.
Returns
True if stream completed normally, false if timeout occurred.

◆ Write() [1/3]

bool rb::SerialStream::Write ( const char * data)

Write null-terminated string data to the serial port.

Parameters
dataNull-terminated string data to write.
Returns
True if write was successful, false otherwise.

◆ Write() [2/3]

bool rb::SerialStream::Write ( const char * data,
int n )

Write binary data to the serial port.

Parameters
dataPointer to data buffer.
nNumber of bytes to write.
Returns
True if write was successful, false otherwise.

◆ Write() [3/3]

bool rb::SerialStream::Write ( const std::string & data)

Write string data to the serial port.

Parameters
dataString data to write.
Returns
True if write was successful, false otherwise.

◆ WriteByte()

bool rb::SerialStream::WriteByte ( char ch)

Write a single byte to the serial port.

Parameters
chByte to write.
Returns
True if write was successful, false otherwise.

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