Unable to determine printer language

J Josh Vance 2 years 11 months ago
180 1 0

Hello -
 
We're in the process of whitelisting our iOS app, so I updated to the latest version of the Link OS API and we also updated the firmware on our QLn220.  Prior to that update and on Android we have no issues, but since the update, we're getting an 'Unable to determine printer language' error when using the ZebraPrinterFactory to get a printer object.  We don't get the error every time.  In fact I've not seen it on the first print, but within 2-5 label prints it occurs and once it does, I have to restart the app to clear the error condition and print again.
 
We're currently on API 1.4.957  and firmware V68.19.15Z.  On the iOS side of things, our test device is Version 9.3.4.  We're using bluetooth to connect and we're sending cpcl.
 
I've seen a few other questions with similar issues and as you can see in the code below, we've tried the proposed solutions (changing the timeout value and forcing 'device.languages' in a SET statement).  Do you have any other ideas to try?
 
Thanks.
 
Josh Vance
 
Here's our current code:
 
 
- (NSString *) sendCPCLToPrinter:(NSString *)CPCLData
{
 
    NSLog(@"in sendFormatToPrinter");
 
   
 
// Instantiate connection for CPCL TCP port at given address.
 
    NSString *serialNumber = @"";
 
    //Find the Zebra Bluetooth Accessory
    EAAccessoryManager *sam = [EAAccessoryManager sharedAccessoryManager];
    NSArray * connectedAccessories = [sam connectedAccessories];
    for (EAAccessory *accessory in connectedAccessories) {
        NSLog(@"BT Device");
        NSLog([accessory serialNumber]);
        if([accessory.protocolStrings indexOfObject:@"com.zebra.rawport"] != NSNotFound){
            serialNumber = accessory.serialNumber;
            break;
            //Note: This will find the first printer connected! If you have multiple Zebra printers connected, you should display a list to the user and have him select the one they wish to use
        }
    }
 
    // Instantiate connection to Zebra Bluetooth accessory
    id thePrinterConn = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];
   
    [((MfiBtPrinterConnection*)thePrinterConn) setTimeToWaitAfterWriteInMilliseconds:300];
 
    // Open the connection - physical connection is established here.
    BOOL success = [thePrinterConn open];
 
    if (success) {
       
        NSError *error = nil;
        id printer = [ZebraPrinterFactory getInstance:thePrinterConn error:&error];
       
        NSError *seterror = nil;
        [SGD SET:@"device.languages" withValue:@"zpl" andWithPrinterConnection:thePrinterConn error:&seterror];
       
        NSError *statuserror = nil;
        PrinterStatus *printerStatus = [printer getCurrentStatus:&statuserror];
        NSString* status = nil;
       
        if (printerStatus.isReadyToPrint) {
           
 
            // Send the data to printer as a byte array.
            NSError *writeerror = nil;
       
            [thePrinterConn write:[CPCLData dataUsingEncoding:NSUTF8StringEncoding] error:&writeerror];
            if (writeerror == nil) {
                NSLog(@"in print - no error");
                [thePrinterConn close];
                return @"SUCCESS";
 
            } else {
                NSLog(@"in print - error");
                NSLog([writeerror localizedDescription]);
                [thePrinterConn close];
                return [NSString stringWithFormat: @"PRINT ERROR: %@",[writeerror localizedDescription]];
            }
           
        } else {
           
            NSLog(@"in print - not isReady");
           
            if (error != nil) {
                 //THIS IS WHERE THE ERROR IS CAUGHT....  error COMES FROM ZebraPrinterFactory above
                return [NSString stringWithFormat: @"PRINTER ERROR: %@",[error localizedDescription]];
            }
           
            if (seterror != nil) {
                return [NSString stringWithFormat: @"PRINTER LANG ERROR: %@",[error localizedDescription]];
            }
           
            if (statuserror != nil) {
                return [NSString stringWithFormat: @"PRINTER STATUS ERROR: %@",[error localizedDescription]];
            }
           
            if (printerStatus.isPaused) {
                return @"PRINTER ERROR: The printer is paused.";
            } else if (printerStatus.isHeadOpen) {
                return @"PRINTER ERROR: The printer is open.";
            } else if (printerStatus.isPaperOut) {
                return @"PRINTER ERROR: The paper is out.";
            } else {
                return(@"PRINTER ERROR: Unknown printer error.");
            }
           
            [thePrinterConn close];
       
           
        }
 
  } else {
 
        NSLog(@"in print - connection error");
        [thePrinterConn close];
       
        return @"CONNECTION ERROR: No connected bluetooth printer found.";
 
    }
 
 
}

Please register or login to post a reply

1 Replies

V Vedsatx Saddvv

Hi Josh,
When you set the PrinterLanguage, are you seeing a statuserror instead? 

Thank you for the code.  I'll attempt to use this to recreate the issue again.  We've had a very hard time recreating this issue ourselves.  It seems to have a lot to do with timing or threading on iOS.  Can I ask if you take this code and put it in a very simple app that just prints a set string, do you see the same issue?  How complex is your app environment?  Do you see this on multiple iOS devices?

Another thing to try is to leave the connection open.  It's not usually what we recommend, but it may overcome this issue.  We believe part of the timing issue is with closing and opening the connection too quickly. 
Robin West

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