Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not receiving data after connection #57

Open
Ngandu opened this issue Jan 10, 2024 · 11 comments
Open

Not receiving data after connection #57

Ngandu opened this issue Jan 10, 2024 · 11 comments

Comments

@Ngandu
Copy link

Ngandu commented Jan 10, 2024

Hey

After connecting successfully, I am not receiving data from the serialport.
Is there an additional step required after connecting?

This is my connection :

SerialPortAPI.setSuPath("/system/xbin/su");
const serialPort = await SerialPortAPI.open("/dev/ttyS4", { baudRate: 115200, dataBits:16 });
@Ngandu Ngandu changed the title Not receiving data Not receiving data after connection Jan 10, 2024
@lagschwein
Copy link

Are you subscribing to the onReceived event like this:

  // subscribe received data
  const sub = serialPort.onReceived(buff => {
    console.log(buff.toString('hex').toUpperCase());
  })

@Ngandu
Copy link
Author

Ngandu commented Jan 15, 2024

Hey @lagschwein
Yes, I am subscribing.

I am working on an RFID Reader, and when the scan/reading is triggered I am not receiving the data.

@lagschwein
Copy link

I would need a bit more information about your code to diagnose the problem

@Ngandu
Copy link
Author

Ngandu commented Jan 16, 2024

const serialPort = useRef();

async function connect() {
    try {
      SerialPortAPI.setSuPath("/system/xbin/su");
      serialPort.current = await SerialPortAPI.open("/dev/ttyS4", { baudRate: 115200 });

      // subscribe received data
      serialPort.current.onReceived(buff => {

        let trmp = buff.toString('hex').toUpperCase();

        console.log(trmp);
      })


    } catch (error) {
      console.warn(error);
    }
  }

  async function disconnect(){

            serialPort.current.close();

  }

async function send(hex){
    // send data with hex format
    try {

     await serialPort.current.send(hex);

    } catch (error) {
      console.warn(error);
    }
  }

Hey @lagschwein
Above is the code.

I use UseRef to keep the state of the connection and have separated the closing and sending through of data.

I know that connection works because I don't get any error when I send data after connecting.

@lagschwein
Copy link

lagschwein commented Jan 16, 2024

Does it work when sending data?

Also are you calling devicePathsAsync() to determine whether /dev/ttys4 is correct serial port path?

@Ngandu
Copy link
Author

Ngandu commented Jan 16, 2024

I think it does cause it does not return any error.
that is after connecting, if I try sending data before connecting I get an error

And yes, the device path is just a check, which works as well.

@lagschwein
Copy link

Does it work when sending data?

Also are you calling devicePathsAsync() to determine whether /dev/ttys4 is correct serial port path?

When I ask does it work I mean are you actually receiving the serial data on the other end of the serial port?

@Ngandu
Copy link
Author

Ngandu commented Jan 16, 2024

Once I connect I can get the device paths, so I am guessing the connection is correct.
But the issue is when I trigger scanning on the device I don't receive any data.

@lagschwein
Copy link

I would suggest switching to using https://github.com/bastengao/react-native-usb-serialport-for-android. I have been having much more success with this module.

@Ngandu
Copy link
Author

Ngandu commented Jan 17, 2024

Thank you @lagschwein
I will try it and give feedback

@lagschwein
Copy link

@Ngandu Depending on your implementation you may need to do some node module patching. There is an issue on that same repo that I replied to with a good solution here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants