Android的BLE,读写特性 [英] Android BLE, read and write characteristics

查看:978
本文介绍了Android的BLE,读写特性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发的Andr​​oid BLE,并且遇到了很多问题,Android的BLE堆栈。

I am currently developing Android BLE, and encounters a lot of problems with the Android BLE stacks..

我的开发工具是三星Galaxy j表示使用的Andr​​oid 4.3。

My development tool is Samsung Galaxy J with Android 4.3.

我想知道我怎么可以读取从BLE和写入特性的特性(就像我确认哪些数据我​​已经收到了,然后我通过发送BLE其他数据)

I want to know how can I read a characteristics from the BLE and the write the characteristics (is like i verify what data I have received, and then I send another data using the BLE)

和我有严重的问题,了解如何在Android BLE回调的作品, 我不明白这5个功能...和手册是不明确的,可以以简单的形式任何善良的灵魂解释???

and I have serious problem understanding how the Android BLE callbacks works, I dont understand these 5 functions...and the manual is not clear, can anyone good soul explain in simple form???

onCharacteristicWrite
onCharacteristicRead
onCharacteristicChanged
onDescriptorRead
onDescriptorWrite

我目前的情况是,我设法阅读onCharacteristicChanged()回调的数据,然后我验证所接收到的我尝试通过发送数据的数据

My current situation is, I managed to read the data in onCharacteristicChanged() callback and then I verified the received the data I try to send the data by using

characteristics.setValue(data)
gatt.writeCharacteristic(characteristics)

不过,Android的BLE堆栈并没有叫onCharacteristicsWrite()而事实上,Android的只是挂在那儿。

But, the Android BLE stack is not calling onCharacteristicsWrite() and in fact, Android just hangs there..

我尝试谷歌关于Android BLE,没有太多的信息,只有一堆抱怨的BLE堆栈不稳定怎么是......

I try to google about Android BLE, there is not much information and only bunch of complains on how unstable the BLE stacks is......

推荐答案

每个从Android BLE回调有其功能;

Each of the callback from the Android BLE has its functions;

这是用来读/写的配置设置BLE装置,一些制造商可能需要一些数据发送到BLE装置,并承认这一点,通过阅读,然后才能连接到BLE装置

This is used to write/read the configuration settings for the BLE device, some manufactures might require to send some data to the BLE device and acknowledge it by reading, before you can connect to the BLE device

这是用于将数据发送到BLE设备,通常在数据模式对BLE设备。 当你输入这个回调称为

This is used to send data to the BLE device, usually in data mode for the BLE device. This callback is called when you type

gatt.writeCharacteristic(characteristics);

onCharacteristicRead

这是用来从BLE设备读取数据 当你写这个code回调被称为

onCharacteristicRead

This is used to read data from the BLE device The callback is called when you write this code

gatt.readCharacteristic(characteristics);

onCharacteristicChanged

当您尝试发送邮件使用writeCharacteristic(特性)数据和BLE装置响应某个值这个回调被调用。

onCharacteristicChanged

This callback is called when you are trying to send data using writeCharacteristic(characteristics) and the BLE device responds with some value.

通常一个BLE装置有几个特点,使之简单,我仅举几个特点

Usually a BLE device has few characteristics, to make it simple, I name a few characteristics

  • - 写特性
  • READ - 读特性
  • WRITE - write Characteristics
  • READ - read Characteristics

要清楚,当你发送数据,则需要使用的特点,然后当BLE设备响应的Andr​​oid应用程序将调用的 READ 特性

To make it clear, when you send data, you will need to use WRITE characteristics and then when the BLE device responds Android app will call READ characteristics

要注意的很重要的一点就是Android的BLE堆栈允许你写在同一时间的特点之一只!!

A very important point to note is Android BLE stack allows you to write characteristics one at a time only!!

例如:如果你试图调用write特性两次在同一时间

Example: IF you try to call write characteristics twice at a same time

gatt.writeCharacteristic(characteristics);
gatt.writeCharacteristic(characteristics);

Android的BLE堆栈不会发出第二次写特性!

The Android BLE stack will not issue the 2nd write characteristics!

这篇关于Android的BLE,读写特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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