ethercat-linux/scripts/README.md

77 lines
2.5 KiB
Markdown
Raw Normal View History

# TwinCAT 自动化基础脚本
路径: `C:\Users\tonycao\work\ethercat-linux\scripts\`
## 脚本清单
| 脚本 | 功能 | 用途 |
|------|------|------|
| `tc-common.ps1` | 共享函数库 | 被 other 脚本 source不单独运行 |
| `tc-register.ps1` | 注册 COM 组件 | 首次使用时运行一次 |
| `tc-activate.ps1` | 激活配置 | `$sysMgr.ActivateConfiguration()` + `StartRestartTwinCAT()` |
| `tc-configure-pdo.ps1` | 配置 EL6695 PDO | ConsumeXml 注入 1024 字节 PDO |
| `tc-verify.ps1` | 验证配置 | 导出 EL6695 XML检查 PDO entries |
| `tc-scan.ps1` | 扫描 EtherCAT | 在线扫描总线设备 |
| `tc-switch-target.ps1` | 切换目标 NetID | 修改项目目标地址 |
| `tc-deploy.ps1` | 全流程编排 | configure → activate → verify |
## 快速使用
### 首次使用
```powershell
# 1. 注册 COM 组件(管理员 PowerShell
.\scripts\tc-register.ps1
# 2. 全流程部署(配置 PDO + 激活 + 验证)
.\scripts\tc-deploy.ps1
```
### 日常操作
```powershell
# 仅激活配置PDO 已在 tsproj 中配好)
.\scripts\tc-activate.ps1
# 验证当前配置
.\scripts\tc-verify.ps1
# 扫描总线
.\scripts\tc-scan.ps1
```
### EL6695 1KB PDO 完整流程
```powershell
# 1. TwinCAT 侧:部署 + 激活
.\scripts\tc-deploy.ps1
# 2. J1900 侧:存储 EEPROM通过 SSH
ssh root@J1900 'echo 73617665 | xxd -r -p > /tmp/save.bin'
# 或通过 el6695_rt 的 verify 模式观察
# 3. J1900 侧:软复位 + Consumer 验证
ssh root@J1900 '/root/gateway/el6695_rt eth1 --consumer --mode verify'
```
## 关键设计决策
### 为什么用 `ActivateConfiguration()` 而不是 `ExecuteCommand("TwinCAT.激活配置")`
DTE 的 `ExecuteCommand` 使用本地化命令名(中文环境是 `TwinCAT.激活配置`
编码/语言版本不同时容易出错。`ITcSysManager.ActivateConfiguration()` 是
automation interface 的直接方法调用,与语言无关。
### 为什么用 TcSysManCmdHelper 做 PDO 配置?
ConsumeXml 是 Beckhoff 官方 CLI 工具支持的 XML 注入方式,
不需要打开 DTE 窗口,适合脚本化。
### 默认路径
```
Solution: C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\TwinCAT_EL6695_Secondary.sln
Tsproj: C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\TwinCAT_EL6695_Secondary.tsproj
Logs: C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\Logs\
Target: 10.0.0.106.1.1 (local UmRT)
```
可通过参数覆盖,如:
```powershell
.\scripts\tc-activate.ps1 -Solution "C:\other\path.sln" -TargetNetId 10.0.0.111.1.1
```