ethercat-linux/scripts/tc-ads-rtt.ps1
Tony Cao 3a26aea082 2kHz spin-lock mode: RTT halved to 2ms, per-byte XOR proof at 500us cycle
- ticker: --spin mode polls FPRD until payload changes (phase-locks
  processing to TwinCAT frame arrival instead of free-running ticker),
  timeout at 1.5 periods keeps loop alive on master stop
- verified: 238k cycles, 0 errors, exec=245us (FPWR-bound),
  TwinCAT PLC task confirmed at 2000.8 Hz (all three tasks 0.5ms;
  base tick was already 50us - no base-time change needed)
- docs: 500us latency plan; scripts: task-rate ADS probe, 2kHz deploy,
  UI automation experiments (pywinauto) for task cycle inspection
2026-07-28 00:11:34 +08:00

32 lines
1.6 KiB
PowerShell

#Requires -RunAsAdministrator
#Requires -Version 5.1
$ErrorActionPreference = 'Continue'
$adsDll = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
Add-Type -Path $adsDll -ErrorAction Stop
$c = New-Object TwinCAT.Ads.TcAdsClient
$c.Connect('169.254.176.217.1.1', 851)
function ReadSym($name, $type) {
try {
$h = $c.CreateVariableHandle($name)
$v = $c.ReadAny($h, $type)
$c.DeleteVariableHandle($h)
return $v
} catch { return "ERR" }
}
Write-Host "nCycles = $(ReadSym 'GVL_Sync.nCycles' ([uint64]))"
Write-Host "bSync = $(ReadSym 'GVL_Sync.bSync' ([bool]))"
Write-Host "nMatchLag = $(ReadSym 'GVL_Sync.nMatchLag' ([int])) (bridge round-trip, PLC cycles)"
Write-Host "nMismatch = $(ReadSym 'GVL_Sync.nMismatch' ([int]))"
Write-Host "--- RTT (PLC cycles, 1 cycle = 1 ms) ---"
Write-Host "nRttCycles = $(ReadSym 'GVL_Sync.nRttCycles' ([int]))"
Write-Host "nRttMin = $(ReadSym 'GVL_Sync.nRttMin' ([int]))"
Write-Host "nRttMax = $(ReadSym 'GVL_Sync.nRttMax' ([int]))"
Write-Host "nRttSum = $(ReadSym 'GVL_Sync.nRttSum' ([int64]))"
Write-Host "nRttCount = $(ReadSym 'GVL_Sync.nRttCount' ([uint64]))"
Write-Host "--- EL1252 DC latch path delay ---"
Write-Host "nLatchCount = $(ReadSym 'GVL_Sync.nLatchCount' ([uint64]))"
Write-Host "nLatchDelayMin = $(ReadSym 'GVL_Sync.nLatchDelayMin' ([int])) us"
Write-Host "nLatchDelayMax = $(ReadSym 'GVL_Sync.nLatchDelayMax' ([int])) us"
Write-Host "nLatchDelaySum = $(ReadSym 'GVL_Sync.nLatchDelaySum' ([int64])) ns"
$c.Dispose()