47 lines
1.7 KiB
PowerShell
47 lines
1.7 KiB
PowerShell
|
|
#Requires -Version 5.1
|
||
|
|
#Requires -RunAsAdministrator
|
||
|
|
$ErrorActionPreference = 'Continue'
|
||
|
|
|
||
|
|
$LogFile = "C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\Logs\dte-commands-test.log"
|
||
|
|
New-Item -ItemType Directory -Force -Path (Split-Path $LogFile) | Out-Null
|
||
|
|
function Write-Log($Message) {
|
||
|
|
$line = "[{0}] {1}" -f (Get-Date -Format 'HH:mm:ss'), $Message
|
||
|
|
Write-Host $line
|
||
|
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Log "=== Test DTE command names ==="
|
||
|
|
$dte = New-Object -ComObject TcXaeShell.DTE.17.0
|
||
|
|
$dte.MainWindow.Visible = $true
|
||
|
|
$dte.Solution.Open('C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Secondary\TwinCAT_EL6695_Secondary.sln')
|
||
|
|
for ($i=1; $i -le 120; $i++) { Start-Sleep -Seconds 1; if ($dte.Solution.IsOpen) { break } }
|
||
|
|
Write-Log "Solution open: $($dte.Solution.IsOpen)"
|
||
|
|
|
||
|
|
$names = @(
|
||
|
|
'TwinCAT.StartTwinCAT',
|
||
|
|
'TwinCAT.StartTwinCATInRunMode',
|
||
|
|
'TwinCAT.RestartTwinCAT',
|
||
|
|
'TwinCAT.RestartTwinCATInRunMode',
|
||
|
|
'TwinCAT.RestartTwinCATInConfigMode',
|
||
|
|
'TwinCAT.RunMode',
|
||
|
|
'TwinCAT.ConfigMode',
|
||
|
|
'TwinCAT.Scan',
|
||
|
|
'TwinCAT.ScanDevices',
|
||
|
|
'TwinCAT.ReloadDevices',
|
||
|
|
'TwinCAT.Build',
|
||
|
|
'TwinCAT.ActivateConfiguration',
|
||
|
|
'TwinCAT.Start'
|
||
|
|
)
|
||
|
|
foreach ($n in $names) {
|
||
|
|
try {
|
||
|
|
$cmd = $dte.Commands.Item($n)
|
||
|
|
Write-Log "Command $n EXISTS IsAvailable=$($cmd.IsAvailable) Enabled=$($cmd.Enabled)"
|
||
|
|
if ($cmd.IsAvailable -and $cmd.Enabled) {
|
||
|
|
try { $dte.ExecuteCommand($n); Write-Log " ExecuteCommand($n) OK" } catch { Write-Log " ExecuteCommand($n) ERR: $($_.Exception.Message)" }
|
||
|
|
}
|
||
|
|
} catch { Write-Log "Command $n NOT FOUND: $($_.Exception.Message)" }
|
||
|
|
}
|
||
|
|
|
||
|
|
try { $dte.Quit() } catch {}
|
||
|
|
Write-Log "=== done ==="
|