56 lines
2.5 KiB
PowerShell
56 lines
2.5 KiB
PowerShell
|
|
param(
|
||
|
|
[string]$Tsproj = 'C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Primary\TwinCATProject1.tsproj'
|
||
|
|
)
|
||
|
|
$ErrorActionPreference = 'Continue'
|
||
|
|
$content = [System.IO.File]::ReadAllText($Tsproj, [System.Text.Encoding]::UTF8)
|
||
|
|
|
||
|
|
Write-Host "=== Fix PDO: add 1024-byte entries to EL6695 IO PDO ==="
|
||
|
|
|
||
|
|
# 1. Expand empty IO Inputs PDO (0x1A08)
|
||
|
|
$oldPdoIn = '<Pdo Name="IO Inputs" Index="#x1a08" Flags="#x0020" SyncMan="3"/>'
|
||
|
|
$newPdoIn = @"
|
||
|
|
<Pdo Name="IO Inputs" Index="#x1a08" Flags="#x0020" SyncMan="3">
|
||
|
|
<Entry Name="IO Inputs" Index="#x6000" Sub="#x01">
|
||
|
|
<Type GUID="{18071995-0000-0000-0000-000300000400}">ARRAY [0..1023] OF BYTE</Type>
|
||
|
|
</Entry>
|
||
|
|
</Pdo>
|
||
|
|
"@
|
||
|
|
if ($content -match [regex]::Escape($oldPdoIn)) {
|
||
|
|
$content = $content -replace [regex]::Escape($oldPdoIn), $newPdoIn
|
||
|
|
Write-Host " IO Inputs PDO expanded"
|
||
|
|
} else { Write-Host " WARN: IO Inputs PDO pattern not found" }
|
||
|
|
|
||
|
|
# 2. Expand empty IO Outputs PDO (0x1608)
|
||
|
|
$oldPdoOut = '<Pdo Name="IO Outputs" Index="#x1608" InOut="1" Flags="#x0020" SyncMan="2"/>'
|
||
|
|
$newPdoOut = @"
|
||
|
|
<Pdo Name="IO Outputs" Index="#x1608" InOut="1" Flags="#x0020" SyncMan="2">
|
||
|
|
<Entry Name="IO Outputs" Index="#x7000" Sub="#x01">
|
||
|
|
<Type GUID="{18071995-0000-0000-0000-000300000400}">ARRAY [0..1023] OF BYTE</Type>
|
||
|
|
</Entry>
|
||
|
|
</Pdo>
|
||
|
|
"@
|
||
|
|
if ($content -match [regex]::Escape($oldPdoOut)) {
|
||
|
|
$content = $content -replace [regex]::Escape($oldPdoOut), $newPdoOut
|
||
|
|
Write-Host " IO Outputs PDO expanded"
|
||
|
|
} else { Write-Host " WARN: IO Outputs PDO pattern not found" }
|
||
|
|
|
||
|
|
# 3. Fix SM lengths
|
||
|
|
$sm2_old = '001c00006400000003000000000000000000001c64010000'
|
||
|
|
$sm2_new = '001c00040000000003000000000000000000001c64010000'
|
||
|
|
# ^^^^ len=0x0400 (1024)
|
||
|
|
if ($content -match [regex]::Escape($sm2_old)) {
|
||
|
|
$content = $content -replace [regex]::Escape($sm2_old), $sm2_new
|
||
|
|
Write-Host " SM2 length fixed to 1024"
|
||
|
|
} else { Write-Host " SM2: pattern not found (may already be correct)" }
|
||
|
|
|
||
|
|
$sm3_old = '008e02002000010004000000000000000200008e20010000'
|
||
|
|
$sm3_new = '008e02040000010004000000000000000200008e20010000'
|
||
|
|
# ^^^^ len=0x0400 (1024)
|
||
|
|
if ($content -match [regex]::Escape($sm3_old)) {
|
||
|
|
$content = $content -replace [regex]::Escape($sm3_old), $sm3_new
|
||
|
|
Write-Host " SM3 length fixed to 1024"
|
||
|
|
} else { Write-Host " SM3: pattern not found (may already be correct)" }
|
||
|
|
|
||
|
|
[System.IO.File]::WriteAllText($Tsproj, $content, [System.Text.Encoding]::UTF8)
|
||
|
|
Write-Host "=== tsproj PDO fix complete ==="
|