Search in sources :

Example 1 with ExtensionObject

use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.

the class ExampleNamespace method addCustomUnionTypeVariable.

private void addCustomUnionTypeVariable(UaFolderNode rootFolder) throws Exception {
    NodeId dataTypeId = CustomUnionType.TYPE_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
    NodeId binaryEncodingId = CustomUnionType.BINARY_ENCODING_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
    UaVariableNode customUnionTypeVariable = UaVariableNode.builder(getNodeContext()).setNodeId(newNodeId("HelloWorld/CustomUnionTypeVariable")).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(newQualifiedName("CustomUnionTypeVariable")).setDisplayName(LocalizedText.english("CustomUnionTypeVariable")).setDataType(dataTypeId).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    CustomUnionType value = CustomUnionType.ofBar("hello");
    ExtensionObject xo = ExtensionObject.encodeDefaultBinary(getServer().getSerializationContext(), value, binaryEncodingId);
    customUnionTypeVariable.setValue(new DataValue(new Variant(xo)));
    getNodeManager().addNode(customUnionTypeVariable);
    customUnionTypeVariable.addReference(new Reference(customUnionTypeVariable.getNodeId(), Identifiers.Organizes, rootFolder.getNodeId().expanded(), false));
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) CustomUnionType(org.eclipse.milo.examples.server.types.CustomUnionType) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)

Example 2 with ExtensionObject

use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.

the class UnifiedAutomationReadCustomDataTypeExample method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    // Decoding a struct with custom DataType requires a DataTypeManager
    // that has the codec registered with it.
    // Add a SessionInitializer that will read any DataTypeDictionary
    // nodes present in the server every time the session is activated
    // and dynamically generate codecs for custom structures.
    client.addSessionInitializer(new DataTypeDictionarySessionInitializer(new GenericBsdParser()));
    client.connect().get();
    DataValue dataValue = client.readValue(0.0, TimestampsToReturn.Neither, NodeId.parse("ns=2;s=Demo.Static.Scalar.WorkOrder")).get();
    ExtensionObject xo = (ExtensionObject) dataValue.getValue().getValue();
    Object value = xo.decode(client.getDynamicSerializationContext());
    logger.info("value: {}", value);
    future.complete(client);
}
Also used : DataTypeDictionarySessionInitializer(org.eclipse.milo.opcua.sdk.client.dtd.DataTypeDictionarySessionInitializer) GenericBsdParser(org.eclipse.milo.opcua.binaryschema.GenericBsdParser) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)

Example 3 with ExtensionObject

use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.

the class SessionDiagnosticsObjectTypeNode method setSessionDiagnostics.

@Override
public void setSessionDiagnostics(SessionDiagnosticsDataType sessionDiagnostics) throws UaException {
    SessionDiagnosticsVariableTypeNode node = getSessionDiagnosticsNode();
    ExtensionObject value = ExtensionObject.encode(client.getStaticSerializationContext(), sessionDiagnostics);
    node.setValue(new Variant(value));
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) SessionDiagnosticsVariableTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.SessionDiagnosticsVariableTypeNode)

Example 4 with ExtensionObject

use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.

the class SessionDiagnosticsObjectTypeNode method setSubscriptionDiagnosticsArray.

@Override
public void setSubscriptionDiagnosticsArray(SubscriptionDiagnosticsDataType[] subscriptionDiagnosticsArray) throws UaException {
    SubscriptionDiagnosticsArrayTypeNode node = getSubscriptionDiagnosticsArrayNode();
    ExtensionObject[] encoded = ExtensionObject.encodeArray(client.getStaticSerializationContext(), subscriptionDiagnosticsArray);
    node.setValue(new Variant(encoded));
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) SubscriptionDiagnosticsArrayTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.SubscriptionDiagnosticsArrayTypeNode)

Example 5 with ExtensionObject

use of org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject in project milo by eclipse.

the class ServerDiagnosticsTypeNode method setSubscriptionDiagnosticsArray.

@Override
public void setSubscriptionDiagnosticsArray(SubscriptionDiagnosticsDataType[] subscriptionDiagnosticsArray) throws UaException {
    SubscriptionDiagnosticsArrayTypeNode node = getSubscriptionDiagnosticsArrayNode();
    ExtensionObject[] encoded = ExtensionObject.encodeArray(client.getStaticSerializationContext(), subscriptionDiagnosticsArray);
    node.setValue(new Variant(encoded));
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) SubscriptionDiagnosticsArrayTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.SubscriptionDiagnosticsArrayTypeNode)

Aggregations

ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)191 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)178 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)98 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)22 PropertyTypeNode (org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode)16 UaException (org.eclipse.milo.opcua.stack.core.UaException)12 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)11 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)11 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)10 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)10 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)9 List (java.util.List)8 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)8 Reference (org.eclipse.milo.opcua.sdk.core.Reference)7 LoggerFactory (org.slf4j.LoggerFactory)7 ArrayList (java.util.ArrayList)6 NoSuchElementException (java.util.NoSuchElementException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AbstractLifecycle (org.eclipse.milo.opcua.sdk.server.AbstractLifecycle)6 Session (org.eclipse.milo.opcua.sdk.server.Session)6