简体   繁体   English

我如何(仅)使用 Eclipse Milo OpcUa 服务器更新 OPC UA 节点的时间戳?

[英]How do I (only) update the timestamp of an OPC UA Node using an Eclipse Milo OpcUa Server?

Thanks for reading this post.感谢您阅读这篇文章。 I am gratefull for every help!我很感激每一个帮助!

Goal:目标:

I am trying to write a ValueNode with the same value, but different timestamp on an Eclipse Milo OpcUa Server.我正在尝试在 Eclipse Milo OpcUa 服务器上编写一个具有相同值但时间戳不同的 ValueNode。 I'm doing all this with Java 11 and Milo 0.3.7.我正在用 Java 11 和 Milo 0.3.7 做这一切。

I tested it among others with the example in the github project.我使用 github 项目中的示例对其进行了测试。 I modified the function addScalarNodes in the class ExampleNamespace to write the same value with an updated timestamp once a second.我修改了 ExampleNamespace 类中的函数 addScalarNodes,以每秒一次的更新时间戳写入相同的值。 Checking the node with UaExpert, the timestamp remains on the same value.使用 UaExpert 检查节点,时间戳保持相同的值。 Only if I update the value too, the timestamp updates.只有当我也更新值时,时间戳才会更新。

private void addScalarNodes(UaFolderNode rootNode) {
        UaFolderNode scalarTypesFolder = new UaFolderNode(
            getNodeContext(),
            newNodeId("HelloWorld/ScalarTypes"),
            newQualifiedName("ScalarTypes"),
            LocalizedText.english("ScalarTypes")
        );

        getNodeManager().addNode(scalarTypesFolder);
        rootNode.addOrganizes(scalarTypesFolder);

        for (Object[] os : STATIC_SCALAR_NODES) {
            String name = (String) os[0];
            NodeId typeId = (NodeId) os[1];
            Variant variant = (Variant) os[2];

            UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(getNodeContext())
                .setNodeId(newNodeId("HelloWorld/ScalarTypes/" + name))
                .setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
                .setUserAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
                .setBrowseName(newQualifiedName(name))
                .setDisplayName(LocalizedText.english(name))
                .setDataType(typeId)
                .setTypeDefinition(Identifiers.BaseDataVariableType)
                .build();

            node.setValue(new DataValue(variant));

            node.setAttributeDelegate(new ValueLoggingDelegate());

            getNodeManager().addNode(node);
            scalarTypesFolder.addOrganizes(node);

            if (name.equals("Boolean")) {
                Thread t = new Thread(() -> {
                    while (true) {
                        try {
                            Thread.sleep(1000L);
                            node.setValue(new DataValue(new Variant(Boolean.FALSE)));
                            System.out.println(node.getValue().getSourceTime());
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                        }
                    }
                });
                t.start();
            }
        }
    }

My Question(s):我的问题:

1) Is updating the timestamp only allowed in OPC UA specs. 1) 正在更新仅在 OPC UA 规范中允许的时间戳。

2) How can I achive this with Milo? 2) 我怎样才能用 Milo 做到这一点?

Thanks in advance!提前致谢!

EDIT I check the timestamp by active reading:编辑我通过主动阅读检查时间戳:

Server-side writing:服务端写法:

private void handleValueUpdate(Object value, DateTime dateTime) {
        node.setValue(new DataValue(
            new Variant(value),
            StatusCode.GOOD,
            dateTime));
    }

Client-side reading:客户端阅读:

VariableNode variableNode = getOpcClient().getAddressSpace().getVariableNode(new NodeId(namespaceIndex, nodeIdentifier)).get();
return variableNode.readValue().get().getSourceTime();

Are you checking by reading (refreshing attributes pane) or with a subscription and monitored item?您是通过阅读(刷新属性窗格)还是通过订阅和受监控项目进行检查?

If you're using MonitoredItems the default MonitoringFilter when not otherwise specified uses DataChangeTrigger.StatusValue , which includes changes to value or quality, but not timestamp, so most clients will not ask for or receive timestamp-only changes by default.如果您正在使用 MonitoredItems,则默认的 MonitoringFilter 在未另行指定时使用DataChangeTrigger.StatusValue ,其中包括对值或质量的更改,但不包括时间戳,因此默认情况下大多数客户端不会要求或接收仅时间戳更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM