Giter VIP home page Giter VIP logo

Comments (7)

GreenGI avatar GreenGI commented on August 19, 2024 2

Hey, yeah, we have a working fork for reading data. Nothing pretty, but it gets the job done:
https://github.com/edvijaka/react-native-usbserial

from react-native-usbserial.

stefan-beyer avatar stefan-beyer commented on August 19, 2024

How about just giving the port.read() method a fixed buffer? Or we specify the buffersize via param.
The following code is completely untested:

    private static final int READ_BUFFER_SIZE = 256;
    ...
    public void readAsync(Promise promise) {
        if (port != null) {
            byte[] buffer = new byte[READ_BUFFER_SIZE];
            try {
                int bytesRead = port.read(buffer, SERIAL_TIMEOUT);
                String byteString = new String(buffer, 0, bytesRead);
                promise.resolve(byteString);
            } catch (IOException e) {
                promise.reject(e);
            }
        } else {
            promise.resolve(getNoPortErrorMessage());
        }
    }

from react-native-usbserial.

wil93 avatar wil93 commented on August 19, 2024

I studied the source code of this project a little bit and it looks like, for writing data, it just calls this:

return this.UsbSerialModule.writeInDeviceAsync(this.id, value);

Is it much harder to change this to 'read'? What exactly needs to be done to support reading from serial?

from react-native-usbserial.

gabrielhpugliese avatar gabrielhpugliese commented on August 19, 2024

Hi guys, have anyone implemented it already? I'm willing to pay for it if needed.

from react-native-usbserial.

gabrielhpugliese avatar gabrielhpugliese commented on August 19, 2024

Hey @GreenGI thank you.
Is this usage correct?

        DeviceEventEmitter.addListener('newData', (e) => {
          console.log('newData', e);
        });

from react-native-usbserial.

GreenGI avatar GreenGI commented on August 19, 2024

Basically - yes. This is how I use it on a component after mounting it:

componentWillMount() {
  this.getDeviceAsync().then(device => {
    if (device) {
      DeviceEventEmitter.addListener('newData', (e) => {
        console.log('newData', e);
      });
      this.readDevice(device.id);
    }
  });
}

getDeviceListAsync = () => {
  return UsbSerialModule.getDeviceListAsync();
};

readDevice = (id) => {
  UsbSerialModule.readDeviceAsync(id);
};

from react-native-usbserial.

omatrot avatar omatrot commented on August 19, 2024

Hi @GreenGI !
Is the code above still working in your fork?
Could you provide the code for getDeviceAsync()?
Thanks in advance.

from react-native-usbserial.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.