Skip to content

UART — read N characters (uart_read_num)

What it does: Reads the specified number of bytes from the UART and attempts to convert them to UTF‑8 text.

uart_read_num

Inputs

  • num: number of characters/bytes to read.

Output

  • Text, or text representation of bytes.
  • None if nothing is available.

When to use it

  • For fixed frame length protocols.
  • When you know exactly how many bytes you expect.

Tips and pitfalls

  • For invalid UTF‑8, a string representing bytes is returned.
  • If the counterparty sends less data, the result may be incomplete.

Generated Python example

part = read_uart(uart1, 8)