Epson ePOS SDK checking for printer status real-time

1.2k Views Asked by At

How do I check for epson receipt printer status in real-time?

Currently, I am using a scheduled timer to run the Epos2Discovery.start every 10 seconds to check for printer availability.

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)
        }
    }
}

This solution work perfectly fine for older TM-T82 (Serial: UEHF...). However, for the newer revision of TM-T82 (Serial: X4XQ...), this seems to be problematic.

The number of concurrent devices running the Epos2Discovery.start timer seems to be affecting the performance of the print.

When using 1 device, it will work just fine, and print out just as fast. However, for 2 devices, the print became slower (Probably 5s slower).

When using 3 devices, the printer status will flicker between online and offline status, and half of the prints will end up with a failed print error prompt. It seems that the running Epos2Discovery concurrently on multiple devices with a recurring timer is causing an issue with the detection of printer.

This only happen on newer revision of the TM model, it's working perfectly fine for my old printers that I bought previously (TM-T88, TM-U220B, TM-T81).

I am wondering if there is any other ways to check for printer status in real-time?

0

There are 0 best solutions below