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: 518
Currently Online:
8 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
hbrackel: 135
pramanj: 86
Francesco Zambon: 81
rocket science: 77
Ibrahim: 76
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
fred: 41
Member Stats:
Guest Posters: 0
Members: 683
Moderators: 16
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1467
Posts: 6261
Newest Members:
digitechroshni, LouieWreve, Kickbiche, karrimacvitie5, graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPoomaModerators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5
Administrators: admin: 1