EddyVerbruggen / nativescript-bluetooth-demo

30 stars 21 forks source link

Uint8Array as write value doesn't work on Android 6.0.1 #16

Closed sebawita closed 7 years ago

sebawita commented 7 years ago

When I try to pass the value as an Uint8Array to call writeWithoutResponse function, the command doesn't seem to be processed correctly. However the same value presented as a string works fine.

Here is an example (the commented out line is for the code that works):

bluetooth.writeWithoutResponse({
    serviceUUID: this.serviceUUID,
    characteristicUUID: this.characteristicUUID,
    peripheralUUID: this.deviceUUID,
    // value: '0x71,0x20,0x40'
    value: new Uint8Array([0x71, 0x20, 0x40])
})

When I tried to manually adapt the steps of Bluetooth._encodeValue to copy the contents of my Uint8Array - like below - then the instruction seems to be processed just fine.

  var result = Array.create("byte", parts.length);

  for (var i=0; i<val.length; i++) {
    result[i] = val[i];
  }
  return result;

Am I using the Uint8Array in a wrong way? This is the way I am used to use it with Web Bluetooth ;)

sebawita commented 7 years ago

I've created the issue in the wrong repo. It can be closed. Moved to: https://github.com/EddyVerbruggen/nativescript-bluetooth/issues/36