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

35 lines
1.4 KiB
PowerShell

#Requires -Version 5.1
#Requires -RunAsAdministrator
$ErrorActionPreference = 'Continue'
$LogFile = "C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\Logs\ads-readstate.log"
New-Item -ItemType Directory -Force -Path (Split-Path $LogFile) | Out-Null
function Write-Log($Message) {
$line = "[{0}] {1}" -f (Get-Date -Format 'HH:mm:ss'), $Message
Write-Host $line
Add-Content -Path $LogFile -Value $line -Encoding UTF8
}
Write-Log "=== ADS ReadState probe ==="
$adsDll = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
try { Add-Type -Path $adsDll -ErrorAction Stop; Write-Log "TwinCAT.Ads loaded" } catch { Write-Log "FATAL: cannot load ADS dll: $_"; exit 1 }
function Read-State($NetId, $Port, $Label) {
$c = New-Object TwinCAT.Ads.TcAdsClient
try {
$c.Connect($NetId, $Port)
$state = $c.ReadState()
Write-Log "$Label state = $($state.AdsState) / deviceState = $($state.DeviceState)"
} catch {
Write-Log "$Label ERR: $($_.Exception.Message)"
} finally { $c.Dispose() }
}
Read-State '169.254.176.217.1.1' 10000 'System(1.1,10000)'
Read-State '169.254.176.217.1.1' 65535 'System(1.1,65535)'
Read-State '169.254.176.217.2.1' 65535 'ECAT1(2.1,65535)'
Read-State '169.254.176.217.2.1' 2 'ECAT1(2.1,2)'
Read-State '169.254.176.217.1.1' 851 'PLC(1.1,851)'
Write-Log "=== done ==="