【问题标题】:Can't not connect my print imz320 and motorola tc55, use bluetooth无法连接我的打印 imz320 和 motorola tc55,使用蓝牙
【发布时间】:2015-12-11 02:49:21
【问题描述】:

我的蓝牙连接有问题,因为有时打印后无法正常工作!,我需要重新启动打印 Zebra im320 并重新连接和配对,这不稳定..

public void pairPrinter()  {
     final UUID SerialPortServiceClass_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
     final BluetoothAdapter BA = BluetoothAdapter.getDefaultAdapter();
     final String PrinterBsid = "AC:3F:A4:18:B2:B0";
     Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            OutputStream sOut;
            BluetoothSocket socket;
            BA.cancelDiscovery();


            BluetoothDevice BD = BA.getRemoteDevice(PrinterBsid);
            try {
                socket = BD.createInsecureRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);
                BD.createInsecureRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);

                if (!socket.isConnected()) {
                   // Thread.sleep(2000);

                    socket.connect();
                    Thread.sleep(2000); // <-- WAIT FOR SOCKET
                }
                sOut = socket.getOutputStream();
                String cpclData = "! 0 200 200 210 1\r\n"
                        + "TEXT 4 0 30 40 This is a CPCL test.\r\n"
                        + "FORM\r\n";
                sOut.write(cpclData.getBytes());
                sOut.flush();
                sOut.close();

                socket.close();
                BA.cancelDiscovery();


            } catch (IOException e) {
                Log.e("", "IOException");
                e.printStackTrace();
                return;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    t.start();
}

这是我的日志

E/BluetoothEventLoop.cpp﹕onDiscoverServicesResult: D-Bus 错误: org.bluez.Error.Failed (Connection timed out)

D/BluetoothService﹕清理失败的 UUID 通道查找:AC:3F:A4:18:B2:B0 00001101-0000-1000-8000-00805f9b34fb

E/: IOException

W/System.err: java.io.IOException: 服务发现失败

W/System.err: atandroid.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:465)

W/System.err:atandroid.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:230)

W/System.err:atcom.example.msanchez.printzebra.MainActivity$1.run(MainActivity.java:73)

W/System.err﹕在 java.lang.Thread.run(Thread.java:856)

【问题讨论】:

    标签: java android android-studio bluetooth


    【解决方案1】:

    您的代码似乎调用了两次createInsecureRfcommSocketToServiceRecord API。这似乎不对。

    您使用哪种设备在 iMZ320 上打印?我过去用 Android v4.1 和 Android v4.4 做过一些测试,它们的行为不同。

    您可以查看original discussion on Zebra developer's forum 以获得一些指导。

    可能与了解您在打印机上运行的固件版本有关,同样,Zebra 开发人员论坛应该在这种情况下提供帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 2011-08-22
      • 2018-07-16
      相关资源
      最近更新 更多