react-native-serial-port-api icon indicating copy to clipboard operation
react-native-serial-port-api copied to clipboard

Cannot read property 'open' of null

Open juanstan opened this issue 2 years ago • 4 comments
trafficstars

This plugin is not working for me. It does not recognise the class as it returns null

"

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

async function example() {
/*  const devices = await SerialPortAPI.devicePathsAsync();
  console.log(devices)*/
  const serialPort = await SerialPortAPI.open("/dev/ttyS4", { baudRate: 38400 });
  console.log(serialPort, 'serialPort');

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

  // unsubscribe
  // sub.remove();

  // send data with hex format
  await serialPort.send('00FF');

  // close
  serialPort.close();

}

example();

"

juanstan avatar Jun 17 '23 21:06 juanstan

Which version?

bastengao avatar Jun 19 '23 06:06 bastengao

Hello,

I tried the version v.1.4.0-rc.1 as I saw it in previous messages. Previously I think I tried the latest version.

Thank you

juanstan avatar Jun 19 '23 09:06 juanstan

Do you know if it works with expo? Thank you!

juanstan avatar Jun 19 '23 12:06 juanstan

I am not familiar with Expo. Can you try the latest version?

bastengao avatar Jun 20 '23 01:06 bastengao