ethercat-linux/scripts/tc-configure-pdo.ps1

95 lines
2.8 KiB
PowerShell
Raw Permalink Normal View History

#Requires -Version 5.1
<#
.SYNOPSIS
Configure EL6695 PDOs to 1024 bytes via TcSysManCmdHelper ConsumeXml.
.DESCRIPTION
Uses TcSysManCmdHelper.exe (Beckhoff CLI tool) to inject the PDO
configuration into the .tsproj file, then activate + save.
The ConsumeXml payload sets:
0x1608 (IO Outputs) 0x7000:01 ARRAY[0..1023] OF BYTE (SyncMan 2)
0x1A08 (IO Inputs) 0x6000:01 ARRAY[0..1023] OF BYTE (SyncMan 3)
.PARAMETER ProjectDir
Directory containing the .tsproj file.
.PARAMETER PayloadBytes
PDO payload size in bytes. Default: 1024.
.PARAMETER Activate
After configuring, also activate + save. Default: $true.
.EXAMPLE
.\tc-configure-pdo.ps1
.\tc-configure-pdo.ps1 -PayloadBytes 512
.\tc-configure-pdo.ps1 -Activate:$false
#>
[CmdletBinding()]
param(
[string]$ProjectDir = $null,
[int]$PayloadBytes = 1024,
[switch]$Activate = $true
)
. "$PSScriptRoot\tc-common.ps1"
if (-not $ProjectDir) { $ProjectDir = Split-Path $script:DefaultTsproj -Parent }
$tsproj = Join-Path $ProjectDir "TwinCAT_EL6695_Secondary.tsproj"
$helper = "C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\TcSysManCmdHelper.exe"
New-Log $script:DefaultLogDir
$LogFile = Join-Path $script:DefaultLogDir "configure-pdo.log"
Write-Log "=== Configure EL6695 PDO ${PayloadBytes}B ===" $LogFile
Write-Log "Project: $tsproj" $LogFile
if (-not (Test-Path $helper)) { Write-Log "FATAL: TcSysManCmdHelper.exe not found" $LogFile; exit 1 }
if (-not (Test-Path $tsproj)) { Write-Log "FATAL: .tsproj not found" $LogFile; exit 1 }
# Backup
$bak = $tsproj + ".bak_" + (Get-Date -Format 'yyyyMMdd_HHmmss')
Copy-Item $tsproj $bak -Force
Write-Log "Backup: $bak" $LogFile
# ConsumeXml payload
$lastSub = "{0:X4}" -f ($PayloadBytes - 1)
$xml = @"
<TreeItem>
<EtherCAT>
<Slave>
<Pdo Name="IO Outputs" Index="#x1608" InOut="1" Flags="#x0020" SyncMan="2">
<Entry Name="IO Outputs" Index="#x7000" Sub="#x01">
<Type>ARRAY [0..$lastSub] OF BYTE</Type>
</Entry>
</Pdo>
<Pdo Name="IO Inputs" Index="#x1a08" Flags="#x0020" SyncMan="3">
<Entry Name="IO Inputs" Index="#x6000" Sub="#x01">
<Type>ARRAY [0..$lastSub] OF BYTE</Type>
</Entry>
</Pdo>
</Slave>
</EtherCAT>
</TreeItem>
"@
# Build argument list
$argList = @(
"-v", "4026.0",
"-o", $tsproj,
"-x", $script:El6695Path,
$xml
)
if ($Activate) {
$argList += @("-a", "-s", $tsproj)
}
Write-Log "Running TcSysManCmdHelper..." $LogFile
$proc = Start-Process -FilePath $helper -ArgumentList $argList -Wait -PassThru -NoNewWindow
Write-Log "Exit code: $($proc.ExitCode)" $LogFile
if ($proc.ExitCode -ne 0) {
Write-Log "WARNING: non-zero exit. Check TwinCAT System Manager messages." $LogFile
}
Write-Log "=== Configure PDO complete ===" $LogFile