Getting data from the server
Posted: 05 Dec 2021, 18:31
The documentation has a lesson on creating a connection to the server and reading data from it. But there is no example of how to get the data of a specific tag or nodeid. I would like to see an example of how to get historical data for a period of time using an existing tag. The documentation only describes the technical properties, but the logic of using these tools is absolutely not clear. Is it possible to provide an example of obtaining such data?
I have this data structure.
The example from the 1st lesson is being executed. I connect to the server and read the time from it.
But I would like to get the historical data of a certain tag (TNPZ.P_NEFT.R1.M). What do I need to do?
I have this data structure.
The example from the 1st lesson is being executed. I connect to the server and read the time from it.
But I would like to get the historical data of a certain tag (TNPZ.P_NEFT.R1.M). What do I need to do?
Code: Select all
UaStatus SampleClient::read()
{
UaStatus result;
ServiceSettings serviceSettings;
UaReadValueIds nodeToRead;
UaDataValues values;
UaDiagnosticInfos diagnosticInfos;
nodeToRead.create(1);
nodeToRead[0].AttributeId = OpcUa_Attributes_Value;
nodeToRead[0].NodeId.Identifier.Numeric = OpcUaId_Server_ServerStatus_CurrentTime;
printf("\nReading ...\n");
result = m_pSession->read(
serviceSettings,
0,
OpcUa_TimestampsToReturn_Both,
nodeToRead,
values,
diagnosticInfos);
if (result.isGood())
{
if (OpcUa_IsGood(values[0].StatusCode))
{
printf("ServerStatusCurrentTime: %s\n", UaVariant(values[0].Value).toString().toUtf8());
}
else
{
printf("Read failed for item[0] with status %s\n", UaStatus(values[0].StatusCode).toString().toUtf8());
}
}
else
{
printf("Read failed with status %s\n", result.toString().toUtf8());
}
return result;
}