Skip to main content

Send and read serial data from the CLI

Use mimick uart to talk to a DUT's serial port one step at a time. Each command opens the port, does one thing, and returns, so you can call it from a shell script or a runbook. To type at the port yourself, use mimick connect instead.

What you need​

  • Operator access to the bench
  • A serial port (linux-tty) with a uart interface, wired to your DUT
  • An active bench (mimick bench use <your-bench>)

Find the uart location with mimick peripheral list. It ends in .uart0.

Write data​

mimick uart <location> write "reboot"

The command sends the bytes exactly as you give them and prints nothing when they are written. It does not add a line ending. If your DUT expects one, put it in the string. In bash, $'...' turns \r and \n into the real characters:

mimick uart <location> write $'reboot\r\n'

To send raw bytes, give them as hex and add --binary:

mimick uart <location> write --binary 01abcdef55

A hex string with an odd number of digits, or a character that is not 0-9 or a-f, is rejected before anything is sent. Add --format json to print the number of bytes written.

Read data​

mimick uart <location> read --bytes 64 --timeout 5s

The command waits for up to --bytes bytes (4096 by default) and stops at --timeout (10 seconds by default). Through the Cloud, a wait beyond two minutes with no traffic is ended. It writes what arrived to standard output and nothing else, so you can redirect it to a file and get the exact bytes:

mimick uart <location> read --bytes 1024 > capture.bin

A read that ends at the timeout with some data succeeds. A read that gets no data exits with an error and a non-zero status. --format hex prints the bytes as hex, and --format json prints them as a hex string with a byte count.

The bench only hears what the DUT sends while the command is running. Bytes the DUT sent before you ran it are not kept. To send a command and catch its reply, use transfer.

Send a command and read the reply​

mimick uart <location> transfer $'STATUS?\r\n' --expect 'OK|ERR' --timeout 5s

The bench starts listening before it sends, so a fast reply is not lost. The command writes the reply to standard output.

  • With --expect, the command keeps reading until the regular expression matches what has arrived. If it does not match before --timeout, the command prints what it did get and exits with an error.
  • Without --expect, the command returns the first reply that arrives.

transfer takes the same --binary and --format options as the other two.

In a runbook​

mimick uart console.uart0 write $'login\r\n'
mimick uart console.uart0 transfer $'uname -a\r\n' --expect 'Linux' > uname.txt

If a command fails​

What you seeWhat to do
the call stopped making progressThe Cloud ends a call that waits two minutes with no traffic, so a --timeout above two minutes can't be reached. Use a shorter --timeout and read again.
timed out after ... waiting for dataThe DUT sent nothing. Check the wiring and baud rate, or raise --timeout.
the reply did not match --expectThe reply did not match. Check the pattern and the output the command printed.
--binary data must be hex bytesGive an even number of hex digits, such as 01abcdef55.
this port has no tty interfaceThe Station runs an older release that needs a tty interface on the port. Update the Station, or ask your org admin to add a tty interface.
this peripheral does not support ...The port's driver can't do that.
the Station does not know how to ...The Station runs an older release. Update it, then try again.
the bench "<name>" is offlineCheck that the bench has power and a network connection.
A permission errorAsk your org admin for the Operator grant on the bench.