[C#.NET] PrintStoredFormat doesn't make printer print the stored format file

[C#.NET] PrintStoredFormat doesn't make printer print the stored format file

[C#.NET] PrintStoredFormat doesn't make printer print the stored format file


Audience
Tags

I am using Zebra SDK v2.15.2634 to develop Xamarin.Android application. It looks good until I try to execute following line:
var btAddress = "48:A4:93:89:63:97";
Connection connection = new BluetoothConnection(btAddress);
connection.MaxTimeoutForRead = 30000;
ZebraPrinter printer;
try
{
connection.Open();
// Successful printed.
//var bytes = Encoding.UTF8.GetBytes("^PON^LH0,0^FWN^XA^FO150,200^FDHelloWorld^FS^XZ");
//connection.Write(bytes);
printer = ZebraPrinterFactory.GetInstance(connection);
Dictionary vars = new Dictionary
{
};
printer.PrintStoredFormat("E:HELLO2.ZPL", vars, "utf-8");
}
catch (ConnectionException e)
{
Console.WriteLine(e.ToString());
}
catch (ZebraPrinterLanguageUnknownException e)
{
Console.WriteLine(e.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
connection.Close();
}
The printer showed it got bluetooth activity by flashing the icon on display. But nothing print out.
Environment:
- Printer model: ZQ520
- Zebra SDK v2.15.2634
- Visual Studio 2019
- Xamarin.Android
FYI:
- There is HELLO2.ZPL file on the printer's flash storage.
- Successfully printed, if I send this file to printer via Printer Tools Program.
- There is no problem with connection, my app can connect to printer successfully.
- I can execute BluetoothConnection.Write() method successfully with printed slip, on following code:
var bytes = Encoding.UTF8.GetBytes("^PON^LH0,0^FWN^XA^FO150,200^FDHelloWorld^FS^XZ");
connection.Write(bytes);
The stored file is the problem.
- I used both manual created ZPL file and from Zebra Designer 3, both stored on the printer.
- I tried to PrintStoredFormat() with both of them. Nothing happened.
- The code has no exception and the connection was closed successfully.
How to reproduce the project and file I attached:
- Please store "HELLO2.ZPL" (manually created) and GT.ZPL (Zebra Designer generated) on the ZQ520
Additional question
- Do we have to name file in capital letter before send to printer? for ex. hello2.zpl
- if not, do we still to put its into capital letter when we refer to its path? for ex. printer.PrintStoredFormat("E:HELLO2.ZPL", vars, "utf-8");

Submitted by SSi1 on May 03, 2021 Permalink

Based on the code snippet above, there are a few things I'd like to comment on.
1. The filenames of the files stored on the printer are case insensitive. You can use either uppercase, lowercase or mixed cases. They all should work.
2. It's unclear if the try{} block is executed on a UI thread or a background thread. When interacting with the printer, such as getting printer status or executing print functions via Link-OS SDK API, please do not use the UI thread. Always spin off a separate thread when interacting with the printer.
3. After calling printer.PrintStoredFormat() API, please add a delay before closing the connection to make sure that the data has been transmitted to the printer at Bluetooth link layer. The return of printer.PrintStoredFormat() API doesn't necessary mean that the entire data has been sent to the printer at the link layer. The suggested code is below. Hope this helps.

await Task.Run(async () => {
try {

connection.Open();

ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

Dictionary vars = new Dictionary { };

printer.PrintStoredFormat("E:HELLO2.ZPL", vars, "utf-8");

await Task.Delay(1000);

} catch (Exception e) {
await DisplayConnectionStatusAsync($"Error: {e.Message}", Color.Red, 3000);
} finally {
try {
connection?.Close();

} catch (ConnectionException) { }
}
});