68 lines
3.0 KiB
PowerShell
68 lines
3.0 KiB
PowerShell
|
|
#Requires -RunAsAdministrator
|
||
|
|
#Requires -Version 5.1
|
||
|
|
<#
|
||
|
|
.SYNOPSIS
|
||
|
|
Fix TwinCAT EtherCAT adapter IP and activate EL6695 configuration.
|
||
|
|
.DESCRIPTION
|
||
|
|
1. Find TwinCAT-Intel adapter by MAC 00-15-17-8A-B3-DA
|
||
|
|
2. Set IP to 169.254.176.217/16 (matches registry AmsNetId 169.254.176.217.1.1)
|
||
|
|
3. Build and activate TwinCAT project with correct target
|
||
|
|
4. Wait for activation to settle
|
||
|
|
#>
|
||
|
|
|
||
|
|
Write-Host "=== Fix TwinCAT EtherCAT IP + Activate EL6695 ===" -ForegroundColor Cyan
|
||
|
|
|
||
|
|
$targetMac = '00-15-17-8A-B3-DA'
|
||
|
|
$targetIp = '169.254.176.217'
|
||
|
|
$prefix = 16
|
||
|
|
$targetNetId = '169.254.176.217.1.1'
|
||
|
|
$helper = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\TcSysManCmdHelper.exe'
|
||
|
|
$tsproj = 'C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\TwinCAT_EL6695_Secondary.tsproj'
|
||
|
|
|
||
|
|
# 1. Find adapter by MAC
|
||
|
|
$adapter = Get-NetAdapter -Physical | Where-Object { $_.MacAddress -eq $targetMac }
|
||
|
|
if (-not $adapter) {
|
||
|
|
Write-Host "Available physical adapters:" -ForegroundColor Yellow
|
||
|
|
Get-NetAdapter -Physical | Select-Object Name, MacAddress, Status, LinkSpeed | Format-Table -AutoSize
|
||
|
|
Write-Error "Cannot find adapter with MAC $targetMac"
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host "Found adapter: $($adapter.Name) (MAC: $targetMac)" -ForegroundColor Green
|
||
|
|
|
||
|
|
# 2. Set IP
|
||
|
|
$existing = Get-NetIPAddress -InterfaceIndex $adapter.ifIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue
|
||
|
|
foreach ($ip in $existing) {
|
||
|
|
Write-Host " Removing existing IP: $($ip.IPAddress)" -ForegroundColor Gray
|
||
|
|
Remove-NetIPAddress -InterfaceIndex $adapter.ifIndex -IPAddress $ip.IPAddress -Confirm:$false -ErrorAction SilentlyContinue
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host "Setting IP to $targetIp/$prefix ..." -ForegroundColor Cyan
|
||
|
|
New-NetIPAddress -InterfaceIndex $adapter.ifIndex -IPAddress $targetIp -PrefixLength $prefix -AddressFamily IPv4 -ErrorAction Stop | Out-Null
|
||
|
|
|
||
|
|
$verify = Get-NetIPAddress -InterfaceIndex $adapter.ifIndex -AddressFamily IPv4 | Select-Object IPAddress, PrefixLength, AddressState
|
||
|
|
Write-Host "IP set OK:" -ForegroundColor Green
|
||
|
|
$verify | Format-Table -AutoSize
|
||
|
|
|
||
|
|
# 3. Build + Activate TwinCAT
|
||
|
|
Set-Location -LiteralPath 'C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary'
|
||
|
|
|
||
|
|
Write-Host "Building TwinCAT project..." -ForegroundColor Cyan
|
||
|
|
& $helper -v 4026.0 -o $tsproj -t $targetNetId -b 2>&1
|
||
|
|
$buildExit = $LASTEXITCODE
|
||
|
|
Write-Host "Build exit code: $buildExit" -ForegroundColor $(if ($buildExit -eq 0) { 'Green' } else { 'Red' })
|
||
|
|
|
||
|
|
Start-Sleep -Seconds 2
|
||
|
|
|
||
|
|
Write-Host "Activating + Restarting TwinCAT..." -ForegroundColor Cyan
|
||
|
|
$cmd = '{"commands":[{"method":"ActivateConfiguration"},{"method":"StartRestartTwinCAT"}]}'
|
||
|
|
& $helper -v 4026.0 -o $tsproj -t $targetNetId -c $cmd 2>&1
|
||
|
|
$actExit = $LASTEXITCODE
|
||
|
|
Write-Host "Activate exit code: $actExit" -ForegroundColor $(if ($actExit -eq 0) { 'Green' } else { 'Red' })
|
||
|
|
|
||
|
|
Write-Host "Waiting 10s for TwinCAT to settle..." -ForegroundColor Cyan
|
||
|
|
Start-Sleep -Seconds 10
|
||
|
|
|
||
|
|
Write-Host "=== Done ===" -ForegroundColor Green
|
||
|
|
Write-Host "Next: run J1900 verify via serial: /root/gateway/el6695_rt eth1 --mode verify" -ForegroundColor Yellow
|