root 2 年 前
コミット
5202aaf0fa
2 ファイル変更7 行追加3 行削除
  1. 1 1
      config/config.json
  2. 6 2
      main.py

+ 1 - 1
config/config.json

@@ -9,7 +9,7 @@
     "sys_conf": {
       "jinjiaqu": {
         "support": {
-          "opc_server_url": "opc.tcp://192.168.10.133:49320",
+          "opc_server_url": "opc.tcp://10.71.208.71:8098/TM.LongWallMind.OPCUAServer4.x",
           "sys_key": "support",
           "sys_name": "电液控",
           "file_name": "support.json",

+ 6 - 2
main.py

@@ -60,7 +60,7 @@ def get():
     for group in point_base_dic:
         for item in point_base_dic[group]:
             point_arr.append(item['key'])
-
+    
     # 根据服务地址获取Opc数据
     data = asyncio.run(get_opc_data(sys_url, point_arr, 2))
     # 显示请求地址IP
@@ -100,7 +100,10 @@ async def get_opc_data(sys_url, point_arr, ns=2):
             while i < len(point_arr):
                 node = f"ns={ns};s={point_arr[i]}"
                 tag = client.get_node(node)
-                sub = await client.create_subscription(500, handler)
+                try:
+                    sub = await client.create_subscription(500, handler)
+                except Exception as e:
+                    raise Exception("连接opc服务错误!")
                 value = None
                 try:
                     value = await tag.read_value()
@@ -120,6 +123,7 @@ async def get_opc_data(sys_url, point_arr, ns=2):
             return result_arr
     finally:
         # 网络连通性测试
+        print("报错咯")
         sys_ip = sys_url[10: sys_url.index(":", 10)]
         os.system(f'ping {sys_ip} -n 1')