- 8B PDO config: ULINT-sized payload, no 0x1A01 diag PDO on SM3 (device rejected SM3=8 with diag assigned: 'size not allowed, min/max 0xa') - twin_layout_blob_sized(): single 64-bit mapping entry for 8B payloads - Ticker: per-byte XOR 0x5A transform in 8B mode so TwinCAT can verify every byte individually (1KB path unchanged, const-guarded) - TwinCAT automation scripts: deploy with RPC retry, LinkVariables-based whole-array relink (element links only carry 1 byte), ADS watch, diag - Docs: 8B design, verification methodology, test report
77 lines
2.5 KiB
Markdown
77 lines
2.5 KiB
Markdown
# 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
|
||
```
|