What happen if i close bluetooth connection once a day after my multiple print jobs completed

// Expert user has replied.
E Efkan YILMAZ 3 years 5 months ago
12 1 0

Before the discussion start, i need to provide some info on my background.
I have a android app develop under XAMARIN ANDROID platform. The android app will pair with a ZEBRA printer ZQ521. All the print jobs is send from android device to ZQ521 printer via Bluetooth connections. I have use LINK OS XAMARIN SDK's API to handle the Bluetooth communication between android device and ZEBRA ZQ521. Below is the sample source code i tried.
=======================================================================================================================
public void Print(IConnection connection)
{
string zpl = "^XA^POI^MNN^LL90^PW400^FO20,20^A0N,50,50^FDTEST^FS^XZ";//sample content to print
try
{
connection.Open();
connection.Write(Encoding.UTF8.GetBytes(zpl));
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Exception:" + e.Message);
}
finally
{
if (connection.IsConnected)
connection.Close();
}
}
=======================================================================================================================
What happen now is whenever i call connection.Close(); to close the bluetooth connection, it took about 5 to 8 seconds to complete the action. This is troublesome to my use case as we need to print on average 300 to 500 print jobs a day. If each print jobs take 5 to 10 secs to complete, our user will need more time to complete 300 to 500 print jobs.
I have decided to redesign how i handle the LINK OS API. Below is the steps
1. I will set my connection object to singleton object (which means i only create the object once).
1. When user start to use our app, i will call connection.Open(); 1 times.
2. I WILL NOT call connection.close() for each print jobs
3. By the end of day i will force my app to reboot the android device so that zebra bluetooth connection is close after user's daily operation ended.
My question is
1. What is the impact if i didn't close the bluetooth connection, if is the concern of memory resources, i have utilize singleton pattern on connection object to ensure the connection is only created once., will that help?

Please Register or Login to post a reply

1 Replies

S Steven Si

The time to wait before close is set to 5 seconds in SDK. This is to prevent from closing the connection prematurely when there are still data being transmitted at the Bluetooth link layer.
We can certainly keep the Bluetooth connection open for the entire lifecycle of the workflow, as long as we check the connection status before sending any print jobs. This is because the printer may be out of the Bluetooth range and no longer reachable, therefore, the connection object is stale and no longer valid. In this case, we need to close the connection and create a new connection object. Hope this helps.

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