- 8B PDO config: ULINT-sized payload, no 0x1A01 diag PDO on SM3 (device rejected SM3=8 with diag assigned: 'size not allowed, min/max 0xa') - twin_layout_blob_sized(): single 64-bit mapping entry for 8B payloads - Ticker: per-byte XOR 0x5A transform in 8B mode so TwinCAT can verify every byte individually (1KB path unchanged, const-guarded) - TwinCAT automation scripts: deploy with RPC retry, LinkVariables-based whole-array relink (element links only carry 1 byte), ADS watch, diag - Docs: 8B design, verification methodology, test report
82 lines
2.6 KiB
PowerShell
82 lines
2.6 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Scan the EtherCAT bus and list discovered devices.
|
|
|
|
.DESCRIPTION
|
|
Opens the solution, switches to CONFIG mode (so scanning is possible),
|
|
then polls the EtherCAT device's ProduceXml for FoundDevices/FoundBoxes.
|
|
|
|
.PARAMETER Solution
|
|
Path to the .sln file.
|
|
|
|
.EXAMPLE
|
|
.\tc-scan.ps1
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$Solution = $null,
|
|
[string]$TargetNetId = "10.0.0.106.1.1"
|
|
)
|
|
. "$PSScriptRoot\tc-common.ps1"
|
|
if (-not $Solution) { $Solution = $script:DefaultSolution }
|
|
|
|
New-Log $script:DefaultLogDir
|
|
$LogFile = Join-Path $script:DefaultLogDir "scan.log"
|
|
|
|
Write-Log "=== EtherCAT Scan ===" $LogFile
|
|
|
|
$dte = Get-Dte -Visible:$true
|
|
try {
|
|
if (-not (Open-Solution -Dte $dte -Solution $Solution)) { throw "Solution did not open" }
|
|
$sysMgr = Get-SysManager -Dte $dte
|
|
try { $sysMgr.SetTargetNetId($TargetNetId) } catch { }
|
|
|
|
# Activate to go online (needed for scanning)
|
|
Write-Log "Activating config to go online..." $LogFile
|
|
try { $sysMgr.ActivateConfiguration() } catch { Write-Log "Activate warning: $_" $LogFile }
|
|
Start-Sleep -Seconds 10
|
|
|
|
# Find EtherCAT device
|
|
$io = Find-TreeItem -SysMgr $sysMgr -Paths @("TIID")
|
|
if (-not $io) { throw "TIID not found" }
|
|
|
|
# Enumerate children to find EtherCAT device
|
|
foreach ($child in $io) {
|
|
$xml = $null
|
|
try { $xml = $child.ProduceXml($false) } catch { }
|
|
if ($xml -and $xml -match "<ItemSubType>(\d+)</ItemSubType>") {
|
|
$sub = [int]$Matches[1]
|
|
if ($sub -in @(90, 91, 92) -or $child.Name -like "*EtherCAT*") {
|
|
Write-Log "EtherCAT device: $($child.Name) SubType=$sub" $LogFile
|
|
|
|
# Poll for boxes
|
|
for ($poll = 0; $poll -lt 10; $poll++) {
|
|
Start-Sleep -Seconds 2
|
|
$devXml = $child.ProduceXml($false)
|
|
if ($devXml -match "FoundBoxes") {
|
|
Write-Log "FoundBoxes detected" $LogFile
|
|
break
|
|
}
|
|
}
|
|
|
|
# List boxes
|
|
foreach ($box in $child) {
|
|
Write-Log " Box: $($box.Name) Type=$($box.ItemType)" $LogFile
|
|
}
|
|
|
|
# Save XML
|
|
$outFile = Join-Path $script:DefaultLogDir "scan_device.xml"
|
|
[System.IO.File]::WriteAllText($outFile, $child.ProduceXml($true))
|
|
Write-Log "Device XML saved: $outFile" $LogFile
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Log "=== Scan complete ===" $LogFile
|
|
}
|
|
finally {
|
|
try { $dte.Quit() } catch { }
|
|
}
|