|
@@ -21,7 +21,6 @@ import org.eclipse.milo.opcua.stack.client.DiscoveryClient;
|
|
|
import org.eclipse.milo.opcua.stack.core.BuiltinDataType;
|
|
|
import org.eclipse.milo.opcua.stack.core.Identifiers;
|
|
|
import org.eclipse.milo.opcua.stack.core.UaException;
|
|
|
-import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
|
|
|
import org.eclipse.milo.opcua.stack.core.types.builtin.*;
|
|
|
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned;
|
|
|
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
|
|
@@ -341,4 +340,60 @@ public class OpcUaUtil {
|
|
|
}
|
|
|
return "通信异常(" + message + ")";
|
|
|
}
|
|
|
+
|
|
|
+ public static Result getNextAllItem(DataSource dataSource, String itemStr) {
|
|
|
+ OpcUaClient opcUaClient = null;
|
|
|
+ try {
|
|
|
+ opcUaClient = createClient(dataSource);
|
|
|
+ if (Blank.isEmpty(opcUaClient)) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "客户端创建失败");
|
|
|
+ }
|
|
|
+ opcUaClient.connect().get();
|
|
|
+ return Result.ok(getNextItem(opcUaClient, null));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
|
|
|
+ } finally {
|
|
|
+ if (Blank.isNotEmpty(opcUaClient)) {
|
|
|
+ opcUaClient.disconnect();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<? extends UaNode> getNextItem(OpcUaClient client, String itemStr) throws UaException {
|
|
|
+ if (Blank.isEmpty(client)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (Blank.isEmpty(itemStr)) {
|
|
|
+ return browserTree(client, null);
|
|
|
+ } else {
|
|
|
+ String[] split = itemStr.split("\\.");
|
|
|
+ List<? extends UaNode> nodes = browserTree(client, null);
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String itemId = split[i];
|
|
|
+ for (UaNode nd : nodes) {
|
|
|
+ if (itemId.equals(nd.getNodeId().getIdentifier())) {
|
|
|
+ nodes = browserTree(client, nd);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nodes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过上一级,获取下一次的所有item
|
|
|
+ *
|
|
|
+ * @param client
|
|
|
+ * @param uaNode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<? extends UaNode> browserTree(OpcUaClient client, UaNode uaNode) throws UaException {
|
|
|
+ if (uaNode == null) {
|
|
|
+// nodes = client.getAddressSpace().browseNodes(Identifiers.ObjectsFolder);//从根目录
|
|
|
+ return client.getAddressSpace().browseNodes(Identifiers.ViewsFolder);
|
|
|
+ } else {
|
|
|
+ return client.getAddressSpace().browseNodes(uaNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|