Avatar
Please consider registering
guest
sp_LogInOut Log Insp_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 RSSsp_TopicIcon
TUaVariant AsType() missing?
July 27, 2023
16:36, EEST
Avatar
Guido Niewerth
Member
Members
Forum Posts: 15
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:
Guest(s) 43
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 90
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 732
Moderators: 8
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1545
Posts: 6516
Newest Members:
mood edibles, LouieWreve, daniellabdx, janessan21, sammiebeak359, gena7127517, thorstenbouldin, Brett.Rollason, steven014223542, Roberthat
Moderators: Jouni Aro: 1029, Pyry: 1, Petri: 1, Bjarne Boström: 1045, Jimmy Ni: 26, Matti Siponen: 353, Lusetti: 0, Elias: 0
Administrators: admin: 1