Closed Abdarrahmane-NEINE closed 2 years ago
@Avery246813579
I am also asking the same question in Stack overflow https://stackoverflow.com/q/71285933/15793994
Can you post your code?
Hi @Avery246813579 I'm working with @Abdarrahmane-NEINE on this issue.
This is the problem we're having :
printImage({
ipAddress: "192.168.10.32",
modelName: "BROTHER HL-L3270CDW series Printer"
}, uri, {autoCut: false}).then(() => {
console.log("Discover Manual Successful");
}).catch((e) => {
console.log("Discover Manual failed")
console.log(e) // There was an error trying to print the image
});
How can we have a more detailed error on the issue ? We don't know much about Objective C, so your help will be much appreciated
Hello @Avery246813579 , @bulby97
While I try to search the error I return to the Brother guide (https://support.brother.com/g/s/es/htmldoc/mobilesdk/guide/print-image.html) to implement the SDK and I see that I should specify the model of my printer in the printImage function into the ReactNativeBrotherPrinters.m file.
I edited this by replacing QL by PT, because in the example they use the QL model and me I have a PT model.
But also, if I try to print, I have another error message (Error - Print Image: SetLabelSizeError) :
the content of the printImage function: RCT_REMAP_METHOD(printImage, deviceInfo:(NSDictionary )device printerUri: (NSString )imageStr printImageOptions:(NSDictionary )options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { NSLog(@"Called the printImage function"); BRPtouchDeviceInfo deviceInfo = [self deserializeDeviceInfo:device];
BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:deviceInfo.strIPAddress];
BRLMPrinterDriverGenerateResult *driverGenerateResult = [BRLMPrinterDriverGenerator openChannel:channel];
if (driverGenerateResult.error.code != BRLMOpenChannelErrorCodeNoError ||
driverGenerateResult.driver == nil) {
NSLog(@"%@", @(driverGenerateResult.error.code));
return;
}
NSString * paperSize = [self defaultPaperSize:deviceInfo.strModelName];
NSLog(@"Paper Size: %@", paperSize);
BRLMPrinterDriver *printerDriver = driverGenerateResult.driver;
BRLMPrinterModel model = [BRLMPrinterClassifier transferEnumFromString:deviceInfo.strModelName];
// BRLMQLPrintSettings *qlSettings = [[BRLMQLPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:model];
BRLMPTPrintSettings *ptSettings = [[BRLMPTPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:model];
ptSettings.autoCut = true;
NSLog(@"Cut Options %@", options[@"autoCut"]);
if (options[@"autoCut"]) {
ptSettings.autoCut = [options[@"autoCut"] boolValue];
}
NSURL *url = [NSURL URLWithString:imageStr];
BRLMPrintError *printError = [printerDriver printImageWithURL:url settings:ptSettings];
if (printError.code != BRLMPrintErrorCodeNoError) {
NSLog(@"Error - Print Image: %@", printError); // the error of "SetLabelSizeError"
// NSLog(@"Error - Print Image: %@", @(printError.code));
NSError* error = [NSError errorWithDomain:@"com.react-native-brother-printers.rn" code:1 userInfo:[NSDictionary dictionaryWithObject:printError.description forKey:NSLocalizedDescriptionKey]];
reject(PRINT_ERROR, @"There was an error trying to print the image", error);
} else {
NSLog(@"Success - Print Image");
resolve(Nil);
}
[printerDriver closeChannel];
}
I tried to add a label size and change the declaration of the url, I am also adding an image in node_modules/react-native-brother-printers/ios/Resources/icon.png and I try to print it.
But I get another error ( Error - Print Image: FilepathURLError):
the content of the printImage function in this case:
RCT_REMAP_METHOD(printImage, deviceInfo:(NSDictionary )device printerUri: (NSString )imageStr printImageOptions:(NSDictionary )options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { NSLog(@"Called the printImage function"); BRPtouchDeviceInfo deviceInfo = [self deserializeDeviceInfo:device];
BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:deviceInfo.strIPAddress];
BRLMPrinterDriverGenerateResult *driverGenerateResult = [BRLMPrinterDriverGenerator openChannel:channel];
if (driverGenerateResult.error.code != BRLMOpenChannelErrorCodeNoError ||
driverGenerateResult.driver == nil) {
NSLog(@"%@", @(driverGenerateResult.error.code));
return;
}
NSString * paperSize = [self defaultPaperSize:deviceInfo.strModelName];
NSLog(@"Paper Size: %@", paperSize);
BRLMPrinterDriver *printerDriver = driverGenerateResult.driver;
BRLMPrinterModel model = [BRLMPrinterClassifier transferEnumFromString:deviceInfo.strModelName];
// BRLMQLPrintSettings *qlSettings = [[BRLMQLPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:model];
BRLMPTPrintSettings *ptSettings = [[BRLMPTPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:model];
// BRLMPTPrintSettings *ptSettings = [[BRLMPTPrintSettings alloc] initDefaultPrintSettingsWithPrinterModel:BRLMPrinterModelPT_P950NW];
ptSettings.labelSize = BRLMMWPrintSettingsPaperSizeA7;//test to resolve size error
ptSettings.autoCut = true;
NSLog(@"Cut Options %@", options[@"autoCut"]);
if (options[@"autoCut"]) {
ptSettings.autoCut = [options[@"autoCut"] boolValue];
}
// NSURL *url = [NSURL URLWithString:imageStr];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"./Resources/icon" withExtension:@"png"];
BRLMPrintError *printError = [printerDriver printImageWithURL:url settings:ptSettings];
if (printError.code != BRLMPrintErrorCodeNoError) {
NSLog(@"Error - Print Image: %@", printError); // the error of "FilepathURLError"
// NSLog(@"Error - Print Image: %@", @(printError.code));
NSError* error = [NSError errorWithDomain:@"com.react-native-brother-printers.rn" code:1 userInfo:[NSDictionary dictionaryWithObject:printError.description forKey:NSLocalizedDescriptionKey]];
reject(PRINT_ERROR, @"There was an error trying to print the image", error);
} else {
NSLog(@"Success - Print Image");
resolve(Nil);
}
[printerDriver closeChannel];
}
Must appreciated your help.
Finally I get it and I can print with my printer, the issue isn't in this module. This module work awesome.
Just this module is for the QL series, and if someone has another printer module he should edit the ReactNativeBrotherPrinters.m file.
Because in the Brother Print SDK Manual (https://support.brother.com/g/s/es/htmldoc/mobilesdk/guide/print-image.html), they offer an example for each series.
And if someone has an error message for example SetLabelSizeError he should return in the Manual and search the setting of his printer, in my case it is BRLMPTPrintSettingsLabelSize :(https://support.brother.com/g/s/es/htmldoc/mobilesdk/reference/ios_v4/brlmptprintsettings.html#labelsize).
@Avery246813579 , @bulby97 Thank you very much for your help.
@Avery246813579 I am using iOS and I am traying to print an image or a file with this module, but I don't yet.
Does any one do that or have any idea to do that.
I ma traying that with this example https://github.com/Avery246813579/react-native-brother-printers/tree/master/example
Thank you for your help.