serial
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSerial — 嵌入式串口调试工具
Serial — Embedded Serial Port Debugging Tool
统一封装端口发现、实时监控、数据发送、日志记录和 Hex 查看能力。
Unified encapsulation of port discovery, real-time monitoring, data sending, log recording, and Hex viewing capabilities.
配置
Configuration
环境级配置 (skill/config.json
)
skill/config.jsonEnvironment-level Configuration (skill/config.json
)
skill/config.jsonserial skill 的环境级配置目前为空对象 ,因为串口参数属于工程级配置,统一在工作区的 中管理。
{}.embeddedskills/config.jsonThe environment-level configuration for the serial skill is currently an empty object since serial port parameters belong to project-level configuration and are managed uniformly in of the workspace.
{}.embeddedskills/config.json工程级配置 (.embeddedskills/config.json
)
.embeddedskills/config.jsonProject-level Configuration (.embeddedskills/config.json
)
.embeddedskills/config.json工作区下的 存放工程级串口配置:
.embeddedskills/config.jsonjson
{
"serial": {
"port": "",
"baudrate": 115200,
"bytesize": 8,
"parity": "none",
"stopbits": 1,
"encoding": "utf-8",
"timeout_sec": 1.0,
"log_dir": ".embeddedskills/logs/serial"
}
}| 字段 | 说明 | 默认值 |
|---|---|---|
| 串口号,如 | |
| 波特率 | |
| 数据位 | |
| 校验位:none/even/odd/mark/space | |
| 停止位:1/1.5/2 | |
| 文本编码 | |
| 读写超时(秒) | |
| 日志输出目录 | |
The under the workspace stores project-level serial port configurations:
.embeddedskills/config.jsonjson
{
"serial": {
"port": "",
"baudrate": 115200,
"bytesize": 8,
"parity": "none",
"stopbits": 1,
"encoding": "utf-8",
"timeout_sec": 1.0,
"log_dir": ".embeddedskills/logs/serial"
}
}| Field | Description | Default Value |
|---|---|---|
| Serial port number, e.g., | |
| Baud rate | |
| Data bits | |
| Parity: none/even/odd/mark/space | |
| Stop bits: 1/1.5/2 | |
| Text encoding | |
| Read/write timeout (seconds) | |
| Log output directory | |
参数解析优先级
Parameter Parsing Priority
- CLI 参数 (,
--port等) - 最高优先级--baudrate - 工程级配置 (中的
.embeddedskills/config.json部分)serial - 状态文件 (中的历史记录)
.embeddedskills/state.json - 默认值 - 最低优先级
- CLI parameters (,
--port, etc.) - Highest priority--baudrate - Project-level configuration (the section in
serial).embeddedskills/config.json - State file (historical records in )
.embeddedskills/state.json - Default values - Lowest priority
自动扫描行为
Automatic Scanning Behavior
当未指定 时,脚本会自动扫描系统串口:
port- 若只找到一个串口,自动使用该端口并写入工程配置
- 若找到多个串口,返回候选列表让用户选择(通过 指定)
--port - 若未找到串口,提示错误
When is not specified, the script automatically scans system serial ports:
port- If only one serial port is found, it is automatically used and written to the project configuration
- If multiple serial ports are found, a candidate list is returned for the user to select (specify via )
--port - If no serial ports are found, an error is prompted
子命令
Subcommands
| 子命令 | 用途 | 风险 |
|---|---|---|
| 扫描可用串口 | 低 |
| 实时查看文本输出 | 低 |
| 发送文本或 Hex 数据 | 中 |
| 实时查看二进制流 | 低 |
| 保存串口日志到文件 | 低 |
| Subcommand | Purpose | Risk |
|---|---|---|
| Scan available serial ports | Low |
| View text output in real-time | Low |
| Send text or Hex data | Medium |
| View binary stream in real-time | Low |
| Save serial port logs to files | Low |
执行流程
Execution Flow
- 检查 是否可用,未安装时提示
pyserialpip install pyserial - 按优先级解析参数:CLI > 工程级配置 > 状态文件 > 默认值
- 无子命令时默认执行
scan - 使用解析后的连接参数
monitor / send / hex / log - 若未指定 ,自动扫描系统串口:
port- 唯一候选:自动使用并写入工程配置
- 多候选:返回列表让用户选择
- 成功执行后,将确认的参数写回工程配置
- 运行对应脚本并输出结构化结果
- 失败时优先反馈端口占用、驱动、波特率和编码问题
- Check if is available; prompt
pyserialif not installedpip install pyserial - Parse parameters by priority: CLI > Project-level configuration > State file > Default values
- Execute by default when no subcommand is specified
scan - use the parsed connection parameters
monitor / send / hex / log - If is not specified, automatically scan system serial ports:
port- Unique candidate: automatically use and write to project configuration
- Multiple candidates: return list for user selection
- After successful execution, write the confirmed parameters back to the project configuration
- Run the corresponding script and output structured results
- When failed, prioritize feedback on port occupation, driver, baud rate, and encoding issues
脚本调用
Script Invocation
所有脚本位于 skill 目录的 下,通过 直接调用。
脚本会按优先级从 CLI 参数、工程级配置、状态文件中读取参数。
scripts/pythonbash
undefinedAll scripts are located in the directory of the skill, and can be directly called via .
Scripts read parameters from CLI parameters, project-level configuration, and state files according to priority.
scripts/pythonbash
undefined扫描串口
Scan serial ports
python scripts/serial_scan.py [--filter <关键词>] [--json]
python scripts/serial_scan.py [--filter <keyword>] [--json]
实时监控
Real-time monitoring
python scripts/serial_monitor.py [--port <串口>] [--baudrate <波特率>] [--timestamp] [--filter <regex>] [--timeout <秒>] [--json]
python scripts/serial_monitor.py [--port <serial port>] [--baudrate <baud rate>] [--timestamp] [--filter <regex>] [--timeout <seconds>] [--json]
发送数据
Send data
python scripts/serial_send.py [--port <串口>] [--baudrate <波特率>] <data> [--hex] [--crlf] [--repeat <次>] [--wait-response] [--json]
python scripts/serial_send.py [--port <serial port>] [--baudrate <baud rate>] <data> [--hex] [--crlf] [--repeat <times>] [--wait-response] [--json]
Hex 查看
Hex viewing
python scripts/serial_hex.py [--port <串口>] [--baudrate <波特率>] [--width <列>] [--timeout <秒>] [--json]
python scripts/serial_hex.py [--port <serial port>] [--baudrate <baud rate>] [--width <columns>] [--timeout <seconds>] [--json]
日志记录
Log recording
python scripts/serial_log.py [--port <串口>] [--baudrate <波特率>] [--output <文件>] [--duration <秒>] [--format text|csv|json] [--json]
undefinedpython scripts/serial_log.py [--port <serial port>] [--baudrate <baud rate>] [--output <file>] [--duration <seconds>] [--format text|csv|json] [--json]
undefined输出格式
Output Format
单次命令返回标准 JSON:
json
{
"status": "ok",
"action": "scan",
"summary": "发现 2 个串口",
"details": { ... }
}持续命令(monitor --json、hex --json)输出 JSON Lines,结束摘要写入 stderr。
错误输出:
json
{
"status": "error",
"action": "monitor",
"error": { "code": "port_busy", "message": "串口被其他程序占用" }
}Single command returns standard JSON:
json
{
"status": "ok",
"action": "scan",
"summary": "Found 2 serial ports",
"details": { ... }
}Continuous commands (monitor --json, hex --json) output JSON Lines, and the end summary is written to stderr.
Error output:
json
{
"status": "error",
"action": "monitor",
"error": { "code": "port_busy", "message": "Serial port is occupied by another program" }
}核心规则
Core Rules
- 不自动猜测端口和波特率,发现多个候选串口时不自动选择
- 参数解析优先级:CLI > 工程级配置 > 状态文件 > 默认值
- 未指定 时自动扫描,唯一候选自动写入配置,多候选需用户选择
port - 成功执行后,确认的参数自动写回
.embeddedskills/config.json - 未明确说明用途时不主动发送任何串口数据
- 输出的持续流使用 JSON Lines,摘要写 stderr 不污染数据流
--json - 正则过滤失败不应导致监控退出
- Do not automatically guess ports and baud rates; do not automatically select when multiple candidate serial ports are found
- Parameter parsing priority: CLI > Project-level configuration > State file > Default values
- Automatically scan when is not specified; automatically write the unique candidate to configuration, require user selection for multiple candidates
port - After successful execution, automatically write confirmed parameters back to
.embeddedskills/config.json - Do not actively send any serial port data when the purpose is not clearly stated
- Continuous streams of output use JSON Lines, and summaries are written to stderr without polluting the data stream
--json - Regular expression filtering failure should not cause monitoring to exit
参考
References
- :常见 USB 转串口芯片 VID/PID 映射
references/common_devices.json
- : VID/PID mapping of common USB-to-serial chips
references/common_devices.json