我正在尝试使用统一自动化的 opc ua DLL 从 Opc ua Server (Siemens) 读取日期和时间 (#DT)。但我得到错误的价值:
西门子 S7 1500 opc ua 客户端 DT#2008-10-25-08:12:34.567 --> 17.09.1142 05:08:27
我正在使用以下代码:
var td = ReadValue(NodeId).ToByteArray();
long temp = BitConverter.ToInt64(td, 0);
DateTime dateTimeVar = new DateTime(temp);
读取值函数:
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;
}