ethercat-linux/scripts/tc-relink-800b.ps1

63 lines
2.6 KiB
PowerShell
Raw Normal View History

#Requires -RunAsAdministrator
$ErrorActionPreference = "Continue"
$dte = New-Object -ComObject TcXaeShell.DTE.17.0
$dte.MainWindow.Visible = $true
try { $dte.SuppressUI = $false } catch {}
$dte.Solution.Open("C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Primary_800B\TwinCATProject1.sln")
Start-Sleep 20
$sm = $null
for ($i = 0; $i -lt 20; $i++) {
try { $sm = $dte.Solution.Projects.Item(1).Object; if ($sm) { break } } catch {}
Start-Sleep 3
}
if (-not $sm) { Write-Host "no sysmgr"; exit 1 }
try { $sm.SetTargetNetId("169.254.176.217.1.1") } catch {}
Start-Sleep 2
$box = "TIID^设备 1 (EtherCAT)^模块 3 (EK1100)^模块 10 (EL6695)"
$cands = @(
"$box^IO Outputs^IO Outputs",
"$box^IO Outputs^IO Outputs[0]",
"$box^IO Inputs^IO Inputs",
"$box^IO Inputs^IO Inputs[0]"
)
foreach ($c in $cands) {
$it = $null
try { $it = $sm.TryLookupTreeItem($c) } catch { Write-Host "err $c : $_" }
if ($it) {
$sz = ""
try { $sz = $it.BitSize } catch {}
Write-Host "OK: $c name=$($it.Name) type=$($it.ItemType) bitsize=$sz"
} else {
Write-Host "MISS: $c"
}
}
$varAin = "TIPC^PlcSync^PlcSync Instance^PlcTask Inputs^GVL_Sync.aIn1"
$varAout = "TIPC^PlcSync^PlcSync Instance^PlcTask Outputs^GVL_Sync.aOut1"
foreach ($v in @($varAin, $varAout)) {
$it = $null
try { $it = $sm.TryLookupTreeItem($v) } catch {}
if ($it) { Write-Host "PLC OK: $v" } else { Write-Host "PLC MISS: $v" }
}
Write-Host "--- unlink existing ---"
try { $sm.UnlinkVariables($varAin, "$box^IO Inputs^IO Inputs") ; Write-Host "unlinked aIn1" } catch { Write-Host "unlink aIn1: $_" }
try { $sm.UnlinkVariables($varAout, "$box^IO Outputs^IO Outputs"); Write-Host "unlinked aOut1" } catch { Write-Host "unlink aOut1: $_" }
Write-Host "--- link whole arrays ---"
try { $sm.LinkVariables($varAin, "$box^IO Inputs^IO Inputs"); Write-Host "linked aIn1" } catch { Write-Host "link aIn1: $_" }
try { $sm.LinkVariables($varAout, "$box^IO Outputs^IO Outputs"); Write-Host "linked aOut1" } catch { Write-Host "link aOut1: $_" }
$xml = $sm.ProduceMappingInfo()
[System.IO.File]::WriteAllText("C:\Users\tonycao\work\ethercat-linux\tmp_mapping2.xml", $xml, [System.Text.Encoding]::UTF8)
Write-Host "mapping saved"
Write-Host "--- save + activate + restart ---"
try { $dte.Solution.SaveAll(); Write-Host "saved" } catch { Write-Host "save: $_" }
try { $sm.ActivateConfiguration(); Write-Host "activated" } catch { Write-Host "activate: $_" }
Start-Sleep 10
try { $sm.StartRestartTwinCAT(); Write-Host "restart issued" } catch { Write-Host "restart: $_" }
Start-Sleep 10
Write-Host "done"