Xamarin Bluetooth prining very slow

// Expert user has replied.
C Clark Brown 2 years 5 months ago
57 4 0

Following several example of code posted here to print to bluetooth printer. VS 2019, LinkOS_Xamarin_SDK 1.20
Install app on Zebra TC 51, paired with ZQ511

When printing sending ZPL to printer, is taking about 10 to 15 seconds to print , the line ConnectionBuilder.Current.Build("BT:" + address) is taking about 6+ seconds

I crated a test print function below , how can i get the IConnection thePrinterConn = ConnectionBuilder.Current.Build("BT:" + address); to execute faster ?

private void Print_Clicked(object sender, EventArgs e)
{
var watch = new System.Diagnostics.Stopwatch();
watch.Start();

string address = Preferences.Get("printer_key", "default_value"); // 1 ms

IConnection thePrinterConn = ConnectionBuilder.Current.Build("BT:" + address); // 6219 ms

// var thePrinterConn = ConnectionBuilder.Current.Build("BT:" + address); // 6219 ms

// tested withiut "BT:" -
//var thePrinterConn = ConnectionBuilder.Current.Build(address); // 17164 ms 17.164 sec

watch.Stop();
warningLabel.IsVisible = true;
warningLabel.Text = $"Execution connectbuild Time: {watch.ElapsedMilliseconds} ms";

//open connection
thePrinterConn.Open(); // 1216 ms - 1.2 sec

string zpl = "^XA^FO45,25^BY1^BCN,127,N,N,,N,A^FD1234567890^FS^FT29,173^CI0^A0N,20,27^FDTest5678901Test^F^PQ1^XZ";
// Send the data to printer as a byte array.
thePrinterConn.Write(System.Text.Encoding.ASCII.GetBytes(zpl)); // 494 ms .5 sec

// Close

thePrinterConn.Close(); // 920 ms 1 sec

/// total 17272

}

Please register or login to post a reply

4 Replies

S Steven Si

If you want to establish a Bluetooth connection faster, then don't use the ConnectionBuilder class. Because the ConnectionBuilder.Current.Build() will actually open and then close the Bluetooth connection before it returns the connection object to the caller. This roundtrip takes time, especially it takes 5 seconds to close the Bluetooth connection.

Instead, you can use the BluetoothConnection class to create a Bluetooth connection object by passing in the Bluetooth MAC address to BluetoothConnection(), then followed by calling the Open() on this Bluetooth connection object. This way, you by-pass the unneeded close function, which cuts the time by at least 5 seconds.

C Clark Brown

using BluetoothConnection was faster but still to print is taking about 7 seconds, where before total was about 13 seconds.
I am getting closer with BluetoothAdapter, it is prininting within 2 seconds. Only issue now, is it only prints first time, won't print after.
Working on determining the casue now.

S Steven Si

There are a few properties (TimeToWaitBeforeClose, TimeToWaitForMoreData, etc.) in the BluetoothConnection class, which you can adjust the timeout values for your needs, so to reduce the overall time it takes for Open -> Print -> Close. I think the default value for TimeToWaitBeforeClose is set to 5,000ms (i.e. 5 seconds). Depending on the length of ZPL script, you may be able to reduce the value, so that you can short the total time overall.

J Julius Francis

I experienced similar troubles, but I'm not sure if it will help for you, however, it might happen when the printer receiver system can no longer handle the quantity of data required to imprint. In either case, the data cable connection has to be changed. And if none of them function, the router motor that pulls the ink to print on the paper must be replaced. I hope that will do. 

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