25 lines
919 B
PowerShell
25 lines
919 B
PowerShell
$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
|
|
}
|
|
$prev = $null
|
|
for ($k = 1; $k -le 10; $k++) {
|
|
$nc = ReadSym 'GVL_Sync.nCycles' ([uint64])
|
|
$bs = ReadSym 'GVL_Sync.bSync' ([bool])
|
|
$nrs = ReadSym 'GVL_Sync.nReturnedSeq' ([uint64])
|
|
$nm = ReadSym 'GVL_Sync.nMismatch' ([int])
|
|
$lag = [int64]$nc - [int64]$nrs
|
|
$delta = if ($null -ne $prev) { $nm - $prev } else { 0 }
|
|
$prev = $nm
|
|
Write-Host ("{0,2} nCycles={1,-8} lag={2,4} bSync={3} nMismatch={4} delta={5}" -f $k, $nc, $lag, $bs, $nm, $delta)
|
|
if ($k -lt 10) { Start-Sleep -Seconds 60 }
|
|
}
|
|
$c.Dispose()
|