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
OPC UA Client Read From Server
July 25, 2017
9:12, EEST
Avatar
amruthadevaraju
Member
Members
Forum Posts: 3
Member Since:
July 25, 2017
sp_UserOfflineSmall Offline

Hello ,

I have to read data from server using a client code which i have developed in VS c++ . I want to know if i can pass a variable in the server node to read instead of hardcoding it.
I am pasting the sample code below.
I am getting BadIDUnkown as the output. Please HELP!!

UaStatus result;
ServiceSettings serviceSettings;
UaReadValueIds nodeToRead;
UaDataValues values;
UaDiagnosticInfos diagnosticInfos;

// Configure one node to read
// We read the value of the ServerStatus -> CurrentTime
nodeToRead.create(1);
nodeToRead[0].AttributeId = OpcUa_Attributes_Value;
nodeToRead[0].NodeId.Identifier.Numeric = OpcUaId_Server_ServerStatus_CurrentTime; //This works fine
nodeToRead[0].NodeId.Identifier.Numeric = (int) settings.currentTime; //But, this gives an ERROR. settings.currentTime is a charecter array inside a structure. It contains “OpcUaId_Server_ServerStatus_CurrentTime” but I am not able to read this.

printf(“
Reading …
“);
result = m_pSession->read(
serviceSettings,
0,
OpcUa_TimestampsToReturn_Both,
nodeToRead,
values,
diagnosticInfos);

if (result.isGood())
{
// Read service succeded – check status of read value
if (OpcUa_IsGood(values[0].StatusCode))
{
printf(“ServerStatus_State: %s
“, UaVariant(values[0].Value).toString().toUtf8());
}
else
{
printf(“Read failed for item[0] with status %s
“, UaStatus(values[0].StatusCode).toString().toUtf8());
}
}
else
{
// Service call failed
printf(“Read failed with status %s
“, result.toString().toUtf8());
}

July 25, 2017
15:51, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

You seem to have a custom way to store the NodeIds. So you will need custom code, which can map your representation to the same value as OpcUaId_Server_ServerStatus_CurrentTime

July 26, 2017
7:05, EEST
Avatar
amruthadevaraju
Member
Members
Forum Posts: 3
Member Since:
July 25, 2017
sp_UserOfflineSmall Offline

Jouni Aro said
You seem to have a custom way to store the NodeIds. So you will need custom code, which can map your representation to the same value as OpcUaId_Server_ServerStatus_CurrentTime  

Seems to working Now. Thank You soo much Jouni Aro!Smile

July 26, 2017
7:08, EEST
Avatar
amruthadevaraju
Member
Members
Forum Posts: 3
Member Since:
July 25, 2017
sp_UserOfflineSmall Offline

Update :
Apart from the soln. Jouni Aro posted, In my code, I have defined the nodeId to take in a numeric value. i.e (nodeToRead[0].NodeId.Identifier.Numeric) if i replace the same wih nodeToRead[0].NodeId.Identifier.String , then it can take in the char variable. Works fine for Me!
Smile

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
9 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: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6260

Newest Members:

sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule

Moderators: Jouni Aro: 1009, 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