From 4be0e6b2651f3d85d99f8c9b0ee6636610e9f6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cliang=5Ftao001=E2=80=9D?= Date: Fri, 2 Aug 2024 15:22:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=B0=83=E7=94=A8BleManage?= =?UTF-8?q?r=E7=9A=84notify=E6=8E=A5=E5=8F=A3=E5=90=8E=EF=BC=8C=E5=9C=A8on?= =?UTF-8?q?NotifySuccess=E5=9B=9E=E8=B0=83=E4=B8=AD=E5=86=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8BleManager=E7=9A=84write=E6=96=B9=E6=B3=95=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E6=8A=A5=E9=94=99device=20is=20busy=E7=9A=84BUG?= =?UTF-8?q?=E3=80=82=202.=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E3=80=82=203.=E4=BF=AE=E6=94=B9changelog=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “liang_tao001” --- AppScope/app.json5 | 2 +- CHANGELOG.md | 4 ++ entry/oh-package.json5 | 2 +- library/oh-package.json5 | 2 +- .../src/main/ets/bluetooth/BleConnector.ets | 39 ++++--------------- 5 files changed, 14 insertions(+), 35 deletions(-) diff --git a/AppScope/app.json5 b/AppScope/app.json5 index 1148bae..9def6f6 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,7 +3,7 @@ "bundleName": "cn.openharmony.fastble", "vendor": "example", "versionCode": 1000000, - "versionName": "2.0.1", + "versionName": "2.0.2", "icon": "$media:app_icon", "label": "$string:app_name" } diff --git a/CHANGELOG.md b/CHANGELOG.md index f303b58..a61e575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.0.2 + +- 修改调用BleManager的notify接口后,在onNotifySuccess回调中再调用BleManager的write方法后,报错device is busy的BUG。 + ## v2.0.1 - 新增notify特征值改变事件监听 diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index 77527a2..a7736af 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -5,7 +5,7 @@ "name": "entry", "description": "Please describe the basic information.", "main": "", - "version": "2.0.1", + "version": "2.0.2", "dependencies": { "@ohos/fastble": "file:../library" } diff --git a/library/oh-package.json5 b/library/oh-package.json5 index d1fe202..df77601 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -12,6 +12,6 @@ "description": "FastBle是一个处理蓝牙BLE设备的库,可以对蓝牙BLE设备进行过滤,扫描,连接,读取,写入等", "main": "Index.ets", "repository": "https://gitee.com/openharmony-sig/FastBle", - "version": "2.0.1", + "version": "2.0.2", "dependencies": {} } diff --git a/library/src/main/ets/bluetooth/BleConnector.ets b/library/src/main/ets/bluetooth/BleConnector.ets index a21836b..8ebd4c2 100644 --- a/library/src/main/ets/bluetooth/BleConnector.ets +++ b/library/src/main/ets/bluetooth/BleConnector.ets @@ -148,11 +148,14 @@ export default class BleConnector { return false; } - try { - gatt.setCharacteristicChangeNotification(characteristic, enable); - this.notifyMsgInit(); - bleNotifyCallback?.onNotifySuccess() + const func = async (): Promise => { + await gatt.setCharacteristicChangeNotification(characteristic, enable); + this.notifyMsgInit(); + bleNotifyCallback?.onNotifySuccess() + } + func() + return true } catch (err) { this.notifyMsgInit(); if (bleNotifyCallback != null) { @@ -160,34 +163,6 @@ export default class BleConnector { } return false; } - - - let descriptor: ble.BLEDescriptor | null = null; - if (useCharacteristicDescriptor) { - descriptor = this.getDescriptor(characteristic, characteristic.characteristicUuid); - } else { - descriptor = this.getDescriptor(characteristic, BleConnector.UUID_CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR); - } - if (descriptor == null) { - this.notifyMsgInit(); - if (bleNotifyCallback != null) { - bleNotifyCallback.onNotifyFailure(new OtherException("descriptor equals null")); - } - return false; - } else { - let u8Array: Uint8Array = new Uint8Array(enable ? BleConnector.ENABLE_NOTIFICATION_VALUE : BleConnector.DISABLE_NOTIFICATION_VALUE) - descriptor.descriptorValue = this.typedArrayToBuffer(u8Array); - try { - gatt.writeDescriptorValue(descriptor) - return true - } catch (e) { - this.notifyMsgInit(); - if (bleNotifyCallback != null) { - bleNotifyCallback.onNotifyFailure(new OtherException("gatt writeDescriptor fail")); - } - return false - } - } } /** -- Gitee