如何使用 D-Bus 获取设备名称

How to get device name with D-Bus?

本文关键字:设备名 获取 D-Bus 何使用      更新时间:2023-10-16

我在Linux上用C++开发了一个应用程序,它与blueooth设备(如蓝牙插座或扬声器)进行交互。我使用 D-Bus 命令获取配对设备的列表:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.ListDevices

它返回:

method return sender=:1.0 -> dest=:1.90 reply_serial=2
   array [
      object path "/org/bluez/489/hci0/dev_00_1F_C5_75_45_5E"
      object path "/org/bluez/489/hci0/dev_F0_13_C3_00_A1_08"
      object path "/org/bluez/489/hci0/dev_00_11_12_30_76_21"
      object path "/org/bluez/489/hci0/dev_00_11_12_30_76_22"
      object path "/org/bluez/489/hci0/dev_00_11_12_30_76_23"
      object path "/org/bluez/489/hci0/dev_00_11_12_30_76_24"
   ]

这很棒,但我不仅需要 MAC,还需要设备名称(例如"linvor"或"GT-I9300")。

请帮助我以正确的方式获得这些名字。

试试这个命令: dbus-send --system --type=method_call --print-reply --dest=org.bluez "/org/bluez/489/hci0/dev_00_1F_C5_75_45_5E" org.bluez.Device.GetProperties ,您将获得有关该设备的所有信息