124 lines
4.5 KiB
PowerShell
124 lines
4.5 KiB
PowerShell
#Requires -Version 7.0
|
|
<#
|
|
.SYNOPSIS
|
|
End-to-end CLI test for the Siemens S7 driver bridged through the OtOpcUa server.
|
|
|
|
.DESCRIPTION
|
|
Five assertions (probe / driver-loopback / forward-bridge / reverse-bridge /
|
|
subscribe-sees-change) against a Siemens S7-300/400/1200/1500 or compatible
|
|
soft-PLC. python-snap7 simulator (task #216) or real hardware both work.
|
|
|
|
Prereqs:
|
|
- S7 simulator / PLC on $S7Host:$S7Port
|
|
- On real S7-1200/1500: PUT/GET communication enabled in TIA Portal.
|
|
- OtOpcUa server running with an S7 DriverInstance bound to the same
|
|
endpoint + a Tag at DB1.DBW0 Int16 published under -BridgeNodeId.
|
|
|
|
.PARAMETER S7Host
|
|
Host:port of the S7 simulator / PLC. Default 127.0.0.1:102.
|
|
|
|
.PARAMETER Cpu
|
|
S7200 / S7200Smart / S7300 / S7400 / S71200 / S71500 (default S71500).
|
|
|
|
.PARAMETER Slot
|
|
CPU slot. Default 0 (S7-1200/1500). S7-300 uses 2.
|
|
|
|
.PARAMETER Address
|
|
S7 address to exercise. Default DB1.DBW0.
|
|
|
|
.PARAMETER OpcUaUrl
|
|
OtOpcUa server endpoint.
|
|
|
|
.PARAMETER BridgeNodeId
|
|
NodeId at which the server publishes the Address.
|
|
#>
|
|
|
|
param(
|
|
[string]$S7Host = "127.0.0.1:102",
|
|
[string]$Cpu = "S71500",
|
|
[int]$Slot = 0,
|
|
[string]$Address = "DB1.DBW0",
|
|
[string]$OpcUaUrl = "opc.tcp://localhost:4840",
|
|
[Parameter(Mandatory)] [string]$BridgeNodeId
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
. "$PSScriptRoot/_common.ps1"
|
|
|
|
$hostPart, $portPart = $S7Host.Split(":")
|
|
$port = [int]$portPart
|
|
|
|
$s7Cli = Get-CliInvocation `
|
|
-ProjectFolder "src/ZB.MOM.WW.OtOpcUa.Driver.S7.Cli" `
|
|
-ExeName "otopcua-s7-cli"
|
|
$opcUaCli = Get-CliInvocation `
|
|
-ProjectFolder "src/ZB.MOM.WW.OtOpcUa.Client.CLI" `
|
|
-ExeName "otopcua-cli"
|
|
|
|
$commonS7 = @("-h", $hostPart, "-p", $port, "-c", $Cpu, "--slot", $Slot)
|
|
$results = @()
|
|
|
|
$results += Test-Probe `
|
|
-Cli $s7Cli `
|
|
-ProbeArgs (@("probe") + $commonS7)
|
|
|
|
$writeValue = Get-Random -Minimum 1 -Maximum 9999
|
|
$results += Test-DriverLoopback `
|
|
-Cli $s7Cli `
|
|
-WriteArgs (@("write") + $commonS7 + @("-a", $Address, "-t", "Int16", "-v", $writeValue)) `
|
|
-ReadArgs (@("read") + $commonS7 + @("-a", $Address, "-t", "Int16")) `
|
|
-ExpectedValue "$writeValue"
|
|
|
|
$bridgeValue = Get-Random -Minimum 10000 -Maximum 19999
|
|
$results += Test-ServerBridge `
|
|
-DriverCli $s7Cli `
|
|
-DriverWriteArgs (@("write") + $commonS7 + @("-a", $Address, "-t", "Int16", "-v", $bridgeValue)) `
|
|
-OpcUaCli $opcUaCli `
|
|
-OpcUaUrl $OpcUaUrl `
|
|
-OpcUaNodeId $BridgeNodeId `
|
|
-ExpectedValue "$bridgeValue"
|
|
|
|
$reverseValue = Get-Random -Minimum 20000 -Maximum 29999
|
|
$results += Test-OpcUaWriteBridge `
|
|
-OpcUaCli $opcUaCli `
|
|
-OpcUaUrl $OpcUaUrl `
|
|
-OpcUaNodeId $BridgeNodeId `
|
|
-DriverCli $s7Cli `
|
|
-DriverReadArgs (@("read") + $commonS7 + @("-a", $Address, "-t", "Int16")) `
|
|
-ExpectedValue "$reverseValue"
|
|
|
|
$subValue = Get-Random -Minimum 30000 -Maximum 32766
|
|
$results += Test-SubscribeSeesChange `
|
|
-OpcUaCli $opcUaCli `
|
|
-OpcUaUrl $OpcUaUrl `
|
|
-OpcUaNodeId $BridgeNodeId `
|
|
-DriverCli $s7Cli `
|
|
-DriverWriteArgs (@("write") + $commonS7 + @("-a", $Address, "-t", "Int16", "-v", $subValue)) `
|
|
-ExpectedValue "$subValue"
|
|
|
|
# PR-S7-D2 / #300 — UDT-member round-trip. Exercises the byte offsets the
|
|
# driver's UDT fan-out uses when expanding a UDT-typed parent tag into per-
|
|
# member scalar leaves: Real at DB1.DBD400 and Int16 at DB1.DBW404 match the
|
|
# `MyUdt` layout seeded by Docker/profiles/s7_1500.json's udt_layout meta-seed
|
|
# and declared by S7_1500UdtFanOutTests. The CLI itself is UDT-unaware so the
|
|
# e2e step writes / reads at the explicit member byte offsets — proves the
|
|
# wire-level path the fan-out emits is sound end-to-end.
|
|
$udtPressureAddress = $Address.Substring(0, $Address.IndexOf('.')) + ".DBD400"
|
|
$udtPressureValue = "27.5"
|
|
$results += Test-DriverLoopback `
|
|
-Cli $s7Cli `
|
|
-WriteArgs (@("write") + $commonS7 + @("-a", $udtPressureAddress, "-t", "Float32", "-v", $udtPressureValue)) `
|
|
-ReadArgs (@("read") + $commonS7 + @("-a", $udtPressureAddress, "-t", "Float32")) `
|
|
-ExpectedValue $udtPressureValue
|
|
|
|
$udtStatusAddress = $Address.Substring(0, $Address.IndexOf('.')) + ".DBW404"
|
|
$udtStatusValue = Get-Random -Minimum 100 -Maximum 999
|
|
$results += Test-DriverLoopback `
|
|
-Cli $s7Cli `
|
|
-WriteArgs (@("write") + $commonS7 + @("-a", $udtStatusAddress, "-t", "Int16", "-v", $udtStatusValue)) `
|
|
-ReadArgs (@("read") + $commonS7 + @("-a", $udtStatusAddress, "-t", "Int16")) `
|
|
-ExpectedValue "$udtStatusValue"
|
|
|
|
Write-Summary -Title "S7 e2e" -Results $results
|
|
if ($results | Where-Object { -not $_.Passed }) { exit 1 }
|