Giter Club home page Giter Club logo

Comments (2)

DeanNode avatar DeanNode commented on May 24, 2024 1

对于判断是否成功连接的代码补充。通过查看源码发现:如果根据PrinterReader中的 readDataImmediately(buffer) 如果返回结果值不为-1似乎就可以判断为已经连接蓝牙打印机设备。
`
class PrinterReader extends Thread {
private boolean isRun = false;

    private byte[] buffer = new byte[100];

    public PrinterReader() {
        isRun = true;
    }

    @Override
    public void run() {
        try {
            while (isRun) {
                //读取打印机返回信息,打印机没有返回纸返回-1
                Log.e(TAG,"wait read ");
                **int len = readDataImmediately(buffer);**
                Log.e(TAG," read "+len);
                if (len > 0) {
                    Message message = Message.obtain();
                    message.what = READ_DATA;
                    Bundle bundle = new Bundle();
                    bundle.putInt(READ_DATA_CNT, len); //数据长度
                    bundle.putByteArray(READ_BUFFER_ARRAY, buffer); //数据
                    message.setData(bundle);
                    mHandler.sendMessage(message);
                }
            }
        } catch (Exception e) {//异常断开
            if (deviceConnFactoryManagers[id] != null) {
                closePort(id);
                mHandler.obtainMessage(Constant.abnormal_Disconnection).sendToTarget();
            }
        }
    }

    public void cancel() {
        isRun = false;
    }
}

`

from bluetooth_print.

thon-ju avatar thon-ju commented on May 24, 2024

非常感谢,你可以推送下你的修改,我合并进去

from bluetooth_print.

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.