uart - Send and Extract UART response

Send text to a UART port and/or wait for a response, optionally extracting values from the response into test plan keys.

If sendText is given, it is transmitted first. If expectText and/or extractText are given, the command then waits (up to timeout) for the receive buffer to contain a match; extractText is a regular expression matched against the accumulated buffer, and its capture groups are stored in the corresponding key names given by extractKey. If neither expectText nor extractText is given, the command sends and returns immediately without waiting on a response. Unless noflush is set, the receive buffer is flushed before waiting and the transmit buffer is flushed after sending.

Usage:

- command: uart <uartPort> [noflush]
  [expect: [hex] <expectText>]
  [extract: <extractText>]
  [extractKey: <key>...]
  [send: [hex] <sendText>]
  [retry: <retryCount>]
  [timeout: <timeout>]

Argument

Description

uartPort

UART port name: UART0, UART1, UART2, etc. Must match a port configured (built-in or via uartCfg - Configure UART).

expectText

Text to expect in the response, prior to extraction. If the hex keyword is used, expectText is interpreted as a hex string.

extractText

Regular expression to extract from the response (uses RE2 Syntax, except \C). Each capture group is stored in the corresponding extractKey.

key

Key(s) in which to store extracted text. To save multiple values, use multiple capture groups.

sendText

Text to send before waiting for a response. If the hex keyword is used, sendText is interpreted as a hex string.

noflush

Don’t flush the receive buffer before waiting, or the transmit buffer after sending.

retryCount

Number of times to retry the test step (optional)

timeout

Timeout, in milliseconds, to wait for expectText/extractText to match (default: 1000ms)

Use uart for a single-step send/expect/extract exchange. For a fire-and-forget expectation set earlier and awaited later (e.g. across an intervening operator step), use uartExpect - Set expectation for uartAwait together with uartAwait - Await UART response instead.

Examples