Search code examples
swiftepson

Epos2Printer SDK: Swift


I have been trying for a while now and cannot seem to connect to my Epson TM-T88V printer from my app built with Swift. I have tried what I learned here https://github.com/Shoptree/epsonPrintSDK/issues/3 and was able to make a connection, but it is a dated SDK and I need more printers to be compatible. I have also looked at the Epson pdf guide written in Obj-C and the Java version.

I have tried many variations of the following. (Note: I have no problem bridging the headers and getting access to the library.

var printer = Epos2Printer(printerSeries: 0, lang: 1)

    printer.connect("TCP:192.168.X.X", timeout: 10000)
    printer.beginTransaction()
    printer.addText("Hello World")
    printer.addCut(1)

Thanks in advance!


Solution

  • I am not sure if you still have this problem, but according to your code I can suggest couple of fixes:

    1. Put correct printer series.
    2. Add couple of feed lines. Some Epson printers don't print if there is no enough lines to print (6-8 lines enough).
    3. Call beginTransaction after adding text and cut.
    4. Call sendData and endTransaction at the end.

    Here is updated code:

    var printer = Epos2Printer(printerSeries: EPOS2_TM_T88.rawValue, lang: EPOS2_MODEL_ANK.rawValue)
    printer.connect("TCP:192.168.X.X", timeout: 10000)
    printer.addFeedLine(5)
    printer.addText("Hello World")
    printer.addFeedLine(5)
    printer.addCut(EPOS2_CUT_FEED.rawValue)
    
    printer.beginTransaction()
    printer.sendData(Int(EPOS2_PARAM_DEFAULT))
    printer.endTransaction()