【问题标题】:org.bluez.GattCharacteristic1 WriteValue methodorg.bluez.GattCharacteristic1 WriteValue 方法
【发布时间】:2017-10-23 10:41:04
【问题描述】:

我正在使用 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;
    }
}

【问题讨论】:

  • 造成这个问题的代码在哪里?
  • 你应该在你的帖子中发布它

标签: c api glib dbus bluez


【解决方案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);

【讨论】:

  • 感谢您的回复 :) 您能帮我在使用 g_dbus_proxy_call_sync 调用 WriteValue 方法时如何传递这些参数
  • 我添加了一个 untested 示例——我认为这是正确的,但这些可能很棘手……developer.gnome.org/glib/stable/gvariant-format-strings.html 是一个很好的资源,当你试图做到这一点时—— - 它还解释了“builder as g_variant_new() argument”技巧。
  • 对我来说也是非常有用的答案。我测试了你的例子并且它有效。 @JussiKukkonen
猜你喜欢
  • 2019-01-05
  • 1970-01-01
  • 2021-07-23
  • 1970-01-01
  • 2013-08-13
  • 2021-03-07
  • 2022-12-09
  • 1970-01-01
  • 2021-11-24
相关资源
最近更新 更多