Auto: s7-a5 — LOGO!/S7-200 V-memory parser

Add CPU-aware overload S7AddressParser.Parse(string, CpuType?) that
accepts the V area letter for S7-200 / S7-200 Smart / LOGO! 0BA8 and
maps it to DataBlock DB1. V is rejected on S7-300/400/1200/1500 and on
the legacy CPU-agnostic Parse(string) overload. Width suffixes mirror
M/I/Q (VB/VW/VD/V0.0). S7Driver passes _options.CpuType so live tag
config picks up family-aware parsing.

Tests cover S7200/S7200Smart/Logo0BA8 positive cases, modern-family
rejection, and CPU-agnostic rejection.

Closes #291
This commit is contained in:
Joseph Doherty
2026-04-25 16:58:34 -04:00
parent 6737edbad2
commit e5122c546b
3 changed files with 121 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using Shouldly;
using Xunit;
using S7NetCpuType = global::S7.Net.CpuType;
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Tests;
@@ -121,4 +122,45 @@ public sealed class S7AddressParserTests
r.DbNumber.ShouldBe(1);
r.Size.ShouldBe(S7Size.Word);
}
// --- V-memory (S7-200 / S7-200 Smart / LOGO!) ---
[Theory]
[InlineData("VB0", S7Size.Byte, 0, 0)]
[InlineData("VW0", S7Size.Word, 0, 0)]
[InlineData("VD4", S7Size.DWord, 4, 0)]
[InlineData("V0.0", S7Size.Bit, 0, 0)]
[InlineData("V10.7", S7Size.Bit, 10, 7)]
public void Parse_V_memory_maps_to_DB1_for_S7200(string input, S7Size size, int byteOff, int bitOff)
{
var r = S7AddressParser.Parse(input, S7NetCpuType.S7200);
r.Area.ShouldBe(S7Area.DataBlock);
r.DbNumber.ShouldBe(1);
r.Size.ShouldBe(size);
r.ByteOffset.ShouldBe(byteOff);
r.BitOffset.ShouldBe(bitOff);
}
[Theory]
[InlineData(S7NetCpuType.S7200Smart)]
[InlineData(S7NetCpuType.Logo0BA8)]
public void Parse_V_memory_maps_to_DB1_for_S7200Smart_and_LOGO(S7NetCpuType cpu)
{
var r = S7AddressParser.Parse("VW0", cpu);
r.Area.ShouldBe(S7Area.DataBlock);
r.DbNumber.ShouldBe(1);
r.Size.ShouldBe(S7Size.Word);
}
[Theory]
[InlineData(S7NetCpuType.S71500)]
[InlineData(S7NetCpuType.S71200)]
[InlineData(S7NetCpuType.S7300)]
[InlineData(S7NetCpuType.S7400)]
public void Parse_V_memory_rejected_on_modern_families(S7NetCpuType cpu)
=> Should.Throw<FormatException>(() => S7AddressParser.Parse("VW0", cpu));
[Fact]
public void Parse_V_memory_rejected_when_no_CpuType_supplied()
=> Should.Throw<FormatException>(() => S7AddressParser.Parse("VW0"));
}