Page 1 of 1

Getting data from the server

Posted: 05 Dec 2021, 18:31
by alexanderzhirov
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.

Image
Image

The example from the 1st lesson is being executed. I connect to the server and read the time from it.

Image

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;
}

Re: Getting data from the server

Posted: 30 Dec 2021, 11:42
by Support Team
Hi,

there is a lot of example code in the full client example, which should guide you to the solution.
https://documentation.unified-automation.com/uasdkcpp/1.7.5/html/L2TutorialClientExample.html

You should look into the code provided with the SDK:
Read historical data on a variable (methods historyReadDataRaw, historyReadDataProcessed, historyReadDataAtTime)