RangeError: Source is too large


#1

Hi,

I’m new to Ionic and Javascript. I have a bluetooth serial application receiving data from a device that it is showed in a list in one page, but some times, I’m getting the following error:

Error in Success callbackId: BluetoothSerial1064132651 : RangeError: Source is too large
cordova.js:312
RangeError: Source is too large
    at Uint8Array.set (<anonymous>)
    at SafeSubscriber._next (file:///android_asset/www/build/main.js:1272:24)
    at SafeSubscriber.__tryOrUnsub (file:///android_asset/www/build/vendor.js:31613:16)
    at SafeSubscriber.next (file:///android_asset/www/build/vendor.js:31560:22)
    at Subscriber._next (file:///android_asset/www/build/vendor.js:31500:26)
    at Subscriber.next (file:///android_asset/www/build/vendor.js:31464:18)
    at successWrapper (file:///android_asset/www/plugins/cordova-plugin-bluetooth-serial/www/bluetoothSerial.js:84:13)
    at Object.callbackFromNative (file:///android_asset/www/cordova.js:293:58)
    at <anonymous>:1:9

After that error my list stop updating values. The app restore the communications after reentering to this page again.

I’m not sure if the problem is in my code or it is related to Bluetooth Serial native plug in.

This is my code that wait for bluetooth data, the data stream begin with these bytes: 85 170 2 and has 53 data bytes in total.

BTData() {
    
    let Buffer = new Uint8Array(128);
    let i = 0;
    let myZone = new NgZone({ });
    let waitEnc:boolean = true;
    
    this.BTSerial.subscribeRawData().subscribe ((data) => {          
 
      let x = 0;
      let Bytes = new Uint8Array(data);
              
      if (waitEnc)
      {
        x = Bytes.indexOf(85);
        if (x >= 0)
        {          
          Bytes = Bytes.slice (x);
          Buffer.set (Bytes, 0);            
          i = Bytes.length;
          waitEnc = false;         
        }
      }
      else
      {
        Buffer.set (Bytes, i);
        i += Bytes.length;
      }

      if (i > 2) 
      {
        if (Buffer[0] != 85 || Buffer[1] != 170 || Buffer[2] != 0)
        {
          waitEnc = true;
          i = 0;
        }
        else if (i > 52)
        {
          console.log("OK ");                   
            myZone.run(() => {        
            this.setListaValues(Buffer);            
         });

          waitEnc = true;
          i = 0;
        }       
      }
    },
      () => {
        // Error        
        //this.msjTitulo = "Error";
        //this.navColor = "danger";
        //console.log ("Error");
       }
    );
  }