issue Reading DT (date and time) from opc ua siemens

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
asdin
Jr. Member
Jr. Member
Posts: 3
Joined: 14 Nov 2019, 10:05

issue Reading DT (date and time) from opc ua siemens

Post by asdin »

I'm trying to read the date and time (#DT) from Opc ua Server (Siemens) using opc ua DLLs of unifiedautomation. But i get wrong value:
siemens S7 1500 opc ua client DT#2008-10-25-08:12:34.567 --> 17.09.1142 05:08:27

I'm using the following code:

Code: Select all

var td = ReadValue(NodeId).ToByteArray();
long temp = BitConverter.ToInt64(td, 0);
DateTime dateTimeVar = new DateTime(temp); 
ReadValue function:

Code: Select all

public Variant ReadValue(string VariableIdentifier)
{
            Variant data = new Variant();

            List<DataValue> results = read(VariableIdentifier);
            if (results.Count > 0)
            {
                if (StatusCode.IsGood(results[0].StatusCode))
                {
                    data = results[0].WrappedValue;
                    m_OpcError = "OK";
                }
                else
                {
                    m_OpcError = results[0].StatusCode.Message;
                }
            }
            else
            {
                m_OpcError = "ReadValue function: it Couldn't read data from OPC UA Server (empty data)";
            }

            return data;
}        

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: issue Reading DT (date and time) from opc ua siemens

Post by Support Team »

Hello,

You should to use the method Variant.ToDateTime().
Best regards
Unified Automation Support Team

Post Reply