Cross-Platform App Development for Printing

Good Evening developers!

I'm very excited to announce we now support Xamarin in our Link-OS Multiplatform SDK.  This is a subject near and dear to me.  I, like many developers in this business, am primarily a C# coder.  Many developers who use our products have worked on server and older Windows Mobile/CE OS's using .NET.  Not to mention, I like C# and Visual Studio. Updating skills for these newer mobile OS's is a difficult transition.  Xamarin, just acquired by Microsoft, is a developer toolset that allows me and other developers to use our skills and create modern apps for mobile OS's or move older apps to them.

 

 

Xamarin is integrated into Visual Studio (2012 and 2015) and is now FREE for small teams.  There is also a Xamarin Studio for MAC users and iOS development.  You can write apps in C# and compile them for Android or iOS. 

 

 

I was also proud to be the lead developer on this project at Zebra.   Now you know who to blame if your favorite feature is not there yet.    I focused this SDK on maximum platform code reuse, ease of development, and giving you good samples to work from.  We are releasing the SDK as a Xamarin Plugin to enable the greatest amount of cross-platform support with the least amount of platform specific coding. 95% of the APIs are completely reusable across Android, iOS, and Forms apps even though the underlying libraries are very hardware targeted.  We also added a Developer Demo to show best practices in a real printing app. 

 

 

The supported API's are light right now, but we plan to update and add more over time and as the other SDK's get updated.  I'd love to hear your feedback on what we can do to improve this kit.  You have a lot of influence over these SDK's as Zebra is committed to enabling our developer community.

 

 

You can find the Plugin in the LINK-OS MULTIPLATFORM SDK, the Xamarin Component Store, and Nuget

Full API Documentation is on Zebra Techdocs

 

Robin West

Solution Architect

Alberto Silva

Hi,

What about Windows 10 (UWP, desktop, tablets and mobile) and Xamarin.Forms apps running on Windows, do you plan to support printing to Zebra printers from such apps using C#?

Thanks,

Alberto Silva


Darryn Campbell

Hi,

Like Alberto Silva said, does the Xamarin SDK support Windows 10 and Xamarin.Forms? I find that the Zebra PC SDK is based on Java, do you have solutions for Windows app using C#?

Thanks.


Paul Sparks

Hi, I am using the LinkOS sdk for android xamarin, I am able to connect via BT-mac and connection open fine able to get a readytoprint status, but when i write the zpl to the connection, the printer does nothing.  Is there any special android permissions i need to grant for it to be able to print?

The printer is new ZQ510.

Here is my code:

calling with simple zpl:

                    var sb = new StringBuilder();

                        sb.AppendLine("^ XA");

                        sb.AppendLine("^ LH 1000,100");

                        sb.AppendLine("^ FO20,10");

                        sb.AppendLine("^ ADN,50,30");

                        sb.AppendLine("^ FD'''From:''' ABC Company^ FS");

                        sb.AppendLine("^ LH0,0");

                        sb.AppendLine("^ XZ");

                    

                        var zpl = sb.ToString();

                        printer = new ZebraPrinter();

                        var ret = printer.PrintIt(zpl);

   

    public class ZebraPrinter

    {

        private string printCommand;

        LinkOS.Plugin.Abstractions.IConnection connection;

        const string tag = "BasicPrintApp";

        public ZebraPrinter()

        {

        }

        // This is THE method

        public string PrintIt(string printingString, string mac = null)

        {

            printCommand = printingString;

            if(connection == null)

            {

                if (mac == null)

                    connection = ConnectionBuilder.Current.Build("BT:24:71:89:55:20:B0");

                else

                    connection = ConnectionBuilder.Current.Build("BT:" + mac);

            }

            if (!connection.IsConnected)

            {

                connection.Open();

            }

          

            if ((CheckPrinterStatus(connection)))

            {

                connection.Write(Encoding.ASCII.GetBytes(printCommand));

             

                Thread.Sleep(500);

            }

            else

            {

                return "Printer is not ready.";

            }

            connection.Close();

           

            return "Printed Ok";

        }

        private bool SetPrintLanguage(LinkOS.Plugin.Abstractions.IConnection connection)

        {

            string setLanguage = "! U1 setvar \"device.languages\" \"zpl\"\r\n\r\n! U1 getvar \"device.languages\"\r\n\r\n";

            byte[] response = connection.SendAndWaitForResponse(Encoding.ASCII.GetBytes(setLanguage), 500, 500);

            string s = Encoding.ASCII.GetString(response);

            if (!s.Contains("zpl"))

            {

                Log.Debug(tag, "Not a ZPL printer.");

                return false;

            }

            return true;

        }

        private bool CheckPrinterStatus(LinkOS.Plugin.Abstractions.IConnection connection)

        {

            IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection);

            var lang = printer.PrinterControlLanguage;

          

            IPrinterStatus status = printer.CurrentStatus;

            if (!status.IsReadyToPrint)

            {

                Log.Debug(tag, "Printer in Error: " + status.ToString());

            }

            return true;

        }

    }