Reputation: 1821
I am using ePOS2 SDK from Epson to communicate with receipt printer TM-M30. I am able to successfully connect to printer and print some data.but i need to open cash drawer. so currently i does not know in which printer cash drawer is connected.so currently i added for loop and check all the printer.pls check my code
NSMutableArray *SelectedPrinter=[[NSUSERDEFAULTS valueForKey:@"SelectedPrinter"] mutableCopy];
for (int i=0; i<SelectedPrinter.count; i++)
{
[self printdataWithTarget:[[SelectedPrinter objectAtIndex:i] valueForKey:@"modelName"] withDeviceName:[[SelectedPrinter objectAtIndex:i] valueForKey:@"portName"]];
}
-(void)printdataWithTarget:(NSString*)target withDeviceName:(NSString *)deviceName
{
[[MPOSPrinter sharedManager] disconnectPrinter];
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void)
{
[[MPOSPrinter sharedManager] disconnectPrinter];
if ([[MPOSPrinter sharedManager] initializePrinter:deviceName])
{
if (![[MPOSPrinter sharedManager] connectPrinterWithPort:target])
{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
});
//showAlert(@"",@"Please ensure your device is connected with the Printer and you have selected this hardware from the settings menu.");
}
else
{
if ([[MPOSPrinter sharedManager] isPrintable:[[[MPOSPrinter sharedManager] printer] getStatus]])
{
[[[MPOSPrinter sharedManager] printer] addTextAlign:1];
[[[MPOSPrinter sharedManager] printer] addText:@""];
[[[MPOSPrinter sharedManager] printer] forceStopSound:0];
[[[MPOSPrinter sharedManager] printer] setReceiveEventDelegate:self];
[[[MPOSPrinter sharedManager] printer] addPulse:EPOS2_DRAWER_HIGH time:EPOS2_PULSE_100];
[[[MPOSPrinter sharedManager] printer] sendData:EPOS2_PARAM_DEFAULT];
}
else{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
}
}
}
else
{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
NSLog(@"Not Initialize");
}
});
}
Upvotes: 0
Views: 490
Reputation: 86
I would suggest that you "getStatus" and then check if the drawer is in the "unknown" state. If it is connected it ought to report "open" or "closed".
Upvotes: 0