<# .SYNOPSIS Launches the python-snap7 S7 server with one of the integration-test profiles. Foreground process — Ctrl+C to stop. Mirrors the pymodbus `serve.ps1` wrapper in tests\...\Modbus.IntegrationTests\Pymodbus\. .PARAMETER Profile Which profile JSON to load: currently only 's7_1500' ships. Additional families (S7-1200, S7-300) can drop in as new JSON files alongside. .PARAMETER Port TCP port to bind. Default 1102 (non-privileged; matches Snap7ServerFixture default endpoint). Pass 102 to match S7 standard — requires root on Linux + triggers Windows Firewall prompt. .EXAMPLE .\serve.ps1 -Profile s7_1500 .EXAMPLE .\serve.ps1 -Profile s7_1500 -Port 102 #> [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateSet('s7_1500')] [string]$Profile, [int]$Port = 1102 ) $ErrorActionPreference = 'Stop' $here = $PSScriptRoot # python-snap7 installs the `snap7` Python package; we call via `python -m` # or via the server.py shim in this folder. Shim path is simpler to diagnose. $python = Get-Command python -ErrorAction SilentlyContinue if (-not $python) { $python = Get-Command py -ErrorAction SilentlyContinue } if (-not $python) { Write-Error "python not found on PATH. Install Python 3.10+ and 'pip install python-snap7'." exit 1 } # Verify python-snap7 is installed so failures surface here, not in a # confusing ImportError from server.py. & $python.Source -c "import snap7.server" 2>$null if ($LASTEXITCODE -ne 0) { Write-Error "python-snap7 not importable. Install with: pip install 'python-snap7>=2.0'" exit 1 } $jsonFile = Join-Path $here "$Profile.json" if (-not (Test-Path $jsonFile)) { Write-Error "Profile config not found: $jsonFile" exit 1 } Write-Host "Starting python-snap7 server: profile=$Profile TCP=localhost:$Port" Write-Host "Ctrl+C to stop." & $python.Source (Join-Path $here "server.py") $jsonFile --port $Port