2016-12-07 24 views
6

characterstic yazarken 128 okuma işlemi gerçekleştirmek için başarıyla am güçlü ben BLE device.I üzerinde okuma ve yazma işlemlerini gerçekleştirmek çalışıyorum kütüphaneye react-native-ble-managerBle-alma hata kodu - Aşağıdaki kullanıyorum

tepki. Ama BLE cihazına yazarken hata kodu 128 alıyorum.

ilk ben karakteristik için bildirim sağlayan am -

const base64String = new Buffer('0x00B00050D0', 'hex').toString('base64'); 

    BleManager.write(peripheralId, serviceId, characteristicId, base64Value) 

Yaz operasyon dönüş hata kodu -128 - base64 dizeye
dönüştürme 'onaltılık' value -

BleManager.startNotification(peripheralId, serviceId, characteristicId) 

Yazma böyledir

:(

GÜNCELLEME - Bu bildirim başlatmak ve tam dosyasını değer-yazma kod parçacığı olan bu bir hayır kaynaklar hatadır burada-BluetoothLeService.java

public void writeCharacteristic(BleCharacteristic bleCharacteristic, String inputValue) { 

    if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
     Log.w(TAG, "BluetoothAdapter not initialized"); 
     return; 
    } 

    if (!bleCharacteristic.isNotificationStarted()) { 
     Log.w(TAG, "Notification not started please start notification"); 
     return; 
    } 

    BluetoothGattCharacteristic bluetoothGattCharacteristic = bleCharacteristic.getBluetoothGattCharacteristic(); 
    bluetoothGattCharacteristic.setValue(inputValue); 
    mBluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic); 
} 

public void setCharacteristicNotification(BleCharacteristic bleCharacteristic) { 
    if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
     Log.w(TAG, "BluetoothAdapter not initialized"); 
     return; 
    } 
    boolean enable = !bleCharacteristic.isNotificationStarted(); 
    Log.d(TAG, "setCharacteristicNotification(device=" + mBluetoothDeviceAddress + ", UUID=" 
      + bleCharacteristic.getUUID().toString() + ", enable=" + enable + ")"); 
    BluetoothGattCharacteristic characteristic = mBluetoothGatt.getService(bleCharacteristic.getServiceUUID()).getCharacteristic(bleCharacteristic.getUUID()); 
    mBluetoothGatt.setCharacteristicNotification(characteristic, enable); 
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 
    descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[]{0x00, 0x00}); 
    boolean result = mBluetoothGatt.writeDescriptor(descriptor); 
    bleCharacteristic.setNotificationStarted(result); 
    Log.d(TAG, "setCharacteristicNotification(device=" + mBluetoothDeviceAddress + ", UUID=" 
      + bleCharacteristic.getUUID().toString() + ", enabled=" + result + ")"); 
} 
+0

: Burada

bir örnektir. 0_r1/stack/include/gatt_api.h # 49) bu hata 'GATT_NO_RESOURCES' anlamına gelir. – Distjubo

+0

Sadece ne anlama geldiğinden emin değil, 'write' yerine' writeWithoutResponse' kullandığınızda ne olur? Bu sorununuzu çözüyor mu? – Distjubo

+0

@Distjubo WriteWithoutResponse ile denedim ve herhangi bir hata atmadım ama sorunlar 1 yazıyor. yazdıktan sonra bir yanıt bekliyorum 2. Karakteristik tip yazılabilir YazmadıWithoutResponse – Subham

cevap

2

bulunabilir. Tanımlayıcıyı yazdığından emin misin? Eğer tanımlayıcıyı (BluetoothGattDescriptor) ayarlamaz ve sadece yazmayı çağırırsanız, bu hatayı alırsınız. [Bu] (https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1 göre

protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); 

public boolean setCharacteristicNotification(BluetoothDevice device, UUID serviceUuid, UUID characteristicUuid, 
     boolean enable) { 
    if (IS_DEBUG) 
     Log.d(TAG, "setCharacteristicNotification(device=" + device.getName() + device.getAddress() + ", UUID=" 
       + characteristicUuid + ", enable=" + enable + ")"); 
    BluetoothGatt gatt = mGattInstances.get(device.getAddress()); //I just hold the gatt instances I got from connect in this HashMap 
    BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid).getCharacteristic(characteristicUuid); 
    gatt.setCharacteristicNotification(characteristic, enable); 
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID); 
    descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); 
    return gatt.writeDescriptor(descriptor); //descriptor write operation successfully started? 
} 

Source

+0

Evet, bunu benzer şekilde yapıyorum. Öncelikle, karakteristik için yazmayı ve yazmaya çalışmayı etkinleştiririm. Ama her zaman hata kodu -128 ile döner. Kodu da yakında göndereceğim. – Subham

+0

Tamam, lütfen en son kodla yazıyı güncelledikten sonra bana bildirin. – Faraz

+0

Kodumu buraya ittim: //github.com/shubhapp/BleManager/blob/master/Application/src/main/java/com/km2/blemanager/connection/BleConnectionManager.java. Bugün bir şey gözlemledim - İlk defa yazmaya başladığımda, durum 128 alıyorum ancak daha sonra, bağlantıyı kesene ve tekrar bağlanana kadar her zaman 0 durumu alıyorum. Ama hiç bir çıkış değeri almamıştım – Subham

İlgili konular