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.
After finishing printing I am keeping connection to printer, so next time I need to print something I don't connect to it again.
However connection is alive for only 90 seconds. After 90 seconds of inactivity connection printer is dropped and Epos2Printer
notifies delegate that power is off:
func onPtrStatusChange(_ printerObj: Epos2Printer, eventType: Int32) {
let eventStatus = Epos2StatusEvent(rawValue: eventType)
// Event status is EPOS2_EVENT_POWER_OFF here
}
I don't see any parameters for Epos2Printer
to keep connection alive.
Does anybody know how force printer to keep connection beyond 90 seconds?
Turned out Epos2Printer
uses TCP connection to communicate with printer and TCP itself drops connection in 90 seconds.
To avoid this I am sending signal to empty printer port for cash drawer after 85 seconds of inactivity:
printer.addPulse(EPOS2_DRAWER_5PIN.rawValue, time: EPOS2_PULSE_100.rawValue)
printer.beginTransaction()
printer.sendData(Int(EPOS2_PARAM_DEFAULT))
printer.endTransaction()
printer.clearCommandBuffer()