Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
TUaVariant AsType() missing?
July 27, 2023
16:36, EEST
Avatar
Guido Niewerth
Member
Members
Forum Posts: 13
Member Since:
August 23, 2022
sp_UserOfflineSmall Offline

Hello,

I’m trying to read node attributes from nodes an ran across this Delphi snippet from the “UaSampleClientForms.pas” sample:

procedure TUaSampleClientForm.AddSelectedNodesToDataView;
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:

TUaNodeClass read_node_class( TUaClient* client, TUaNodeId& node_id )
{
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?

July 28, 2023
10:05, EEST
Avatar
Ari-Pekka Soikkeli
Member
Members
Forum Posts: 5
Member Since:
February 14, 2022
sp_UserOfflineSmall Offline

Hello,

You can read NodeId values by using the TUaVariant.AsNodeId property:

TUaDataValue DataValue = UaClient->ReadAttribute(SomeNodeId, aiNodeId);
TuaNodeId NodeId = DataValue.Value.AsNodeId;

To read other structured types, you can try TUaVariant.AsStructure:

TUaDataValue DataValue = UaClient->ReadValue(Id_Server_ServerStatus);
TUaStatusCode StatusCode = DataValue.StatusCode;

if (StatusCode.IsGood) {
_di_IUaStructure S = DataValue.Value.AsStructure;
_di_IUaServerStatusDataType ServerStatus;
if (S->Supports(ServerStatus)) {

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
23 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: 734

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1523

Posts: 6449

Newest Members:

christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16, edgardo3518

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1