A serial device I/O tool
tio is a serial device tool which features a straightforward command-line and configuration file interface to easily connect to serial TTY devices for basic I/O operations.
To make a simpler serial device tool for working with serial TTY devices with less focus on classic terminal/modem features and more focus on the needs of embedded developers and hackers.
tio was originally created as an alternative to screen for connecting to serial devices when used in combination with tmux.
For more usage details please see the man page documentation here.
The command-line interface is straightforward as reflected in the output from
tio --help:
…By default tio automatically connects to the provided TTY device. If the device
is not present, tio will wait for it to appear and then connect. If the
connection is lost (e.g. device is unplugged), it will wait for the device to
reappear and then reconnect. However, if the --no-reconnect option is
provided, tio will exit if the device is not present or an established
connection is lost.
Typical use is without options:
$ tio /dev/ttyUSB0Which corresponds to the commonly used default options:
$ tio --baudrate 115200 --databits 8 --flow none --stopbits 1 --parity none /dev/ttyUSB0List available serial devices:
…It is recommended to connect serial TTY devices by ID:
$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTCHUV56-if00-port0Note: Using serial devices by ID helps ensure that tio automatically reconnects to the same serial device when reattached, even when it enumerates differently.
If no serial device by ID is available it is recommended to connect via topology ID (TID):
$ tio bCC2Note: The TID is unique and will stay the same as long as your USB serial port device plugs into the same USB topology (same ports, same hubs, same connections, etc.). This way it is possible for tio to successfully reconnect to the same device.
Connect automatically to first new appearing serial device:
$ tio --auto-connect newConnect automatically to latest registered serial device:
$ tio --auto-connect latestIt is possible to use exclude options to affect which serial devices are involved in the automatic connection strategy:
$ tio --auto-connect new --exclude-devices "/dev/ttyACM?,/dev/ttyUSB2"And to exclude drivers by pattern:
$ tio --auto-connect new --exclude-drivers "cdc_acm,ftdi_sio"Note: Pattern matching supports '*' and '?'. Use comma separation to define multiple patterns.
To include drivers by specific pattern simply negate the exclude option:
$ tio --auto-connect new --exclude-drivers !("cp2102")Log to file with autogenerated filename:
$ tio --log /dev/ttyUSB0Log to file with specific filename:
$ tio --log --log-file my-log.txtEnable ISO8601 timestamps per line:
$ tio --timestamp --timestamp-format iso8601 /dev/ttyUSB0Output to hex with width 16:
$ tio --output-mode hex16 /dev/ttyUSB0Redirect I/O to IPv4 network socket on port 4242:
$ tio --socket inet:4242 /dev/ttyUSB0Map NL to CR-NL on input from device and DEL to BS on output to device:
$ tio --map INLCRNL,ODELBS /dev/ttyUSB0Pipe data to the serial device:
$ cat data.bin | tio /dev/ttyUSB0Manipulate modem lines on connect:
$ tio --script "tio.set{DTR=high,RTS=low}; tio.msleep(100); tio.set{DTR=toggle,RTS=toggle}" /dev/ttyUSB0Pipe command to serial device and wait for line response within 1 second:
$ echo "*IDN?" | tio /dev/ttyACM0 --script "tio.expect('\r\n', 1000)" --mute
KORAD KD3305P V4.2 SN:32475045Various in session key commands are supported. When tio is started, press ctrl-t ? to list the available key commands.
…If needed, the prefix key (ctrl-t) can be remapped via configuration file.
Options can be set via the configuration file first found in any of the following locations in the order listed:
The configuration file supports profiles using named sections which can be activated via the command-line by name or pattern. A profile specifies which TTY device to connect to and other options.
Example configuration file:
…To use a specific profile by name simply start tio like so:
$ tio rpi3Or by pattern match:
$ tio usb12Another more elaborate configuration file example is available here.
Tio suppots Lua scripting to easily automate interaction with the tty device.
In addition to the standard Lua API tio makes the following functions and variables available:
tio.expect(pattern, timeout)Waits for the Lua pattern to match or timeout before continuing. Timeout is in milliseconds, defaults to 0 meaning it will wait forever.
Returns the captures from the pattern or nil on timeout.
tio.read(size, timeout)Read up to size bytes from serial device. If timeout is 0 or not provided it
will wait forever until data is ready to read.
Returns a string up to size bytes long on success and nil on timeout.
tio.readline(timeout)Read line from serial device. If timeout is 0 or not provided it will wait forever until data is ready to read.
Returns a string on success and nil on timeout. On timeout a partially read
line may be returned as a second return value.
tio.write(string)Write string to serial device.
Returns the tio table.
tio.send(file, protocol)Send file using x/y-modem protocol.
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
tio.ttysearch()Search for serial devices.
Returns a table of number indexed tables, one for each serial device found. Each of these tables contains the serial device information accessible via the following string indexed elements "path", "tid", "uptime", "driver", "description".
Returns nil if no serial devices are found.
tio.set{line=state, ...}Set state of one or multiple tty modem lines.
Line can be any of DTR, RTS, CTS, DSR, CD, RI
State is high, low, or toggle.
tio.sleep(seconds)Sleep for seconds.
tio.msleep(ms)Sleep for milliseconds.
tio.alwaysechoA boolean value, defaults to true.
If tio.alwaysecho is false, the result of tio.read, tio.readline or
tio.expect will only be returned from the function and not logged or printed.
If tio.alwaysecho is set to true, reading functions also emit a single
timestamp to stdout and log file per options.timestamp and options.log.
Packages for various GNU/Linux distributions are available. Please consult your package manager tool to find and install tio.
If you would like to see tio included in your favorite distribution, please reach out to its package maintainers team.
Install latest stable version:
$ snap install tio --classicNote: Classic confinement is currently required due to limitations of the snapcraft framework. See Issue #187 for discussion.
If you have brew installed:
$ brew install tioIf you have MSYS2 installed:
$ pacman -S tioThe latest source releases can be found here.
Before running the install steps make sure you have glib and lua libraries installed. For example:
$ sudo apt install libglib2.0-dev liblua5.2-devInstall steps:
$ meson setup build
$ meson compile -C build
$ meson install -C buildSee meson_options.txt for tio specific build options.
Note: The meson install steps may differ depending on your specific system.
Getting permission access errors trying to open your serial device?
Add your user to the group which allows serial device access permanently. For example, to add your user to the 'dialout' group do:
sudo usermod -a -G dialout <username>Switch to the "dialout" group, temporary but immediately for this session.
newgrp dialoutThis is an open source project - all contributions (bug reports, code, doc, ideas, etc.) are welcome.
Please use the github issue tracker and pull request features.
Also, if you find this free open source software useful please feel free to consider making a donation of your choice:
Submit bug reports via GitHub: https://github.com/tio/tio/issues
Visit tio.github.io
tio is GPLv2+. See LICENSE file for more details.
Maintained by Martin Lund <[email protected]>
See the AUTHORS file for full list of contributors.
No open issues yet, or sync has not completed.