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: 1026
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: 1919

Currently Online:
16 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: 726

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_gallery

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

Administrators: admin: 1