Error connecting to printer ZD620 through bluetooth from Android devices

// Expert user has replied.
S Shiyam SS 3 years 7 months ago
68 1 0

Hi,
We have built a Xamarin app that can print some labels. We run this app in Android 8.x and use bluetooth connectivity for sending print jobs. Randomly, the connection creation is failing with below exception. I'm not sure what exactly is causing this exception when trying to connect as its very random. Any help in this highly appreciated.
Zebra.Sdk.Comm.ConnectionException: Could not connect to device: read failed, socket might closed or timeout, read ret: -1 ---> Zebra.Sdk.Comm.ConnectionException: read failed, socket might closed or timeout, read ret: -1
--- End of inner exception stack trace ---
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method) [0x00068] in :0
at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod) [0x0000e] in :0
at Zebra.Sdk.Comm.ConnectionA.Open () [0x0004a] in :0
at LinkOS.Plugin.ConnectionImplementation.Open () [0x00001] in :0
at MACHe.Implementations.Services.Printing.Label.ZebraPrinterConnectionService.ConnectToZebraPrinter (MACHe.Implementations.Services.Printing.Library.Printer printer) [0x0004c] in :0
--- End of managed Zebra.Sdk.Comm.ConnectionException stack trace ---
com.zebra.sdk.comm.ConnectionException: Could not connect to device: read failed, socket might closed or timeout, read ret: -1
at com.zebra.sdk.comm.ConnectionA.throwAsConnectionException(Unknown Source:40)
at com.zebra.sdk.comm.ConnectionA.open(Unknown Source:37)
at com.zebra.sdk.comm.BluetoothConnection.open(Unknown Source:3)
Caused by: com.zebra.sdk.comm.ConnectionException: read failed, socket might closed or timeout, read ret: -1
at com.zebra.sdk.comm.internal.BluetoothZebraConnectorImpl.open(Unknown Source:36)
at com.zebra.sdk.comm.ConnectionA.open(Unknown Source:7)
... 1 more
SDK: LinkOs Xamarin SDK 1.2.0
Connection creation Code
var connection = ConnectionBuilder.Current.Build($"BT:{printer.macAddr}");
connection.Open(); // This is where we get Exception
Printer Model: ZD620
Cheers,
Shiyam

Please Register or Login to post a reply

1 Replies

S Steven Si

Before calling connection.Open(), make sure the connection closing is not in progress. For example, it takes 5 seconds (by default) to completely close a BT connection. If the BT connect was in the middle of closing, we would get an exception if we called connection.Open(). Make sure the open() and close() are not interleaved, which is a common cause of this type of exceptions randomly.

CONTACT
Can’t find what you’re looking for?