<tfoot id='PpGpm'></tfoot>
        <bdo id='PpGpm'></bdo><ul id='PpGpm'></ul>

      <small id='PpGpm'></small><noframes id='PpGpm'>

      <i id='PpGpm'><tr id='PpGpm'><dt id='PpGpm'><q id='PpGpm'><span id='PpGpm'><b id='PpGpm'><form id='PpGpm'><ins id='PpGpm'></ins><ul id='PpGpm'></ul><sub id='PpGpm'></sub></form><legend id='PpGpm'></legend><bdo id='PpGpm'><pre id='PpGpm'><center id='PpGpm'></center></pre></bdo></b><th id='PpGpm'></th></span></q></dt></tr></i><div id='PpGpm'><tfoot id='PpGpm'></tfoot><dl id='PpGpm'><fieldset id='PpGpm'></fieldset></dl></div>

      1. <legend id='PpGpm'><style id='PpGpm'><dir id='PpGpm'><q id='PpGpm'></q></dir></style></legend>

        Bluez 的 C/C++ BLE 读/写示例

        C/C++ BLE read/write example with Bluez(Bluez 的 C/C++ BLE 读/写示例)
        • <i id='pZxmu'><tr id='pZxmu'><dt id='pZxmu'><q id='pZxmu'><span id='pZxmu'><b id='pZxmu'><form id='pZxmu'><ins id='pZxmu'></ins><ul id='pZxmu'></ul><sub id='pZxmu'></sub></form><legend id='pZxmu'></legend><bdo id='pZxmu'><pre id='pZxmu'><center id='pZxmu'></center></pre></bdo></b><th id='pZxmu'></th></span></q></dt></tr></i><div id='pZxmu'><tfoot id='pZxmu'></tfoot><dl id='pZxmu'><fieldset id='pZxmu'></fieldset></dl></div>
            <bdo id='pZxmu'></bdo><ul id='pZxmu'></ul>

                  <tbody id='pZxmu'></tbody>
                  <tfoot id='pZxmu'></tfoot>
                • <legend id='pZxmu'><style id='pZxmu'><dir id='pZxmu'><q id='pZxmu'></q></dir></style></legend>

                  <small id='pZxmu'></small><noframes id='pZxmu'>

                  本文介绍了Bluez 的 C/C++ BLE 读/写示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我开始使用微控制器和树莓派(tardis BLE 加密狗)构建一个简单的 BLE 网络.作为起点,我正在寻找一个简单的 C 或 C++ 示例来读/写 BLE 设备,类似于我能够通过命令行执行的操作.到目前为止,我发现的例子相当复杂.作为一名 BLE 初学者,我需要一些非常简单的示例来构建,然后再进行更复杂的设计.我可以像下面的 gatttool 示例中那样对 BLE 设备名称进行硬编码.

                  I am starting to build up a simple BLE network with a microcontroller and a raspberry pi (tardis BLE dongle). As a starting point, I am looking for a simple C or C++ example to read/write a BLE device, similar to what I am able to do over the command line. The examples I have found so far are quite complicated. As a BLE beginner I need some very simple examples to build from before moving forward with a more complicated design. I am okay with hard-coding the BLE device name as I have in the gatttool example below.

                  这是我目前使用 Bluez 命令行选项的方式.

                  Here is how I currently use the command line options from Bluez.

                  从命令行我可以使用:

                  $ sudo hcitool lescan
                  LE Scan ...
                  BB:A0:50:02:18:07 MyDevice
                  

                  接下来我可以使用 gatttool 在命令行上连接到设备:

                  Next I am able to connect to the device on the command line with gatttool:

                  $ sudo gatttol -b BB:A0:50:02:18:07 -I
                  [BB:A0:50:02:18:07][LE]> connect
                  Attempting to connect to BB:A0:50:02:18:07
                  Connection successful
                  

                  我终于可以使用适当的句柄进行读写了

                  Finally I am able to read and write using the appropriate handles

                  [BB:A0:50:02:18:07][LE]> char-write-req 000f 0100
                  Characteristic value was written successfully
                  [BB:A0:50:02:18:07][LE]> char-write-cmd 0011 4C467A
                  

                  我用于初步研究和入门的一些网站:
                  http://people.csail.mit.edu/albert/bluez-intro/c404.html
                  https://github.com/carsonmcdonald/bluez-实验/blob/master/experiments/scantest.c

                  Some sites I have used for initial research and to get started:
                  http://people.csail.mit.edu/albert/bluez-intro/c404.html
                  https://github.com/carsonmcdonald/bluez-experiments/blob/master/experiments/scantest.c

                  推荐答案

                  Bluez(Linux 官方蓝牙堆栈)已移至 DBUS 用于其 API.在过去,接受"分叉"bluez 代码以访问 Linux 上的 BLE 支持,而现在的方法是使用 DBUS.Bluez DBUS API 记录在此处:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

                  Bluez (Linux official Bluetooth stack) has moved to DBUS for its API. While in the past, it was 'accepted' to 'fork' bluez code to access BLE support on Linux, now the approach is to use DBUS. Bluez DBUS API is documented here: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

                  要么直接与 DBUS 对话以获取蓝牙 C/C++ 应用程序,要么使用 GATT 库作为助手.第二种方法可能是初学者的最佳方法(也适用于希望让 Bluez 程序不可知的非初学者,例如支持其他操作系统或 Bluez pre-DBUS API 或使其源代码更具可读性).

                  Either you directly speak to DBUS for your bluetooth C/C++ application or you use a GATT library as a helper. The second one is probably the best approach for beginner (and also for non-beginner who would prefer to keep their program Bluez agnostic for instance to support other OSes or Bluez pre-DBUS API or to have their sources more readable).

                  支持现代 D-BUS API 的 GATT 库之一是 gattlib(注意:我是该库的作者).这是一个基于此库的简单示例,用于读取/写入 BLE 设备:https://github.com/labapart/gattlib/blob/master/examples/read_write/read_write.c

                  One of these GATT libraries that support modern D-BUS API is gattlib (note: I am the author of this library). Here is a simple example based on this library for reading/writing a BLE device: https://github.com/labapart/gattlib/blob/master/examples/read_write/read_write.c

                  这篇关于Bluez 的 C/C++ BLE 读/写示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)

                • <small id='GHbq9'></small><noframes id='GHbq9'>

                  <i id='GHbq9'><tr id='GHbq9'><dt id='GHbq9'><q id='GHbq9'><span id='GHbq9'><b id='GHbq9'><form id='GHbq9'><ins id='GHbq9'></ins><ul id='GHbq9'></ul><sub id='GHbq9'></sub></form><legend id='GHbq9'></legend><bdo id='GHbq9'><pre id='GHbq9'><center id='GHbq9'></center></pre></bdo></b><th id='GHbq9'></th></span></q></dt></tr></i><div id='GHbq9'><tfoot id='GHbq9'></tfoot><dl id='GHbq9'><fieldset id='GHbq9'></fieldset></dl></div>
                    • <bdo id='GHbq9'></bdo><ul id='GHbq9'></ul>

                        <legend id='GHbq9'><style id='GHbq9'><dir id='GHbq9'><q id='GHbq9'></q></dir></style></legend>
                          <tbody id='GHbq9'></tbody>
                        <tfoot id='GHbq9'></tfoot>