我正在使用Epson的ePOS2 SDK与收据打印机TM-M30通信。 我能够成功连接到打印机并打印一些数据。但是我需要打开现金抽屉。所以目前我不知道连接哪个打印机现金抽屉。所以目前我添加了循环并检查所有打印机。请检查我的代码
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");
}
});
}
答案 0 :(得分:0)
我建议您“ getStatus”,然后检查抽屉是否处于“未知”状态。如果已连接,则应报告“打开”或“关闭”。