Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [milo-dev] Read out Data with Milo

Hello Simon,
To follow up on Mads email, here is some code from my UI project that displays attributes of the DataValue object that you might find instructive.

public synchronized DataValue readSynch(NodeId nodeId) throws Exception {
checkPreconditions();

try {
VariableNode node = opcUaClient.getAddressSpace().createVariableNode(nodeId);
DataValue value = node.readValue().get(REQUEST_TIMEOUT, REQUEST_TIMEOUT_UNIT);
return value;
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}

private void onSelectNode(OpcUaTreeNode treeNode) throws Exception {
selectedTreeNode = treeNode;

NodeId nodeId = treeNode.getNodeId();

// fill in attributes
ReferenceDescription ref = treeNode.getReferenceDescription();

NodeClass nodeClass = ref.getNodeClass();
NodeId nodeDataType = null;
Class<?> javaType = null;
boolean clazzIsArray = false;

Object value = null;
OffsetDateTime zdt = null;
String valueText = null;
String typeText = null;

if (nodeClass.equals(NodeClass.Variable)) {
DataValue dataValue = getApp().getOpcUaClient().readSynch(nodeId);
Variant variant = dataValue.getValue();
value = variant.getValue();

if (value != null) {
clazzIsArray = value.getClass().isArray();

// data type
Optional<NodeId> dataType = dataValue.getValue().getDataType();

if (dataType.isPresent()) {
nodeDataType = dataType.get();
}
javaType = BuiltinDataType.getBackingClass(nodeDataType);

selectedTreeNode.setNodeDataType(nodeDataType);

// timestamp
zdt = DomainUtils.localTimeFromDateTime(dataValue.getServerTime());
}
}

if (value != null) {
if (!clazzIsArray) {
typeText = javaType.getSimpleName();

if (javaType.equals(DateTime.class)) {
valueText = DomainUtils.utcTimeFromDateTime((DateTime) value).toString();
} else {
valueText = value.toString();
}
} else {
// array or matrix
UInteger[] dims = getApp().getOpcUaClient().getArrayDimensions(nodeId);

// check for matrix
if (dims != null) {
if (dims.length == 1) {
typeText = "Array of " + javaType.getSimpleName() + " with dimension " + arrayToString(dims);
} else {
typeText = "Matrix of " + javaType.getSimpleName() + " with dimensions " + arrayToString(dims);
}
}
StringBuilder sb = new StringBuilder();
arrayToStringRecursive(value, sb);
valueText = sb.toString();
}
}

this.lbNodeId.setText(nodeId.toParseableString());
this.lbNodeDescription.setText(ref.getBrowseName().getName());

this.lbNodeType.setText(typeText);

if (valueText != null) {
this.taNodeValue.setText(valueText);
} else {
this.taNodeValue.clear();
}

if (zdt != null) {
this.lbNodeTimestamp.setText(zdt.toString());
} else {
this.lbNodeTimestamp.setText(null);
}
}

On Fri, Jun 1, 2018 at 6:21 AM, Mads Stavang <stavang@xxxxxxxxx> wrote:
Hi Simon,

readValue() returns a CompletableFuture. Call its method get(), and it returns the object of desire (in this case DataValue). I would recommend to read about the CompletableFuture interface. It is used extensively in the milo project. Just google it, there are many tutorials explaining it.

Mads

On Fri 1. Jun 2018 at 15:09, Simon Felderer <simon-felderer@xxxxxxxxxx> wrote:

Hey guys, 

if I am using the Code of the Blog OPC UA solutions with Eclipse Milo, and I am trying to read out the value of  a Node ID choosen, I always get as a result something like: java.util.concurrent.CompletableFuture@753436a5[Completed normally]


Does anybody know how I can get the real value of that specific NodeID? 

My Code is the same as in OPC UA solutions from Jens: 

NodeId nodeIdString = new NodeId(1, "PLC.Manufacturere");

CompletableFuture<org.eclipse.milo.stack.core.types.buildin.DataValue> value = client.readValue(0,TimestampsToReturn.Both, nodeIdString);


Thank you! 



_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/milo-dev

_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/milo-dev



Back to the top