Split the manual into a README index plus docs/ sections covering hardware selection, Linux and Windows serial servers, shared frpc configuration via env templating, client testing, security, and troubleshooting. Store real frpc credentials in an ignored .env and track images with Git LFS. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
103 lines
2.5 KiB
Markdown
103 lines
2.5 KiB
Markdown
[返回首页](../README.md)
|
||
|
||
# RFC 2217 客户端端到端测试
|
||
|
||
本文用于从远程客户端验证完整的 RFC 2217 链路:客户端通过 FRP 公网端点连接串口服务,完成 RFC 2217 协商、双向数据传输和远程串口参数修改。
|
||
|
||
## 准备 pySerial
|
||
|
||
Linux 或其他通常以 `python3` 启动 Python 的环境:
|
||
|
||
```bash
|
||
python3 -m pip install pyserial
|
||
```
|
||
|
||
Windows PowerShell:
|
||
|
||
```powershell
|
||
py -m pip install pyserial
|
||
```
|
||
|
||
## 使用 miniterm 连接
|
||
|
||
Linux:
|
||
|
||
```bash
|
||
python3 -m serial.tools.miniterm \
|
||
rfc2217://FRPS_HOST:2217 \
|
||
9600
|
||
```
|
||
|
||
Windows PowerShell:
|
||
|
||
```powershell
|
||
py -m serial.tools.miniterm "rfc2217://FRPS_HOST:2217" 9600
|
||
```
|
||
|
||
将 `FRPS_HOST`、端口 `2217` 和初始波特率 `9600` 替换为实际部署值。
|
||
|
||
对于需要轮询调制解调器状态的设备,pySerial URL 可使用:
|
||
|
||
```text
|
||
rfc2217://FRPS_HOST:2217?poll_modem
|
||
```
|
||
|
||
## 显式测试远程波特率修改
|
||
|
||
保存并运行以下 Python 脚本:
|
||
|
||
```python
|
||
import serial
|
||
|
||
port = serial.serial_for_url(
|
||
"rfc2217://FRPS_HOST:2217",
|
||
baudrate=9600,
|
||
timeout=1,
|
||
)
|
||
|
||
print("Initial baud rate:", port.baudrate)
|
||
port.baudrate = 19200
|
||
print("Changed baud rate:", port.baudrate)
|
||
|
||
port.write(b"test\r\n")
|
||
print(port.read(100))
|
||
port.close()
|
||
```
|
||
|
||
Linux 运行方式:
|
||
|
||
```bash
|
||
python3 baud_test.py
|
||
```
|
||
|
||
Windows PowerShell 运行方式:
|
||
|
||
```powershell
|
||
py .\baud_test.py
|
||
```
|
||
|
||
执行 `port.baudrate = 19200` 时,pySerial 会发送 RFC 2217 控制命令。该命令经 FRP 转发后,应由串口服务器应用到 Linux 串口设备或 Windows COM 端口。不要只检查脚本中的属性值;还应确认物理串口确实切换到对应波特率。
|
||
|
||
## 端到端验收项目
|
||
|
||
至少验证以下项目:
|
||
|
||
1. RFC 2217 协商成功。
|
||
2. 串口数据可以双向传输。
|
||
3. 客户端修改波特率时,物理串口参数随之改变。
|
||
4. 断开后可以重新连接。
|
||
5. USB 串口转换器拔出并重新插入后,服务能够恢复。
|
||
6. 重启后,设备与串口服务的映射仍然正确。
|
||
|
||
## 为什么 TCP 可达不等于 RFC 2217 可用
|
||
|
||
普通 `telnet`、裸 TCP 客户端或端口探测只能证明 TCP 连接能够建立,不能验证 RFC 2217 协商,也不能验证远程波特率等串口控制功能。测试客户端必须实现 RFC 2217。
|
||
|
||
例如,Windows 上的下列命令只验证 TCP 可达性:
|
||
|
||
```powershell
|
||
Test-NetConnection FRPS_HOST -Port 2217
|
||
```
|
||
|
||
即使该命令成功,仍必须使用 pySerial/miniterm 和波特率修改脚本完成上述端到端测试。
|