以下是设置 OPC UA 服务器的代码:
import sys
from opcua import ua, Server
server = Server()
server.set_endpoint("opc.tcp://127.0.0.1:4808/")
server.set_server_name("ServerOPC")
uri = "http://server"
idx = server.register_namespace(uri)
objects = server.get_objects_node()
Object_1 =objects.add_object(idx,'MyFirstObject')
Object_2 =objects.add_object(idx,'MySecondObject')
Object_3 =objects.add_object(idx,'MyThirdObject')
Discret_1 = Object_1.add_variable(idx,'Discret_1',[0,0,0,0,0,0,0,0],varianttype=ua.VariantType.Int16)
Discret_2 = Object_2.add_variable(idx,'Discret_2',[0,0,0,0,0,0,0,0],varianttype=ua.VariantType.Int16)
Analog_3 = Object_3.add_variable(idx,'Analog_3',[10,20,30,40,50],varianttype=ua.VariantType.Int16)
Discret_1.set_writable()
Discret_2.set_writable()
Analog_3.set_writable()
server.allow_remote_admin(allow=True)
server.start()
我可以使用 UaExpert 成功读取和写入变量。但是我在 SCADA 客户端(WinCC)上失败了。我已建立连接并且可以浏览节点(变量)。类型是兼容的。但是当我启动运行时模式时,我的服务器会出现以下错误。
有谁知道如何解决这个问题?提前致谢!