Connect to Serial Devices with tio: 5 Easy Steps
To connect to serial devices on Linux you need a terminal program that opens a tty such as /dev/ttyUSB0 with the right line settings, and tio does exactly that with very few options. The first version of this guide listed commands that do not work as described (a shell redirect to log data, a hex pipe, sudo for permission errors), so it was rewritten from a real lab run.
All examples ran on 2026-11-01 in a debian:13 container with tio 3.9. There was no physical adapter: socat created two linked pseudo terminals (/tmp/ttyA for tio, /tmp/ttyB for a small script that plays the device and answers every line with ECHO: ...). Pseudo terminals do not enforce a baud rate, so a real baud mismatch (garbled text) is not shown here.
Contents
Install tio and open your first session
tio is in the Debian and Ubuntu repositories, so a normal install is enough. Debian 13 ships version 3.9:
$ sudo apt install tio
Then pass the device file of one of your serial devices. The defaults are 115200 baud, 8 data bits, no parity, 1 stop bit and no flow control, which is what most USB-to-serial boards use. Type a line and press Enter; the quit key is not Ctrl-C but ctrl-t q (the program says so itself):
$ tio /tmp/ttyA
[03:02:11.349] tio 3.9
[03:02:11.349] Press ctrl-t q to quit
[03:02:11.350] Connected to /tmp/ttyA
ECHO: hello
ECHO: AT
[03:02:14.364] Disconnected
When you work with serial devices, everything tio itself prints starts with a timestamp in brackets; the lines without one (ECHO: hello) came from the device. That difference is useful when you read a log later.
Find your serial devices and fix Permission denied
Plug the adapter in and look at ls /dev/ttyUSB* /dev/ttyACM*; tio -l lists the serial devices it can see (it printed nothing in the container, which has no real ports). If you pass a name that does not exist, tio does not fail: it waits for the device to appear, which is handy for boards that reboot but confusing when you mistyped the path. Add -n to get an error instead:
$ timeout 3 tio /dev/ttyUSB9
[02:45:33.289] Warning: Could not open /dev/ttyUSB9 (No such file or directory)
[02:45:33.289] Waiting for tty device..
A permission problem looks different. With the device owned by root and mode 600, an ordinary user gets this:
$ setpriv --reuid=65534 --regid=65534 --clear-groups tio -n /tmp/ttyA
[03:04:03.570] tio 3.9
[03:04:03.570] Non-interactive mode enabled
[03:04:03.570] Press ctrl-c to quit
[03:04:03.571] Error: Could not open tty device (Permission denied)
Do not reach for sudo tio, as the old guide suggested. On Debian and Ubuntu serial ports belong to the dialout group (group 20 in the lab). Once the device was root:dialout with mode 660, the same user connected as soon as it had that group:
$ ls -lL /tmp/ttyA; getent group dialout
crw-rw----. 1 root dialout 136, 0 Nov 1 03:04 /tmp/ttyA
dialout:x:20:
On a real machine run sudo usermod -aG dialout $USER and log in again. Check the group name on your distribution: some use uucp instead.
Set the serial devices line settings: baud, data bits, parity, stop bits
Serial devices only talk when both ends agree on the line settings. The options are -b (baud), -d (data bits 5-8), -p (odd|even|none|mark|space), -s (1 or 2) and -f (hard|soft|none). After connecting, ctrl-t c prints the active configuration, which is the quickest way to prove you typed what you meant:
$ tio -b 9600 -d 7 -p even -s 2 /tmp/ttyA
[03:02:16.381] tio 3.9
[03:02:16.381] Press ctrl-t q to quit
[03:02:16.381] Connected to /tmp/ttyA
[03:02:17.384] Configuration:
[03:02:17.384] Device: /tmp/ttyA
[03:02:17.384] Baudrate: 9600
[03:02:17.384] Databits: 7
[03:02:17.384] Flow: none
[03:02:17.384] Stopbits: 2
[03:02:17.384] Parity: even
If the text from your serial devices is garbage, the usual causes are the wrong baud rate or the wrong parity, so try the speed printed in the device manual first (9600 and 115200 cover most boards).
Key commands, timestamps and local echo for serial devices
Every key command starts with ctrl-t. ctrl-t ? lists them all; the ones you will use most are c (configuration), e (local echo), t (timestamps), f (log to file), L (line states), b (send break) and q (quit). To stamp each line from the start, use -t, and add -e if your device does not echo what you type:
$ tio -t -e /tmp/ttyA
[03:02:18.394] tio 3.9
[03:02:18.394] Press ctrl-t q to quit
[03:02:18.394] Connected to /tmp/ttyA
one
[03:02:19.398] ECHO: one
two
[03:02:20.404] ECHO: two
[03:02:21.407] Disconnected
Hex data and logging for serial devices
The old guide said tio has no hex support and suggested echo -en '\x01\x02' | tio. In fact tio has --output-mode hex to show what the device sends, so the reply ECHO: hi followed by CR LF appears as bytes:
$ tio --output-mode hex /tmp/ttyA
[03:02:21.412] tio 3.9
[03:02:21.412] Press ctrl-t q to quit
[03:02:21.413] Connected to /tmp/ttyA
45 43 48 4f 3a 20 68 69 0d 0a
For input, --input-mode hex takes two hex digits per byte and sends each pair immediately. Spaces and Enter are not hex characters, so tio warns about them; the device still received exactly 01 02 ff:
$ tio --input-mode hex /tmp/ttyA
[03:02:23.428] Connected to /tmp/ttyA
[03:02:24.532] Warning: Invalid hex character: '32' (0x20)
[03:02:24.632] Warning: Invalid hex character: '32' (0x20)
[03:02:24.732] Warning: Invalid hex character: '13' (0x0d)
device received:
00000000: 0102 ff ...
To keep a record, use tio's own logging instead of a shell redirect. -L --log-file name saves what the device sent, and the log holds the device text only, not tio's status lines:
$ tio -L --log-file /tmp/session.log /tmp/ttyA
[03:04:03.550] Saved log to file /tmp/session.log
$ cat -A /tmp/session.log | head
ECHO: logged^M$
Mistakes from older guides to avoid
Three claims about serial devices from the previous version of this article did not hold in the lab:
- Redirect for logging.
tio /dev/ttyS0 > output.log &is not a logging method. With a pipe on stdin and stdout redirected, tio switches to non-interactive mode, and the file contained only tio's status lines. The device had receivedhello(confirmed on its side) but its reply never reached the file:
$ (sleep 1; echo hello; sleep 2) | timeout 6 tio -n /tmp/ttyA > /tmp/output.log; echo ---; cat -A /tmp/output.log
---
^M[03:04:03.598] tio 3.9^M$
^M[03:04:03.598] Non-interactive mode enabled^M$
^M[03:04:03.598] Press ctrl-c to quit^M$
^M[03:04:03.598] Connected to /tmp/ttyA^M$
^M[03:04:06.598] Disconnected^M$
- Using sudo for every connection. Join the
dialoutgroup instead (see above). - Raw bytes by pipe. This does work for sending, and the device saw the three bytes, but you get no reply back, so use an interactive session when you need the reply:
$ echo -en '\x01\x02\x03' | timeout 4 tio -n /tmp/ttyA >/dev/null; xxd /tmp/dev_rx.bin
00000000: 0102 03 ...
Also remember that the names of serial devices differ by hardware: /dev/ttyS* are the motherboard UARTs, while USB adapters usually show up as /dev/ttyUSB* (FTDI, CH340, CP210x) or /dev/ttyACM* (Arduino-style boards). Check dmesg right after plugging the cable in to see which name the kernel gave it.
FAQ
How do I exit tio when serial devices keep sending? Press ctrl-t and then q, as the banner in the first session says.
What happens if the device does not exist? tio prints the warning and waits for it to appear; with -n it stops with an error instead, as shown above.
Are there alternatives for serial devices? Yes: screen, minicom and picocom do the same job. The tio README and manual page at github.com/tio/tio document every option used above.
If you also manage servers over SSH, the guide how to enable SSH on Ubuntu covers the network side of remote access, and checking NVMe SSD temperature shows another hardware check you can do from the same terminal.
Comments
Post a Comment