我正在使用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;
}
}
答案 0 :(得分:1)
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);