How to get value from Arraybuffer of BLE device read characteristic value

I have gone through doc of IONIC 2 which is https://ionicframework.com/docs/v2/native/ble/ . From there conversion of arraybuffer to string is given which is not working for me . As shown in image image
image
How to get firmware version from this data from read characteristics as Arraybuffer conversion code of IONIC 2 which is: function bytesToString(buffer) {
return String.fromCharCode.apply(null, new Uint8Array(buffer));
} is not working for me. Using that code I am getting output: îÍy}ùt. I am new to ionic . I have Byte Transmission Order least significant octet first (i.e., little endian). please provide me conversion solution. Thank you.

1 Like

Sorry you found the solution?, it’s that I’m the same

Yes , I found the solution. Here is my solution.

       var convertData = String.fromCharCode.apply(null, buffer);
  var hexResult = [];
  for (var i = 0; i < convertData.length; i++) {

    var resultNumber = convertData.charCodeAt(i);   //Dec
    var str = (+resultNumber).toString(16)
    var resultString: String = ""
    if (str.length <= 1) {
      resultString = ("0" + (+resultNumber).toString(16)).toUpperCase().substring(-2); //String
    } else {
      resultString = ("" + (+resultNumber).toString(16)).toUpperCase().substring(-2); //String
    }

    hexResult[i] = "0x" + resultString;

  }

  console.log("hex data:::" + hexResult)

hexresult will have hexadecimal values of buffer received from read characteristics…