1 Reply Latest reply on May 16, 2018 11:38 AM by Robin West

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

    Charitha Wickramasinghe

      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 <5ba493cd13a6476cb6f38f54ba338afd>:0

        at ZSD.iOS.Interfaces.TotalPrint.SendTotalPrint () [0x000b5]}

       

      I tried both Xamarin PCL and Xamarin.Ios project

        • Re: Unable to print text in IMZ320 bluetooth printer using LinkOS Xamarin IOS
          Robin West

          Hi Charitha, Did you pair the printer in the iOS settings before this? Also is the protocol string in the info.plist file?

           

          Also the discovery code is not necessary here where you know the serial number already.

          // IDiscoveryEventHandler handler = DiscoveryHandlerFactory.Current.GetInstance();

          // handler.OnDiscoveryError += DiscoveryHandler_OnDiscoveryError;

          // handler.OnDiscoveryFinished += DiscoveryHandler_OnDiscoveryFinished;

          // handler.OnFoundPrinter += DiscoveryHandler_OnFoundPrinter;

          // BluetoothDiscoverer.Current.FindPrinters(null, handler);