Commit d5c7acb2 authored by oroulet's avatar oroulet Committed by oroulet

make sure passing structc as method argument works

parent 12c0e7a0
......@@ -422,7 +422,9 @@ def _vtype_to_argument(vtype):
if isinstance(vtype, ua.Argument):
return vtype
arg = ua.Argument()
if isinstance(vtype, ua.VariantType):
if hasattr(vtype, "data_type"):
arg.DataType = vtype.data_type
elif isinstance(vtype, ua.VariantType):
arg.DataType = ua.NodeId(vtype.value)
else:
arg.DataType = ua.NodeId(vtype)
......
......@@ -20,11 +20,11 @@ async def main():
await new_struct(server, idx, "MyStruct", [
new_struct_field("MyBool", ua.VariantType.Boolean),
new_struct_field("MyUInt32", ua.VariantType.UInt32),
new_struct_field("MyUInt32List", ua.VariantType.UInt32, array=True),
])
await new_struct(server, idx, "MyOptionalStruct", [
new_struct_field("MyBool", ua.VariantType.Boolean),
new_struct_field("MyUInt32", ua.VariantType.UInt32),
new_struct_field("MyUInt32List", ua.VariantType.UInt32, array=True),
new_struct_field("MyInt64", ua.VariantType.Int64, optional=True),
])
await new_enum(server, idx, "MyEnum", [
......@@ -38,7 +38,7 @@ async def main():
await server.nodes.objects.add_variable(idx, "my_enum", ua.MyEnum.toto)
await server.nodes.objects.add_variable(idx, "my_struct", ua.Variant(ua.MyStruct(), ua.VariantType.ExtensionObject))
my_struct_optional = ua.MyOptionalStruct()
my_struct_optional.MyUInt32 = 45
my_struct_optional.MyUInt32List = [45, 67]
my_struct_optional.MyInt64 = -67
await server.nodes.objects.add_variable(idx, "my_struct_optional", ua.Variant(my_struct_optional, ua.VariantType.ExtensionObject))
......
......@@ -1343,3 +1343,35 @@ async def test_custom_struct_of_struct_with_spaces(opc):
var = await opc.opc.nodes.objects.add_variable(idx, "my mother struct", mystruct)
val = await var.read_value()
assert val.My_Sub_Struct.My_UInt32 == 78
async def test_custom_method_with_struct(opc):
idx = 4
data_type, nodes = await new_struct(opc.opc, idx, "MyStructArg", [
new_struct_field("MyBool", ua.VariantType.Boolean),
new_struct_field("MyUInt32", ua.VariantType.UInt32, array=True),
])
await opc.opc.load_data_type_definitions()
@uamethod
def func(parent, mystruct):
print(mystruct)
mystruct.MyUInt32.append(100)
return mystruct
methodid = await opc.server.nodes.objects.add_method(
ua.NodeId("ServerMethodWithStruct", 10),
ua.QualifiedName('ServerMethodWithStruct', 10),
func, [ua.MyStructArg], [ua.MyStructArg]
)
mystruct = ua.MyStructArg()
mystruct.MyUInt32 = [78, 79]
assert data_type.nodeid == mystruct.data_type
result = await opc.opc.nodes.objects.call_method(methodid, mystruct)
assert result.MyUInt32 == [78, 79, 100]
......@@ -332,7 +332,17 @@ def test_guid():
assert v == v2
def test_nodeid():
def test_nodeid_guid_string():
n = ua.GuidNodeId(identifier=uuid.uuid4())
s = n.to_string()
n2 = ua.NodeId.from_string(s)
s2 = n2.to_string()
print(n, n2, s, s2)
assert n == n2
assert s == s2
def test__nodeid():
nid = ua.NodeId()
assert nid.NodeIdType == ua.NodeIdType.TwoByte
nid = ua.NodeId(446, 3, ua.NodeIdType.FourByte)
......
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