BlueZ D-Bus C或C ++示例 [英] BlueZ D-Bus C or C++ Sample

查看:373
本文介绍了BlueZ D-Bus C或C ++示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个应用程序,该应用程序搜索附近的蓝牙设备并与之通信。我的应用程序将用C ++编写,并打算在Linux下工作。

I am trying to write an application which searches Bluetooth devices nearby and communicates with them. My application is going to be written in C++, and intended to work under Linux.

4年前,我使用了BlueZ。但是现在,正如我所看到的,API进行了很多更改,现在使用的是D-Bus。我没有使用D-Bus的经验。我看了一些与客户端/服务器模型有关的教程。现在,我可以使用D-Bus。

4 years ago, I used BlueZ. But now, as I see, the API has been changed a lot and now it's using D-Bus. I was not experienced with D-Bus. I looked at some tutorials related to client/server model. Now, I'm OK with D-Bus.

但是我找不到任何示例说明如何在D-Bus中使用BlueZ。我需要一些将BlueZ和D-Bus一起使用的指导。

But I couldn't find any example which explains how to use BlueZ with D-Bus. I need some guidance for using BlueZ and D-Bus together.

是否有任何教程或示例可用于在C或C ++中通过D-Bus使用BlueZ?

Are there any tutorial or sample for working with BlueZ via D-Bus in C or C++?

(注意:已经用谷歌搜索过)

(note: already googled it)

推荐答案

您可能想签出最新Bluez源代码的 client 文件夹中的 main.c 文件。它是 bluetoothctl 工具的源代码。也运行它。源代码准确地显示了他们如何使用GDBus,包括代理,代理,调用方法(如API文档(/ doc文件夹)中所述)以及所有这些。

You might want to check out the main.c file in the client folder of the most recent Bluez source code. It's the source code for the bluetoothctl tool. Run it too. The source code shows exactly how they use GDBus, including proxies, agents, calling methods like described in the API documentation (/doc folder) and all that. It's in C and uses the high level API.

我建议您逐步执行代码,因为花了我2个星期的时间,试图理解C中的Bluez,并且事实证明,没有文档,但是当我阅读main.c文件时,我一天就可以准备好。阅读正确的DBus API文档以及更重要的概念。一些帮助了我的文档:

I suggest you step through the code because it took me 2 weeks endlessly trying to understand Bluez in C and the fact that there's no documentation, but when I read that main.c file I was ready in a day. Read up on proper DBus API documentation and more importantly the concepts. Some documents that helped me:

gdbus工具: https ://developer.gnome.org/gio/stable/gdbus.html

这些包含对gdbus的所有调用以及main.c文件中的对象并很好地解释它们。 https://developer.gnome.org/gio/stable/gdbus-convenience.html

These contain all the calls to gdbus and objects in the main.c file and explain them very well. https://developer.gnome.org/gio/stable/gdbus-convenience.html

D-Feet,这是检查和了解系统上Dbus的宝贵工具。尝试签出/ bluez总线。 https://wiki.gnome.org/action/show/Apps/DFeet? action = show& redirect = DFeet

D-Feet, an invaluable tool to inspecting and learning about Dbus on your system. Try checking out the /bluez bus. https://wiki.gnome.org/action/show/Apps/DFeet?action=show&redirect=DFeet

sudo apt -get install d-feet

教程虽然不多,但是值得一读以了解一些概念,因为bluetoothctl工具适合他们想在这里说。 http://dbus.freedesktop.org/doc/dbus-tutorial.html

Not much of a tutorial, but worth a read to understand some concepts, as the bluetoothctl tool fits into what they're trying to say here. http://dbus.freedesktop.org/doc/dbus-tutorial.html

虽然bluectlctl创建了一个交互式外壳,所以浪费时间尝试放入代码中可能并不明智,而只是从中选择需要的东西。

The bluetoothctl creates an interactive shell though, so it might not be wise to waste time trying to fit in your code, but just pick what you need from it.

这篇关于BlueZ D-Bus C或C ++示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆