ethercat-linux/scripts/tc-ads-soak.ps1

33 lines
1.3 KiB
PowerShell
Raw Permalink Normal View History

param([int]$Minutes = 190, [string]$LogFile = "$env:TEMP\soak.log")
$ErrorActionPreference = 'Stop'
$adsDll = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
Add-Type -Path $adsDll
$c = New-Object TwinCAT.Ads.TcAdsClient
$c.Connect('169.254.176.217.1.1', 851)
function ReadSym($name, $type) {
$h = $c.CreateVariableHandle($name)
$v = $c.ReadAny($h, $type)
$c.DeleteVariableHandle($h)
return $v
}
$prevMism = $null
$prevCyc = $null
for ($k = 0; $k -lt $Minutes; $k++) {
try {
$nc = ReadSym 'GVL_Sync.nCycles' ([uint64])
$bs = ReadSym 'GVL_Sync.bSync' ([bool])
$nm = ReadSym 'GVL_Sync.nMismatch' ([int])
$lag = ReadSym 'GVL_Sync.nMatchLag' ([int])
$dmism = if ($null -ne $prevMism) { $nm - $prevMism } else { 0 }
$rate = if ($null -ne $prevCyc) { ([int64]$nc - $prevCyc) / 60.0 } else { 0 }
$prevMism = $nm
$prevCyc = [int64]$nc
$line = "{0} k={1,3} nCycles={2,-9} rate={3,7:F1}/s bSync={4} lag={5,4} nMismatch={6} dMism={7}" -f (Get-Date -Format 'HH:mm:ss'), $k, $nc, $rate, $bs, $lag, $nm, $dmism
} catch {
$line = "{0} k={1,3} ADS ERROR: {2}" -f (Get-Date -Format 'HH:mm:ss'), $k, $_.Exception.Message
}
Add-Content -Path $LogFile -Value $line
Start-Sleep -Seconds 60
}
$c.Dispose()