31 lines
1.4 KiB
PowerShell
31 lines
1.4 KiB
PowerShell
|
|
#Requires -RunAsAdministrator
|
||
|
|
# 5-hour stability monitor: logs PLC sync metrics to CSV every 60s.
|
||
|
|
$ErrorActionPreference = 'Continue'
|
||
|
|
Add-Type -Path 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
|
||
|
|
$logFile = 'C:\Users\tonycao\work\ethercat-linux\monitor_5h.csv'
|
||
|
|
'timestamp,nCycles,bSync,nReturnedSeq,nMismatch,nProcMismatch' | Out-File $logFile -Encoding utf8
|
||
|
|
$start = Get-Date
|
||
|
|
for ($i = 0; $i -lt 300; $i++) {
|
||
|
|
try {
|
||
|
|
$c = New-Object TwinCAT.Ads.TcAdsClient
|
||
|
|
$c.Connect('169.254.176.217.1.1', 851)
|
||
|
|
$h1 = $c.CreateVariableHandle('GVL_Sync.nCycles')
|
||
|
|
$h2 = $c.CreateVariableHandle('GVL_Sync.bSync')
|
||
|
|
$h3 = $c.CreateVariableHandle('GVL_Sync.nReturnedSeq')
|
||
|
|
$h4 = $c.CreateVariableHandle('GVL_Sync.nMismatch')
|
||
|
|
$h5 = $c.CreateVariableHandle('GVL_Sync.nProcMismatch')
|
||
|
|
$nc = $c.ReadAny($h1, [uint64])
|
||
|
|
$bs = $c.ReadAny($h2, [bool])
|
||
|
|
$nrs = $c.ReadAny($h3, [uint64])
|
||
|
|
$nm = $c.ReadAny($h4, [int])
|
||
|
|
$npm = $c.ReadAny($h5, [uint32])
|
||
|
|
$c.Dispose()
|
||
|
|
$ts = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
|
||
|
|
"$ts,$nc,$bs,$nrs,$nm,$npm" | Out-File $logFile -Append -Encoding utf8
|
||
|
|
} catch {
|
||
|
|
$ts = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
|
||
|
|
"$ts,ERROR,,,," | Out-File $logFile -Append -Encoding utf8
|
||
|
|
}
|
||
|
|
Start-Sleep -Seconds 60
|
||
|
|
}
|