Commit 43436b74 authored by Mathias Lüdtke's avatar Mathias Lüdtke Committed by oroulet

introduced call_method_full

outputs the full CallMethodResult object instead of the OutputArguments only
parent 1e06fcef
......@@ -12,28 +12,34 @@ def call_method(parent, methodid, *args):
nodeid of method as a NodeId object
arguments are variants or python object convertible to variants.
which may be of different types
returns a list of variants which are output of the method
returns a list of values or a single value depending on the output of the method
"""
if isinstance(methodid, (str, ua.uatypes.QualifiedName)):
methodid = parent.get_child(methodid).nodeid
elif isinstance(methodid, node.Node):
methodid = methodid.nodeid
arguments = []
for arg in args:
if not isinstance(arg, ua.Variant):
arg = ua.Variant(arg)
arguments.append(arg)
result = _call_method(parent.server, parent.nodeid, methodid, arguments)
result = call_method_full(parent, methodid, *args)
if len(result.OutputArguments) == 0:
return None
elif len(result.OutputArguments) == 1:
return result.OutputArguments[0].Value
return result.OutputArguments[0]
else:
return [var.Value for var in result.OutputArguments]
return result.OutputArguments
def call_method_full(parent, methodid, *args):
"""
Call an OPC-UA method. methodid is browse name of child method or the
nodeid of method as a NodeId object
arguments are variants or python object convertible to variants.
which may be of different types
returns a CallMethodResult object with converted OutputArguments
"""
if isinstance(methodid, (str, ua.uatypes.QualifiedName)):
methodid = parent.get_child(methodid).nodeid
elif isinstance(methodid, node.Node):
methodid = methodid.nodeid
result = _call_method(parent.server, parent.nodeid, methodid, to_variant(*args))
result.OutputArguments = [var.Value for var in result.OutputArguments]
return result
def _call_method(server, parentnodeid, methodid, arguments):
request = ua.CallMethodRequest()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment