OPC UA 客户端:调用方法

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

我正在尝试从 OPC UA 服务器设备调用方法。 这是方法: StartScan Method

它包含两个参数: InputArguments OutputArguments

我无法使用我的代码:

from opcua import Client, ua

url = "opc.tcp://10.239.37.236:4840"
client = Client(url)
#client.set_user = "user"
#client.set_password = "pw"
client.connect()

print("client connected")

while True:
    lsd = client.get_node("ns=4; i=6013")
    LastScanData = lsd.get_value()
    print(LastScanData)

    start = client.get_node("ns=3; i=7009")
    input_Arg = client.get_node("ns=3, i=6051")

    res = start.call_method(input_Arg,  ua.Variant(5, ua.VariantType.UInt32), ua.Variant(99, ua.VariantType.UInt32))
    time.sleep(1)

有人可以帮助我吗?我是 OPC UA 的新手。谢谢。

python opc-ua opc
2个回答
2
投票

您必须获取父对象并从中使用 call_method 。第一个参数就是你的方法。这应该有效。

method = client.get_node("ns=3; i=7009")
parent_obj = "ns=3; i=xxxx" # Nodeid of the object
obj = client.get_node(parent_obj)
inp1 = ua.Variant(5, ua.VariantType.UInt32)
out = obj.call_method(method, inp1)

0
投票

是否成功调用opc ua方法ScanStart?我正在尝试通过 python 连接到 SICK RFID 读取器...无法弄清楚要使用哪些参数...

© www.soinside.com 2019 - 2024. All rights reserved.