

16:36, EEST

August 23, 2022

Hello,
I’m trying to read node attributes from nodes an ran across this Delphi snippet from the “UaSampleClientForms.pas” sample:
var
DataValue: TUaDataValue;
I: Integer;
TreeNode: TBrowseTreeNode;
begin
for I := 0 to AddressSpaceView.SelectionCount-1 do
begin
if AddressSpaceView.Selections[I] is TBrowseTreeNode then
begin
try
TreeNode := TBrowseTreeNode(AddressSpaceView.Selections[I]);
DataValue := UaClient.ReadAttribute(TreeNode.NodeId, aiNodeClass);
if DataValue.Value.AsType<TUaNodeClass> = ncVariable then
AddNodeToDataView(MonitoredItemView, TreeNode);
except
on E: Exception do
; // Failed – should we notify?
end;
end;
end;
end;
I tried the relavant part in my C++ application:
{
TUaDataValue data_value = client->ReadAttribute( node_id, aiNodeClass );
// The following line produces a compiler error
return data_value.Value.AsType<TUaNodeClass>();
// The following line works, because TUaNodeClass is an enumeration.
// But how do I deal with aiNodeId where the TUaVariant holds a TUaNodeId object?
return static_cast<TUaNodeClass>( data_value.Value.AsUInt32 );
}
The compiler error message is:
No member named ‘AsType’ in Prosysopc::Uabase::TUaVariant.
I searched the “ProsysOPC.UaBase.hpp” file for a “AsType” member, but didn’t find anything. There are some conversion functions, but no generic one. I tried ‘AsUInt32’ because TNodeClass is an enumeration and it worked, but I wonder how I can access structure values like TUaNodeId for the aiNodeId attribute?
I am using
– Embarcadero RAD Studio Alexandria 11.2
– Prosys Sentrol OPC UA SDK 7.6.0 for Alexandria 11.x
building for the Win32 platform.
Edit:
How do I post formatted code?
10:05, EEST

February 14, 2022

Hello,
You can read NodeId values by using the TUaVariant.AsNodeId property:
TuaNodeId NodeId = DataValue.Value.AsNodeId;
To read other structured types, you can try TUaVariant.AsStructure:
TUaStatusCode StatusCode = DataValue.StatusCode;
if (StatusCode.IsGood) {
_di_IUaStructure S = DataValue.Value.AsStructure;
_di_IUaServerStatusDataType ServerStatus;
if (S->Supports(ServerStatus)) {
…
1 Guest(s)
