xseignard / cordovarduino

Cordova/Phonegap plugin for USB host serial communication from an Android device.
MIT License
166 stars 110 forks source link

registerReadCallback not receiving any data #126

Closed mvaljento closed 3 years ago

mvaljento commented 3 years ago

I'm using cordovarduino 0.0.10 with Ionic 5 along with @ionic-native/serial 5.30.0. I'm connecting to a FTDI device through USB on PWA running Android 8. I also tested on Android 10.

I'm managing to establish a connection and receive "registerReadCallback: true" from registerReadCallback. However, after that I receive no data in the callback even though the device should be sending serial data. I tested that it's sending data with a serial terminal app.

Changing dtr and rts attributes made no difference. Baudrate and other settings are correct since I took them from the terminal app and the connection is established.

Calling serial.read at any time results in an empty ArrayBuffer.

this.serial.requestPermission({
        vid: MY_VID,
        pid: MY_PID,
        driver: 'FtdiSerialDriver',
      }).then(() => {
        console.log('[Serial] permission granted');
        this.serial.open({
          baudRate: 115200,
          dataBits: 8,
          stopBits: 1,
          parity: 0,
          dtr: true,
          rts: false,
          sleepOnPause: true // The port with automatically close, and resume once the app is brought back to foreground.
        }).then(() => {
          console.log('Serial connection opened');
          this.serial.registerReadCallback().subscribe((data) => {
            console.log('[Serial] event', data);
          });
          resolve(this.serial);
        }).catch((error: any) => {
          console.error('[Serial] open error', error);
          reject();
        });
      }).catch((error: any) => {
        console.error('[Serial] permission error', error);
        reject();
      });
mvaljento commented 3 years ago

This was not a bug. Another process was consuming the messages.

joeyoyo commented 3 years ago

Have you solved this problem? I had the same problem, sending a 96 bytes message to the board using the writeHex method, However , i can not receive "registerReadCallback: true" from registerReadCallback. But other bytes can