Zebra ZQ520 Printer - Update Firmware - Using LinkOS SDK iOS

// Expert user has replied.
M Michael Goodwin 3 years 5 months ago
51 3 0

We are having issues with the Zebra printer disconnecting when we send the firmware update to the iOS device. When we push the firmware to the device, the printer changes its text to "Downloading Firmware" but never finishes.
Here is a code snippet
id conn = [self getPrinterConnection:reject];
if (conn != nil) {
// Get the printer
NSError* printerError = nil;
[conn open];
[NSThread sleepForTimeInterval:1.0];
// Fetch the printer and file objects for file manipulation
if (printerError == nil) {
// Get the firmware file from app resources
NSURL* filePath = [[NSBundle mainBundle] URLForResource:@"SP76-005093A" withExtension:@".zpl"];
NSData* firmwareData = [NSData dataWithContentsOfURL:filePath];
@try {
// Send the file to the printer
BOOL didSend = [conn write:firmwareData error:&printerError];
} @catch (NSException* e) {
NSLog(@"%@", [e reason]);
reject(@"print_error", [e reason], [self getError:[e reason]]);
} @finally {
[conn close];
}
} else {
NSLog(@"%@", [printerError localizedDescription]);
}
resolve(@"Done!");
} else {
reject(@"print_error", @"Error connecting to printer", [self getError:@"Error connecting to printer"]);
}

Please Register or Login to post a reply

3 Replies

S Steven Si

Instead of using the write API with 1 second delay, can you try the following API from the FileUtil class?

(BOOL) sendFileContents: (NSString *) filePath error: (NSError **) errorLet the sendFileContents API take care of the underneath regulation on the size of chunk behind the scene. I've tried this API a few minutes ago. It only took about ~20min to update a 20MB firmware.
One more thing worth to mention here, do not use UI thread when open the Bluetooth connection and send the firmware to the printer. Use a separate thread to do Bluetooth related work.
 

M Michael Goodwin

I can get this to run without the printer disconnecting. There is a 1 second delay after each write. The problem is that the most I can send is 950 bytes per second. This is causing it to take 8 hours to transfer the file. Do you have any suggestions or examples of how to do this without it taking so long?
id conn = [self getPrinterConnection:reject];
if (conn != nil) {
// Get the printer
NSError* printerError = nil;
// Open the connection to the printer
[conn open];
[NSThread sleepForTimeInterval:1.0];
// Fetch the printer and file objects for file manipulation
if (printerError == nil) {
// Get the firmware file from app resources
NSURL* filePath = [[NSBundle mainBundle] URLForResource:@"SP76-005093A" withExtension:@".zpl"];
NSData* firmwareData = [NSData dataWithContentsOfURL:filePath];
@try {
// get length of firmware data.
NSUInteger length = [firmwareData length];
// Set the chunk size
NSUInteger chunkSize = 950;
// The current chunk
NSUInteger currentChunkSize = length > chunkSize
? chunkSize
: length - chunkSize;
for(NSUInteger offset = 0; offset < [firmwareData length]; offset += currentChunkSize) {
// Get the current chunk
NSData* chunk = [NSData dataWithBytes:(char *)[firmwareData bytes] + offset
length:currentChunkSize];
//
BOOL isConnected = [conn open];
// Ensure the printer is still connected
if(isConnected) {
// Send the current chunk
NSInteger bytesWritten = [conn write:chunk error:&printerError];
// Ensure sent
if(bytesWritten == chunkSize){
NSLog(@"%zd", (offset + bytesWritten));
}
else {
NSLog(@"Bad stuff happened!");
break;
}
}
else {
// It disconnected
NSLog(@"Printer is disconnected!");
break;
}
// Set the next chunk size
currentChunkSize = length - offset > chunkSize ? chunkSize : length - offset;
}
} @catch (NSException* e) {
NSLog(@"%@", [e reason]);
reject(@"print_error", [e reason], [self getError:[e reason]]);
} @finally {
[conn close];
}
} else {
NSLog(@"%@", [printerError localizedDescription]);
}
resolve(@"Done!");
} else {
reject(@"print_error", @"Error connecting to printer", [self getError:@"Error connecting to printer"]);
}

S Steven Si

Do you use iOS Bluetooth to send the firmware? The size of the firmware is about 30MB. We cannot use one write statement to send the 30MB data at once, which will blow off the buffer. We need to break the 30MB data into small chunks and send one chunk at a time. Please try to write 1KB (1024 bytes) at a time. Hope this helps.

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