serialport-tool 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/bin/cli.js +8 -0
- package/dist/index.js +1284 -0
- package/dist/public/index.html +1931 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hbysgx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Serialport Tool
|
|
2
|
+
|
|
3
|
+
> 串口调试助手 Web 版 - 基于 Bun.js + serialport,浏览器端操作串口
|
|
4
|
+
|
|
5
|
+
 
|
|
6
|
+
|
|
7
|
+
串口调试助手 Web 版:
|
|
8
|
+
- 后端使用 **Bun.js** + `serialport` 库管理串口
|
|
9
|
+
- 前端为纯 HTML/CSS/JS SPA,在浏览器中运行
|
|
10
|
+
- 通过 WebSocket 实现实时串口数据收发
|
|
11
|
+
- **启动时自动打开浏览器**访问对应地址
|
|
12
|
+
|
|
13
|
+
## ✨ 核心特性
|
|
14
|
+
|
|
15
|
+
- 🔌 **完整串口参数** - 波特率 1200~921600 / 数据位 / 校验 / 停止位 / 流控
|
|
16
|
+
- 📋 **预设指令** - 分组管理 + ASCII/HEX 双格式 + ⌘1~⌘9 全局快捷键
|
|
17
|
+
- 📁 **会话管理** - 左侧树状目录,每个会话独立保存完整配置 + 预设
|
|
18
|
+
- 🔄 **自动保存** - 参数变更 0.2s 后自动写回当前会话
|
|
19
|
+
- 📜 **实时日志** - ASCII + HEX 双视图,时间戳,可导出 .txt
|
|
20
|
+
- 🔄 **设备热插拔** - 自动 3s 扫描串口设备
|
|
21
|
+
- 🎯 **本地回显** - 区分 TX(绿) / RX(蓝)
|
|
22
|
+
- 🌐 **浏览器操作** - 启动后在浏览器中使用,无需安装桌面应用
|
|
23
|
+
|
|
24
|
+
## 📦 安装与运行
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 安装依赖
|
|
28
|
+
bun install
|
|
29
|
+
|
|
30
|
+
# 启动 (自动打开浏览器)
|
|
31
|
+
bun run start
|
|
32
|
+
|
|
33
|
+
# 开发模式 (热重载)
|
|
34
|
+
bun run dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
启动后终端显示地址,浏览器会自动打开 `http://localhost:8765`。
|
|
38
|
+
|
|
39
|
+
### 作为 npm 包使用
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# 全局安装
|
|
43
|
+
npm install -g serialport-tool
|
|
44
|
+
|
|
45
|
+
# 运行
|
|
46
|
+
serialport-tool
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 🖥 界面布局
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
┌──────────────┬────────────────────────────────────────────┐
|
|
53
|
+
│ │ ConnectionView — 右上 │
|
|
54
|
+
│ │ 设备/参数/连接按钮/状态 │
|
|
55
|
+
│ ├──────────────┬─────────────────────────────┤
|
|
56
|
+
│ Session │ │ ReceiveView │
|
|
57
|
+
│ Sidebar │ PresetPanel │ (接收区) │
|
|
58
|
+
│ (全高) │ ├─────────────────────────────┤
|
|
59
|
+
│ │ │ SendView │
|
|
60
|
+
│ │ │ (发送区) │
|
|
61
|
+
└──────────────┴──────────────┴─────────────────────────────┘
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## ⌨️ 快捷键
|
|
65
|
+
|
|
66
|
+
| 快捷键 | 功能 |
|
|
67
|
+
|---|---|
|
|
68
|
+
| ⌘O | 连接串口 |
|
|
69
|
+
| ⌘D | 断开串口 |
|
|
70
|
+
| ⌘S | 保存会话 |
|
|
71
|
+
| ⌘1~⌘9 | 发送绑定快捷键的预设指令 |
|
|
72
|
+
| ⌘⇧P | 切换预设面板显隐 |
|
|
73
|
+
| ⌘⇧S | 切换会话侧栏显隐 |
|
|
74
|
+
| ⌘↩ | 发送输入框内容 |
|
|
75
|
+
|
|
76
|
+
## 📁 工程结构
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
serial_tool/
|
|
80
|
+
├── bin/
|
|
81
|
+
│ └── cli.js # CLI 入口 (npm bin)
|
|
82
|
+
├── src/
|
|
83
|
+
│ ├── index.ts # 主入口 — HTTP + WebSocket 服务器
|
|
84
|
+
│ ├── serial-port.ts # 串口管理 (serialport 封装)
|
|
85
|
+
│ ├── app-config.ts # 应用配置 (持久化)
|
|
86
|
+
│ ├── preset-store.ts # 预设指令管理
|
|
87
|
+
│ ├── session-store.ts # 会话管理 (树状文件系统)
|
|
88
|
+
│ └── public/
|
|
89
|
+
│ └── index.html # 前端 SPA
|
|
90
|
+
├── package.json
|
|
91
|
+
├── tsconfig.json
|
|
92
|
+
└── README.md
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 💾 持久化策略
|
|
96
|
+
|
|
97
|
+
### 配置 (`~/.serial_tool/config.json`)
|
|
98
|
+
|
|
99
|
+
所有串口参数、视图设置保存在 JSON 文件中,启动时自动恢复。
|
|
100
|
+
|
|
101
|
+
### 会话 (`~/.serial_tool/sessions/`)
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
~/.serial_tool/sessions/
|
|
105
|
+
├── <session-name>.json # 会话 A (含配置快照 + 预设 + 日志)
|
|
106
|
+
├── <folder>/ # 自定义目录
|
|
107
|
+
│ └── <session>.json # 目录中的会话
|
|
108
|
+
└── ...
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
每个会话 JSON 包含完整的配置快照、预设分组、日志条目。
|
|
112
|
+
|
|
113
|
+
### 预设 (`~/.serial_tool/presets.json`)
|
|
114
|
+
|
|
115
|
+
全局预设文件。会话加载时会话级预设独立存储在会话 JSON 中。
|
|
116
|
+
|
|
117
|
+
## 🎯 核心使用流程
|
|
118
|
+
|
|
119
|
+
1. 启动 `serialport-tool` → 浏览器自动打开
|
|
120
|
+
2. 左侧点 `+` 新建会话(如"我的ESP32")
|
|
121
|
+
3. 顶栏选择串口设备 + 波特率 115200
|
|
122
|
+
4. 点 **连接**
|
|
123
|
+
5. 预设面板中添加预设指令,可选绑定快捷键
|
|
124
|
+
6. 一切变更自动保存到会话
|
|
125
|
+
|
|
126
|
+
## 🔧 串口权限
|
|
127
|
+
|
|
128
|
+
如果提示无法打开设备:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# 查看设备
|
|
132
|
+
ls -la /dev/cu.*
|
|
133
|
+
|
|
134
|
+
# 加入 uucp 组 (macOS)
|
|
135
|
+
sudo dseditgroup -o edit -a $(whoami) -t user _uucp
|
|
136
|
+
|
|
137
|
+
# Linux
|
|
138
|
+
sudo usermod -a -G dialout $(whoami)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 📝 License
|
|
142
|
+
|
|
143
|
+
MIT
|