Giter VIP home page Giter VIP logo

Comments (3)

wildfire810 avatar wildfire810 commented on June 22, 2024
                byte[] buffer = getStickPackageHelper().execute(SerialHelper.this.mInputStream);
                if (buffer != null && buffer.length > 0) {
                    ComBean ComRecData = new ComBean(SerialHelper.this.sPort, buffer, buffer.length);
                    SerialHelper.this.onDataReceived(ComRecData);
                }

// int available = SerialHelper.this.mInputStream.available();
//
// if (available > 0) {
// byte[] buffer = new byte['?'];
// int size = SerialHelper.this.mInputStream.read(buffer);
// if (size > 0) {
// ComBean ComRecData = new ComBean(SerialHelper.this.sPort, buffer, size);
// SerialHelper.this.onDataReceived(ComRecData);
// }
// } else {
// SystemClock.sleep(50);
// }

这个地方,没有处理读取到的长度

from android-serialport.

xmaihh avatar xmaihh commented on June 22, 2024

默认实现的是 BaseStickPackageHelper,实现如下:

 @Override
    public byte[] execute(InputStream is) {
        try {
            int available = is.available();
            if (available > 0) {
                byte[] buffer = new byte['?'];
                int size = is.read(buffer);
                if (size > 0) {
                    return buffer;
                }
            } else {
                SystemClock.sleep(50);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

可以看到 byte[] buffer = new byte['?'];,定义了一个长度为63的字节数组(?的ascii值为63),所以总是返回63字节的数据。
无法确定收到数据大小的原因见issue1
你需要通过实现AbsStickPackageHelper接口,按照你的协议(帧头+数据长度+数据+校验值)来取数据。

from android-serialport.

wildfire810 avatar wildfire810 commented on June 22, 2024

谢谢。能看懂了。

from android-serialport.

Related Issues (20)

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.