gpt4 book ai didi

iOS 仅使用 Epos2Printer 打印一次

转载 作者:技术小花猫 更新时间:2023-10-29 11:01:34 24 4
gpt4 key购买 nike

我使用以下代码在 Epson TM-T20 上使用 Epson ePOS SDK for iOS 打印内容 SDK .问题是该应用程序只打印一次。该应用程序必须重新启动才能再次打印。代码有什么问题?

    printer = Epos2Printer(printerSeries: 2, lang: 1)
printer?.setReceiveEventDelegate(self)
printer?.addText("text")

printer!.connect("TCP:192.168.1.185", timeout:Int(EPOS2_PARAM_DEFAULT))
printer!.beginTransaction()

printer?.sendData(Int(EPOS2_PARAM_DEFAULT))
printer?.endTransaction()
// printer?.disconnect()
printer?.clearCommandBuffer()
printer?.setReceiveEventDelegate(nil)

尽管在文档中使用过,但使用 printer?.disconnect() 会使应用程序卡住,所以我不得不将其注释掉。

如果您想查看 API 文档,里面有一个 PDF the SDK's download .

更新:根据答案更新代码(应用仍然卡住):

func printReceipt() {
var printer: Epos2Printer?
printer = Epos2Printer(printerSeries: 2, lang: 1)
if printer == nil {
print(“Printer not found!! 11")
}
printer?.setReceiveEventDelegate(self)

printer?.addTextFont(2)
printer?.addTextSize(1, height: 1)
printer?.addText(“My Text")
printer?.addFeedUnit(10)
printer?.addCut(0)

var result: Int = Int(EPOS2_SUCCESS.rawValue)

result = Int(printer!.connect("TCP:192.168.1.185", timeout:Int(EPOS2_PARAM_DEFAULT)));
result = Int(printer!.beginTransaction())

printer?.sendData(Int(EPOS2_PARAM_DEFAULT))

DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {
printer?.clearCommandBuffer()
printer?.setReceiveEventDelegate(nil)
printer?.endTransaction()
printer?.disconnect()
printer = nil;
}
}

最佳答案

我有同样的问题,您必须实现 Epos2PtrReceiveDelegate 并使用 onPtrReceive 遵守其协议(protocol),并包括在该委托(delegate)内断开打印机。

示例如下:

希望对您有所帮助!

public func onPtrReceive(_ printerObj: Epos2Printer!, code: Int32, status: Epos2PrinterStatusInfo!, printJobId: String!) {

printerObj.endTransaction()
printerObj.disconnect()
printerObj.clearCommandBuffer()
printerObj.setReceiveEventDelegate(nil)

}

干杯!

关于iOS 仅使用 Epos2Printer 打印一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42154061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com