Python OPCUA DisplayNames不显示

问题描述 投票:0回答:1

当我尝试用Python启动一个OPC UA服务器(运行python 3.7),并为一个节点设置一个DisplayName时,我有奇怪的行为。DisplayName属性被正确设置。当我在OPC UA客户端工具中检查它时,如 https:/github.comFreeOpcUaopcua-client-gui。 你可以在属性区域看到DisplayName的值......但正如预期的那样,树状视图没有在第一列中显示DisplayName。

是否有什么问题?是我疏忽了什么,还是我可能做错了什么?是不是不支持?事情是这样的,如果我用python OPC UA Modeler设置一个OPC UA服务器 https:/github.comFreeOpcUaopcua-modeler。 并连接到这个服务器的DisplayNames显示在第一列。

有什么想法或建议吗?THX in advance.

下面是示例代码

import sys
import locale
import time
from datetime import datetime

from opcua import ua, uamethod, Server

# Set Locale
locale.setlocale(locale.LC_ALL, 'de_DE')
t = time.strftime("%a, %d %b %Y %H:%M:%S")
print (t) # works fine: Fr, 05 Jun 2020 14:37:02

# Set Server 
server = Server()

server.set_endpoint("opc.tcp://localhost:48400")

uri = "http://opcfoundation.org/UA/"
idx = server.register_namespace(uri)
objects = server.get_objects_node()

storage = objects.add_object(idx, "storage")
storage.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Lager")))
storage.set_attribute(ua.AttributeIds.Description, ua.DataValue(ua.LocalizedText("")))
print("") 
print(storage.get_display_name()) # Works fine: LocalizedText(Encoding:2, Locale:None, Text:Lager)
print("")

st_ready = storage.add_variable(idx, "storage_ready", True)
st_ready.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Lager bereit")))
st_ready.set_attribute(ua.AttributeIds.Description, ua.DataValue(ua.LocalizedText("")))

stock = storage.add_object(idx, "stock")
stock.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Lagerbestand")))
stock.set_attribute(ua.AttributeIds.Description, ua.DataValue(ua.LocalizedText("")))

# Values in Stock
circles = stock.add_object(idx, "circles")
circles.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Kreise")))
squaes = stock.add_object(idx, "squares")
squaes.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Quadrate")))
triangles = stock.add_object(idx, "triangles")
triangles.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Dreiecke")))

red_c = circles.add_variable(idx, "red", 1)
red_c.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Rot")))
blue_c = circles.add_variable(idx, "blue", 1)
blue_c.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Blau")))
red_s = squaes.add_variable(idx, "red", 1)
red_s.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Rot")))
blue_s = squaes.add_variable(idx, "blue", 1)
blue_s.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Blau")))
red_t = triangles.add_variable(idx, "red", 0)
red_t.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Rot")))
blue_t = triangles.add_variable(idx, "blue", 1)
blue_t.set_attribute(ua.AttributeIds.DisplayName, ua.DataValue(ua.LocalizedText("Blau")))

# Start Server
server.start()

这里是第一列没有DisplayNames,但在OPC UA客户端窗口的属性区域设置了值。

OPC UA客户端窗口

python opc-ua displayname-attribute
1个回答
0
投票

我建议使用另一个OPC UA客户端工具。

UaExpert - 一个全功能的OPC UA客户端。

原因是:

  1. FreeOpcUa不在持续开发中。
  2. 支持文件有限
  3. UaExpert被设计为一个通用的测试客户端,支持OPC UA功能,如数据访问、警报和条件、历史访问和UA方法的调用。
  4. 它提供树状视图和 其他功能
© www.soinside.com 2019 - 2024. All rights reserved.