use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project iot-tree by bambooww.
the class ConnPtOPCUA method writeUaNodeTreeJson.
public void writeUaNodeTreeJson(Writer w, boolean b_var, boolean force_refresh) throws Exception {
if (uaClient == null) {
throw new Exception("no UaClient connected");
}
// find /Root/Objects nodes
UaNode root = findUaNodeByPath(uaClient, new String[] { "Objects" });
if (root == null)
throw new Exception("no /Root/Objects/ node found");
// UaObjectNode uaou= new UaObjectNode(
// uaClient,
// getNodeId(),
// getBrowseName(),
// getDisplayName(),
// getDescription(),
// getWriteMask(),
// getUserWriteMask(),
// getEventNotifier()
// );
// NodeId nid = n.getNodeId() ;
w.write("{\"id\":\"" + UUID.randomUUID().toString() + "\"");
w.write(",\"nc\":0");
w.write(",\"icon\": \"fa fa-sitemap fa-lg\"");
w.write(",\"text\":\"" + this.getOpcEndPointURI() + "\"");
w.write(",\"state\": {\"opened\": true}");
List<? extends UaNode> nodes = uaClient.getAddressSpace().browseNodes(root);
if (nodes != null && nodes.size() > 0) {
w.write(",\"children\":[");
//
boolean bfirst = true;
for (UaNode node : nodes) {
String bn = node.getBrowseName().getName();
if (bn.startsWith("_"))
continue;
if (!b_var && node instanceof UaVariableNode)
continue;
if (bfirst)
bfirst = false;
else
w.write(',');
writeUaNodeTreeJson(w, uaClient, node, b_var);
}
w.write("]");
}
w.write("}");
// writeUaNodeTreeJson(w,uaClient,root);
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project iot-tree by bambooww.
the class ConnPtOPCUA method listBindBeSelectedItems.
private void listBindBeSelectedItems(List<BindItem> bis, OpcUaClient client, String ppath, UaNode n) throws Exception {
NodeId nid = n.getNodeId();
String bn = n.getBrowseName().getName();
if (n instanceof UaVariableNode) {
UaVariableNode uvn = (UaVariableNode) n;
DataValue dataval = uvn.getValue();
Object valob = dataval.getValue().getValue();
if (valob != null && valob.getClass().isArray()) {
Object[] objectArray = (Object[]) valob;
valob = Arrays.deepToString(objectArray);
}
String val_dt = Convert.toFullYMDHMS(dataval.getSourceTime().getJavaDate());
NodeId dt = uvn.getDataType();
UaVariableTypeNode vtn = uvn.getTypeDefinition();
UInteger[] arrdim = vtn.getArrayDimensions();
UaDataTypeNode tpnode = (UaDataTypeNode) uaClient.getAddressSpace().getNode(dt);
String datatp = tpnode.getBrowseName().getName();
String arr_dim = "";
if (arrdim != null && arrdim.length > 0) {
arr_dim = Convert.combineWith(arrdim, ',');
}
BindItem bi = new BindItem(ppath + "/" + bn, datatp);
bi.setVal(valob);
bis.add(bi);
return;
}
List<? extends UaNode> nodes = client.getAddressSpace().browseNodes(n);
if (nodes != null && nodes.size() > 0) {
if (Convert.isNullOrEmpty(ppath))
ppath = bn;
else
ppath += "/" + bn;
for (UaNode node : nodes) {
String bn0 = node.getBrowseName().getName();
if (bn0.startsWith("_"))
continue;
listBindBeSelectedItems(bis, client, ppath, node);
}
}
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project netxms by netxms.
the class ServerConnection method readNodeValue.
/**
* Read value of given node from server
*
* @param nodeId node ID
* @return node value
* @throws Exception
*/
private String readNodeValue(NodeId nodeId) throws Exception {
UaVariableNode node = session.getAddressSpace().getVariableNode(nodeId);
DataValue value = node.readValue();
return value.getValue().toString();
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project netxms by netxms.
the class ServerConnection method writeNodeValue.
/**
* @param nodeId
* @param value
* @return
* @throws Exception
*/
private boolean writeNodeValue(NodeId nodeId, String newValue) throws Exception {
UaVariableNode node = session.getAddressSpace().getVariableNode(nodeId);
// Determine data type
ExpandedNodeId dataType = dataTypeCache.get(nodeId);
if (dataType == null) {
Variant value = node.readValue().getValue();
dataType = value.getDataType().get();
if (dataType == null) {
Platform.writeDebugLog(6, String.format("OPCUA: writeNodeValue(%s, \"%s\") for %s: cannot read data type", nodeId.toString(), value, url));
return false;
}
Platform.writeDebugLog(6, String.format("OPCUA: writeNodeValue(%s, \"%s\") for %s: type %s", nodeId.toString(), value, url, dataType.toString()));
dataTypeCache.put(nodeId, dataType);
}
Variant v;
if (Identifiers.Boolean.equals(dataType)) {
v = new Variant(Boolean.parseBoolean(newValue));
} else if (Identifiers.Int32.equals(dataType) || Identifiers.UInt32.equals(dataType)) {
v = new Variant(Integer.parseInt(newValue));
} else if (Identifiers.Int64.equals(dataType) || Identifiers.UInt64.equals(dataType)) {
v = new Variant(Long.parseLong(newValue));
} else {
v = new Variant(newValue);
}
CompletableFuture<List<StatusCode>> f = session.writeValues(ImmutableList.of(nodeId), ImmutableList.of(new DataValue(v)));
StatusCode status = f.get().get(0);
Platform.writeDebugLog(6, String.format("OPCUA: writeNodeValue(%s, \"%s\") for %s: status %s", nodeId.toString(), newValue, url, status.toString()));
return status.isGood();
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode in project iot-tree by bambooww.
the class ConnPtOPCUA method writeBindBeSelectTreeNode.
private void writeBindBeSelectTreeNode(Writer w, UaNode n) throws Exception {
// boolean bvar = n instanceof UaVariableNode;
NodeId nid = n.getNodeId();
w.write("{\"id\":\"" + nid.toParseableString() + "\"");
w.write(",\"nc\":" + n.getNodeClass().getValue());
if (n instanceof UaVariableNode) {
w.write(",\"tp\": \"tag\"");
w.write(",\"icon\": \"fa fa-tag fa-lg\"");
// if("BooleanArray".contentEquals(node.getBrowseName().getName()))
// {
// System.out.println("1");
// }
UaVariableNode uvn = (UaVariableNode) n;
DataValue dataval = uvn.getValue();
Object valob = dataval.getValue().getValue();
if (valob != null && valob.getClass().isArray()) {
Object[] objectArray = (Object[]) valob;
valob = Arrays.deepToString(objectArray);
}
String serverdt = Convert.toFullYMDHMS(dataval.getSourceTime().getJavaDate());
w.write(",\"val\":\"" + valob + "\"");
w.write(",\"val_dt\":\"" + serverdt + "\"");
NodeId dt = uvn.getDataType();
UaVariableTypeNode vtn = uvn.getTypeDefinition();
UInteger[] arrdim = vtn.getArrayDimensions();
UaDataTypeNode tpnode = (UaDataTypeNode) uaClient.getAddressSpace().getNode(dt);
String vt = tpnode.getBrowseName().getName();
w.write(",\"vt\":\"" + vt + "\"");
if (arrdim != null && arrdim.length > 0) {
w.write(",\"arr_dim\":\"" + Convert.combineWith(arrdim, ',') + "\"");
}
w.write(",\"text\":\"" + n.getDisplayName().getText() + ":" + vt + "\"}");
} else {
w.write(",\"tp\": \"tagg\"");
w.write(",\"icon\": \"fa fa-folder fa-lg\"");
w.write(",\"children\": true ");
w.write(",\"text\":\"" + n.getDisplayName().getText() + "\"}");
}
}
Aggregations