ethercat-linux/scripts/tc-check-el6695.ps1

120 lines
3.5 KiB
PowerShell
Raw Permalink Normal View History

#Requires -Version 5.1
<#
.SYNOPSIS
Check EL6695 EtherCAT status via TwinCAT automation interface.
.DESCRIPTION
Opens the solution, reads EtherCAT master state, finds EL6695,
reports AL state, PDO mapping, SM configuration, and CoE objects.
#>
[CmdletBinding()]
param(
[string]$Solution = "C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\TwinCAT_EL6695_Secondary.sln",
[string]$TargetNetId = "10.0.0.106.1.1",
[switch]$Visible
)
. "$PSScriptRoot\tc-common.ps1"
$LogFile = Join-Path $script:DefaultLogDir "check-el6695.log"
New-Log $script:DefaultLogDir
Write-Log "=== Check EL6695 Status ===" $LogFile
try {
$dte = Get-Dte -Visible:$Visible
} catch {
Write-Log "FATAL: Cannot create DTE — $_" $LogFile
Write-Host "ERROR: Cannot create DTE: $_" -ForegroundColor Red
exit 1
}
try {
if (-not (Open-Solution -Dte $dte -Solution $Solution)) {
throw "Solution did not open"
}
$sysMgr = Get-SysManager -Dte $dte
if (-not $sysMgr) {
Write-Log "FATAL: SysManager is null" $LogFile
Write-Host "ERROR: SysManager is null" -ForegroundColor Red
exit 1
}
Write-Log "SysManager obtained OK" $LogFile
# Try to get project info
try {
$proj = $dte.Solution.Projects.Item(1)
Write-Log "Project: $($proj.Name)" $LogFile
Write-Host "Project: $($proj.Name)"
} catch {
Write-Log "Cannot get project: $_" $LogFile
}
# Try to access EtherCAT master via automation interface
# The key is to enumerate tree items to find the EtherCAT master and devices
try {
$configMgr = $sysMgr.ConfigurationManager
Write-Log "ConfigurationManager obtained" $LogFile
# Try to get the build info
$buildInfo = $configMgr.BuildInfo
Write-Log "BuildInfo: $($buildInfo | Out-String)" $LogFile
Write-Host "BuildInfo: $($buildInfo | Out-String)"
} catch {
Write-Log "ConfigManager error: $_" $LogFile
}
# Use JSON command to query EtherCAT state
Write-Log "Querying EtherCAT state via JSON command..." $LogFile
# Create a temp JSON command file
$jsonCmd = @"
{
"commands": [
{
"method": "GetInfo",
"params": {}
}
]
}
"@
$jsonFile = Join-Path $env:TEMP "tc_query.json"
$jsonCmd | Out-File -FilePath $jsonFile -Encoding UTF8
try {
$result = & "C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\TcSysManCmdHelper.exe" `
-v 4026.0 `
-o $Solution `
-j $jsonFile 2>&1
Write-Log "JSON query result: $result" $LogFile
Write-Host "JSON query result: $result"
} catch {
Write-Log "JSON query error: $_" $LogFile
}
# Try to read specific CoE objects via command
Write-Log "Trying to read CoE objects via command interface..." $LogFile
# Try using the -c command option
$cmdJson = '{"method":"ReadCoE","params":{"address":"0x1018","subIndex":1}}'
try {
$result = & "C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\TcSysManCmdHelper.exe" `
-v 4026.0 `
-o $Solution `
-c $cmdJson 2>&1
Write-Log "CoE read result: $result" $LogFile
Write-Host "CoE read result: $result"
} catch {
Write-Log "CoE read error: $_" $LogFile
}
Write-Log "=== Check complete ===" $LogFile
Write-Host "`nCheck complete. Log: $LogFile" -ForegroundColor Green
} finally {
try { $dte.Quit() } catch { }
}