Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OPC UA client: Call Methods

Tags:

python

opc

opc-ua

I'm Trying to call a method from a OPC UA server device. this is the method: StartScan Method

It contains Two Arguments: InputArguments OutputArguments

I'm not able with my code:

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)

Can someone help me? I'm new in OPC UA. Thanks.

like image 956
Leonardo Tavolari Avatar asked Sep 05 '26 13:09

Leonardo Tavolari


1 Answers

You have to get the parent object and use call_method from it. The first parameter is then your method. This should work.

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)
like image 161
Schroeder Avatar answered Sep 07 '26 02:09

Schroeder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!