1 Reply Latest reply on Aug 7, 2017 11:16 AM by Samantha Corn

    Not able to print from Android BT using LinkOS

    Paul Sparks

      Hi

       

      I have a Zebra ZQ510 BT printer, and i am not able to print using the sdk.  I can connect and get a ready to print status, but when i write the zpl via the connection it does nothing.  The Icons on the printer do blink but nothing is printed.  Here is my code.  Can someone please help as i am lost into what i am doing wrong.

       

      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();
                              var printer = new ZebraPrinter();
      
      
                              var result = 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;
              }
          }
             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());
                  }
                  
      Link
      
      
      
      
      
      
        • Re: Not able to print from Android BT using LinkOS
          Samantha Corn

          Hi Paul,

           

          This seems to be an issue with your ZPL, not the actual app. There shouldn't be any spaces after the ^ character in your ZPL. Try changing your code to:

           

          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");