Problem with printing label

E Evgeniy Ravinskiy 2 years 11 months ago
11 1 0

Hi. I have a problem with printing label. I have a WebView app with button (Print), when i push the button (Print), sometimes label is not printed without any errors. I tried to change timeout but this didn’t help.
We have 5 printers QLn 320 with last firmware V68.19.15Z and many iPad with iOS 9.2, 9.1, 8.1. This problem has long. Label 43x25мм and print 5 lines. 1-2Lines - Name, 3Lines - Size, 4Lines - order,date,article, 5Lines - barcode.
I use Zebra SDK and print code is:
 
-(
-(void)printWithGCDWithParameters:(NSDictionary *)parameters {
    //Dispatch this task to the default queue
    buttonhome.enabled = NO;
    buttonSettings.enabled = NO;
    viewPrinting.hidden = NO;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
        // Instantiate connection to Zebra Bluetooth accessory
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSString *serialNumber = [defaults valueForKey:@"selectedPrinterSN"];
        id thePrinterConn = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];
        NSInteger timeout = [defaults integerForKey:@"OZTimeout"];
        if (timeout 30) {
            timeout = 30;
        }
        else if (timeout > 300) {
            timeout = 300;
        }
        [((MfiBtPrinterConnection*)thePrinterConn) setTimeToWaitAfterWriteInMilliseconds:timeout];
        [((MfiBtPrinterConnection*)thePrinterConn) setTimeToWaitAfterReadInMilliseconds:timeout];
      
        BOOL success = [thePrinterConn open];
      
        NSString *size = [parameters valueForKey:@"size"];
        size = [size stringByReplacingOccurrencesOfString:@"" withString:@""];
        size = [size stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        NSInteger symbolCount = 33;
        NSString *name = [parameters valueForKey:@"title"];
        NSString *name2 = @"";
        if (name.length > symbolCount) {
            name2 = [name substringFromIndex:symbolCount];
            name = [name substringToIndex:symbolCount];
          }
        NSString *zplData = [NSString stringWithFormat:
                              @"^XA^LH25,23^POI^CFT,20,20^CI28^FT5,5^FH^A@N,20,20,E:TT0003M_.TTF^FD%@^FS^FT5,25^FH^A@N,20,20,E:TT0003M_.TTF^FD%@^FS^FT5,45^FH^A@N,20,20,E:TT0003M_.TTF^FD%@%@^FS^FT5,65^FH^A@N,20,20,E:TT0003M_.TTF^FDЗаказ № %@   %@   %@^FS^FO30,80^BY2 ^BCN,50,Y,N,N,A^FD%@^FS^XZ",
                             name, name2, size.length > 0 ? @"Размер: " : @"", size, [parameters valueForKey:@"number"],[parameters valueForKey:@"nowDate"], [parameters valueForKey:@"artPostavshik"], [parameters valueForKey:@"barnumber"]];
      
        NSError *error = nil;
 
        NSMutableData *data = [[zplData dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];
      
        long blockSize = 1024;
        long totalSize = data.length;
        long bytesRemaining = totalSize;
        while (bytesRemaining > 0) {
            long bytesToSend = MIN(blockSize, bytesRemaining);
            NSRange range = NSMakeRange(0, bytesToSend);
          
            NSData *partialLabel = [data subdataWithRange:range];
            [thePrinterConn write:partialLabel error:&error];
          
            bytesRemaining -= bytesToSend;
          
            [data replaceBytesInRange:range withBytes:NULL length:0];
            if (error) {
                break;
            }
        }
      
        [thePrinterConn close];

Please register or login to post a reply

1 Replies

V Vedsatx Saddvv

Hi Evgeniy,
You said that "sometimes label is not printed without any errors" has the label ever printed successfully? When you tap on the Print button, does this icon on the LCD blink (this would indicate that it is receiving data)?

I am looking at your label format right now and noticed a few things that you can do to simplify the format a bit. You use the ^A@N,20,20,E:TT0003M_.TTF command several times in the label and unless you are changing the font elsewhere (which I don't think you are), you can just specify that command once and until a new font name is specified by ^A@ it will stay as the active font, so you can remove the other duplicate lines.

Also, I see that you have the ^FH command in your label, per the programming guide, that needs to come directly before the ^FD command.
The ^FH command allows you to enter the hexadecimal value for any character directly into the ^FD statement. The ^FH command must precede each ^FD command that uses
hexadecimals in its field. Are you using hexadecimals in the ^FD commands that come after? I didn't see any but wasn't sure if maybe I didn't understand the code. If you aren't using hex values, you can remove those lines (^FH).

Try moving those around and let me know if you see any change in what prints.

Thank you,
Beverly

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