Epson ePOS SDK实时检查打印机状态

问题描述 投票:2回答:1

如何实时检查epson票据打印机的状态?

当前,我正在使用计划的计时器来运行Epos2Discovery.start每10秒检查一次打印机的可用性。

printerCheckTimer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(checkPrinter), userInfo: nil, repeats: true)


// Listen for printer connection
@objc func checkPrinter() {
        // Stop previous epson printer discovery if any, and reset scanned epson printers array
        var result = EPOS2_SUCCESS.rawValue
        result = Epos2Discovery.stop()

        // Search for epson printers
        result = Epos2Discovery.start(filterOption, delegate: self)
        if result != EPOS2_SUCCESS.rawValue {
            print(result)
        }
}

// Delegate for epson printer discovery
func onDiscovery(_ deviceInfo: Epos2DeviceInfo!) {
    // Loop all the connected epson printers port, and see if they exists in the nearby ports
    for (printerId, connectedPrinterPort) in self.connectedEpsonPrinters {
        if connectedPrinterPort == deviceInfo.target {
            onlineEpsonPrinters[printerId] = Int(Date().timeIntervalSince1970)
        }
    }
}

此解决方案对于较旧的TM-T82(序列号:UEHF ...)非常有效。但是,对于较新版本的TM-T82(序列号:X4XQ ...),这似乎有问题。

运行Epos2Discovery.start计时器的并发设备数似乎正在影响打印性能。

使用一台设备时,它可以正常工作,并且打印速度一样快。但是,对于2台设备,打印速度会变慢(可能会慢5秒)。

[使用3台设备时,打印机状态将在联机和脱机状态之间闪烁,并且一半的打印结果将显示失败的打印错误提示。似乎在多个设备上同时运行具有定期计时器的Epos2Discovery导致打印机检测出现问题。

[这只会在TM型号的新版本上发生,对于我以前购买的旧打印机(TM-T88,TM-U220B,TM-T81)来说,它的工作情况很好。

我想知道是否还有其他方法可以实时检查打印机状态?

printing printers epson receipt epos
1个回答
0
投票

=>您不能同时通信多台打印机。您必须一一访问打印机。如果第一个打印机进程完成,则可以启动第二个打印机进程。

=>您可以使用监视器方法来检查打印机状态。当应用程序启动时

Printer printer = null;
try {
printer = new Printer(printer.TM_T88, printer.MODEL_ANK, this);
}
catch (Exception e) {
//Displays error messages
}
printer.setStatusChangeEventListener(this);
try {
printer.connect("TCP:192.168.192.168", printer.PARAM_DEFAULT);
}
catch (Exception e) {
//Displays error messages
}
try {
printer.setInterval(3000);
printer.startMonitor();
}
catch (Exception e) {
//Displays error messages
}
Repeats
//Buffers the print data(addText..)
//Sends the print data (sendData)
When application closes
try {
printer.stopMonitor();
}
catch (Exception e) {
//Displays error messages
}
try {
printer.disconnect();
}
catch (Exception e) {
//Displays error messages
}
© www.soinside.com 2019 - 2024. All rights reserved.