2017-06-06 6 views
0

Je dois envoyer comme valeur 0x0001, 0x0002 dans BLE setValue(),ble Android setValue comme 0x0001

Est-ce que quelqu'un sait comment transmettre?

pour l'exemple:

private void command() { 
    ongoing.setValue(0x0001); //error 
    mBluetoothLeService.writeCharacteristic(ongoing); 
    BluetoothLeService.setCharacteristicNotification(ongoing, true); 
    ... 
    ... 
    ... 
    mBluetoothLeService.readCharacteristic(ongoing); 
} 

Thanks. 

dans DeviceControlActivity.java:

private void displayGattServices(List<BluetoothGattService> gattServices){ 
    UUID UBI_COMMAND = UUID.fromString(SampleGattAttributes.UBI_ONGOING_INFO_SERVICE_UUID); 
    ... 
    ... 
    if (uuid.equals(SampleGattAttributes.UBI_ONGOING_INFO_SERVICE_UUID)){ 
     ongoing = gattService.getCharacteristic(UBI_ONGOING); 
    } 
} 
+0

Quel est le type de 'continuous'? – Sweeper

+0

Il devrait être BluetoothGattCharacteristic parce qu'il est passé à une méthode qui l'exige? – CmosBattery

+0

J'ai seulement lu, mais voir ici pour l'écriture: https://stackoverflow.com/questions/36163998/writing-data-to-bluetooth-le-characteristic-in-android ... Notamment, vous pourriez utiliser un méthode réelle comme @Override public void onCharacteristicWrite (BluetoothGatt gatt, .... pour écrire les données.Mais vous pourriez ne pas être écrit correctement selon le lien – CmosBattery

Répondre

1

d'abord définir le format d'entrée (octet) puis définissez la valeur de characterstics. Veuillez vérifier l'extrait ci-dessous. La fonction "writeCharacterstics" est disponible dans le BluetoothGatt. Si vous n'avez pas défini de méthode dans votre service, modifiez également l'objet "mBluetoothLeService" en objet "gatt" pour écrire la valeur.

  byte[] value = {(byte) 0x01}; 
      characteristic.setValue(value); 
      mBluetoothLeService.writeCharacteristic(characteristic); 
+0

Merci beaucoup. –