ethercat-linux/scripts/tc-activate-restart.ps1
Tony Cao 309aaba342 EL6695 8-byte bidirectional exchange with per-byte verification
- 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
2026-07-27 19:01:05 +08:00

82 lines
2.5 KiB
PowerShell

#Requires -Version 5.1
[CmdletBinding()]
param(
[string]$Solution = $null,
[string]$TargetNetId = "10.0.0.106.1.1"
)
. "$PSScriptRoot\tc-common.ps1"
if (-not $Solution) { $Solution = $script:DefaultTsproj }
New-Log $script:DefaultLogDir
$LogFile = Join-Path $script:DefaultLogDir "activate-restart.log"
Write-Log "=== Activate + Restart TwinCAT (direct TcSysManager) ===" $LogFile
# 1. Open project using TcSysManCmdHelper (avoids DTE COM issues)
$helper = "C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\TcSysManCmdHelper.exe"
Write-Log "Opening project with TcSysManCmdHelper..." $LogFile
& $helper -v 4026.0 -o $Solution 2>&1 | Tee-Object -FilePath $LogFile -Append
Write-Log "Open exit code: $LASTEXITCODE" $LogFile
# 2. Get TcSysManager COM object directly (not via DTE.Object)
function Get-TcSysManagerDirect {
$progIds = @("TcSysManager", "TcXaeShell.TcSysManager", "TcXaeMgmt.TcSysManager", "TwinCAT.SystemManager")
foreach ($id in $progIds) {
try {
$obj = [System.Runtime.InteropServices.Marshal]::GetActiveObject($id)
if ($obj) { return @{ Object = $obj; ProgId = $id } }
} catch { }
try {
$obj = New-Object -ComObject $id -ErrorAction Stop
if ($obj) { return @{ Object = $obj; ProgId = $id } }
} catch { }
}
return $null
}
$smInfo = Get-TcSysManagerDirect
if (-not $smInfo) {
Write-Log "FATAL: Cannot get TcSysManager COM object" $LogFile
Write-Error "Cannot get TcSysManager COM object"
exit 1
}
Write-Log "TcSysManager obtained via $($smInfo.ProgId)" $LogFile
$sysMgr = $smInfo.Object
try {
# Set target
try {
$sysMgr.SetTargetNetId($TargetNetId)
Write-Log "SetTargetNetId $TargetNetId OK" $LogFile
} catch {
Write-Log "SetTargetNetId warning: $_" $LogFile
}
# Activate
Write-Log "Calling ActivateConfiguration()..." $LogFile
try {
$sysMgr.ActivateConfiguration()
Write-Log "ActivateConfiguration() OK" $LogFile
} catch {
Write-Log "ActivateConfiguration() error: $_" $LogFile
}
Start-Sleep -Seconds 5
# Restart TwinCAT
Write-Log "Calling StartRestartTwinCAT()..." $LogFile
try {
$sysMgr.StartRestartTwinCAT()
Write-Log "StartRestartTwinCAT() OK" $LogFile
} catch {
Write-Log "StartRestartTwinCAT() error: $_" $LogFile
}
Start-Sleep -Seconds 10
Write-Log "=== Activate+Restart complete ===" $LogFile
} finally {
# Don't release COM object aggressively; let XAE process keep it alive
}