nauful / LibUA

Open-source OPC UA client and server library
Apache License 2.0
250 stars 90 forks source link

NodeVariables don't currently expose ArrayDimensions #178

Closed bevanweiss closed 1 week ago

bevanweiss commented 1 month ago

According to: https://reference.opcfoundation.org/Core/Part5/docs/5.3

If the ValueRank specifies an array of a specific dimension (i.e. ValueRank > 0) then the ArrayDimensions Attribute shall be specified.

However for some of the OPC-UA NodeSets which specify a ValueRank of > 0, there is no returned ArrayDimensions image

My thought is that this could be implemented as something like the below. However I'm not sure on the best way of getting the value for all the various type of NodeVariable definitions (many of which only have value because of it being returned from HandleReadRequestInternal).

var arrayValue = value as Array;
var nodeVar = node as NodeVariable;
object dims = null;
if (arrayValue is not null && nodeVar.ValueRank >= 0)
{
    var newDims = new uint[arrayValue.Rank];
    for (var j = 0; j < newDims.Length; ++j)
    {
        newDims[j] = (uint)test.GetLength(j);
    }
    dims = newDims;
}
nauful commented 1 month ago

Hello,

I would leave this as an implementation defined by whomever implements the server instead of via SDK via HandleReadRequest. Many lightweight applications won't populate fields NodeVariable to add to the default address space. Instead, they maintain a lightweight Dictionary<NodeId,...> for their own nodes. HandleReadRequest should return values for fields as necessary, nor BadAttributeIdInvalid/BadNotImplemented as allowed by their use cases.