<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      遍歷OPCUA節(jié)點

      1.使用OPCUA,獲取PLC數(shù)據(jù)
      問題:如果是結(jié)構(gòu)體,數(shù)組發(fā)現(xiàn)不能夠使用符號訪問,只能用數(shù)字訪問
      image

      為了解決這個問題,通過代碼獲取所有的節(jié)點數(shù)據(jù),然后構(gòu)建到map里面
      簡介訪問數(shù)據(jù)
      image

      package plc.gy;
      
      import cn.hutool.core.util.StrUtil;
      import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
      import org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode;
      import org.eclipse.milo.opcua.stack.core.Identifiers;
      import org.eclipse.milo.opcua.stack.core.UaException;
      import org.eclipse.milo.opcua.stack.core.types.builtin.*;
      import org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection;
      import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
      import org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription;
      import org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult;
      import org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription;
      
      import java.util.*;
      import java.util.concurrent.ExecutionException;
      
      import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
      
      public class OpcUaNodeMapper {
          private static final String REQUIRED_KEYWORD = "服務(wù)器";
      
      
          public static void main(String[] args) {
              String endpointUrl = "opc.tcp://192.168.10.10:4840"; // OPC UA服務(wù)器地址
      
              try {
                  OpcUaClient client = OpcUaClient.create(
                          endpointUrl,
                          endpoints -> endpoints.stream()
                                  .filter(e -> e.getSecurityPolicyUri().equals("http://opcfoundation.org/UA/SecurityPolicy#None"))
                                  .findFirst(),
                          configBuilder -> configBuilder
                                  .setApplicationName(LocalizedText.english("OPC UA Mapper"))
                                  .setApplicationUri("urn:eclipse:milo:examples:client")
                                  .setRequestTimeout(uint(5000))
                                  .build()
                  );
      
                  client.connect().get();
                  System.out.println("已連接到OPC UA服務(wù)器: " + endpointUrl);
      
                  Map<String, NodeId> nodeMap = new LinkedHashMap<>();
                  browseAndPrint(client, Identifiers.RootFolder, "", nodeMap);
      
                  client.disconnect().get();
                  System.out.println("已斷開與服務(wù)器的連接");
      
              } catch (Exception e) {
                  System.err.println("通信失敗: " + e.getMessage());
                  e.printStackTrace();
              }
          }
      
          private static void browseAndPrint(OpcUaClient client, NodeId nodeId, String path, Map<String, NodeId> nodeMap)
                  throws ExecutionException, InterruptedException, UaException {
      
              BrowseDescription browse = new BrowseDescription(
                      nodeId,
                      BrowseDirection.Forward,
                      Identifiers.References,
                      true,
                      uint(NodeClass.Object.getValue() | NodeClass.Variable.getValue()),
                      uint(0x3f)
              );
      
              BrowseResult result = client.browse(browse).get();
              ReferenceDescription[] refs = result.getReferences();
      
              if (refs == null) return;
      
              for (ReferenceDescription ref : refs) {
                  NodeId childId = ref.getNodeId().toNodeId(client.getNamespaceTable()).orElse(null);
                  if (childId == null) continue;
      
                  String browseName = ref.getBrowseName().getName();
                  String currentPath = path.isEmpty() ? browseName : path + "." + browseName;
                  NodeClass nodeClass = ref.getNodeClass();
      
                  // 1. 區(qū)分大小寫
                  boolean hasServer = StrUtil.contains(currentPath, "服務(wù)器");
      
                  nodeMap.put(currentPath, childId);
      
                  String nodeType = (nodeClass == NodeClass.Variable) ? "變量節(jié)點" : "對象節(jié)點";
                  System.out.println("映射: " + currentPath + " → " + childId + "(" + nodeType + ")");
      
                  // 如果是變量節(jié)點,輸出基礎(chǔ)類型和數(shù)據(jù)類型
                  if (nodeClass == NodeClass.Variable) {
                      UaVariableNode varNode = client.getAddressSpace().getVariableNode(childId);
                      NodeId dataTypeId = varNode.getDataType();
                      String dataTypeStr = dataTypeId != null ? dataTypeId.toParseableString() : "未知";
      
                      String dataTypeName = client.getAddressSpace()
                              .getNode(dataTypeId)
                              .getBrowseName()
                              .getName();
      
                      System.out.println("  基礎(chǔ)類型: " + currentPath + ", 數(shù)據(jù)類型: " + dataTypeName);
                  }
      
                  // 遞歸瀏覽子節(jié)點
                  browseAndPrint(client, childId, currentPath, nodeMap);
              }
          }
      }
      
      

      image

      優(yōu)化1

      package plc.gy;
      
      import cn.hutool.core.util.StrUtil;
      import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
      import org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode;
      import org.eclipse.milo.opcua.stack.core.Identifiers;
      import org.eclipse.milo.opcua.stack.core.UaException;
      import org.eclipse.milo.opcua.stack.core.types.builtin.*;
      import org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection;
      import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
      import org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription;
      import org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult;
      import org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription;
      
      import java.util.*;
      import java.util.concurrent.ExecutionException;
      
      import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
      
      public class OpcUaNodeMapper {
          private static final String REQUIRED_KEYWORD = "服務(wù)器";
      
      
          public static void main(String[] args) {
              String endpointUrl = "opc.tcp://192.168.10.10:4840"; // OPC UA服務(wù)器地址
      
              try {
                  OpcUaClient client = OpcUaClient.create(
                          endpointUrl,
                          endpoints -> endpoints.stream()
                                  .filter(e -> e.getSecurityPolicyUri().equals("http://opcfoundation.org/UA/SecurityPolicy#None"))
                                  .findFirst(),
                          configBuilder -> configBuilder
                                  .setApplicationName(LocalizedText.english("OPC UA Mapper"))
                                  .setApplicationUri("urn:eclipse:milo:examples:client")
                                  .setRequestTimeout(uint(5000))
                                  .build()
                  );
      
                  client.connect().get();
                  System.out.println("已連接到OPC UA服務(wù)器: " + endpointUrl);
      
                  Map<String, NodeId> nodeMap = new LinkedHashMap<>();
                  browseAndPrint(client, Identifiers.RootFolder, "", nodeMap);
      
                  client.disconnect().get();
                  System.out.println("已斷開與服務(wù)器的連接");
      
              } catch (Exception e) {
                  System.err.println("通信失敗: " + e.getMessage());
                  e.printStackTrace();
              }
          }
      
          private static void browseAndPrint(OpcUaClient client, NodeId nodeId, String path, Map<String, NodeId> nodeMap)
                  throws ExecutionException, InterruptedException, UaException {
      
              BrowseDescription browse = new BrowseDescription(
                      nodeId,
                      BrowseDirection.Forward,
                      Identifiers.References,
                      true,
                      uint(NodeClass.Object.getValue() | NodeClass.Variable.getValue()),
                      uint(0x3f)
              );
      
              BrowseResult result = client.browse(browse).get();
              ReferenceDescription[] refs = result.getReferences();
      
              if (refs == null) return;
      
              for (ReferenceDescription ref : refs) {
                  NodeId childId = ref.getNodeId().toNodeId(client.getNamespaceTable()).orElse(null);
                  if (childId == null) continue;
      
                  String browseName = ref.getBrowseName().getName();
                  String currentPath = path.isEmpty() ? browseName : path + "." + browseName;
                  NodeClass nodeClass = ref.getNodeClass();
      
                  // 1. 區(qū)分大小寫
                  boolean hasServer = StrUtil.contains(currentPath, "服務(wù)器");
      
                  nodeMap.put(currentPath, childId);
      
                  String nodeType = (nodeClass == NodeClass.Variable) ? "變量節(jié)點" : "對象節(jié)點";
                  System.out.println("映射: " + currentPath + " → " + childId + "(" + nodeType + ")");
      
                  // 如果是變量節(jié)點,輸出基礎(chǔ)類型和數(shù)據(jù)類型
                  if (nodeClass == NodeClass.Variable) {
                      UaVariableNode varNode = client.getAddressSpace().getVariableNode(childId);
                      NodeId dataTypeId = varNode.getDataType();
                      String dataTypeStr = dataTypeId != null ? dataTypeId.toParseableString() : "未知";
      
                      String dataTypeName = client.getAddressSpace()
                              .getNode(dataTypeId)
                              .getBrowseName()
                              .getName();
      
                      System.out.println("  基礎(chǔ)類型: " + currentPath + ", 數(shù)據(jù)類型: " + dataTypeName);
                  }
      
                  // 遞歸瀏覽子節(jié)點
                  browseAndPrint(client, childId, currentPath, nodeMap);
              }
          }
      }
      
      
      posted @ 2025-07-15 16:44  拿受用  閱讀(130)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 天天澡日日澡狠狠欧美老妇| 中文无码vr最新无码av专区| 崇信县| 国产精品无码一区二区牛牛| 亚洲精品一区二区三区蜜| 亚洲一区二区三级av| 精品免费看国产一区二区| 99久久无码一区人妻a黑| yyyy在线在片| 国产不卡在线一区二区| 日韩精品不卡一区二区三区| 国产超碰无码最新上传| 果冻传媒18禁免费视频| 97国产揄拍国产精品人妻| 亚洲欧洲国产综合一区二区 | 老熟妇乱子交视频一区| 久久精品国产88精品久久| 中文字幕 欧美日韩| 人人澡人摸人人添| 亚洲天堂网中文在线资源| 亚洲乱熟女一区二区三区| 国产成人精品亚洲资源| 午夜福利电影| 国产高清在线精品一区不卡| 2021国产精品视频网站| 色综合久久精品亚洲国产| 日韩av无码精品人妻系列| 免费无码成人AV片在线| 国产伦一区二区三区久久| 秋霞电影院午夜无码免费视频| 天堂网av成人在线观看| 精品无码国产污污污免费| 极品少妇的粉嫩小泬视频| 国产精品午夜福利免费看| 亚洲国产精品久久久天堂麻豆宅男 | 91中文字幕一区在线| 久久欧洲精品成av人片| 久久精品国产只有精品96| 国产va免费精品观看精品| av天堂亚洲天堂亚洲天堂| 国产日韩综合av在线|