
TIO是一种串行设备工具,具有直接的命令行和配置文件接口,可轻松连接到基本I/O操作的串行TTY设备。

为了制作一个更简单的串行设备工具,用于使用串行TTY设备,较少关注经典终端/调制解调器功能,并更多地关注嵌入式开发人员和黑客的需求。
TIO最初是作为屏幕的替代方法,用于与TMUX结合使用时连接到串行设备。
有关更多用法详细信息,请在此处查看MAN页面文档。
命令行接口很简单,如tio --help的输出所反映:
Usage: tio [<options>] <tty-device|profile|tid>
Connect to TTY device directly or via configuration profile or topology ID.
Options:
-b, --baudrate <bps> Baud rate (default: 115200)
-d, --databits 5|6|7|8 Data bits (default: 8)
-f, --flow hard|soft|none Flow control (default: none)
-s, --stopbits 1|2 Stop bits (default: 1)
-p, --parity odd|even|none|mark|space Parity (default: none)
-o, --output-delay <ms> Output character delay (default: 0)
-O, --output-line-delay <ms> Output line delay (default: 0)
--line-pulse-duration <duration> Set line pulse duration
-a, --auto-connect new|latest|direct Automatic connect strategy (default: direct)
--exclude-devices <pattern> Exclude devices by pattern
--exclude-drivers <pattern> Exclude drivers by pattern
--exclude-tids <pattern> Exclude topology IDs by pattern
-n, --no-reconnect Do not reconnect
-e, --local-echo Enable local echo
--input-mode normal|hex|line Select input mode (default: normal)
--output-mode normal|hex|hexN Select output mode (default: normal)
-t, --timestamp Enable line timestamp
--timestamp-format <format> Set timestamp format (default: 24hour)
--timestamp-timeout <ms> Set timestamp timeout (default: 200)
-l, --list List available serial devices, TIDs, and profiles
-L, --log Enable log to file
--log-file <filename> Set log filename
--log-directory <path> Set log directory path for automatic named logs
--log-append Append to log file
--log-strip Strip control characters and escape sequences
-m, --map <flags> Map characters
-c, --color 0..255|bold|none|list Colorize tio text (default: bold)
-S, --socket <socket> Redirect I/O to socket
--rs-485 Enable RS-485 mode
--rs-485-config <config> Set RS-485 configuration
--alert bell|blink|none Alert on connect/disconnect (default: none)
--mute Mute tio messages
--script <string> Run script from string
--script-file <filename> Run script from file
--script-run once|always|never Run script on connect (default: always)
--exec <command> Execute shell command with I/O redirected to device
-v, --version Display version
-h, --help Display help
Options and profiles may be set via configuration file.
In session you can press ctrl-t ? to list available key commands.
See the man page for more details.
默认情况下,TIO会自动连接到提供的TTY设备。如果不存在设备,则TIO将等待它出现,然后连接。如果丢失了连接(例如设备被拔下),则将等待设备重新出现然后重新连接。但是,如果提供了--no-reconnect选项,则如果不存在设备或丢失了已建立的连接,则TIO将退出。
典型的用途是没有选项:
$ tio /dev/ttyUSB0
对应于常用的默认选项:
$ tio --baudrate 115200 --databits 8 --flow none --stopbits 1 --parity none /dev/ttyUSB0
列表可用串行设备:
$ tio --list
Device TID Uptime [s] Driver Description
----------------- ---- ------------- ---------------- --------------------------
/dev/ttyS4 BaaB 19526.576 port 16550A UART
/dev/ttyS5 eV0Z 19525.845 port 16550A UART
/dev/ttyUSB1 bCC2 1023.274 ftdi_sio TTL232R-3V3
/dev/ttyUSB0 SPpw 978.527 ftdi_sio TTL232RG-VREG3V3
/dev/ttyACM0 i5q4 2.079 cdc_acm ST-Link VCP Ctrl
By-id
--------------------------------------------------------------------------------
/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTCHUV56-if00-port0
/dev/serial/by-id/usb-FTDI_TTL232RG-VREG3V3_FT1NELUB-if00-port0
/dev/serial/by-id/usb-STMicroelectronics_STLINK-V3_004900343438510234313939-if02
By-path
--------------------------------------------------------------------------------
/dev/serial/by-path/pci-0000:00:14.0-usb-0:8.1.3.1.4:1.0-port0
/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:8.1.3.1.4:1.0-port0
/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:6.4:1.0-port0
/dev/serial/by-path/pci-0000:00:14.0-usb-0:6.4:1.0-port0
/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:6.3:1.2
/dev/serial/by-path/pci-0000:00:14.0-usb-0:6.3:1.2
Configuration profiles (/home/lundmar/.config/tio/config)
--------------------------------------------------------------------------------
rpi3 stm32 esp32 am64-evm
imx8mp-evk nucleo-h743zi2 usb-devices
建议通过ID连接串行TTY设备:
$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTCHUV56-if00-port0
注意:使用ID串行设备有助于确保重新连接时TIO自动重新连接到同一串行设备,即使它以不同的方式枚举。
如果没有可用ID的串行设备,建议通过拓扑ID(TID)连接:
$ tio bCC2
注意:TID是唯一的,只要您的USB串行端口设备插入相同的USB拓扑(相同的端口,相同的集线器,相同的连接等),将保持相同的时间。这样,TIO可以成功重新连接到同一设备。
自动连接到第一个新的出现串行设备:
$ tio --auto-connect new
自动连接到最新的注册串行设备:
$ tio --auto-connect latest
可以使用排除选项来影响自动连接策略中涉及哪些串行设备:
$ tio --auto-connect new --exclude-devices "/dev/ttyACM?,/dev/ttyUSB2"
并按模式排除驱动程序:
$ tio --auto-connect new --exclude-drivers "cdc_acm,ftdi_sio"
注意:模式匹配支持'*'和'?'。使用逗号分隔来定义多种模式。
要按特定模式包括驱动程序,只需否定排除选项:
$ tio --auto-connect new --exclude-drivers !("cp2102")
登录以自动化文件名提交文件:
$ tio --log /dev/ttyUSB0
登录以特定文件名提交文件:
$ tio --log --log-file my-log.txt
每行启用ISO8601时间戳:
$ tio --timestamp --timestamp-format iso8601 /dev/ttyUSB0
输出宽度16的十六进制:
$ tio --output-mode hex16 /dev/ttyUSB0
将I/O重定向到端口4242上的IPv4网络套接字:
$ tio --socket inet:4242 /dev/ttyUSB0
管道数据到串行设备:
$ cat data.bin | tio /dev/ttyUSB0
连接上操纵调制解调器线:
$ tio --script "set{DTR=high,RTS=low}; msleep(100); set{DTR=toggle,RTS=toggle}" /dev/ttyUSB0
管道命令到串行设备,并在1秒内等待线路响应:
$ echo "*IDN?" | tio /dev/ttyACM0 --script "expect('rn', 1000)" --mute
KORAD KD3305P V4.2 SN:32475045
支持各种会话密钥命令。当Tio启动时,按CTRL-T?列出可用的密钥命令。
[15:02:53.269] Key commands:
[15:02:53.269] ctrl-t ? List available key commands
[15:02:53.269] ctrl-t b Send break
[15:02:53.269] ctrl-t c Show configuration
[15:02:53.269] ctrl-t e Toggle local echo mode
[15:02:53.269] ctrl-t f Toggle log to file
[15:02:53.269] ctrl-t F Flush data I/O buffers
[15:02:53.269] ctrl-t g Toggle serial port line
[15:02:53.269] ctrl-t i Toggle input mode
[15:02:53.269] ctrl-t l Clear screen
[15:02:53.269] ctrl-t L Show line states
[15:02:53.269] ctrl-t m Change mapping of characters on input or output
[15:02:53.269] ctrl-t o Toggle output mode
[15:02:53.269] ctrl-t p Pulse serial port line
[15:02:53.269] ctrl-t q Quit
[15:02:53.269] ctrl-t r Run script
[15:02:53.269] ctrl-t R Execute shell command with I/O redirected to device
[15:02:53.269] ctrl-t s Show statistics
[15:02:53.269] ctrl-t t Toggle line timestamp mode
[15:02:53.269] ctrl-t v Show version
[15:02:53.269] ctrl-t x Send file via Xmodem
[15:02:53.269] ctrl-t y Send file via Ymodem
[15:02:53.269] ctrl-t ctrl-t Send ctrl-t character
如果需要,可以通过配置文件重新映射前缀密钥(CTRL-T)。
可以通过列出的顺序中的任何一个位置中的任何一个位置中首先在以下任何位置中找到选项:
配置文件使用命名部分支持配置文件,这些部分可以通过名称或模式通过命令行激活。配置文件指定要连接到哪些TTY设备以及其他选项。
示例配置文件:
[default]
baudrate = 115200
databits = 8
parity = none
stopbits = 1
color = 10
[rpi3]
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
no-reconnect = true
log = true
log-file = rpi3.log
line-pulse-duration = DTR=200,RTS=150
color = 11
[svf2]
device = /dev/ttyUSB0
baudrate = 9600
script = expect("login: "); write("rootn"); expect("Password: "); write("rootn")
color = 12
[esp32]
device = /dev/serial/by-id/usb-0403_6014-if00-port0
script = set{DTR=high,RTS=low}; msleep(100); set{DTR=low,RTS=high}; msleep(100); set{RTS=low}
script-run = once
color = 13
[usb-devices]
pattern = ^usb([0-9]*)
device = /dev/ttyUSB%m1
color = 14
要使用名称的特定配置文件,只需这样的启动TIO:
$ tio rpi3
或按模式匹配:
$ tio usb12
另一个更精致的配置文件示例此处可用。
Tio Suppots lua脚本可轻松自动与TTY设备的交互作用。
除了LUA API TIO之外,还可以提供以下功能:
expect(string, timeout)
Expect string - waits for string to match or timeout before continueing.
Supports regular expressions. Special characters must be escaped with '\'.
Timeout is in milliseconds, defaults to 0 meaning it will wait forever.
Returns 1 on successful match, 0 on timeout, or -1 on error.
On successful match it also returns the match string as second return value.
read(size, timeout)
Read from serial device. If timeout is 0 or not provided it will wait
forever until data is ready to read.
Returns number of bytes read on success, 0 on timeout, or -1 on error.
On success, returns read string as second return value.
read_line(timeout)
Read line from serial device. If timeout is 0 or not provided it will
wait forever until data is ready to read.
Returns number of bytes read on success, 0 on timeout, or -1 on error.
On success, returns the string that was read as second return value.
Also emits a single timestamp to stdout and log file per options.timestamp
and options.log.
write(string)
Write string to serial device.
Returns number of bytes written on success or -1 on error.
send(file, protocol)
Send file using x/y-modem protocol.
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
tty_search()
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.
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.
sleep(seconds)
Sleep for seconds.
msleep(ms)
Sleep for miliseconds.
exit(code)
Exit with exit code.
提供各种GNU/Linux发行版的软件包。请咨询您的包装管理器工具以查找和安装TIO。
如果您想看到您喜欢的发行版中包含的TIO,请与其包装维护者团队联系。
安装最新稳定版本:
$ snap install tio --classic
注意:由于Snapcraft框架的局限性,目前需要经典限制。有关讨论,请参见第187期。
如果您安装了啤酒:
$ brew install tio
如果已安装MSYS2:
$ pacman -S tio
最新的源版本可以在此处找到。
在运行安装步骤之前,请确保安装了GLIB和LUA库。例如:
$ sudo apt install libglib2.0-dev liblua5.2-dev
安装步骤:
$ meson setup build
$ meson compile -C build
$ meson install -C build
有关TIO特定的构建选项,请参见Meson_options.txt。
注意:介子安装步骤可能会根据您的特定系统而有所不同。
获得许可访问错误试图打开串行设备?
将您的用户添加到允许串行设备永久访问的组中。例如,要将用户添加到“拨号”组中:
sudo usermod -a -G dialout < username >切换到“拨号”组,临时但立即进行本次会议。
newgrp dialout这是一个开源项目 - 欢迎所有贡献(错误报告,代码,文档,想法等)。
请使用GitHub问题跟踪器并提取请求功能。
另外,如果您发现此免费的开源软件有用,请随时考虑对您的选择捐款:

通过GitHub提交错误报告:https://github.com/tio/tio/issues
访问tio.github.io
TIO是GPLV2+。有关更多详细信息,请参见许可证文件。
由Martin Lund <[email protected]>维护
有关贡献者的完整列表,请参见作者文件。