0

我试过milo,但是我发现很难一个一个地创建数据对象。milo可以通过读取xml文件生成相应的代码吗?如何?非常感谢!

4

1 回答 1

0

是的你可以

private void addCustomStructTypeVariable(UaFolderNode rootFolder) throws Exception {
        NodeId dataTypeId = CustomStructType.TYPE_ID
            .localOrThrow(getServer().getNamespaceTable());

        NodeId binaryEncodingId = CustomStructType.BINARY_ENCODING_ID
            .localOrThrow(getServer().getNamespaceTable());

        UaVariableNode customStructTypeVariable = UaVariableNode.builder(getNodeContext())
            .setNodeId(newNodeId("HelloWorld/CustomStructTypeVariable"))
            .setAccessLevel(AccessLevel.READ_WRITE)
            .setUserAccessLevel(AccessLevel.READ_WRITE)
            .setBrowseName(newQualifiedName("CustomStructTypeVariable"))
            .setDisplayName(LocalizedText.english("CustomStructTypeVariable"))
            .setDataType(dataTypeId)
            .setTypeDefinition(Identifiers.BaseDataVariableType)
            .build();

        CustomStructType value = new CustomStructType(
            "foo",
            uint(42),
            true
        );

        ExtensionObject xo = ExtensionObject.encodeDefaultBinary(
            getServer().getSerializationContext(),
            value,
            binaryEncodingId
        );

        customStructTypeVariable.setValue(new DataValue(new Variant(xo)));

        getNodeManager().addNode(customStructTypeVariable);

        customStructTypeVariable.addReference(new Reference(
            customStructTypeVariable.getNodeId(),
            Identifiers.Organizes,
            rootFolder.getNodeId().expanded(),
            false
        ));
    }
于 2020-09-07T11:31:40.450 回答