review(Driver.AbCip): fix declared UDT array members read as scalar (Medium)
Re-review at 7286d320. AbCip-016 (Medium): two cooperating defects made a declared array
member (e.g. REAL[4]) read one scalar/null — fan-out dropped ElementCount/IsArray, and
UdtMemberLayout.TryBuild ignored array members (mis-placing later members). Fix: thread
array shape through fan-out + opt whole-UDT grouping out when any member is an array + TDD.
AbCip-017 (severity-read StatusCode, Low) deferred.
This commit is contained in:
@@ -156,6 +156,37 @@ public sealed class AbCipArrayTests
|
||||
snapshots.Single().Value.ShouldNotBeOfType<int[]>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Driver.AbCip-016 — a DECLARED UDT member that is a 1-D array (<c>Setpoints : REAL[4]</c>)
|
||||
/// must READ as a typed CLR array, matching the array node it discovers as. Before the fix
|
||||
/// the member fan-out in <c>InitializeAsync</c> dropped the member's <c>ElementCount</c> /
|
||||
/// <c>IsArray</c>, so the fanned-out runtime definition defaulted to scalar and the read
|
||||
/// returned a single element (or null) instead of the array — a declared-type-vs-runtime-value
|
||||
/// mismatch.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Declared_udt_array_member_reads_as_typed_array()
|
||||
{
|
||||
var (drv, factory) = NewDriver(
|
||||
new AbCipTagDefinition("Motor", "ab://10.0.0.5/1,0", "Motor", AbCipDataType.Structure,
|
||||
Members:
|
||||
[
|
||||
new AbCipStructureMember("Setpoints", AbCipDataType.Real, ElementCount: 4),
|
||||
new AbCipStructureMember("Speed", AbCipDataType.DInt),
|
||||
]));
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
factory.Customise = p => new ArrayFakeAbCipTag(p, new float[] { 1.5f, 2.5f, 3.5f, 4.5f });
|
||||
|
||||
var snapshots = await drv.ReadAsync(["Motor.Setpoints"], CancellationToken.None);
|
||||
|
||||
snapshots.Single().StatusCode.ShouldBe(AbCipStatusMapper.Good);
|
||||
var value = snapshots.Single().Value.ShouldBeOfType<float[]>();
|
||||
value.ShouldBe([1.5f, 2.5f, 3.5f, 4.5f]);
|
||||
// The fanned-out member runtime must thread the member's element count to libplctag.
|
||||
factory.Tags["Motor.Setpoints"].CreationParams.ElementCount.ShouldBe(4);
|
||||
factory.Tags["Motor.Setpoints"].CreationParams.IsArray.ShouldBeTrue();
|
||||
}
|
||||
|
||||
// ---- Resolver: arrayLength threading ----
|
||||
|
||||
/// <summary>The equipment-tag resolver threads arrayLength into the def's ElementCount.</summary>
|
||||
|
||||
Reference in New Issue
Block a user