Files
qrcode-reader-hardware/utils/debugger_script.ps1
Mysteo91 e40a82a218 --upd
2023-08-02 18:21:46 +03:00

51 lines
1.4 KiB
PowerShell

$dir=$PSScriptRoot
$MyCommand="$dir"+"\stlink\st-info.exe --probe --hot-plug"
Invoke-Expression -Command $MyCommand | Out-String -OutVariable output
$DevicesNum=$output.Substring($output.IndexOf("Found") + 7, 1)
if ($DevicesNum -eq 1)
{
$serial=$output.Substring($output.Trim().IndexOf("serial") + 12, 24)
}
else
{
Write-Host -ForegroundColor Yellow -BackgroundColor Blue 'Press key which number of debugger you wanna use'
$key=Read-Host
$res=$output.Split('.')[$key]
$res=$res.Substring(0, $res.Length-2)
$serial=$res.Substring($res.IndexOf("serial") + 12 , 24)
Write-Host -ForegroundColor Yellow -BackgroundColor Blue "Your select is : `r`n $res"
}
$serial=$serial.ToCharArray()
$StringForCompare='adapter serial "'
for ($i = 0; $i -lt $serial.Count; $i=$i+2) {
$StringForCompare=$StringForCompare.Insert($StringForCompare.Length,"\x$($serial.Get($i))$($serial.Get($i+1))")
}
$StringForCompare=$StringForCompare.Insert($StringForCompare.Length,'"')
$Path = "$dir"+"/board.cfg"
$Lines = [System.IO.File]::ReadAllLines($Path)
foreach ($line in $lines)
{
if ($line -match "adapter serial")
{
if ($line -notmatch $StringForCompare)
{
$Lines[$Lines.IndexOf($line)]=$StringForCompare
}
[System.IO.File]::WriteAllLines($Path, $Lines)
exit
}
}
$Lines[0]=$StringForCompare
[System.IO.File]::WriteAllLines($Path, $Lines)