0

I have developed a React Native app for Android device to connect with a HW board and one of the functionality is to communicate with HW board with Serial I/F Adapter from Mobile .

I have tried out multiple npm packages and none of them I could get to work.

Here is my sample code

import SerialPortAPI from 'react-native-serial-port-api';

    const path = await SerialPortAPI.devicePaths(paths => {
      console.log("List paths", paths)
    })


  const connectDevice = async (cfg) => {
    const { baudRate, serialPortName, stopBits } = cfg
    serialPort = await SerialPortAPI.open(serialPortName, { baudRate, stopBits});

    const sub = serialPort.onReceived(buff => {
      const str = buff.toString('hex').toUpperCase()
      console.log(str);
    })
    await serialPort.send('A7B7');
  }

It is NOT listing the device List connected and also not able to open/write/read. Other packages I tried are:

  1. react-native-usbserial
  2. react-native-serialport
  3. react-native-usb-serialport
  4. react-native-serial-port-api

I any pointers and working sample will be of great help. Regards Raghu VT

Raghu Vallikkat
  • 365
  • 5
  • 16
  • Did you try connecting to the HW board using some serial terminal app to test if it is even able to connect to Android? Also, were you ever able to solve the problem and get it working? – D J Sep 11 '22 at 14:49

1 Answers1

0

Are you connecting the phone to your pc or it should work as host? I think that is key point to understand.

My phone is Host and I started with Android code.

Would recommend to use Android to test if possible.

You want to pay attention to the port type used.

If you use a USB AB connector you need to use an otg cable or adapter.

if case of type C , this will be detected automatically.

Hope could provide some hints

Mono Brezel
  • 133
  • 1
  • 2
  • 6