我对 OPU UA 很陌生,如果这是一个非常基本的问题,请原谅。 我有一个需要设置 3 个参数的方法。使用 UaExpert 效果很好。
我的代码如下
id_types = await client.get_namespace_index(config.NS_TYPES)
id_core = await client.get_namespace_index(config.NS_CORE)
machine = await client.nodes.objects.get_child(
[f"{id_core}:HEIDENHAIN NC", f"{id_core}:Machine"])
tool_data_methods = await machine.get_child(
[
f"{id_types}:ToolDataManagement",
f"{id_types}:ToolDataAccess",
]
)
arg1 = ua.Variant("1:Length",ua.VariantType.String)
arg2 = ua.Variant(258, ua.VariantType.Double)
update_tool_data_method = await tool_data_methods.get_child([f"{id_types}:UpdateToolDataItems"])
update_data = await tool_data_methods.call_method(
update_tool_data_method,
(arg1,arg2),
ua.Variant(12, ua.VariantType.UInt32),
ua.Variant(0, ua.VariantType.Byte)
)
我收到此错误:
BadInvaildArgument:一个或多个参数无效。
我尝试过的是这样的:
id_types = await client.get_namespace_index(config.NS_TYPES)
id_core = await client.get_namespace_index(config.NS_CORE)
machine = await client.nodes.objects.get_child(
[f"{id_core}:HEIDENHAIN NC", f"{id_core}:Machine"])
tool_data_methods = await machine.get_child(
[
f"{id_types}:ToolDataManagement",
f"{id_types}:ToolDataAccess",
]
)
arg1 = ("1:Length")
arg2 = ua.Variant(258, ua.VariantType.Double)
arg3 = ua.KeyValuePair(arg1,arg2)
update_tool_data_method = await tool_data_methods.get_child([f"{id_types}:UpdateToolDataItems"])
update_data = await tool_data_methods.call_method(
update_tool_data_method,
(arg3),
ua.Variant(12, ua.VariantType.UInt32),
ua.Variant(0, ua.VariantType.Byte)
)
我收到此错误:
TypeError:必须使用数据类类型或实例进行调用。
有人可以给我提示如何进行 KeyValuePair 参数吗?
第一个参数是一个列表,所以试试这个:
id_types = await client.get_namespace_index(config.NS_TYPES)
id_core = await client.get_namespace_index(config.NS_CORE)
machine = await client.nodes.objects.get_child(
[f"{id_core}:HEIDENHAIN NC", f"{id_core}:Machine"])
tool_data_methods = await machine.get_child(
[
f"{id_types}:ToolDataManagement",
f"{id_types}:ToolDataAccess",
]
)
arg1 = ("1:Length")
arg2 = ua.Variant(258, ua.VariantType.Double)
arg3 = [ua.KeyValuePair(arg1,arg2)]
update_tool_data_method = await tool_data_methods.get_child([f"{id_types}:UpdateToolDataItems"])
update_data = await tool_data_methods.call_method(
update_tool_data_method,
arg3,
ua.UInt32(12),
ua.Byte(0)
)