Unable to print text in IMZ320 bluetooth printer using LinkOS Xamarin IOS

C Charitha Wickramasinghe 3 years 6 months ago
3 0 0

I use Zebra IMZ320 bluetooth printer and I try to print text via LinkOS.Plugin in Xamarin IOS. But its unable to print using the sample code which you gave.http://techdocs.zebra.com/link-os/2-13/xamarin/
I have attached my code and error herewith.

public void SendTotalPrint()
        {
            string message = "";

            IConnection connection = null;

            connection = ConnectionBuilder.Current.Build("BT:XXXXJ165202255");
            //await Task.Run(() => {
            connection.Initialize("BT:XXXXJ165202255");
            connection.TimeToWaitAfterWrite = 4000;

            IDiscoveryEventHandler handler = DiscoveryHandlerFactory.Current.GetInstance();

            handler.OnDiscoveryError += DiscoveryHandler_OnDiscoveryError;

            handler.OnDiscoveryFinished += DiscoveryHandler_OnDiscoveryFinished;

            handler.OnFoundPrinter += DiscoveryHandler_OnFoundPrinter;

            BluetoothDiscoverer.Current.FindPrinters(null, handler);

            try
            {
                connection.Open();

                IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.ZPL, connection);

                string pl = printer.PrinterControlLanguage.ToString();

                string zpl = "^XA^POI^MNN^LL90^PW400^FO20,20^A0N,50,50^FDTEST^FS^XZ";

                connection.Write(Encoding.UTF8.GetBytes(zpl));

            }
            catch (Exception e)
            {
                message = "Exception: " + (e.Message);
            }
            finally
            {
                if ((connection != null) && (connection.IsConnected))
                {
                    connection.Close();
                }
            }

        }

Error occur in connection.Write(Encoding.UTF8.GetBytes(zpl)); as
{LinkOS.Plugin.ConnectionException: Error writing to connection
  at LinkOS.Plugin.ConnectionImplementation.Write (System.Byte[] data) [0x00052] in :0
  at ZSD.iOS.Interfaces.TotalPrint.SendTotalPrint () [0x000b5]}

I tried both Xamarin PCL and Xamarin.Ios project

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