pw_stream_uart_linux#
pw_stream_uart_linux
implements the
pw::stream::NonSeekableReaderWriter
interface for reading from and
writing to a UART using Linux TTY interfaces.
Note
This module will likely be superseded by a future pw_uart
interface.
C++#
-
class UartStreamLinux : public pw::stream::NonSeekableReaderWriter#
pw::stream::NonSeekableReaderWriter
implementation for UARTs on Linux.Public Functions
-
Status Open(const char *path, uint32_t baud_rate)#
Open a UART device using the specified baud rate.
- return:
OK
- The device was successfully opened and configured.INVALID_ARGUMENT
- An unsupported baud rate was supplied.FAILED_PRECONDITION
- A device was already open.UNKNOWN
- An error was returned by the operating system.
- Parameters:
path – [in] Path to the TTY device.
baud_rate – [in] Baud rate to use for the device.
-
Status Open(const char *path, uint32_t baud_rate)#
Examples#
Pigweed AI summary: This paragraph provides a simple example of writing to a UART (Universal Asynchronous Receiver-Transmitter). It includes code snippets in C++ that demonstrate opening a UART stream, setting the baud rate, and writing data to the stream.
A simple example illustrating writing to a UART:
constexpr const char* kUartPath = "/dev/ttyS0";
constexpr uint32_t kBaudRate = 115200;
pw::stream::UartStreamLinux stream;
PW_TRY(stream.Open(kUartPath, kBaudRate));
std::array<std::byte, 10> to_write = {};
PW_TRY(stream.Write(to_write));
Caveats#
Pigweed AI summary: The given paragraph states that there are no interfaces provided for configuring data bits, stop bits, or parity. It also mentions that the supported baud rates are limited but can potentially be expanded by modifying the "Open" method.
No interfaces are supplied for configuring data bits, stop bits, or parity.
Supported baud rates are limited but could be extended by modifying the Open
method.