Reputation: 1
I have problems with the connection of bluetooth because sometimes print and after not works!, I need restar the print Zebra im320 and reconnect and pair and this isn't stable..
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();
}
And this my logs
E/BluetoothEventLoop.cpp﹕ onDiscoverServicesResult: D-Bus error: org.bluez.Error.Failed (Connection timed out)
D/BluetoothService﹕ Cleaning up failed UUID channel lookup: AC:3F:A4:18:B2:B0 00001101-0000-1000-8000-00805f9b34fb
E/﹕ IOException
W/System.err﹕ java.io.IOException: Service discovery failed
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﹕ at java.lang.Thread.run(Thread.java:856)
Upvotes: 0
Views: 272
Reputation: 6506
Seems that your code is calling twice the createInsecureRfcommSocketToServiceRecord
API. This doesn't seem right.
Which device are you using to print on the iMZ320? I've done some test in the past with Android v4.1 and Android v4.4 and they've a different behaviour.
You can take a look at the original discussion on Zebra developer's forum for some guidance.
May be relevant to understand which Firmware version you're running on the printer, again, the Zebra developer's forum should help in this case.
Upvotes: 0