fix(s7): treat ArrayCount>=1 as array so 1-element arrays read as arrays (review I-2)

This commit is contained in:
Joseph Doherty
2026-06-16 22:12:30 -04:00
parent 49ac1392a8
commit 3bbe39c166
2 changed files with 46 additions and 11 deletions
@@ -442,11 +442,12 @@ public sealed class S7Driver
? parsed
: S7AddressParser.Parse(tag.Address);
// Array path: a tag with a declared count > 1 reads a CONTIGUOUS block of
// Array path: a tag with a declared count >= 1 reads a CONTIGUOUS block of
// count × element-bytes in a SINGLE round-trip (Plc.ReadBytesAsync), then decodes each
// element from its big-endian slice into an element-typed CLR array. The scalar path
// (count null / <= 1) is left byte-for-byte unchanged below.
if (tag.ArrayCount is > 1)
// (count null) is left byte-for-byte unchanged below. A count of 1 IS a valid 1-element
// array (the foundation materialises a [1] OPC UA array node when isArray:true).
if (tag.ArrayCount is >= 1)
return await ReadArrayAsync(plc, tag, addr, ct).ConfigureAwait(false);
// S7.Net's string-based ReadAsync returns object where the boxed .NET type depends on
@@ -793,10 +794,10 @@ public sealed class S7Driver
var folder = builder.Folder("S7", "S7");
foreach (var t in _options.Tags)
{
// A tag carrying an array count (> 1) surfaces as a 1-D OPC UA array node; a missing
// count or a count of 1 stays scalar (count == 1 array adds no information over a
// scalar and would force every read down the slower block path).
var isArray = t.ArrayCount is > 1;
// A tag carrying a non-null array count (>= 1) surfaces as a 1-D OPC UA array node.
// A null count stays scalar. A count of 1 IS a valid 1-element array: the foundation
// materialises a [1] OPC UA array node when isArray:true, so the driver must agree.
var isArray = t.ArrayCount is >= 1;
folder.Variable(t.Name, t.Name, new DriverAttributeInfo(
FullName: t.Name,
DriverDataType: MapDataType(t.DataType),