简体   繁体   English

Qt中的Dbus org.bluez实现

[英]Dbus org.bluez implementation in Qt

I started to work with DBus and bluetooth in Qt. 我开始在Qt中使用DBus和蓝牙。 I want to develop a script that will just call method through DBus and get a reply. 我想开发一个仅通过DBus调用方法并得到回复的脚本。 The part of the code is here (that is the main part acutally): 代码的一部分在这里(这是主要部分):

QString hostname("00:07:80:60:CE:22");
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusInterface interface("org.bluez", "/", "Manager", bus, 0);

qDebug()<<"is valid: "<<interface.isValid()<<interface.lastError();

interface.lastError() gives following error: interface.lastError()给出以下错误:

QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.bluez was not provided by any .service files") QDBusError(“ org.freedesktop.DBus.Error.ServiceUnknown”,“任何服务文件均未提供名称org.bluez”)

I have bluez and dbus installed. 我安装了bluez和dbus。 I can search for bluetooth devices from command. 我可以从命令中搜索蓝牙设备。

I also tried command sudo bluetoothd -d -n and I Get this: D-Bus setup failed: Name already in use bluetoothd[21952]: Unable to get on D-Bus 我也尝试了命令sudo bluetoothd -d -n,我得到了:D-Bus设置失败:名称已经在使用中bluetoothd [21952]:无法上D-Bus

Does anyone know what could be a problem? 有谁知道可能是个问题?

The error you are getting ( name already in use ) means that the bluetooth daemon is already running on your system. 您得到的错误( name already in use )意味着您的系统上已经运行了蓝牙守护程序。 You can stop it by doing sudo service bluetooth stop , although I feel like it is a pretty brutal way to end the bluetooth daemon. 您可以通过执行sudo service bluetooth stop来停止它,尽管我觉得这是结束蓝牙守护程序的一种非常残酷的方法。 If you end the daemon, you also end the BlueZ D-Bus implementation, so you wouldn't be able to use it. 如果您结束守护程序,那么您还将结束BlueZ D-Bus实现,因此您将无法使用它。

Although I've never worked with Qt's bluetooth/dbus implementation, there are a few problems with your code: 尽管我从未使用过Qt的蓝牙/ dbus实现,但是您的代码仍存在一些问题:

First of all, the BlueZ interface is published through the system bus, not the session bus, so that's the first change that should be made. 首先,BlueZ接口是通过系统总线发布的,而不是通过会话总线发布的,因此这是应该进行的第一个更改。

Second, what is the function of the "Manager" parameter your passing? 其次,您传递的"Manager"参数的功能是什么? If you are trying to hook into a DBus interface called "Manager" then there is none. 如果您试图连接到名为"Manager"的DBus接口,则没有接口。 I'm not sure if there was, seeing as you asked this question in 2013. You can see the DBus interfaces BlueZ implements using a program called D-Feet. 我不确定是否有这种情况,您在2013年曾问过这个问题。您可以看到BlueZ使用名为D-Feet的程序实现的DBus接口。 You should try it out, as it has helped me understand the workings of BlueZ with DBus. 您应该尝试一下,因为它帮助我了解了DBZ与BlueZ的配合。 I recommend sudo apt-get install d-feet . 我建议sudo apt-get install d-feet The only interfaces that are published at the "/" path are org.freedesktop.DBus.Introspectable and org.freedesktop.DBus.Objectmanager . "/"路径上发布的唯一接口是org.freedesktop.DBus.Introspectableorg.freedesktop.DBus.Objectmanager Again, this can easily be seen and experimented with using D-Feet, as it allows visual representations of the abstract interfaces and paths. 同样,使用D-Feet可以很容易地看到并进行试验,因为它可以直观地表示抽象的接口和路径。

If, by any chance, you run into trouble later regarding GATT; 如果您以后碰巧遇到关贸总协定的麻烦, run bluetoothd with the -E experimental flag; 使用-E实验性标志运行bluetoothd this enables BlueZ GATT functionality. 这将启用BlueZ GATT功能。 (Just a heads up). (抬起头)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM