ethercat-linux/scripts/tc-ads-watch.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

41 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 Read-Sym($name, $type) {
try {
$h = $c.CreateVariableHandle($name)
$v = $c.ReadAny($h, $type)
$c.DeleteVariableHandle($h)
return $v
} catch { return "ERR: $($_.Exception.Message)" }
}
function Read-Bytes($name) {
try {
$h = $c.CreateVariableHandle($name)
$arr = $c.ReadAny($h, [byte[]], @(8))
$c.DeleteVariableHandle($h)
return $arr
} catch { return $null }
}
for ($i = 1; $i -le 8; $i++) {
$nc = Read-Sym 'GVL_Sync.nCycles' ([uint32])
$bs = Read-Sym 'GVL_Sync.bSync' ([bool])
$lag = Read-Sym 'GVL_Sync.nMatchLag' ([int])
$nmis = Read-Sym 'GVL_Sync.nMismatch' ([int])
$out = Read-Bytes 'GVL_Sync.aOut1'
$in = Read-Bytes 'GVL_Sync.aIn1'
$outH = if ($out) { [BitConverter]::ToString($out) } else { 'ERR' }
$inH = if ($in) { [BitConverter]::ToString($in) } else { 'ERR' }
# per-byte verify against expected transform for current cycle (lag unknown here)
$xorH = if ($in) { [BitConverter]::ToString([byte[]]($in | ForEach-Object { $_ -bxor 0x5A })) } else { 'ERR' }
Write-Host ("[{0}] nCyc={1} bSync={2} lag={3} mism={4}" -f $i, $nc, $bs, $lag, $nmis)
Write-Host (" aOut1(sent) = {0}" -f $outH)
Write-Host (" aIn1(recv) = {0} aIn1^5A = {1}" -f $inH, $xorH)
Start-Sleep -Seconds 3
}
$c.Dispose()