OPCFoundation / UA-.NETStandard

OPC Unified Architecture .NET Standard
Other
1.94k stars 942 forks source link

Server question about setting negative values to a BaseDataVariableState<double> #2766

Closed KTW-NIRAS closed 1 week ago

KTW-NIRAS commented 1 week ago

Type of issue

Current Behavior

I have the following method to create server variables:

protected BaseDataVariableState<double> CreateVariable(NodeState parent, string path, string name, double value, DateTime timestamp)
{
   var variable = new BaseDataVariableState<double>(parent);
   variable.SymbolicName = name;
   variable.ReferenceTypeId = ReferenceTypes.Organizes;
   variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
   variable.NodeId = new NodeId(path, NamespaceIndex);
   variable.BrowseName = new QualifiedName(path, NamespaceIndex);
   variable.DisplayName = new LocalizedText("en", name);
   variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
   variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
   variable.DataType = DataTypeIds.Double;
   variable.ValueRank = ValueRanks.Scalar;
   variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
   variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
   variable.Historizing = false;
   variable.IsValueType = true;
   variable.Value = value;
   variable.Timestamp = timestamp;
   variable.StatusCode = StatusCodes.Good;
   variable.OnSimpleWriteValue = new NodeValueSimpleEventHandler(OnWriteVariableValue);
   parent?.AddChild(variable);
   return variable;
}

Setting and updating data from code works as expected. (Both negative and positive values)

But if I try setting a negative value from tools like Matricon OPC UA Explorer, the server responds with this error:
Write request for ns=<Namespace>;s=<VariableName> failed due to :BadOutOfRange: The value was out of range.(0x803C0000)

The OnSimpleWriteValue, OnWriteValue and OnValidate methods are not even called when a negative value is entered.

Can anyone help me get this working?

Expected Behavior

No response

Steps To Reproduce

No response

Environment

- OS: Windows 10 Enterprise 22H2
- Environment: Microsoft Visual Studio Enterprise 2022 (64-bit) 17.11.3
- Runtime: .NET 8.0
- Nuget Version: 1.5.374.118
- Component: Opc.Ua.Server
- Server: Own implementation based on Reference Server code
- Client: Matrikon OPC UA Explorer

Anything else?

No response

KTW-NIRAS commented 1 week ago

Sorry, this was an issue with the old version of Matrikon OPC UA Explorer. Things work as expected in the newest version.