bluetooth ble writecharacteristics return write_empty ondeviceresult

bluetooth ble writecharacteristics return write_empty ondeviceresult

我刚刚成功连接到蓝牙设备,并启用了读写通知。但是在我将值设置为 true 并调用 writecharacteristics 方法后,我可以写入设备并从 bledevice 获得写空响应。

对 ble 设备的写请求流程应该是什么?

    public void onServicesDiscovered(BluetoothGatt bluetoothGatt, int i) {

                BLEService.this.f8468j = BLEService.this.f8466h.getCharacteristic(BLEService.this.f8462d);//readchar.

                BLEService.this.f8467i = BLEService.this.f8466h.getCharacteristic(BLEService.this.f8460b);//writechar.

                 setcharacteristicnotification(true, bluetoothgat, BLEService.this.f8467i);  

// i need to writechar right now in here. but ondeviceresult returns "write_empty"... what is wrong?





bArr = new byte[]{97,48,24,69,96,27,79,91,55,7,30,63,87,84,7,87}
    this.BluetoothGattCharacteristicwrite.setValue(bArr);

    this.BluetoothGatt.writeCharacteristic(this.BluetoothGattCharacteristicwrite);

        super.onServicesDiscovered(bluetoothGatt, i);
    }
};

-

  private void setcharacteristicnotification(boolean z, BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
        if (bluetoothGatt != null && bluetoothGattCharacteristic != null) {
            bluetoothGatt.setCharacteristicNotification(bluetoothGattCharacteristic, z);
            BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(BLEService.this.f8463e);
            if (descriptor != null) {
                descriptor.setValue(z ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
                BLEService.this.f8465g.writeDescriptor(descriptor);
            }
           //("BLEService", "=== enableNotification isWriting = true ===");
            BLEService.this.m11448a(7);
        }
    }

您不能同时有多个未完成的 GATT 请求。现在,您无需等待 onDescriptorWrite 即可调用 writeDescriptor,然后调用 writeCharacteristic。