Files
scanner_record/project/test/README-PLC.md
T
2026-06-09 14:32:13 +08:00

46 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# PLC 通信诊断说明
## 运行诊断
```bash
npm run test:plc -- <IP地址> [机架号] [槽号]
# 例:
npm run test:plc -- 192.168.11.111 0 1
```
## 诊断输出说明
| 步骤 | 检查项目 | 成功标志 |
|------|---------|---------|
| 1 | node-snap7 模块加载 | `✓ module loaded` |
| 2 | S7Client 实例化 | `✓ S7Client 实例化成功` |
| 3 | ConnectTo 直连 | 返回码 0 = 成功 |
| 4 | SetConnectionParams + Connect 备选 | 同上 |
| 5 | 版本和绑定信息汇总 | — |
## 常见问题
### TypeError: Wrong arguments
`node-snap7` 的 C++ 绑定与当前 Node.js 版本 ABI 不兼容。
**已知兼容版本:** Node.js 18.x / 20.x / 22.x / 24.x
**不兼容:** Node.js >= 25
**解决方案 A — 降级 Node:**
```bash
nvm install 22
nvm use 22
npm rebuild node-snap7
```
**解决方案 B — 使用 koffi FFI(不限制 Node 版本):**
(开发中)
## 连接参数
- 西门子 S7-1200: rack=0, slot=1
- 西门子 S7-1500: rack=0, slot=1
- 西门子 S7-300: rack=0, slot=2
- 西门子 S7-400: rack=0, slot=3