如果在目标c中使用epson打印机连接打印机,则连接多台打印机并打开现金抽屉

时间:2019-04-15 07:22:31

标签: ios objective-c iphone thermal-printer epson

我正在使用for循环连接用于打开现金抽屉的多台打印机,但不适用于多台打印机。 打开现金抽屉后,我也想打印收据

我的代码在这里:

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 个答案:

没有答案