我正在使用Bluez-5.43,并且正在使用dbus API。
尝试使用WriteValue方法将值写入特征时,出现以下错误:
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method "WriteValue" with signature "ay" on interface "org.bluez.GattCharacteristic1" doesn't exist.
如果有人帮助我解决这个问题,我将不胜感激:)
这是导致此问题的代码:
GVariant *char_value = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), buffer, *buffer_len, TRUE, NULL, NULL);
if (char_value == NULL){
printf("converting value error\n");
return -1;
}
else{
printf("converting value succeed\n");
g_dbus_proxy_call_sync (char_write_proxy, "WriteValue", g_variant_new ("(@ay)", char_value), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
printf("lign 154\n");
if (error != NULL){
printf("write failed: %s\n", error->message);
return -1;
}
else
break;
}
}
最佳答案
WriteValue()签名实际上是“ aya {sv}”,换句话说,您需要一个(通常为空)字典作为第二个参数。
该文档非常好:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt
构建字典的方式有多种,我更喜欢Variantbuilder。像这样:
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE("a{sv}"));
write_value_argument = g_variant_new ("(@aya{sv})", char_value, &builder);