蓝牙热敏打印机打印半串

时间:2017-11-15 14:51:29

标签: android thermal-printer

请帮助我,我浪费了一整天但是无法弄清楚为什么我的热敏打印机在收据时会打印一半文字。它在58mm Mini Bluetooth Thermal Printer中完美运作。但是当我进入热敏打印机LESHP 80mm Wireless Bluetooth Thermal时,此打印机仅打印一半的文本。

这是我的代码:

void findBT() {

    try {
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if (mBluetoothAdapter == null) {

        }

        if (!mBluetoothAdapter.isEnabled()) {
            Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBluetooth, 0);
        }

        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

        if (pairedDevices.size() > 0) {
            for (BluetoothDevice device : pairedDevices) {

                if (device.getName().contains("Printer")) {

                    mmDevice = device;

                }
            }



        }
        else {
            Toast.makeText(this,"device not pair.",Toast.LENGTH_LONG).show();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
 void SendDateBT() throws IOException {
    try {

        // Standard SerialPortService ID
        UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");


        mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);

        mmSocket.connect();
        mmOutputStream = mmSocket.getOutputStream();
        mmInputStream = mmSocket.getInputStream();
        mmOutputStream.write(mytext.getBytes());

        mmOutputStream.flush();
        mmOutputStream.close();
        mmInputStream.close();
        mmSocket.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

当我想打印收据时,我称这两个功能为:

findBT();
SendDatBt();

2 个答案:

答案 0 :(得分:0)

我在写入数据后使用暂停,在刷新前1-2秒尝试并关闭连接。 这是我写的应用程序:https://play.google.com/store/apps/details?id=pe.diegoveloper.printerserverapp

答案 1 :(得分:0)

经过大量的搜索和我的工作,我试过这个。

{{1}}