Code no longer works using Xamarin LinkOS to print to ZQ510 via Bluetooth on iPad

K Kevin Snow 3 years 6 months ago
30 1 0

Hello,
 
We have a body of code that is running in the following environment:
 

C# / Xamarin / LinkOS_Xaramin_SDK version 1.1.75
Xcode 9.2
iPad running iOS 11.2.1
Printing via bluetooth to ZEBRA ZQ510

 
The method below deployed to a half-dozen developer iPads and was working from all of them up until a couple of weeks ago.  In the code below we try to access "printer.CurrentStatus" we are now getting the error "Error getting status: Malformed status response - unable to determine printer status"
 
That line previously worked but if we skip over that section and just go to connection.Write the code executes with-out error but it never prints (it used to print)
 
       // Before call this method we use DiscoveryHandlerFactory to discover a printer and use the following method to print to the connection. 
      // The attached screen shots show the connection object when we get to this method
        public void SendPrintCommandToBluetoothPrinterIfConnectedAndReadyToPrint(IConnection connection, string zplCommand)
        {
            try
            {
                if (!connection.IsConnected)
                    connection.Open();
 
                var printer = LinkOS.Plugin.ZebraPrinterFactory.Current.GetInstance(LinkOS.Plugin.Abstractions.PrinterLanguage.ZPL, connection);
 
                 // The line below now yields the error "Error getting status: Malformed status response - unable to determine printer status"
                if (!printer.CurrentStatus.IsReadyToPrint)
                {
                    var message = $"Printer is not ready for print.  Printer status is currently set to: {printer.CurrentStatus.Status}";
                    _logger.Warn(message);
                }
                else
                {
                     // Bluetooth communications must be handled on a separate thread and it's
                     // best practice to handle network coms on it as well
                     // If I skip the line that reads "printer.CurrentStatus.IsReadyToPrint" then I get to the line below and it executes with-out error but the printer does not print
                    // (I have tried with and with-out Task.Factory)
                     Task.Factory.StartNew(() => connection.Write(Encoding.ASCII.GetBytes(zplCommand)));
 
                     connection.Close();
                }
            }
            catch (Exception e)
            {
                _logger.Error($"An error occurred while trying to send the following command to the printer: {zplCommand}", e);
            }
            finally
            {
                connection?.Close();
            }
        }
 
I attached screen shots showing the connection object and also the exception itself.
 
Also on the iPad I downloaded Zebra Utilities app and was able to connect to and print to the printer so I believe the printer is working.
 
I also tried resetting the settings and re-configuring bluetooth with the following commands (which I can send via usb on pc)
! U1 do "device.restore_defaults" "bluetooth"
! U1 do "device.restore_defaults" "ip"
! U1 do "device.restore_defaults" "wlan"
! U1 do "device.restore_defaults" "power"
! U1 do "device.restore_defaults" "display"
 
! U1 setvar "bluetooth.enable" "on"
! U1 setvar "bluetooth.friendly_name" "BluePrinter"
! U1 setvar "bluetooth.discoverable" "on"
! U1 setvar "bluetooth.minimum_security_mode" "1"
! U1 setvar "bluetooth.bonding" "on"
! U1 setvar "bluetooth.enable_reconnect" "iOS_only"
! U1 setvar "bluetooth.le.controller_mode" "both"
! U1 setvar "bluetooth.le.minimum_security" "none"
! U1 do "device.reset" ""
 
 
I wanted to see if anyone knew of any recents changes that would have broken things or if I'm printing incorrectly and this shouldn't have worked to begin with?
 
Thanks in advance for any and all help you can give.

Please Register or Login to post a reply

1 Replies

K Kevin Snow

Below is just another perspective.  I tried to get all of the printer related code in one view.  Again, everything used to work and I can successfully connect to the printer.  Getting the printer status or trying to print now results in the error "Error getting status: Malformed status response - unable to determine printer status"  Unfortunately delivery of the product is blocked until we can get this working again.

           TestPrinnerButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var bthandler = DiscoveryHandlerFactory.Current.GetInstance();
                //bthandler.OnDiscoveryError += (IDiscoveryHandler handler, string message) => { error(message); };
                //bthandler.OnDiscoveryFinished += (IDiscoveryHandler handler) => { error("Could not find a connected Zebra bluetooth printer."); };
                bthandler.OnFoundPrinter += (IDiscoveryHandler handler, IDiscoveredPrinter discoveredPrinter) =>
                {
                    var connection = discoveredPrinter.Connection;

                    try
                    {
                        //I have tried increasing all the time-outs
                        //connection.TimeToWaitAfterWrite = 30000;
                        //connection.TimeToWaitAfterRead = 30000;
                        //connection.MaxTimeoutForRead = 30000;

                        if (!connection.IsConnected)
                            connection.Open();

                        var printer = LinkOS.Plugin.ZebraPrinterFactory.Current.GetInstance(LinkOS.Plugin.Abstractions.PrinterLanguage.ZPL, connection);

                        // this works and instantly returns ZPL
                        var printerLanguage = printer.PrinterControlLanguage;

                        // throws exception: "Error getting status: Malformed status response - unable to determine printer status"
                        var printerStatus = printer.CurrentStatus;

                        // If I comment out the line above then we can reach below
                        Task.Factory.StartNew(() =>
                        {
                            // throws exception: "Error getting status: Malformed status response - unable to determine printer status"
                            connection.Write(Encoding.ASCII.GetBytes(ServiceConstants.ZplCommandCalibratePrinterForLabels));
                        }
                      );
                   }
                    catch(Exception exc)
                    {
                        throw exc;
                    }
                    finally
                    {
                        connection?.Close();
                    }
                };

                BluetoothDiscoverer.Current.FindPrinters(null, bthandler);
            };

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