103 lines
3.0 KiB
PowerShell
103 lines
3.0 KiB
PowerShell
|
|
#Requires -Version 5.1
|
||
|
|
[CmdletBinding()]
|
||
|
|
param(
|
||
|
|
[string]$Solution = $null
|
||
|
|
)
|
||
|
|
|
||
|
|
. "$PSScriptRoot\tc-common.ps1"
|
||
|
|
if (-not $Solution) { $Solution = $script:DefaultSolution }
|
||
|
|
|
||
|
|
New-Log $script:DefaultLogDir
|
||
|
|
$LogFile = Join-Path $script:DefaultLogDir "diag-dte.log"
|
||
|
|
|
||
|
|
Write-Log "=== DTE Diagnostic ===" $LogFile
|
||
|
|
|
||
|
|
try {
|
||
|
|
$dte = New-Object -ComObject TcXaeShell.DTE.17.0 -ErrorAction Stop
|
||
|
|
} catch {
|
||
|
|
Write-Log "FATAL: Cannot create DTE: $_" $LogFile
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Log "DTE created OK" $LogFile
|
||
|
|
$dte.MainWindow.Visible = $true
|
||
|
|
|
||
|
|
try {
|
||
|
|
$dte.Solution.Open($Solution)
|
||
|
|
for ($i = 1; $i -le 120; $i++) {
|
||
|
|
Start-Sleep -Seconds 1
|
||
|
|
if ($dte.Solution.IsOpen) { break }
|
||
|
|
}
|
||
|
|
Write-Log "Solution open: $($dte.Solution.IsOpen)" $LogFile
|
||
|
|
|
||
|
|
if (-not $dte.Solution.IsOpen) {
|
||
|
|
Write-Log "Solution did not open" $LogFile
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
# Get SysManager
|
||
|
|
$sysMgr = $null
|
||
|
|
for ($i = 1; $i -le 40; $i++) {
|
||
|
|
try {
|
||
|
|
$sysMgr = $dte.Solution.Projects.Item(1).Object
|
||
|
|
if ($sysMgr) { break }
|
||
|
|
} catch { }
|
||
|
|
Start-Sleep -Seconds 3
|
||
|
|
}
|
||
|
|
Write-Log "SysManager: $(if ($sysMgr) { 'OK' } else { 'null' })" $LogFile
|
||
|
|
|
||
|
|
if (-not $sysMgr) { exit 1 }
|
||
|
|
|
||
|
|
# Set target
|
||
|
|
try {
|
||
|
|
$sysMgr.SetTargetNetId('169.254.176.217.1.1')
|
||
|
|
Write-Log "SetTargetNetId OK" $LogFile
|
||
|
|
} catch {
|
||
|
|
Write-Log "SetTargetNetId error: $_" $LogFile
|
||
|
|
}
|
||
|
|
|
||
|
|
Start-Sleep -Seconds 5
|
||
|
|
|
||
|
|
# Get target info
|
||
|
|
try {
|
||
|
|
$cfg = $sysMgr.ConfigurationManager.ActiveConfiguration
|
||
|
|
Write-Log "Active Target: $($cfg.TargetNetId)" $LogFile
|
||
|
|
Write-Log "Platform: $($sysMgr.ConfigurationManager.ActiveTargetPlatform)" $LogFile
|
||
|
|
} catch {
|
||
|
|
Write-Log "Active config error: $_" $LogFile
|
||
|
|
}
|
||
|
|
|
||
|
|
# Get TIID
|
||
|
|
try {
|
||
|
|
$io = $sysMgr.LookupTreeItem('TIID')
|
||
|
|
Write-Log "TIID node: $(if ($io) { $io.Name } else { 'null' })" $LogFile
|
||
|
|
|
||
|
|
if ($io) {
|
||
|
|
# Try to get ProduceXml to see found devices
|
||
|
|
$xml = $io.ProduceXml($false)
|
||
|
|
$xmlFile = Join-Path $script:DefaultLogDir 'diag_tiid.xml'
|
||
|
|
[System.IO.File]::WriteAllText($xmlFile, $xml, [System.Text.Encoding]::UTF8)
|
||
|
|
Write-Log "TIID XML saved: $xmlFile ($($xml.Length) bytes)" $LogFile
|
||
|
|
|
||
|
|
# Count devices
|
||
|
|
[xml]$doc = $xml
|
||
|
|
$found = $doc.SelectNodes('//FoundDevices/Device')
|
||
|
|
Write-Log "FoundDevices count: $($found.Count)" $LogFile
|
||
|
|
|
||
|
|
foreach ($d in $found) {
|
||
|
|
$subNode = $d.SelectSingleNode('ItemSubType')
|
||
|
|
$nameNode = $d.SelectSingleNode('Name')
|
||
|
|
$sub = if ($subNode) { $subNode.InnerText } else { '?' }
|
||
|
|
$name = if ($nameNode) { $nameNode.InnerText } else { '?' }
|
||
|
|
Write-Log " Found: sub=$sub name=$name" $LogFile
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch {
|
||
|
|
Write-Log "TIID error: $_" $LogFile
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Log "=== Diagnostic complete ===" $LogFile
|
||
|
|
} finally {
|
||
|
|
try { $dte.Quit() } catch { }
|
||
|
|
}
|