Class MiloOpcUaClient
- java.lang.Object
-
- org.eclipse.basyx.vab.protocol.opcua.connector.milo.MiloOpcUaClient
-
- All Implemented Interfaces:
IOpcUaClient
public class MiloOpcUaClient extends Object implements IOpcUaClient
Provides a wrapper around the eclipse Milo OPC UA client that works in the BaSyx environment.
-
-
Constructor Summary
Constructors Constructor Description MiloOpcUaClient(String endpointUrl)
Creates a new OPC UA client for the given endpoint URL with a default configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<org.eclipse.milo.opcua.sdk.client.api.UaClient>
getClient()
Gets the client object from the underlying OPC UA library.ClientConfiguration
getConfiguration()
Gets the current client configuration.String
getEndpointUrl()
Gets the endpoint URL that this client connects to.boolean
hasConnected()
Gets a value signifying whether this client has already attempted to establish a connection to the server endpoint.List<Object>
invokeMethod(NodeId ownerId, NodeId methodId, Object... parameters)
Invokes an OPC UA method on an object.CompletableFuture<List<Object>>
invokeMethodAsync(NodeId ownerId, NodeId methodId, Object... parameters)
Invokes an OPC UA method on an object.Object
readValue(NodeId nodeId)
Reads the current value from an OPC UA node.CompletableFuture<Object>
readValueAsync(NodeId nodeId)
Reads the current value from an OPC UA node.void
setConfiguration(ClientConfiguration configuration)
Sets the client configuration.void
setConfiguration(org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfigBuilder configuration)
Sets advanced configuration settings not available inClientConfiguration
.NodeId
translateBrowsePathToNodeId(String browsePath)
Gets the id of the node matching the given browse path when resolved against the root node.NodeId
translateBrowsePathToNodeId(NodeId startingNode, String relativePath)
Gets the id of the node pointed to by when resolving the given path against the starting node.CompletableFuture<NodeId>
translateBrowsePathToNodeIdAsync(String browsePath)
Gets the id of the node matching the given browse path when resolved against the root node.CompletableFuture<NodeId>
translateBrowsePathToNodeIdAsync(NodeId startingNode, String relativePath)
Gets the id of the node pointed to by when resolving the given path against the starting node.List<NodeId>
translateBrowsePathToParentAndTargetNodeId(String browsePath)
Gets the id of the last two nodes pointed to by when resolving the given path against the starting node.CompletableFuture<List<NodeId>>
translateBrowsePathToParentAndTargetNodeIdAsync(String browsePath)
Gets the id of the last two nodes pointed to by when resolving the given path against the starting node.void
writeValue(NodeId nodeId, Object value)
Writes the value of an OPC UA node.CompletableFuture<Void>
writeValueAsync(NodeId nodeId, Object value)
Writes the value of an OPC UA node.
-
-
-
Constructor Detail
-
MiloOpcUaClient
public MiloOpcUaClient(String endpointUrl)
Creates a new OPC UA client for the given endpoint URL with a default configuration.The client will attempt to discover available endpoint at this URL. The one to use will be selected by looking at the security policy and message security mode. These can be configured using
setConfiguration(ClientConfiguration)
.- Parameters:
endpointUrl
- The client will attempt to discover available endpoints at this URL. Among all of these the one that matches the configured security policy and message security mode will be selected.- Throws:
IllegalArgumentException
- if endpointUrl isnull
.
-
-
Method Detail
-
getConfiguration
public ClientConfiguration getConfiguration()
Gets the current client configuration.See the documentation of
IOpcUaClient.getConfiguration()
for more information.- Specified by:
getConfiguration
in interfaceIOpcUaClient
- Returns:
- A copy of the current configuration.
-
setConfiguration
public void setConfiguration(ClientConfiguration configuration)
Sets the client configuration.See the documentation of
IOpcUaClient.setConfiguration(ClientConfiguration)
for more information.- Specified by:
setConfiguration
in interfaceIOpcUaClient
- Parameters:
configuration
- The configuration to set ornull
to use a default configuration.
-
setConfiguration
public void setConfiguration(org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfigBuilder configuration)
Sets advanced configuration settings not available inClientConfiguration
.This method allows setting a Milo-specific configuration object which gives access to the full range of options that Milo supports as opposed to the limited selection in
ClientConfiguration
.Be aware, that the security policy and message security mode for endpoint selection can only be set using
setConfiguration(ClientConfiguration)
.
Additionally, for settings which are available in both configuration objects,ClientConfiguration
will take precedence overOpcUaClientConfigBuilder
.The order in which you call
setConfiguration(ClientConfiguration)
andsetConfiguration(OpcUaClientConfigBuilder)
is not important. Caution: Use this method at your own risk. Your code might break if BaSyx switches to a newer version of Milo or a different OPC UA implementation altogether.- Parameters:
configuration
- The Milo client configuration object.- Throws:
IllegalStateException
- if this method is called after a connection has been established.
-
getEndpointUrl
public String getEndpointUrl()
Gets the endpoint URL that this client connects to.- Specified by:
getEndpointUrl
in interfaceIOpcUaClient
- Returns:
- The endpoint URL of the server to connect to.
-
hasConnected
public boolean hasConnected()
Gets a value signifying whether this client has already attempted to establish a connection to the server endpoint.See the documentation of
IOpcUaClient.hasConnected()
for more information.- Specified by:
hasConnected
in interfaceIOpcUaClient
- Returns:
true
if a connection attempt has been made,false
otherwise.
-
getClient
public CompletableFuture<org.eclipse.milo.opcua.sdk.client.api.UaClient> getClient()
Gets the client object from the underlying OPC UA library.If the client hasn't been created, yet, it will be created automatically, making any subsequent changes to the configuration impossible. Caution: Use this method at your own risk. The underlying client API might change without notice, making any user code relying on this method fragile.
- Returns:
- The underlying client object.
-
translateBrowsePathToNodeId
public NodeId translateBrowsePathToNodeId(String browsePath)
Gets the id of the node matching the given browse path when resolved against the root node.See the documentation of
IOpcUaClient.translateBrowsePathToNodeId(String)
for more information.- Specified by:
translateBrowsePathToNodeId
in interfaceIOpcUaClient
- Parameters:
browsePath
- The string representation of the browse path.- Returns:
- The id of the node matching the browse path.
-
translateBrowsePathToNodeIdAsync
public CompletableFuture<NodeId> translateBrowsePathToNodeIdAsync(String browsePath)
Gets the id of the node matching the given browse path when resolved against the root node.See the documentation of
IOpcUaClient.translateBrowsePathToNodeIdAsync(String)
for more information.- Specified by:
translateBrowsePathToNodeIdAsync
in interfaceIOpcUaClient
- Parameters:
browsePath
- The string representation of the browse path.- Returns:
- A
CompletableFuture
for the target node's id.
-
translateBrowsePathToNodeId
public NodeId translateBrowsePathToNodeId(NodeId startingNode, String relativePath)
Gets the id of the node pointed to by when resolving the given path against the starting node.See the documentation of
IOpcUaClient.translateBrowsePathToNodeId(NodeId, String)
for more information.- Specified by:
translateBrowsePathToNodeId
in interfaceIOpcUaClient
- Parameters:
startingNode
- The starting node from where to start resolvingrelativePath
.relativePath
- The string representation of the relative path to resolve againststartingNode
.- Returns:
- The id of the node matching the browse path.
-
translateBrowsePathToNodeIdAsync
public CompletableFuture<NodeId> translateBrowsePathToNodeIdAsync(NodeId startingNode, String relativePath)
Gets the id of the node pointed to by when resolving the given path against the starting node.See the documentation of
IOpcUaClient.translateBrowsePathToNodeId(NodeId, String)
for more information.- Specified by:
translateBrowsePathToNodeIdAsync
in interfaceIOpcUaClient
- Parameters:
startingNode
- The starting node from where to start resolvingrelativePath
.relativePath
- The string representation of the relative path to resolve againststartingNode
.- Returns:
- A
CompletableFuture
for the target node's id.
-
translateBrowsePathToParentAndTargetNodeId
public List<NodeId> translateBrowsePathToParentAndTargetNodeId(String browsePath)
Gets the id of the last two nodes pointed to by when resolving the given path against the starting node.See the documentation of
IOpcUaClient.translateBrowsePathToParentAndTargetNodeId(String)
for more information.- Specified by:
translateBrowsePathToParentAndTargetNodeId
in interfaceIOpcUaClient
- Parameters:
browsePath
- The string representation of the browse path.- Returns:
- A list of two node ids, where the first is the method node and the second is its parent.
-
translateBrowsePathToParentAndTargetNodeIdAsync
public CompletableFuture<List<NodeId>> translateBrowsePathToParentAndTargetNodeIdAsync(String browsePath)
Gets the id of the last two nodes pointed to by when resolving the given path against the starting node.See the documentation of
IOpcUaClient.translateBrowsePathToParentAndTargetNodeIdAsync(String)
for more information.- Specified by:
translateBrowsePathToParentAndTargetNodeIdAsync
in interfaceIOpcUaClient
- Parameters:
browsePath
- The string representation of the browse path.- Returns:
- A
CompletableFuture
for a list of parent and method node id.
-
readValue
public Object readValue(NodeId nodeId) throws OpcUaException
Reads the current value from an OPC UA node.See the documentation of
IOpcUaClient.readValue(NodeId)
for more information.- Specified by:
readValue
in interfaceIOpcUaClient
- Parameters:
nodeId
- The id of the node to read.- Returns:
- The node's current value.
- Throws:
OpcUaException
- if an OPC UA related error occurs or if the server can't provide a valid value at this time. This is a generic wrapper type for exceptions thrown by the client library.
-
readValueAsync
public CompletableFuture<Object> readValueAsync(NodeId nodeId)
Reads the current value from an OPC UA node.See the documentation of
IOpcUaClient.readValueAsync(NodeId)
for more information.- Specified by:
readValueAsync
in interfaceIOpcUaClient
- Parameters:
nodeId
- The id of the node to read.- Returns:
- A
CompletableFuture
for the node's current value.
-
writeValue
public void writeValue(NodeId nodeId, Object value) throws OpcUaException
Writes the value of an OPC UA node.See the documentation of
IOpcUaClient.writeValue(NodeId, Object)
for more information.- Specified by:
writeValue
in interfaceIOpcUaClient
- Parameters:
nodeId
- The id of the node to write.value
- The new value to write. Can benull
.- Throws:
OpcUaException
- if an OPC UA related error occurs. This is a generic wrapper type for exceptions thrown by the client library.
-
writeValueAsync
public CompletableFuture<Void> writeValueAsync(NodeId nodeId, Object value)
Writes the value of an OPC UA node.See the documentation of
IOpcUaClient.writeValueAsync(NodeId, Object)
for more information.- Specified by:
writeValueAsync
in interfaceIOpcUaClient
- Parameters:
nodeId
- The id of the node to write.value
- The new value to write. Can benull
.- Returns:
- A
CompletableFuture
.
-
invokeMethod
public List<Object> invokeMethod(NodeId ownerId, NodeId methodId, Object... parameters) throws OpcUaException
Invokes an OPC UA method on an object.See the documentation of
IOpcUaClient.invokeMethod(NodeId, NodeId, Object...)
for more information.- Specified by:
invokeMethod
in interfaceIOpcUaClient
- Parameters:
ownerId
- The node id of the object (or object type) on which to invoke the method.methodId
- The node id of the method to invoke.parameters
- The input parameters of the operation.- Returns:
- The outputs from the operation.
- Throws:
OpcUaException
- if an OPC UA related error occurs. This is a generic wrapper type for exceptions thrown by the client library.
-
invokeMethodAsync
public CompletableFuture<List<Object>> invokeMethodAsync(NodeId ownerId, NodeId methodId, Object... parameters)
Invokes an OPC UA method on an object.See the documentation of
IOpcUaClient.invokeMethodAsync(NodeId, NodeId, Object...)
for more information.- Specified by:
invokeMethodAsync
in interfaceIOpcUaClient
- Parameters:
ownerId
- The node id of the object (or object type) on which to invoke the method.methodId
- The node id of the method to invoke.parameters
- The input parameters of the operation.- Returns:
- A
CompletableFuture
for the method's outputs.
-
-