You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Bash脚本自动化Minicom记录Arduino串口数据的启停?

自动化Minicom录制Arduino串口数据的脚本方案

实现思路

借助expect工具模拟手动操作Minicom的按键流程,完成自动启动串口连接、开启录制、等待指定时长后停止录制并退出的全自动化操作。

完整脚本代码

#!/usr/bin/expect

# 配置参数,按需修改
set serial_port "/dev/cu.usbserial-1420"
set baud_rate 115200
set record_duration 2 ;# 录制时长(单位:秒)
set output_file "minicom.cap" ;# 自定义输出文件名

# 启动Minicom,指定串口、波特率与输出文件
spawn minicom -D $serial_port -b $baud_rate -C $output_file

# 等待Minicom启动,调出菜单(Ctrl+A+Z)
send "\001z"
expect "*Minicom*"

# 开始录制(模拟Shift+L,输入大写L即可)
send "L"
expect "*Capture started*"

# 等待设定的录制时长
sleep $record_duration

# 再次调出菜单并停止录制
send "\001z"
expect "*Minicom*"
send "L"
expect "*Capture stopped*"

# 退出Minicom
send "x"
expect eof

使用步骤

  1. 安装expect工具:
    • Ubuntu/Debian 系统:sudo apt update && sudo apt install expect
    • macOS:brew install expect(需先安装Homebrew)
  2. 将脚本保存为auto_serial_record.sh
  3. 赋予执行权限:chmod +x auto_serial_record.sh
  4. 运行脚本:./auto_serial_record.sh

自定义说明

  • 可直接修改脚本开头的配置参数,调整串口设备、波特率、录制时长或输出文件名
  • 若无需指定自定义输出文件,删除-C $output_file参数即可,默认生成minicom.cap文件

内容的提问来源于stack exchange,提问作者ecjb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 05:25:13