

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)) {
…
Most Users Ever Online: 1919
Currently Online:
126 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 793
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1538
Posts: 6493
Newest Members:
sophiadavis, Waynegalse, Phillipbus, Oscarsat, WilliamJer, WilliamTunse, mvsjonah79, RaymondSmutt, Merlin AI pap, patlawrence98Moderators: Jouni Aro: 1027, Pyry: 1, Petri: 0, Bjarne Boström: 1037, Jimmy Ni: 26, Matti Siponen: 353, Lusetti: 0
Administrators: admin: 1